Ed tanous | 7d95f5f | 2018-03-23 00:19:20 -0700 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.5 FATAL_ERROR) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 2 | |
Ed Tanous | cfbe25d | 2017-05-23 16:34:35 -0700 | [diff] [blame] | 3 | cmake_policy(SET CMP0054 NEW) |
| 4 | |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 5 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) |
| 6 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 7 | option(BUILD_STATIC_LIBS "Built static libraries" ON) |
Ed Tanous | 465b12a | 2018-02-06 16:30:36 -0800 | [diff] [blame] | 8 | option(YOCTO_DEPENDENCIES "Use YOCTO depedencies system" OFF) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 9 | |
Ed tanous | 7d95f5f | 2018-03-23 00:19:20 -0700 | [diff] [blame] | 10 | project(bmc-webserver CXX) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 11 | |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 12 | include(CTest) |
Ed Tanous | f3d847c | 2017-06-12 16:01:42 -0700 | [diff] [blame] | 13 | |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 14 | set(CMAKE_CXX_STANDARD 14) |
| 15 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 16 | |
| 17 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 18 | |
Ed Tanous | c963aa4 | 2017-10-27 16:00:19 -0700 | [diff] [blame] | 19 | SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall") |
Ed Tanous | 0d485ef | 2017-05-23 09:23:53 -0700 | [diff] [blame] | 20 | |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 21 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") |
| 22 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti") |
| 23 | |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 24 | # general |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 25 | option(BMCWEB_BUILD_UT "Enable Unit test" ON) |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 26 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 27 | # security flags |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 28 | SET( |
| 29 | SECURITY_FLAGS |
| 30 | "\ |
| 31 | -fstack-protector-strong \ |
| 32 | -fPIE \ |
| 33 | -fPIC \ |
| 34 | -D_FORTIFY_SOURCE=2 \ |
| 35 | -Wformat \ |
| 36 | -Wformat-security" |
| 37 | ) |
| 38 | SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SECURITY_FLAGS}") |
| 39 | SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO |
| 40 | "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SECURITY_FLAGS}") |
| 41 | SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}") |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 42 | |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 43 | # Enable link time optimization This is a temporary workaround because |
| 44 | # INTERPROCEDURAL_OPTIMIZATION isn't available until cmake 3.9. gcc-ar and gcc- |
| 45 | # ranlib are wrappers around ar and ranlib which add the lto plugin to the |
| 46 | # command line. |
| 47 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
Ed Tanous | ac09331 | 2018-03-16 13:53:05 -0700 | [diff] [blame] | 48 | if(NOT CMAKE_BUILD_TYPE MATCHES Debug) |
Borawski.Lukasz | 109799e | 2018-01-30 15:04:42 +0100 | [diff] [blame] | 49 | STRING(REGEX REPLACE "ar$" "gcc-ar" CMAKE_AR ${CMAKE_AR}) |
| 50 | STRING(REGEX REPLACE "ranlib$" "gcc-ranlib" CMAKE_RANLIB ${CMAKE_RANLIB}) |
| 51 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -fno-fat-lto-objects") |
| 52 | |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 53 | # Reduce the binary size by removing unnecessary dynamic symbol table |
| 54 | # entries |
| 55 | SET( |
| 56 | CMAKE_CXX_FLAGS |
| 57 | "${CMAKE_CXX_FLAGS} \ |
| 58 | -fvisibility=hidden \ |
| 59 | -fvisibility-inlines-hidden \ |
| 60 | -Wl,--exclude-libs,ALL" |
| 61 | ) |
Ed Tanous | ac09331 | 2018-03-16 13:53:05 -0700 | [diff] [blame] | 62 | endif(NOT CMAKE_BUILD_TYPE MATCHES Debug) |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 63 | endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
Borawski.Lukasz | 109799e | 2018-01-30 15:04:42 +0100 | [diff] [blame] | 64 | |
Ed tanous | 7d95f5f | 2018-03-23 00:19:20 -0700 | [diff] [blame] | 65 | if(NOT ${YOCTO_DEPENDENCIES}) # Download and unpack googletest at configure time |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 66 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.in |
| 67 | 3rdparty/CMakeLists.txt) |
Ed tanous | 7d95f5f | 2018-03-23 00:19:20 -0700 | [diff] [blame] | 68 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . |
| 69 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty) |
| 70 | execute_process(COMMAND ${CMAKE_COMMAND} --build . |
| 71 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty) |
| 72 | |
| 73 | set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/prefix ${CMAKE_PREFIX_PATH}) |
| 74 | endif() |
| 75 | |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 76 | # add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING) |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 77 | add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY) |
| 78 | add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 79 | add_definitions(-DBOOST_ALL_NO_LIB) |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 80 | add_definitions(-DBOOST_NO_RTTI) |
| 81 | add_definitions(-DBOOST_NO_TYPEID) |
Ed tanous | 7d95f5f | 2018-03-23 00:19:20 -0700 | [diff] [blame] | 82 | |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 83 | find_package(Boost 1.66 REQUIRED) |
| 84 | include_directories(${BOOST_SRC_DIR}) |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 85 | |
| 86 | # sdbusplus |
| 87 | if(NOT ${YOCTO_DEPENDENCIES}) |
| 88 | include_directories(${CMAKE_BINARY_DIR}/sdbusplus-src |
| 89 | ${CMAKE_BINARY_DIR}/prefix/include) |
| 90 | set(WANT_TRANSACTION 0) |
| 91 | |
| 92 | configure_file(${CMAKE_BINARY_DIR}/sdbusplus-src/sdbusplus/server.hpp.in |
| 93 | ${CMAKE_BINARY_DIR}/prefix/include/sdbusplus/server.hpp @ONLY) |
| 94 | configure_file(${CMAKE_BINARY_DIR}/sdbusplus-src/sdbusplus/bus.hpp.in |
| 95 | ${CMAKE_BINARY_DIR}/prefix/include/sdbusplus/bus.hpp @ONLY) |
| 96 | endif() |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 97 | |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 98 | # Openssl |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 99 | find_package(OpenSSL REQUIRED) |
Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 100 | include_directories(${OPENSSL_INCLUDE_DIR}) |
Ed Tanous | 0d485ef | 2017-05-23 09:23:53 -0700 | [diff] [blame] | 101 | message("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}") |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 102 | |
Ed Tanous | ac09331 | 2018-03-16 13:53:05 -0700 | [diff] [blame] | 103 | # Crow |
| 104 | message("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") |
| 105 | if(CMAKE_BUILD_TYPE MATCHES Debug) |
| 106 | message("Logging disabled") |
| 107 | add_definitions(-DCROW_ENABLE_LOGGING) |
| 108 | add_definitions(-DCROW_ENABLE_DEBUG) |
| 109 | endif(CMAKE_BUILD_TYPE MATCHES Debug) |
| 110 | |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 111 | #add_definitions(-DCROW_ENABLE_LOGGING) |
| 112 | #add_definitions(-DCROW_ENABLE_DEBUG) |
| 113 | |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 114 | add_definitions(-DCROW_ENABLE_SSL) |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 115 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/crow/include) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 116 | |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 117 | # Zlib |
Ed Tanous | 7d3dba4 | 2017-04-05 13:04:39 -0700 | [diff] [blame] | 118 | find_package(ZLIB REQUIRED) |
Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 119 | include_directories(${ZLIB_INCLUDE_DIRS}) |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 120 | |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 121 | # PAM |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 122 | option(WEBSERVER_ENABLE_PAM "enable pam authentication" ON) |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 123 | if("${WEBSERVER_ENABLE_PAM}") |
| 124 | find_package(PAM REQUIRED) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 125 | else() |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 126 | add_definitions("-DWEBSERVER_DISABLE_PAM") |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 127 | endif() |
| 128 | |
Ed tanous | 7d95f5f | 2018-03-23 00:19:20 -0700 | [diff] [blame] | 129 | add_definitions("-Wno-attributes") |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 130 | |
Ed tanous | 7d95f5f | 2018-03-23 00:19:20 -0700 | [diff] [blame] | 131 | # tinyxml2 |
| 132 | find_package(tinyxml2 REQUIRED) |
| 133 | |
| 134 | set(WEBSERVER_MAIN src/webserver_main.cpp) |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 135 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 136 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) |
Borawski.Lukasz | 86e1b66 | 2018-01-19 14:22:14 +0100 | [diff] [blame] | 137 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/redfish-core/include) |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 138 | |
Kowalski, Kamil | f4c4dcf | 2018-01-29 14:55:35 +0100 | [diff] [blame] | 139 | set(SRC_FILES |
| 140 | redfish-core/src/error_messages.cpp |
Kowalski, Kamil | 77dd881 | 2018-04-03 10:15:14 +0200 | [diff] [blame] | 141 | redfish-core/src/utils/json_utils.cpp |
Kowalski, Kamil | f4c4dcf | 2018-01-29 14:55:35 +0100 | [diff] [blame] | 142 | ${GENERATED_SRC_FILES} |
| 143 | ) |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 144 | |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 145 | file(COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) |
| 146 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 147 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/generated) |
| 148 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 149 | # Unit Tests |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 150 | if(${BMCWEB_BUILD_UT}) |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 151 | set(UT_FILES |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 152 | src/crow_test.cpp |
| 153 | src/gtest_main.cpp |
| 154 | src/token_authorization_middleware_test.cpp |
| 155 | src/security_headers_middleware_test.cpp |
| 156 | src/webassets_test.cpp |
| 157 | src/crow_getroutes_test.cpp |
| 158 | src/ast_jpeg_decoder_test.cpp |
| 159 | src/kvm_websocket_test.cpp |
| 160 | src/msan_test.cpp |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 161 | src/ast_video_puller_test.cpp |
| 162 | ${CMAKE_BINARY_DIR}/generated/blns.hpp) # big list of naughty strings |
| 163 | add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp |
| 164 | COMMAND |
| 165 | xxd -i |
| 166 | ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns |
| 167 | ${CMAKE_BINARY_DIR}/generated/blns.hpp) |
Ed Tanous | 4c3cbc6 | 2017-05-16 09:17:42 -0700 | [diff] [blame] | 168 | |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 169 | set_source_files_properties(${CMAKE_BINARY_DIR}/generated/blns.hpp |
| 170 | PROPERTIES |
| 171 | GENERATED |
| 172 | TRUE) # googletest |
| 173 | enable_testing() |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 174 | |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 175 | add_executable(webtest ${SRC_FILES} ${UT_FILES}) |
Ed tanous | 7d95f5f | 2018-03-23 00:19:20 -0700 | [diff] [blame] | 176 | |
| 177 | find_package(GTest REQUIRED) |
| 178 | find_package(GMock REQUIRED) |
| 179 | target_link_libraries(webtest ${GTEST_LIBRARIES}) |
| 180 | target_link_libraries(webtest ${GMOCK_LIBRARIES}) |
| 181 | |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 182 | target_link_libraries(webtest pthread) |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 183 | target_link_libraries(webtest ${OPENSSL_LIBRARIES}) |
| 184 | target_link_libraries(webtest ${ZLIB_LIBRARIES}) |
| 185 | target_link_libraries(webtest pam) |
| 186 | target_link_libraries(webtest tinyxml2) |
| 187 | target_link_libraries(webtest -lstdc++fs) |
| 188 | add_test(webtest webtest "--gtest_output=xml:webtest.xml") |
Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 189 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 190 | endif(${BMCWEB_BUILD_UT}) |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 191 | |
Ed Tanous | 710adfc | 2017-10-24 17:04:52 -0700 | [diff] [blame] | 192 | install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www) |
| 193 | |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 194 | # bmcweb |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 195 | add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES}) |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 196 | target_link_libraries(bmcweb pthread) |
Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 197 | target_link_libraries(bmcweb ${OPENSSL_LIBRARIES}) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 198 | target_link_libraries(bmcweb ${ZLIB_LIBRARIES}) |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 199 | target_link_libraries(bmcweb pam) |
Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 200 | target_link_libraries(bmcweb -lsystemd) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 201 | target_link_libraries(bmcweb -lstdc++fs) |
Borawski.Lukasz | 109799e | 2018-01-30 15:04:42 +0100 | [diff] [blame] | 202 | target_link_libraries(bmcweb tinyxml2) |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 203 | target_link_libraries(bmcweb sdbusplus) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 204 | install(TARGETS bmcweb DESTINATION bin) |
Ed Tanous | cc5a37f | 2017-05-11 10:27:23 -0700 | [diff] [blame] | 205 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 206 | add_executable(getvideo src/getvideo_main.cpp) |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 207 | target_link_libraries(getvideo pthread) |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 208 | |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 209 | # Visual Studio Code helper this needs to be at the end to make sure all |
| 210 | # includes are handled correctly |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 211 | include(CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs) |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 212 | get_property(C_INCLUDE_DIRS |
| 213 | DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 214 | PROPERTY INCLUDE_DIRECTORIES) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 215 | |
Ed Tanous | 580f372 | 2018-03-13 16:59:02 -0700 | [diff] [blame] | 216 | execute_process(COMMAND |
| 217 | python3 |
| 218 | ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py |
| 219 | ${C_INCLUDE_DIRS} |
| 220 | ${CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS} |
| 221 | ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS}) |