blob: db863bbd975a6eb569fa67d5426fcee5720fad1c [file] [log] [blame]
Ed Tanous0fdddb12017-02-28 11:06:34 -08001cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR)
2
Ed Tanouscfbe25d2017-05-23 16:34:35 -07003cmake_policy(SET CMP0054 NEW)
4
Ed Tanous0fdddb12017-02-28 11:06:34 -08005set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
Ed Tanous911ac312017-08-15 09:37:42 -07006message(CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH})
Ed Tanous0fdddb12017-02-28 11:06:34 -08007
Ed Tanous911ac312017-08-15 09:37:42 -07008option(BUILD_STATIC_LIBS "Built static libraries" ON)
Ed Tanous0fdddb12017-02-28 11:06:34 -08009
Ed Tanous2d02dcd2017-05-15 12:25:30 -070010option(HUNTER_ENABLED "Enable hunter package pulling" OFF)
Ed Tanous911ac312017-08-15 09:37:42 -070011
Ed Tanous1ccd57c2017-03-21 13:15:58 -070012include("cmake/HunterGate.cmake")
Ed Tanous0fdddb12017-02-28 11:06:34 -080013HunterGate(
Ed Tanouscfbe25d2017-05-23 16:34:35 -070014 URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz"
15 SHA1 "baf9c8cc4f65306f0e442b5419967b4c4c04589a"
Ed Tanous0fdddb12017-02-28 11:06:34 -080016)
17
Ed Tanous0fdddb12017-02-28 11:06:34 -080018project(bmc-webserver CXX C)
19
Ed Tanousf3d847c2017-06-12 16:01:42 -070020include( CTest )
21
Ed Tanous0fdddb12017-02-28 11:06:34 -080022set(CMAKE_CXX_STANDARD 14)
23set(CMAKE_CXX_STANDARD_REQUIRED ON)
24
25set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
26
Ed Tanousc963aa42017-10-27 16:00:19 -070027SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall")
Ed Tanous0d485ef2017-05-23 09:23:53 -070028
Ed Tanous3dac7492017-08-02 13:46:20 -070029SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
30SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
31
Ed Tanous0fdddb12017-02-28 11:06:34 -080032# general
Ed Tanous911ac312017-08-15 09:37:42 -070033option(BMCWEB_BUILD_UT "Enable Unit test" ON)
Ed Tanous8041f312017-04-03 09:47:01 -070034
Ed Tanous1ccd57c2017-03-21 13:15:58 -070035# security flags
Ed Tanous911ac312017-08-15 09:37:42 -070036SET(SECURITY_FLAGS " -fstack-protector-strong -fPIE -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security")
37SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SECURITY_FLAGS}" )
38SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SECURITY_FLAGS}" )
Ed Tanous7f935f82018-01-25 11:40:21 -080039SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}" )
Ed Tanous3dac7492017-08-02 13:46:20 -070040
Borawski.Lukasz109799e2018-01-30 15:04:42 +010041if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
42 # Enable link time optimization
43 # This is a temporary workaround because INTERPROCEDURAL_OPTIMIZATION isn't available until cmake 3.9.
44 # gcc-ar and gcc-ranlib are wrappers around ar and ranlib which add the lto plugin to the command line.
45 STRING(REGEX REPLACE "ar$" "gcc-ar" CMAKE_AR ${CMAKE_AR})
46 STRING(REGEX REPLACE "ranlib$" "gcc-ranlib" CMAKE_RANLIB ${CMAKE_RANLIB})
47 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -fno-fat-lto-objects")
48
49 # Reduce the binary size by removing unnecessary dynamic symbol table entries
50 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -Wl,--exclude-libs,ALL")
51endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
52
Ed Tanous1ccd57c2017-03-21 13:15:58 -070053#add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanous01250f22017-04-18 17:49:51 -070054add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
55add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080056add_definitions(-DBOOST_ALL_NO_LIB)
Ed Tanous3dac7492017-08-02 13:46:20 -070057add_definitions(-DBOOST_NO_RTTI)
58add_definitions(-DBOOST_NO_TYPEID)
Ed Tanous0d485ef2017-05-23 09:23:53 -070059#set(Boost_USE_STATIC_LIBS ON)
Ed Tanouseb1b8622017-04-25 14:11:46 -070060hunter_add_package(Boost)
Ed Tanous911ac312017-08-15 09:37:42 -070061find_package(Boost)
Ed Tanouse2fc45a2017-04-26 09:19:10 -070062include_directories(${Boost_INCLUDE_DIRS})
Ed Tanous0fdddb12017-02-28 11:06:34 -080063
64#Openssl
Ed Tanous2d02dcd2017-05-15 12:25:30 -070065hunter_add_package(OpenSSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -080066find_package(OpenSSL REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -070067include_directories(${OPENSSL_INCLUDE_DIR})
Ed Tanous0d485ef2017-05-23 09:23:53 -070068message("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
Ed Tanous0fdddb12017-02-28 11:06:34 -080069
Ed Tanous8041f312017-04-03 09:47:01 -070070# Crow
Ed Tanous4c3cbc62017-05-16 09:17:42 -070071#add_definitions(-DCROW_DISABLE_LOGGING)
Ed Tanous8041f312017-04-03 09:47:01 -070072add_definitions(-DCROW_ENABLE_SSL)
73include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -080074
Ed Tanous9b65f1f2017-03-07 15:17:13 -080075#Zlib
Ed Tanous7d3dba42017-04-05 13:04:39 -070076hunter_add_package(ZLIB)
77find_package(ZLIB REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -070078include_directories(${ZLIB_INCLUDE_DIRS})
Ed Tanousf9273472017-02-28 16:05:13 -080079
Ed Tanous911ac312017-08-15 09:37:42 -070080#tinyxml2
81add_subdirectory(tinyxml2)
Ed Tanous4758d5b2017-06-06 15:28:13 -070082
83# PAM
Ed Tanous911ac312017-08-15 09:37:42 -070084option(WEBSERVER_ENABLE_PAM "enable pam authentication" ON)
85if ("${WEBSERVER_ENABLE_PAM}")
86 find_package(PAM REQUIRED)
87else()
88 add_definitions("-DWEBSERVER_DISABLE_PAM")
89endif()
90
Ed Tanous4758d5b2017-06-06 15:28:13 -070091
Ed Tanousc9b55212017-06-12 13:25:51 -070092# Boost-dbus
Ed Tanous911ac312017-08-15 09:37:42 -070093set(BOOST_DBUS_BUILD_UT ${BMCWEB_BUILD_UT})
94add_subdirectory(boost-dbus)
Ed Tanousc9b55212017-06-12 13:25:51 -070095
Ed Tanousf9273472017-02-28 16:05:13 -080096set(WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanous5f34a9c2017-02-28 12:35:13 -080097
Ed Tanous12a002d2017-05-15 11:59:16 -070098# the webassets file has a non-ideal beahvior, where it loads binary data into a std::string
99# due to the way crow is constructed. This causes GCC warnings. Filter them out.
Ed Tanousb4d29f42017-03-24 16:39:25 -0700100if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Ed Tanous12a002d2017-05-15 11:59:16 -0700101 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700102 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-narrowing)
Ed Tanous12a002d2017-05-15 11:59:16 -0700103 endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700104endif()
105
Ed Tanous911ac312017-08-15 09:37:42 -0700106include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Borawski.Lukasz86e1b662018-01-19 14:22:14 +0100107include_directories(${CMAKE_CURRENT_SOURCE_DIR}/redfish-core/include)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700108
Ed Tanous904063f2017-03-02 16:48:24 -0800109set(SRC_FILES
Ed Tanous904063f2017-03-02 16:48:24 -0800110 ${GENERATED_SRC_FILES}
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800111)
112
Ed Tanous93f987d2017-04-17 17:52:36 -0700113file(COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
114
Ed Tanous911ac312017-08-15 09:37:42 -0700115file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/generated)
116
Ed Tanous38bdb982017-03-03 14:19:33 -0800117# Unit Tests
Ed Tanous911ac312017-08-15 09:37:42 -0700118if(${BMCWEB_BUILD_UT})
119 set(UT_FILES
120 src/crow_test.cpp
121 src/gtest_main.cpp
Ed Tanous911ac312017-08-15 09:37:42 -0700122 src/token_authorization_middleware_test.cpp
123 src/security_headers_middleware_test.cpp
124 src/webassets_test.cpp
125 src/crow_getroutes_test.cpp
126 src/ast_jpeg_decoder_test.cpp
127 src/kvm_websocket_test.cpp
128 src/msan_test.cpp
129 src/ci_map_tests.cpp
130 src/ast_video_puller_test.cpp
131 ${CMAKE_BINARY_DIR}/generated/blns.hpp
132 )
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800133 # big list of naughty strings
134 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700135 COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns ${CMAKE_BINARY_DIR}/generated/blns.hpp)
Ed Tanous911ac312017-08-15 09:37:42 -0700136
137 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/blns.hpp
138 PROPERTIES GENERATED TRUE)
Ed Tanous38bdb982017-03-03 14:19:33 -0800139 # googletest
140 enable_testing()
Ed Tanous4c3cbc62017-05-16 09:17:42 -0700141
Ed Tanous911ac312017-08-15 09:37:42 -0700142 hunter_add_package(GTest)
143 find_package(GTest REQUIRED)
Ed Tanous01250f22017-04-18 17:49:51 -0700144 #find_package(GMock CONFIG REQUIRED)
Ed Tanous38bdb982017-03-03 14:19:33 -0800145
Ed Tanous911ac312017-08-15 09:37:42 -0700146 add_executable(webtest ${SRC_FILES} ${UT_FILES})
Ed Tanousc9b55212017-06-12 13:25:51 -0700147 target_link_libraries(webtest gmock gtest)
148 target_link_libraries(webtest pthread)
Ed Tanous911ac312017-08-15 09:37:42 -0700149 target_link_libraries(webtest boost-dbus)
Ed Tanousc9b55212017-06-12 13:25:51 -0700150 target_link_libraries(webtest ${OPENSSL_LIBRARIES})
151 target_link_libraries(webtest ${ZLIB_LIBRARIES})
152 target_link_libraries(webtest pam)
Borawski.Lukasz109799e2018-01-30 15:04:42 +0100153 target_link_libraries(webtest tinyxml2)
Ed Tanous911ac312017-08-15 09:37:42 -0700154 target_link_libraries(webtest -lstdc++fs)
Ed Tanousc9b55212017-06-12 13:25:51 -0700155 add_test(webtest webtest "--gtest_output=xml:webtest.xml")
156
Ed Tanous911ac312017-08-15 09:37:42 -0700157endif(${BMCWEB_BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800158
Ed Tanous710adfc2017-10-24 17:04:52 -0700159install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www)
160
Ed Tanousf9273472017-02-28 16:05:13 -0800161# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800162add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous911ac312017-08-15 09:37:42 -0700163target_link_libraries(bmcweb boost-dbus)
Ed Tanous01250f22017-04-18 17:49:51 -0700164target_link_libraries(bmcweb pthread)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700165target_link_libraries(bmcweb ${OPENSSL_LIBRARIES})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800166target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanous4758d5b2017-06-06 15:28:13 -0700167target_link_libraries(bmcweb pam)
Vernon Mauery168792a2018-01-26 13:42:54 -0800168target_link_libraries(bmcweb -lsystemd)
Ed Tanous911ac312017-08-15 09:37:42 -0700169target_link_libraries(bmcweb -lstdc++fs)
Borawski.Lukasz109799e2018-01-30 15:04:42 +0100170target_link_libraries(bmcweb tinyxml2)
Ed Tanous911ac312017-08-15 09:37:42 -0700171install(TARGETS bmcweb DESTINATION bin)
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700172
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700173add_executable(getvideo src/getvideo_main.cpp)
Ed Tanous01250f22017-04-18 17:49:51 -0700174target_link_libraries(getvideo pthread)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700175
Ed Tanous38bdb982017-03-03 14:19:33 -0800176# Visual Studio Code helper
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800177# this needs to be at the end to make sure all includes are handled correctly
Ed Tanous911ac312017-08-15 09:37:42 -0700178include(CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800179get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
Ed Tanous911ac312017-08-15 09:37:42 -0700180
181execute_process(
182 COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py
183 ${C_INCLUDE_DIRS}
184 ${CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS}
185 ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS}
186)