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 | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 27 | SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Werror -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}" ) |
| 39 | SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}" ) |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 40 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 41 | #add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING) |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 42 | add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY) |
| 43 | add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 44 | add_definitions(-DBOOST_ALL_NO_LIB) |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 45 | add_definitions(-DBOOST_NO_RTTI) |
| 46 | add_definitions(-DBOOST_NO_TYPEID) |
Ed Tanous | 0d485ef | 2017-05-23 09:23:53 -0700 | [diff] [blame] | 47 | #set(Boost_USE_STATIC_LIBS ON) |
Ed Tanous | eb1b862 | 2017-04-25 14:11:46 -0700 | [diff] [blame] | 48 | hunter_add_package(Boost) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 49 | find_package(Boost) |
Ed Tanous | e2fc45a | 2017-04-26 09:19:10 -0700 | [diff] [blame] | 50 | include_directories(${Boost_INCLUDE_DIRS}) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 51 | |
| 52 | #Openssl |
Ed Tanous | 2d02dcd | 2017-05-15 12:25:30 -0700 | [diff] [blame] | 53 | hunter_add_package(OpenSSL) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 54 | find_package(OpenSSL REQUIRED) |
Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 55 | include_directories(${OPENSSL_INCLUDE_DIR}) |
Ed Tanous | 0d485ef | 2017-05-23 09:23:53 -0700 | [diff] [blame] | 56 | message("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}") |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 57 | |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 58 | # Crow |
Ed Tanous | 4c3cbc6 | 2017-05-16 09:17:42 -0700 | [diff] [blame] | 59 | #add_definitions(-DCROW_DISABLE_LOGGING) |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 60 | add_definitions(-DCROW_ENABLE_SSL) |
| 61 | include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 62 | |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 63 | #Zlib |
Ed Tanous | 7d3dba4 | 2017-04-05 13:04:39 -0700 | [diff] [blame] | 64 | hunter_add_package(ZLIB) |
| 65 | find_package(ZLIB REQUIRED) |
Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 66 | include_directories(${ZLIB_INCLUDE_DIRS}) |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 67 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 68 | #tinyxml2 |
| 69 | add_subdirectory(tinyxml2) |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 70 | |
| 71 | # PAM |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 72 | option(WEBSERVER_ENABLE_PAM "enable pam authentication" ON) |
| 73 | if ("${WEBSERVER_ENABLE_PAM}") |
| 74 | find_package(PAM REQUIRED) |
| 75 | else() |
| 76 | add_definitions("-DWEBSERVER_DISABLE_PAM") |
| 77 | endif() |
| 78 | |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 79 | |
Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 80 | # Boost-dbus |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 81 | set(BOOST_DBUS_BUILD_UT ${BMCWEB_BUILD_UT}) |
| 82 | add_subdirectory(boost-dbus) |
Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 83 | |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 84 | set(WEBSERVER_MAIN src/webserver_main.cpp) |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 85 | |
Ed Tanous | 12a002d | 2017-05-15 11:59:16 -0700 | [diff] [blame] | 86 | # the webassets file has a non-ideal beahvior, where it loads binary data into a std::string |
| 87 | # 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] | 88 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
Ed Tanous | 12a002d | 2017-05-15 11:59:16 -0700 | [diff] [blame] | 89 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9) |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 90 | 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] | 91 | endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9) |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 92 | endif() |
| 93 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 94 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 95 | |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 96 | set(SRC_FILES |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 97 | src/base64.cpp |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 98 | ${GENERATED_SRC_FILES} |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 99 | ) |
| 100 | |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 101 | file(COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) |
| 102 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 103 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/generated) |
| 104 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 105 | # Unit Tests |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 106 | if(${BMCWEB_BUILD_UT}) |
| 107 | set(UT_FILES |
| 108 | src/crow_test.cpp |
| 109 | src/gtest_main.cpp |
| 110 | src/base64_test.cpp |
| 111 | src/token_authorization_middleware_test.cpp |
| 112 | src/security_headers_middleware_test.cpp |
| 113 | src/webassets_test.cpp |
| 114 | src/crow_getroutes_test.cpp |
| 115 | src/ast_jpeg_decoder_test.cpp |
| 116 | src/kvm_websocket_test.cpp |
| 117 | src/msan_test.cpp |
| 118 | src/ci_map_tests.cpp |
| 119 | src/ast_video_puller_test.cpp |
| 120 | ${CMAKE_BINARY_DIR}/generated/blns.hpp |
| 121 | ) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 122 | # big list of naughty strings |
| 123 | add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp |
Ed Tanous | cc5a37f | 2017-05-11 10:27:23 -0700 | [diff] [blame] | 124 | 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] | 125 | |
| 126 | set_source_files_properties(${CMAKE_BINARY_DIR}/generated/blns.hpp |
| 127 | PROPERTIES GENERATED TRUE) |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 128 | # googletest |
| 129 | enable_testing() |
Ed Tanous | 4c3cbc6 | 2017-05-16 09:17:42 -0700 | [diff] [blame] | 130 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 131 | hunter_add_package(GTest) |
| 132 | find_package(GTest REQUIRED) |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 133 | #find_package(GMock CONFIG REQUIRED) |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 134 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 135 | add_executable(webtest ${SRC_FILES} ${UT_FILES}) |
Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 136 | target_link_libraries(webtest gmock gtest) |
| 137 | target_link_libraries(webtest pthread) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 138 | target_link_libraries(webtest boost-dbus) |
Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 139 | target_link_libraries(webtest ${OPENSSL_LIBRARIES}) |
| 140 | target_link_libraries(webtest ${ZLIB_LIBRARIES}) |
| 141 | target_link_libraries(webtest pam) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 142 | add_dependencies(webtest tinyxml2_static) |
| 143 | target_link_libraries(webtest tinyxml2_static) |
| 144 | target_link_libraries(webtest -lstdc++fs) |
Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 145 | add_test(webtest webtest "--gtest_output=xml:webtest.xml") |
| 146 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 147 | endif(${BMCWEB_BUILD_UT}) |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 148 | |
Ed Tanous | 710adfc | 2017-10-24 17:04:52 -0700 | [diff] [blame^] | 149 | install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www) |
| 150 | |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 151 | # bmcweb |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 152 | add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES}) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 153 | target_link_libraries(bmcweb boost-dbus) |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 154 | target_link_libraries(bmcweb pthread) |
Ed Tanous | f0226cd | 2017-05-16 12:35:38 -0700 | [diff] [blame] | 155 | target_link_libraries(bmcweb ${OPENSSL_LIBRARIES}) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 156 | target_link_libraries(bmcweb ${ZLIB_LIBRARIES}) |
Ed Tanous | 4758d5b | 2017-06-06 15:28:13 -0700 | [diff] [blame] | 157 | target_link_libraries(bmcweb pam) |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 158 | target_link_libraries(bmcweb -lstdc++fs) |
| 159 | add_dependencies(bmcweb tinyxml2_static) |
| 160 | target_link_libraries(bmcweb tinyxml2_static) |
| 161 | install(TARGETS bmcweb DESTINATION bin) |
Ed Tanous | cc5a37f | 2017-05-11 10:27:23 -0700 | [diff] [blame] | 162 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 163 | add_executable(getvideo src/getvideo_main.cpp) |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 164 | target_link_libraries(getvideo pthread) |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 165 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 166 | # Visual Studio Code helper |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 167 | # 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] | 168 | include(CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs) |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 169 | 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] | 170 | |
| 171 | execute_process( |
| 172 | COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py |
| 173 | ${C_INCLUDE_DIRS} |
| 174 | ${CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS} |
| 175 | ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS} |
| 176 | ) |