blob: 3d6037c7ff32d633c585d37da6ab29e2d5582c92 [file] [log] [blame]
Ed Tanous580f3722018-03-13 16:59:02 -07001cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
Ed Tanous0fdddb12017-02-28 11:06:34 -08002
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 Tanous465b12a2018-02-06 16:30:36 -08009option(YOCTO_DEPENDENCIES "Use YOCTO depedencies system" OFF)
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 Tanous580f3722018-03-13 16:59:02 -070013HunterGate(URL
14 "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz"
15 SHA1
16 "baf9c8cc4f65306f0e442b5419967b4c4c04589a")
Ed Tanous0fdddb12017-02-28 11:06:34 -080017
Ed Tanous0fdddb12017-02-28 11:06:34 -080018project(bmc-webserver CXX C)
19
Ed Tanous580f3722018-03-13 16:59:02 -070020include(CTest)
Ed Tanousf3d847c2017-06-12 16:01:42 -070021
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 Tanous580f3722018-03-13 16:59:02 -070036SET(
37 SECURITY_FLAGS
38 "\
39 -fstack-protector-strong \
40 -fPIE \
41 -fPIC \
42 -D_FORTIFY_SOURCE=2 \
43 -Wformat \
44 -Wformat-security"
45 )
46SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SECURITY_FLAGS}")
47SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO
48 "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SECURITY_FLAGS}")
49SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}")
Ed Tanous3dac7492017-08-02 13:46:20 -070050
Ed Tanous580f3722018-03-13 16:59:02 -070051# Enable link time optimization This is a temporary workaround because
52# INTERPROCEDURAL_OPTIMIZATION isn't available until cmake 3.9. gcc-ar and gcc-
53# ranlib are wrappers around ar and ranlib which add the lto plugin to the
54# command line.
55if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Ed Tanousac093312018-03-16 13:53:05 -070056 if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
Borawski.Lukasz109799e2018-01-30 15:04:42 +010057 STRING(REGEX REPLACE "ar$" "gcc-ar" CMAKE_AR ${CMAKE_AR})
58 STRING(REGEX REPLACE "ranlib$" "gcc-ranlib" CMAKE_RANLIB ${CMAKE_RANLIB})
59 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -fno-fat-lto-objects")
60
Ed Tanous580f3722018-03-13 16:59:02 -070061 # Reduce the binary size by removing unnecessary dynamic symbol table
62 # entries
63 SET(
64 CMAKE_CXX_FLAGS
65 "${CMAKE_CXX_FLAGS} \
66 -fvisibility=hidden \
67 -fvisibility-inlines-hidden \
68 -Wl,--exclude-libs,ALL"
69 )
Ed Tanousac093312018-03-16 13:53:05 -070070 endif(NOT CMAKE_BUILD_TYPE MATCHES Debug)
Ed Tanous580f3722018-03-13 16:59:02 -070071endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Borawski.Lukasz109799e2018-01-30 15:04:42 +010072
Ed Tanous580f3722018-03-13 16:59:02 -070073# add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanous01250f22017-04-18 17:49:51 -070074add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
75add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080076add_definitions(-DBOOST_ALL_NO_LIB)
Ed Tanous3dac7492017-08-02 13:46:20 -070077add_definitions(-DBOOST_NO_RTTI)
78add_definitions(-DBOOST_NO_TYPEID)
Ed Tanous580f3722018-03-13 16:59:02 -070079# set(Boost_USE_STATIC_LIBS ON)
Ed Tanouseb1b8622017-04-25 14:11:46 -070080hunter_add_package(Boost)
Ed Tanous911ac312017-08-15 09:37:42 -070081find_package(Boost)
Ed Tanous580f3722018-03-13 16:59:02 -070082include_directories(${Boost_INCLUDE_DIRS})
Ed Tanous0fdddb12017-02-28 11:06:34 -080083
Ed Tanous580f3722018-03-13 16:59:02 -070084# Openssl
Ed Tanous2d02dcd2017-05-15 12:25:30 -070085hunter_add_package(OpenSSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -080086find_package(OpenSSL REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -070087include_directories(${OPENSSL_INCLUDE_DIR})
Ed Tanous0d485ef2017-05-23 09:23:53 -070088message("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
Ed Tanous0fdddb12017-02-28 11:06:34 -080089
Ed Tanousac093312018-03-16 13:53:05 -070090# Crow
91message("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
92if(CMAKE_BUILD_TYPE MATCHES Debug)
93 message("Logging disabled")
94 add_definitions(-DCROW_ENABLE_LOGGING)
95 add_definitions(-DCROW_ENABLE_DEBUG)
96endif(CMAKE_BUILD_TYPE MATCHES Debug)
97
Ed Tanous8041f312017-04-03 09:47:01 -070098add_definitions(-DCROW_ENABLE_SSL)
Ed Tanous580f3722018-03-13 16:59:02 -070099include_directories(${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800100
Ed Tanous580f3722018-03-13 16:59:02 -0700101# Zlib
Ed Tanous7d3dba42017-04-05 13:04:39 -0700102hunter_add_package(ZLIB)
103find_package(ZLIB REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700104include_directories(${ZLIB_INCLUDE_DIRS})
Ed Tanousf9273472017-02-28 16:05:13 -0800105
Ed Tanous580f3722018-03-13 16:59:02 -0700106# tinyxml2
Ed Tanous465b12a2018-02-06 16:30:36 -0800107if(NOT ${YOCTO_DEPENDENCIES})
Ed Tanous580f3722018-03-13 16:59:02 -0700108 add_subdirectory(tinyxml2)
Ed Tanous465b12a2018-02-06 16:30:36 -0800109else()
Ed Tanous580f3722018-03-13 16:59:02 -0700110 find_package(tinyxml2 REQUIRED)
Ed Tanous465b12a2018-02-06 16:30:36 -0800111endif()
Ed Tanous4758d5b2017-06-06 15:28:13 -0700112# PAM
Ed Tanous911ac312017-08-15 09:37:42 -0700113option(WEBSERVER_ENABLE_PAM "enable pam authentication" ON)
Ed Tanous580f3722018-03-13 16:59:02 -0700114if("${WEBSERVER_ENABLE_PAM}")
115 find_package(PAM REQUIRED)
Ed Tanous911ac312017-08-15 09:37:42 -0700116else()
Ed Tanous580f3722018-03-13 16:59:02 -0700117 add_definitions("-DWEBSERVER_DISABLE_PAM")
Ed Tanous911ac312017-08-15 09:37:42 -0700118endif()
119
Ed Tanousc9b55212017-06-12 13:25:51 -0700120# Boost-dbus
Ed Tanous911ac312017-08-15 09:37:42 -0700121set(BOOST_DBUS_BUILD_UT ${BMCWEB_BUILD_UT})
Ed Tanous465b12a2018-02-06 16:30:36 -0800122if(NOT ${YOCTO_DEPENDENCIES})
Ed Tanous580f3722018-03-13 16:59:02 -0700123 add_subdirectory(boost-dbus)
Ed Tanous465b12a2018-02-06 16:30:36 -0800124else()
Ed Tanous580f3722018-03-13 16:59:02 -0700125 find_package(boost-dbus REQUIRED)
Ed Tanous465b12a2018-02-06 16:30:36 -0800126endif()
Ed Tanousf9273472017-02-28 16:05:13 -0800127set(WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800128
Ed Tanous580f3722018-03-13 16:59:02 -0700129# the webassets file has a non-ideal beahvior, where it loads binary data into a
130# std::string due to the way crow is constructed. This causes GCC warnings.
131# Filter them out.
Ed Tanousb4d29f42017-03-24 16:39:25 -0700132if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Ed Tanous580f3722018-03-13 16:59:02 -0700133 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
134 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp
135 PROPERTIES
136 COMPILE_FLAGS
137 -Wno-narrowing)
138 endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700139endif()
140
Ed Tanous911ac312017-08-15 09:37:42 -0700141include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Borawski.Lukasz86e1b662018-01-19 14:22:14 +0100142include_directories(${CMAKE_CURRENT_SOURCE_DIR}/redfish-core/include)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700143
Ed Tanous580f3722018-03-13 16:59:02 -0700144set(SRC_FILES ${GENERATED_SRC_FILES})
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800145
Ed Tanous93f987d2017-04-17 17:52:36 -0700146file(COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
147
Ed Tanous911ac312017-08-15 09:37:42 -0700148file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/generated)
149
Ed Tanous38bdb982017-03-03 14:19:33 -0800150# Unit Tests
Ed Tanous911ac312017-08-15 09:37:42 -0700151if(${BMCWEB_BUILD_UT})
Ed Tanous580f3722018-03-13 16:59:02 -0700152 set(UT_FILES
153 redfish-core/ut/privileges_test.cpp
154 src/crow_test.cpp
155 src/gtest_main.cpp
156 src/token_authorization_middleware_test.cpp
157 src/security_headers_middleware_test.cpp
158 src/webassets_test.cpp
159 src/crow_getroutes_test.cpp
160 src/ast_jpeg_decoder_test.cpp
161 src/kvm_websocket_test.cpp
162 src/msan_test.cpp
163 src/ci_map_tests.cpp
164 src/ast_video_puller_test.cpp
165 ${CMAKE_BINARY_DIR}/generated/blns.hpp) # big list of naughty strings
166 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
167 COMMAND
168 xxd -i
169 ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns
170 ${CMAKE_BINARY_DIR}/generated/blns.hpp)
Ed Tanous4c3cbc62017-05-16 09:17:42 -0700171
Ed Tanous580f3722018-03-13 16:59:02 -0700172 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/blns.hpp
173 PROPERTIES
174 GENERATED
175 TRUE) # googletest
176 enable_testing()
Ed Tanous38bdb982017-03-03 14:19:33 -0800177
Ed Tanous580f3722018-03-13 16:59:02 -0700178 hunter_add_package(GTest)
179 find_package(GTest REQUIRED) # find_package(GMock CONFIG REQUIRED)
180
181 add_executable(webtest ${SRC_FILES} ${UT_FILES})
182 target_link_libraries(webtest gmock gtest)
183 target_link_libraries(webtest pthread)
184 target_link_libraries(webtest boost-dbus)
185 target_link_libraries(webtest ${OPENSSL_LIBRARIES})
186 target_link_libraries(webtest ${ZLIB_LIBRARIES})
187 target_link_libraries(webtest pam)
188 target_link_libraries(webtest tinyxml2)
189 target_link_libraries(webtest -lstdc++fs)
190 add_test(webtest webtest "--gtest_output=xml:webtest.xml")
Ed Tanousc9b55212017-06-12 13:25:51 -0700191
Ed Tanous911ac312017-08-15 09:37:42 -0700192endif(${BMCWEB_BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800193
Ed Tanous710adfc2017-10-24 17:04:52 -0700194install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www)
195
Ed Tanousf9273472017-02-28 16:05:13 -0800196# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800197add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous911ac312017-08-15 09:37:42 -0700198target_link_libraries(bmcweb boost-dbus)
Ed Tanous01250f22017-04-18 17:49:51 -0700199target_link_libraries(bmcweb pthread)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700200target_link_libraries(bmcweb ${OPENSSL_LIBRARIES})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800201target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanous4758d5b2017-06-06 15:28:13 -0700202target_link_libraries(bmcweb pam)
Vernon Mauery168792a2018-01-26 13:42:54 -0800203target_link_libraries(bmcweb -lsystemd)
Ed Tanous911ac312017-08-15 09:37:42 -0700204target_link_libraries(bmcweb -lstdc++fs)
Borawski.Lukasz109799e2018-01-30 15:04:42 +0100205target_link_libraries(bmcweb tinyxml2)
Ed Tanous911ac312017-08-15 09:37:42 -0700206install(TARGETS bmcweb DESTINATION bin)
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700207
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700208add_executable(getvideo src/getvideo_main.cpp)
Ed Tanous01250f22017-04-18 17:49:51 -0700209target_link_libraries(getvideo pthread)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700210
Ed Tanous580f3722018-03-13 16:59:02 -0700211# Visual Studio Code helper this needs to be at the end to make sure all
212# includes are handled correctly
Ed Tanous911ac312017-08-15 09:37:42 -0700213include(CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs)
Ed Tanous580f3722018-03-13 16:59:02 -0700214get_property(C_INCLUDE_DIRS
215 DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
216 PROPERTY INCLUDE_DIRECTORIES)
Ed Tanous911ac312017-08-15 09:37:42 -0700217
Ed Tanous580f3722018-03-13 16:59:02 -0700218execute_process(COMMAND
219 python3
220 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py
221 ${C_INCLUDE_DIRS}
222 ${CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS}
223 ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS})