blob: b58413ee5f62f9a77d0b105ca638d93b73ac25bc [file] [log] [blame]
Ed Tanous1e439872018-05-18 11:48:52 -07001cmake_minimum_required (VERSION 3.5 FATAL_ERROR)
Ed Tanous0fdddb12017-02-28 11:06:34 -08002
Ed Tanous1e439872018-05-18 11:48:52 -07003cmake_policy (SET CMP0054 NEW)
Ed Tanouscfbe25d2017-05-23 16:34:35 -07004
Ed Tanous1e439872018-05-18 11:48:52 -07005set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
Ed Tanous0fdddb12017-02-28 11:06:34 -08006
Ed Tanous1e439872018-05-18 11:48:52 -07007option (BUILD_STATIC_LIBS "Built static libraries" ON)
8option (YOCTO_DEPENDENCIES "Use YOCTO depedencies system" OFF)
Ed Tanous911ac312017-08-15 09:37:42 -07009
Ed Tanous1e439872018-05-18 11:48:52 -070010option (BMCWEB_ENABLE_KVM "Enable KVM websocket interfaces" ON)
11option (BMCWEB_ENABLE_DBUS_REST "Enable rest dbus interfaces" ON)
12option (BMCWEB_ENABLE_REDFISH "Enable redfish interfaces" ON)
13option (BMCWEB_ENABLE_PHOSPHOR_WEBUI
14 "Enable webui interfaces; Requires
15 DBUS_REST interfaces" ON)
Ed Tanous0fdddb12017-02-28 11:06:34 -080016
Ed Tanous1e439872018-05-18 11:48:52 -070017# 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
21option (
22 BMCWEB_INSECURE_DISABLE_CSRF_PREVENTION
23 "Disable CSRF prevention checks.
24 Should be set to OFF for production systems."
25 OFF
26)
Ed Tanousf3d847c2017-06-12 16:01:42 -070027
Ed Tanous1e439872018-05-18 11:48:52 -070028option (BMCWEB_INSECURE_DISABLE_SSL
29 "Disable SSL ports. Should be set to OFF for
30 production systems."
31 OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080032
Ed Tanous1e439872018-05-18 11:48:52 -070033option (
34 BMCWEB_INSECURE_DISABLE_AUTHENTICATION
35 "Disable authentication on all
36 ports. Should be set to OFF for production systems"
37 OFF
38)
Ed Tanous0fdddb12017-02-28 11:06:34 -080039
Ed Tanous1e439872018-05-18 11:48:52 -070040option (BMCWEB_INSECURE_DISABLE_XSS_PREVENTION "Disable XSS preventions" OFF)
Ed Tanous0d485ef2017-05-23 09:23:53 -070041
Ed Tanous1e439872018-05-18 11:48:52 -070042project (bmc-webserver CXX)
43
44include (CTest)
45
46set (CMAKE_CXX_STANDARD 14)
47set (CMAKE_CXX_STANDARD_REQUIRED ON)
48
49set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
50
51set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall")
52
53set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
54set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
Ed Tanous3dac7492017-08-02 13:46:20 -070055
Ed Tanous0fdddb12017-02-28 11:06:34 -080056# general
Ed Tanous1e439872018-05-18 11:48:52 -070057option (BMCWEB_BUILD_UT "Enable Unit test" ON)
Ed Tanous8041f312017-04-03 09:47:01 -070058
Ed Tanous1ccd57c2017-03-21 13:15:58 -070059# security flags
Ed Tanous1e439872018-05-18 11:48:52 -070060set (
61 SECURITY_FLAGS
62 "\
Ed Tanous580f3722018-03-13 16:59:02 -070063 -fstack-protector-strong \
64 -fPIE \
65 -fPIC \
66 -D_FORTIFY_SOURCE=2 \
67 -Wformat \
68 -Wformat-security"
Ed Tanous1e439872018-05-18 11:48:52 -070069)
70set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SECURITY_FLAGS}")
71set (CMAKE_CXX_FLAGS_RELWITHDEBINFO
72 "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SECURITY_FLAGS}")
73set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}")
Ed Tanous3dac7492017-08-02 13:46:20 -070074
Ed Tanous580f3722018-03-13 16:59:02 -070075# 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 Tanous1e439872018-05-18 11:48:52 -070079if ("${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.Lukasz109799e2018-01-30 15:04:42 +010085
Ed Tanous1e439872018-05-18 11:48:52 -070086 # Reduce the binary size by removing unnecessary dynamic symbol table
87 # entries
88 set (
89 CMAKE_CXX_FLAGS
90 "${CMAKE_CXX_FLAGS} \
Ed Tanous580f3722018-03-13 16:59:02 -070091 -fvisibility=hidden \
92 -fvisibility-inlines-hidden \
93 -Wl,--exclude-libs,ALL"
Ed Tanous1e439872018-05-18 11:48:52 -070094 )
95 endif (NOT CMAKE_BUILD_TYPE MATCHES Debug)
96endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Borawski.Lukasz109799e2018-01-30 15:04:42 +010097
Ed Tanous1e439872018-05-18 11:48:52 -070098if (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 tanous7d95f5f2018-03-23 00:19:20 -0700105
Ed Tanous1e439872018-05-18 11:48:52 -0700106 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/prefix ${CMAKE_PREFIX_PATH})
107endif ()
Ed tanous7d95f5f2018-03-23 00:19:20 -0700108
Ed Tanous580f3722018-03-13 16:59:02 -0700109# add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanous1e439872018-05-18 11:48:52 -0700110add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
111add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
112add_definitions (-DBOOST_ALL_NO_LIB)
113add_definitions (-DBOOST_NO_RTTI)
114add_definitions (-DBOOST_NO_TYPEID)
Ed tanous7d95f5f2018-03-23 00:19:20 -0700115
Ed Tanous1e439872018-05-18 11:48:52 -0700116find_package (Boost 1.66 REQUIRED)
117include_directories (${BOOST_SRC_DIR})
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700118
119# sdbusplus
Ed Tanous1e439872018-05-18 11:48:52 -0700120if (NOT ${YOCTO_DEPENDENCIES})
121 include_directories (${CMAKE_BINARY_DIR}/sdbusplus-src
122 ${CMAKE_BINARY_DIR}/prefix/include)
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700123
Ed Tanous1e439872018-05-18 11:48:52 -0700124 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)
131endif ()
Ed Tanous0fdddb12017-02-28 11:06:34 -0800132
Ed Tanous580f3722018-03-13 16:59:02 -0700133# Openssl
Ed Tanous1e439872018-05-18 11:48:52 -0700134find_package (OpenSSL REQUIRED)
135include_directories (${OPENSSL_INCLUDE_DIR})
136message ("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
Ed Tanous0fdddb12017-02-28 11:06:34 -0800137
Ed Tanousac093312018-03-16 13:53:05 -0700138# Crow
Ed Tanous1e439872018-05-18 11:48:52 -0700139message ("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
140if (CMAKE_BUILD_TYPE MATCHES Debug)
141 message ("Logging disabled")
142 add_definitions (-DCROW_ENABLE_LOGGING)
143 add_definitions (-DCROW_ENABLE_DEBUG)
144endif (CMAKE_BUILD_TYPE MATCHES Debug)
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700145
Ed Tanous8041f312017-04-03 09:47:01 -0700146add_definitions(-DCROW_ENABLE_SSL)
Ed Tanous580f3722018-03-13 16:59:02 -0700147include_directories(${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800148
Ed Tanous580f3722018-03-13 16:59:02 -0700149# Zlib
Ed Tanous1e439872018-05-18 11:48:52 -0700150find_package (ZLIB REQUIRED)
151include_directories (${ZLIB_INCLUDE_DIRS})
Ed Tanousf9273472017-02-28 16:05:13 -0800152
Ed Tanous4758d5b2017-06-06 15:28:13 -0700153# PAM
Ed Tanous1e439872018-05-18 11:48:52 -0700154option (WEBSERVER_ENABLE_PAM "enable pam authentication" ON)
155if ("${WEBSERVER_ENABLE_PAM}")
156 find_package (PAM REQUIRED)
157else ()
158 add_definitions ("-DWEBSERVER_DISABLE_PAM")
159endif ()
Ed Tanous911ac312017-08-15 09:37:42 -0700160
Ed Tanous1e439872018-05-18 11:48:52 -0700161add_definitions ("-Wno-attributes")
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800162
Ed tanous7d95f5f2018-03-23 00:19:20 -0700163# tinyxml2
Ed Tanous1e439872018-05-18 11:48:52 -0700164find_package (tinyxml2 REQUIRED)
Ed tanous7d95f5f2018-03-23 00:19:20 -0700165
Ed Tanous1e439872018-05-18 11:48:52 -0700166set (WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700167
Ed Tanous1e439872018-05-18 11:48:52 -0700168include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
169include_directories (${CMAKE_CURRENT_SOURCE_DIR}/redfish-core/include)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700170
Ed Tanous1e439872018-05-18 11:48:52 -0700171file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include/bmcweb)
172configure_file (settings.hpp.in ${CMAKE_BINARY_DIR}/include/bmcweb/settings.hpp)
173include_directories (${CMAKE_BINARY_DIR}/include)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800174
Ed Tanous1e439872018-05-18 11:48:52 -0700175set (SRC_FILES redfish-core/src/error_messages.cpp
176 redfish-core/src/utils/json_utils.cpp ${GENERATED_SRC_FILES})
Ed Tanous93f987d2017-04-17 17:52:36 -0700177
Ed Tanous1e439872018-05-18 11:48:52 -0700178file (COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
Ed Tanous911ac312017-08-15 09:37:42 -0700179
Ed Tanous38bdb982017-03-03 14:19:33 -0800180# Unit Tests
Ed Tanous1e439872018-05-18 11:48:52 -0700181<<<<<<< HEAD
Ed Tanous911ac312017-08-15 09:37:42 -0700182if(${BMCWEB_BUILD_UT})
Ed Tanous580f3722018-03-13 16:59:02 -0700183 set(UT_FILES
Ed Tanous580f3722018-03-13 16:59:02 -0700184 src/crow_test.cpp
185 src/gtest_main.cpp
186 src/token_authorization_middleware_test.cpp
187 src/security_headers_middleware_test.cpp
188 src/webassets_test.cpp
189 src/crow_getroutes_test.cpp
190 src/ast_jpeg_decoder_test.cpp
191 src/kvm_websocket_test.cpp
192 src/msan_test.cpp
Ed Tanous580f3722018-03-13 16:59:02 -0700193 src/ast_video_puller_test.cpp
194 ${CMAKE_BINARY_DIR}/generated/blns.hpp) # big list of naughty strings
195 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
196 COMMAND
197 xxd -i
198 ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns
199 ${CMAKE_BINARY_DIR}/generated/blns.hpp)
Ed Tanous4c3cbc62017-05-16 09:17:42 -0700200
Ed Tanous580f3722018-03-13 16:59:02 -0700201 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/blns.hpp
202 PROPERTIES
203 GENERATED
204 TRUE) # googletest
205 enable_testing()
Ed Tanous38bdb982017-03-03 14:19:33 -0800206
Ed Tanous580f3722018-03-13 16:59:02 -0700207 add_executable(webtest ${SRC_FILES} ${UT_FILES})
Ed tanous7d95f5f2018-03-23 00:19:20 -0700208
209 find_package(GTest REQUIRED)
210 find_package(GMock REQUIRED)
211 target_link_libraries(webtest ${GTEST_LIBRARIES})
212 target_link_libraries(webtest ${GMOCK_LIBRARIES})
213
Ed Tanous580f3722018-03-13 16:59:02 -0700214 target_link_libraries(webtest pthread)
Ed Tanous580f3722018-03-13 16:59:02 -0700215 target_link_libraries(webtest ${OPENSSL_LIBRARIES})
216 target_link_libraries(webtest ${ZLIB_LIBRARIES})
217 target_link_libraries(webtest pam)
218 target_link_libraries(webtest tinyxml2)
219 target_link_libraries(webtest -lstdc++fs)
220 add_test(webtest webtest "--gtest_output=xml:webtest.xml")
Ed Tanousc9b55212017-06-12 13:25:51 -0700221
Ed Tanous911ac312017-08-15 09:37:42 -0700222endif(${BMCWEB_BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800223
Ed Tanous710adfc2017-10-24 17:04:52 -0700224install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www)
225
Ed Tanousf9273472017-02-28 16:05:13 -0800226# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800227add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous01250f22017-04-18 17:49:51 -0700228target_link_libraries(bmcweb pthread)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700229target_link_libraries(bmcweb ${OPENSSL_LIBRARIES})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800230target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanous4758d5b2017-06-06 15:28:13 -0700231target_link_libraries(bmcweb pam)
Vernon Mauery168792a2018-01-26 13:42:54 -0800232target_link_libraries(bmcweb -lsystemd)
Ed Tanous911ac312017-08-15 09:37:42 -0700233target_link_libraries(bmcweb -lstdc++fs)
Borawski.Lukasz109799e2018-01-30 15:04:42 +0100234target_link_libraries(bmcweb tinyxml2)
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700235target_link_libraries(bmcweb sdbusplus)
Ed Tanous911ac312017-08-15 09:37:42 -0700236install(TARGETS bmcweb DESTINATION bin)
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700237
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700238add_executable(getvideo src/getvideo_main.cpp)
Ed Tanous01250f22017-04-18 17:49:51 -0700239target_link_libraries(getvideo pthread)
Ed Tanous1e439872018-05-18 11:48:52 -0700240=======
241if (${BMCWEB_BUILD_UT})
242 set (UT_FILES src/crow_test.cpp src/gtest_main.cpp
243 src/token_authorization_middleware_test.cpp
244 src/security_headers_middleware_test.cpp src/webassets_test.cpp
245 src/crow_getroutes_test.cpp src/ast_jpeg_decoder_test.cpp
246 src/kvm_websocket_test.cpp src/msan_test.cpp
247 src/ast_video_puller_test.cpp
248 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp) # big list of naughty
249 # strings
250 add_custom_command (OUTPUT ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
251 COMMAND
252 xxd -i
253 ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns
254 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp)
255
256 set_source_files_properties (${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
257 PROPERTIES GENERATED TRUE)
258
259 enable_testing ()
260
261 add_executable (webtest ${SRC_FILES} ${UT_FILES})
262
263 find_package (GTest REQUIRED)
264 find_package (GMock REQUIRED)
265 target_link_libraries (webtest ${GTEST_LIBRARIES})
266 target_link_libraries (webtest ${GMOCK_LIBRARIES})
267
268 target_link_libraries (webtest pthread)
269 target_link_libraries (webtest ${OPENSSL_LIBRARIES})
270 target_link_libraries (webtest ${ZLIB_LIBRARIES})
271 target_link_libraries (webtest pam)
272 target_link_libraries (webtest tinyxml2)
273 target_link_libraries (webtest -lstdc++fs)
274 add_test (webtest webtest "--gtest_output=xml:webtest.xml")
275
276endif (${BMCWEB_BUILD_UT})
277
278install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www)
279
280# bmcweb
281add_executable (bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
282target_link_libraries (bmcweb pthread)
283target_link_libraries (bmcweb ${OPENSSL_LIBRARIES})
284target_link_libraries (bmcweb ${ZLIB_LIBRARIES})
285target_link_libraries (bmcweb pam)
286target_link_libraries (bmcweb -lsystemd)
287target_link_libraries (bmcweb -lstdc++fs)
288target_link_libraries (bmcweb tinyxml2)
289install (TARGETS bmcweb DESTINATION bin)
290
291add_executable (getvideo src/getvideo_main.cpp)
292target_link_libraries (getvideo pthread)
293>>>>>>> a7b5f2d... Implement feature selection in bmcweb
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700294
Ed Tanous580f3722018-03-13 16:59:02 -0700295# Visual Studio Code helper this needs to be at the end to make sure all
296# includes are handled correctly
Ed Tanous1e439872018-05-18 11:48:52 -0700297include (CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs)
298get_property (C_INCLUDE_DIRS
299 DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
300 PROPERTY INCLUDE_DIRECTORIES)
Ed Tanous911ac312017-08-15 09:37:42 -0700301
Ed Tanous1e439872018-05-18 11:48:52 -0700302execute_process (
303 COMMAND python3
304 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py
305 ${C_INCLUDE_DIRS} ${CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS}
306 ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS}
307)