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