Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR) |
| 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}) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 6 | message(CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 7 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 8 | option(BUILD_STATIC_LIBS "Built static libraries" ON) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 9 | |
Ed Tanous | 2d02dcd | 2017-05-15 12:25:30 -0700 | [diff] [blame] | 10 | option(HUNTER_ENABLED "Enable hunter package pulling" OFF) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 11 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 12 | include("cmake/HunterGate.cmake") |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 13 | HunterGate( |
Ed Tanous | cfbe25d | 2017-05-23 16:34:35 -0700 | [diff] [blame] | 14 | URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz" |
| 15 | SHA1 "baf9c8cc4f65306f0e442b5419967b4c4c04589a" |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 16 | ) |
| 17 | |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 18 | project(bmc-webserver CXX C) |
| 19 | |
Ed Tanous | f3d847c | 2017-06-12 16:01:42 -0700 | [diff] [blame] | 20 | include( CTest ) |
| 21 | |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 22 | set(CMAKE_CXX_STANDARD 14) |
| 23 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 24 | |
| 25 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 26 | |
Ed Tanous | c963aa4 | 2017-10-27 16:00:19 -0700 | [diff] [blame] | 27 | SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall") |
Ed Tanous | 0d485ef | 2017-05-23 09:23:53 -0700 | [diff] [blame] | 28 | |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 29 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") |
| 30 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti") |
| 31 | |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 32 | # general |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 33 | option(BMCWEB_BUILD_UT "Enable Unit test" ON) |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 34 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 35 | # security flags |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 36 | SET(SECURITY_FLAGS " -fstack-protector-strong -fPIE -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security") |
| 37 | SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SECURITY_FLAGS}" ) |
| 38 | SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SECURITY_FLAGS}" ) |
Ed Tanous | 7f935f8 | 2018-01-25 11:40:21 -0800 | [diff] [blame] | 39 | SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}" ) |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 40 | |
Borawski.Lukasz | 109799e | 2018-01-30 15:04:42 +0100 | [diff] [blame^] | 41 | if ("${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") |
| 51 | endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 52 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 53 | #add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING) |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 54 | add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY) |
| 55 | add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 56 | add_definitions(-DBOOST_ALL_NO_LIB) |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 57 | add_definitions(-DBOOST_NO_RTTI) |
| 58 | add_definitions(-DBOOST_NO_TYPEID) |
Ed Tanous | 0d485ef | 2017-05-23 09:23:53 -0700 | [diff] [blame] | 59 | #set(Boost_USE_STATIC_LIBS ON) |
Ed Tanous | eb1b862 | 2017-04-25 14:11:46 -0700 | [diff] [blame] | 60 | hunter_add_package(Boost) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 61 | find_package(Boost) |
Ed Tanous | e2fc45a | 2017-04-26 09:19:10 -0700 | [diff] [blame] | 62 | include_directories(${Boost_INCLUDE_DIRS}) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 63 | |
| 64 | #Openssl |
Ed Tanous | 2d02dcd | 2017-05-15 12:25:30 -0700 | [diff] [blame] | 65 | hunter_add_package(OpenSSL) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 66 | find_package(OpenSSL REQUIRED) |
Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 67 | include_directories(${OPENSSL_INCLUDE_DIR}) |
Ed Tanous | 0d485ef | 2017-05-23 09:23:53 -0700 | [diff] [blame] | 68 | message("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}") |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 69 | |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 70 | # Crow |
Ed Tanous | 4c3cbc6 | 2017-05-16 09:17:42 -0700 | [diff] [blame] | 71 | #add_definitions(-DCROW_DISABLE_LOGGING) |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 72 | add_definitions(-DCROW_ENABLE_SSL) |
| 73 | include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 74 | |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 75 | #Zlib |
Ed Tanous | 7d3dba4 | 2017-04-05 13:04:39 -0700 | [diff] [blame] | 76 | hunter_add_package(ZLIB) |
| 77 | find_package(ZLIB REQUIRED) |
Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 78 | include_directories(${ZLIB_INCLUDE_DIRS}) |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 79 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 80 | #tinyxml2 |
| 81 | add_subdirectory(tinyxml2) |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 82 | |
| 83 | # PAM |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 84 | option(WEBSERVER_ENABLE_PAM "enable pam authentication" ON) |
| 85 | if ("${WEBSERVER_ENABLE_PAM}") |
| 86 | find_package(PAM REQUIRED) |
| 87 | else() |
| 88 | add_definitions("-DWEBSERVER_DISABLE_PAM") |
| 89 | endif() |
| 90 | |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 91 | |
Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 92 | # Boost-dbus |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 93 | set(BOOST_DBUS_BUILD_UT ${BMCWEB_BUILD_UT}) |
| 94 | add_subdirectory(boost-dbus) |
Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 95 | |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 96 | set(WEBSERVER_MAIN src/webserver_main.cpp) |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 97 | |
Ed Tanous | 12a002d | 2017-05-15 11:59:16 -0700 | [diff] [blame] | 98 | # 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 Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 100 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
Ed Tanous | 12a002d | 2017-05-15 11:59:16 -0700 | [diff] [blame] | 101 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9) |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 102 | set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-narrowing) |
Ed Tanous | 12a002d | 2017-05-15 11:59:16 -0700 | [diff] [blame] | 103 | endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9) |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 104 | endif() |
| 105 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 106 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) |
Borawski.Lukasz | 86e1b66 | 2018-01-19 14:22:14 +0100 | [diff] [blame] | 107 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/redfish-core/include) |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 108 | |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 109 | set(SRC_FILES |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 110 | ${GENERATED_SRC_FILES} |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 111 | ) |
| 112 | |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 113 | file(COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) |
| 114 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 115 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/generated) |
| 116 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 117 | # Unit Tests |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 118 | if(${BMCWEB_BUILD_UT}) |
| 119 | set(UT_FILES |
| 120 | src/crow_test.cpp |
| 121 | src/gtest_main.cpp |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 122 | 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 Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 133 | # big list of naughty strings |
| 134 | add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp |
Ed Tanous | cc5a37f | 2017-05-11 10:27:23 -0700 | [diff] [blame] | 135 | COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns ${CMAKE_BINARY_DIR}/generated/blns.hpp) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 136 | |
| 137 | set_source_files_properties(${CMAKE_BINARY_DIR}/generated/blns.hpp |
| 138 | PROPERTIES GENERATED TRUE) |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 139 | # googletest |
| 140 | enable_testing() |
Ed Tanous | 4c3cbc6 | 2017-05-16 09:17:42 -0700 | [diff] [blame] | 141 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 142 | hunter_add_package(GTest) |
| 143 | find_package(GTest REQUIRED) |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 144 | #find_package(GMock CONFIG REQUIRED) |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 145 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 146 | add_executable(webtest ${SRC_FILES} ${UT_FILES}) |
Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 147 | target_link_libraries(webtest gmock gtest) |
| 148 | target_link_libraries(webtest pthread) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 149 | target_link_libraries(webtest boost-dbus) |
Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 150 | target_link_libraries(webtest ${OPENSSL_LIBRARIES}) |
| 151 | target_link_libraries(webtest ${ZLIB_LIBRARIES}) |
| 152 | target_link_libraries(webtest pam) |
Borawski.Lukasz | 109799e | 2018-01-30 15:04:42 +0100 | [diff] [blame^] | 153 | target_link_libraries(webtest tinyxml2) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 154 | target_link_libraries(webtest -lstdc++fs) |
Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 155 | add_test(webtest webtest "--gtest_output=xml:webtest.xml") |
| 156 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 157 | endif(${BMCWEB_BUILD_UT}) |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 158 | |
Ed Tanous | 710adfc | 2017-10-24 17:04:52 -0700 | [diff] [blame] | 159 | install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www) |
| 160 | |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 161 | # bmcweb |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 162 | add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES}) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 163 | target_link_libraries(bmcweb boost-dbus) |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 164 | target_link_libraries(bmcweb pthread) |
Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 165 | target_link_libraries(bmcweb ${OPENSSL_LIBRARIES}) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 166 | target_link_libraries(bmcweb ${ZLIB_LIBRARIES}) |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 167 | target_link_libraries(bmcweb pam) |
Vernon Mauery | 168792a | 2018-01-26 13:42:54 -0800 | [diff] [blame] | 168 | target_link_libraries(bmcweb -lsystemd) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 169 | target_link_libraries(bmcweb -lstdc++fs) |
Borawski.Lukasz | 109799e | 2018-01-30 15:04:42 +0100 | [diff] [blame^] | 170 | target_link_libraries(bmcweb tinyxml2) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 171 | install(TARGETS bmcweb DESTINATION bin) |
Ed Tanous | cc5a37f | 2017-05-11 10:27:23 -0700 | [diff] [blame] | 172 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 173 | add_executable(getvideo src/getvideo_main.cpp) |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 174 | target_link_libraries(getvideo pthread) |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 175 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 176 | # Visual Studio Code helper |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 177 | # this needs to be at the end to make sure all includes are handled correctly |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 178 | include(CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs) |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 179 | get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 180 | |
| 181 | execute_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 | ) |