blob: 2bd8a71316186d61e93c033caea27b1d48ecbf67 [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)
Ed Tanous911ac312017-08-15 09:37:42 -07008
Joseph Reynolds7a777f52018-11-07 22:01:31 -06009option (YOCTO_DEPENDENCIES "Use YOCTO dependencies system" OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080010
Joseph Reynolds7a777f52018-11-07 22:01:31 -060011option (BMCWEB_ENABLE_KVM "Enable the KVM host video WebSocket. Path is
12 '/kvmws'. Video is from the BMC's '/dev/video' device." ON)
13option (BMCWEB_ENABLE_DBUS_REST "Enable Phosphor REST (D-Bus) APIs. Paths
14 directly map Phosphor D-Bus object paths, for example,
15 '/xyz/openbmc_project/logging/entry/enumerate'. See
16 https://github.com/openbmc/docs/blob/master/rest-api.md." ON)
17option (BMCWEB_ENABLE_REDFISH "Enable Redfish APIs. Paths are under
18 '/redfish/v1/'. See
19 https://github.com/openbmc/bmcweb/blob/master/DEVELOPING.md#redfish."
20 ON)
21option (BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET "Enable host serial console
22 WebSocket. Path is '/console0'. See
23 https://github.com/openbmc/docs/blob/master/console.md." ON)
24option (BMCWEB_ENABLE_STATIC_HOSTING "Enable serving files from the
25 '/usr/share/www' directory as paths under '/'." ON)
26option (BMCWEB_ENABLE_REDFISH_BMC_JOURNAL "Enable BMC journal access through
27 Redfish. Paths are under
28 '/redfish/v1/Managers/bmc/LogServices/Journal'." OFF)
29option (BMCWEB_ENABLE_REDFISH_RAW_PECI "Enable PECI transactions through
30 Redfish. Paths are under '/redfish/v1/Managers/bmc/LogServices/CpuLog/
31 Actions/Oem/CpuLog.SendRawPeci'." OFF)
32option (BMCWEB_ENABLE_REDFISH_CPU_LOG "Enable CPU log service transactions
33 through Redfish. Paths are under
34 '/redfish/v1/Managers/bmc/LogServices/CpuLog'." OFF)
Ed Tanous1da66f72018-07-27 16:13:37 -070035
Ed Tanousbdd1c832018-10-12 11:00:30 -070036# Insecure options. Every option that starts with a BMCWEB_INSECURE flag should
Ed Tanous1e439872018-05-18 11:48:52 -070037# not be enabled by default for any platform, unless the author fully
38# comprehends the implications of doing so. In general, enabling these options
39# will cause security problems of varying degrees
Ed Tanousf0d73c22018-07-26 14:24:20 -070040option (BMCWEB_INSECURE_DISABLE_CSRF_PREVENTION "Disable CSRF prevention checks.
41 Should be set to OFF for production systems." OFF)
Ed Tanousf3d847c2017-06-12 16:01:42 -070042
Ed Tanousf0d73c22018-07-26 14:24:20 -070043option (BMCWEB_INSECURE_DISABLE_SSL "Disable SSL ports. Should be set to OFF for
44 production systems." OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080045
Ed Tanousf0d73c22018-07-26 14:24:20 -070046option (BMCWEB_INSECURE_DISABLE_AUTHENTICATION "Disable authentication on all
47 ports. Should be set to OFF for production systems" OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080048
Ed Tanous1e439872018-05-18 11:48:52 -070049option (BMCWEB_INSECURE_DISABLE_XSS_PREVENTION "Disable XSS preventions" OFF)
Ed Tanous0d485ef2017-05-23 09:23:53 -070050
Ed Tanous1e439872018-05-18 11:48:52 -070051project (bmc-webserver CXX)
52
53include (CTest)
54
Ed Tanous62288742018-10-16 14:58:20 -070055set (CMAKE_CXX_STANDARD 17)
Ed Tanous1e439872018-05-18 11:48:52 -070056set (CMAKE_CXX_STANDARD_REQUIRED ON)
57
58set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
59
60set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall")
61
62set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
63set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
Ed Tanous3dac7492017-08-02 13:46:20 -070064
Ed Tanous0fdddb12017-02-28 11:06:34 -080065# general
Ed Tanous797d0c02018-08-07 10:22:35 -070066option (BMCWEB_BUILD_UT "Enable Unit test" OFF)
Ed Tanous8041f312017-04-03 09:47:01 -070067
Ed Tanous1ccd57c2017-03-21 13:15:58 -070068# security flags
Ed Tanousf0d73c22018-07-26 14:24:20 -070069set (SECURITY_FLAGS "\
Ed Tanous580f3722018-03-13 16:59:02 -070070 -fstack-protector-strong \
71 -fPIE \
72 -fPIC \
73 -D_FORTIFY_SOURCE=2 \
74 -Wformat \
Ed Tanousf0d73c22018-07-26 14:24:20 -070075 -Wformat-security")
Ed Tanous1e439872018-05-18 11:48:52 -070076set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SECURITY_FLAGS}")
Ed Tanousf0d73c22018-07-26 14:24:20 -070077set (
78 CMAKE_CXX_FLAGS_RELWITHDEBINFO
79 "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SECURITY_FLAGS}"
80)
Ed Tanous1e439872018-05-18 11:48:52 -070081set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}")
Ed Tanous3dac7492017-08-02 13:46:20 -070082
Ed Tanous580f3722018-03-13 16:59:02 -070083# Enable link time optimization This is a temporary workaround because
84# INTERPROCEDURAL_OPTIMIZATION isn't available until cmake 3.9. gcc-ar and gcc-
85# ranlib are wrappers around ar and ranlib which add the lto plugin to the
86# command line.
Ed Tanous1e439872018-05-18 11:48:52 -070087if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
88 if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
89 string (REGEX REPLACE "ar$" "gcc-ar" CMAKE_AR ${CMAKE_AR})
Ed Tanousf0d73c22018-07-26 14:24:20 -070090 string (
91 REGEX
92 REPLACE "ranlib$" "gcc-ranlib" CMAKE_RANLIB ${CMAKE_RANLIB}
93 )
Ed Tanous1e439872018-05-18 11:48:52 -070094 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -fno-fat-lto-objects")
Borawski.Lukasz109799e2018-01-30 15:04:42 +010095
Ed Tanous1e439872018-05-18 11:48:52 -070096 # Reduce the binary size by removing unnecessary dynamic symbol table
97 # entries
Ed Tanousf0d73c22018-07-26 14:24:20 -070098 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
Ed Tanous580f3722018-03-13 16:59:02 -070099 -fvisibility=hidden \
100 -fvisibility-inlines-hidden \
Ed Tanousf0d73c22018-07-26 14:24:20 -0700101 -Wl,--exclude-libs,ALL")
Ed Tanous1e439872018-05-18 11:48:52 -0700102 endif (NOT CMAKE_BUILD_TYPE MATCHES Debug)
103endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Borawski.Lukasz109799e2018-01-30 15:04:42 +0100104
Ed Tanous1e439872018-05-18 11:48:52 -0700105if (NOT ${YOCTO_DEPENDENCIES}) # Download and unpack googletest at configure
106 # time
107 configure_file (CMakeLists.txt.in 3rdparty/CMakeLists.txt)
Ed Tanousf0d73c22018-07-26 14:24:20 -0700108 execute_process (
109 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
110 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty
111 )
112 execute_process (
113 COMMAND ${CMAKE_COMMAND} --build .
114 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty
115 )
Ed tanous7d95f5f2018-03-23 00:19:20 -0700116
Ed Tanous1e439872018-05-18 11:48:52 -0700117 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/prefix ${CMAKE_PREFIX_PATH})
118endif ()
Ed tanous7d95f5f2018-03-23 00:19:20 -0700119
Ed Tanous580f3722018-03-13 16:59:02 -0700120# add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanousd3a38062018-07-27 12:06:29 -0700121add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
Ed Tanous1e439872018-05-18 11:48:52 -0700122add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
123add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
124add_definitions (-DBOOST_ALL_NO_LIB)
125add_definitions (-DBOOST_NO_RTTI)
126add_definitions (-DBOOST_NO_TYPEID)
Ed Tanousc85eb8b2018-10-16 14:59:20 -0700127add_definitions (-DBOOST_COROUTINES_NO_DEPRECATION_WARNING)
Ed tanous7d95f5f2018-03-23 00:19:20 -0700128
Ed Tanous1e439872018-05-18 11:48:52 -0700129find_package (Boost 1.66 REQUIRED)
130include_directories (${BOOST_SRC_DIR})
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700131
132# sdbusplus
Ed Tanous1e439872018-05-18 11:48:52 -0700133if (NOT ${YOCTO_DEPENDENCIES})
James Feista975e9f2018-08-08 14:03:49 -0700134 include_directories (${CMAKE_BINARY_DIR}/sdbusplus-src)
135 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
Ed Tanous1e439872018-05-18 11:48:52 -0700136endif ()
Ed Tanous0fdddb12017-02-28 11:06:34 -0800137
Ed Tanous580f3722018-03-13 16:59:02 -0700138# Openssl
Ed Tanous1e439872018-05-18 11:48:52 -0700139find_package (OpenSSL REQUIRED)
140include_directories (${OPENSSL_INCLUDE_DIR})
141message ("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
Ed Tanous0fdddb12017-02-28 11:06:34 -0800142
Ed Tanous55c7b7a2018-05-22 15:27:24 -0700143# bmcweb
Ed Tanous1e439872018-05-18 11:48:52 -0700144message ("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
145if (CMAKE_BUILD_TYPE MATCHES Debug)
146 message ("Logging disabled")
Ed Tanous55c7b7a2018-05-22 15:27:24 -0700147 add_definitions (-DBMCWEB_ENABLE_LOGGING)
148 add_definitions (-DBMCWEB_ENABLE_DEBUG)
Ed Tanous1e439872018-05-18 11:48:52 -0700149endif (CMAKE_BUILD_TYPE MATCHES Debug)
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700150
Andrew Geissler1f2fbf22018-07-17 07:57:30 -0700151if (NOT "${BMCWEB_INSECURE_DISABLE_SSL}")
Ed Tanousa434f2b2018-07-27 13:04:22 -0700152 add_definitions (-DBMCWEB_ENABLE_SSL)
Andrew Geissler1f2fbf22018-07-17 07:57:30 -0700153endif (NOT "${BMCWEB_INSECURE_DISABLE_SSL}")
Ed Tanous55c7b7a2018-05-22 15:27:24 -0700154include_directories (${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800155
Ed Tanous580f3722018-03-13 16:59:02 -0700156# Zlib
Ed Tanous1e439872018-05-18 11:48:52 -0700157find_package (ZLIB REQUIRED)
158include_directories (${ZLIB_INCLUDE_DIRS})
Ed Tanousf9273472017-02-28 16:05:13 -0800159
Ed Tanous4758d5b2017-06-06 15:28:13 -0700160# PAM
Ed Tanous1e439872018-05-18 11:48:52 -0700161option (WEBSERVER_ENABLE_PAM "enable pam authentication" ON)
162if ("${WEBSERVER_ENABLE_PAM}")
163 find_package (PAM REQUIRED)
164else ()
165 add_definitions ("-DWEBSERVER_DISABLE_PAM")
166endif ()
Ed Tanous911ac312017-08-15 09:37:42 -0700167
Ed Tanousf0d73c22018-07-26 14:24:20 -0700168add_definitions ("-Wno-attributes")
Jennifer Lee03346702018-05-23 14:05:20 -0700169# Copy pam-webserver to etc/pam.d
Ed Tanousf0d73c22018-07-26 14:24:20 -0700170install (
171 FILES ${CMAKE_CURRENT_SOURCE_DIR}/pam-webserver
172 DESTINATION /etc/pam.d/
173 RENAME webserver
174)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800175
Ed tanous7d95f5f2018-03-23 00:19:20 -0700176# tinyxml2
Ed Tanous1e439872018-05-18 11:48:52 -0700177find_package (tinyxml2 REQUIRED)
Ed tanous7d95f5f2018-03-23 00:19:20 -0700178
Ed Tanous1e439872018-05-18 11:48:52 -0700179set (WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700180
Ed Tanous1e439872018-05-18 11:48:52 -0700181include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
182include_directories (${CMAKE_CURRENT_SOURCE_DIR}/redfish-core/include)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700183
Ed Tanous1e439872018-05-18 11:48:52 -0700184file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include/bmcweb)
Ed Tanous1e439872018-05-18 11:48:52 -0700185include_directories (${CMAKE_BINARY_DIR}/include)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800186
Ed Tanousf0d73c22018-07-26 14:24:20 -0700187set (
188 SRC_FILES redfish-core/src/error_messages.cpp
189 redfish-core/src/utils/json_utils.cpp ${GENERATED_SRC_FILES}
190)
Ed Tanous93f987d2017-04-17 17:52:36 -0700191
Ed Tanous1e439872018-05-18 11:48:52 -0700192file (COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
Ed Tanous911ac312017-08-15 09:37:42 -0700193
Ed Tanous38bdb982017-03-03 14:19:33 -0800194# Unit Tests
Ed Tanous1e439872018-05-18 11:48:52 -0700195if (${BMCWEB_BUILD_UT})
Ed Tanousf0d73c22018-07-26 14:24:20 -0700196 set (
197 UT_FILES src/crow_test.cpp src/gtest_main.cpp
198 src/token_authorization_middleware_test.cpp
199 src/security_headers_middleware_test.cpp src/webassets_test.cpp
200 src/crow_getroutes_test.cpp src/ast_jpeg_decoder_test.cpp
201 src/kvm_websocket_test.cpp src/msan_test.cpp
202 src/ast_video_puller_test.cpp src/openbmc_jtag_rest_test.cpp
203 redfish-core/ut/privileges_test.cpp
204 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
205 ) # big list of naughty strings
206 add_custom_command (
207 OUTPUT ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
208 COMMAND
209 xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns
210 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
211 )
Ed Tanous1e439872018-05-18 11:48:52 -0700212
Ed Tanousf0d73c22018-07-26 14:24:20 -0700213 set_source_files_properties (
214 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp PROPERTIES GENERATED TRUE
215 )
Ed Tanous1e439872018-05-18 11:48:52 -0700216 enable_testing ()
217
218 add_executable (webtest ${SRC_FILES} ${UT_FILES})
219
220 find_package (GTest REQUIRED)
221 find_package (GMock REQUIRED)
222 target_link_libraries (webtest ${GTEST_LIBRARIES})
223 target_link_libraries (webtest ${GMOCK_LIBRARIES})
224
225 target_link_libraries (webtest pthread)
226 target_link_libraries (webtest ${OPENSSL_LIBRARIES})
227 target_link_libraries (webtest ${ZLIB_LIBRARIES})
228 target_link_libraries (webtest pam)
229 target_link_libraries (webtest tinyxml2)
Ed Tanousd425c6f2018-05-16 10:20:11 -0700230 target_link_libraries (webtest sdbusplus)
Ed Tanouse0625902018-05-16 13:35:08 -0700231 target_link_libraries (webtest -lsystemd)
Ed Tanous1e439872018-05-18 11:48:52 -0700232 target_link_libraries (webtest -lstdc++fs)
233 add_test (webtest webtest "--gtest_output=xml:webtest.xml")
234
235endif (${BMCWEB_BUILD_UT})
236
237install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www)
238
239# bmcweb
240add_executable (bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous1e439872018-05-18 11:48:52 -0700241target_link_libraries (bmcweb ${OPENSSL_LIBRARIES})
242target_link_libraries (bmcweb ${ZLIB_LIBRARIES})
243target_link_libraries (bmcweb pam)
Brad Bishop79ba46f2018-11-29 10:57:31 -0500244target_link_libraries (bmcweb -latomic)
Ed Tanous1e439872018-05-18 11:48:52 -0700245target_link_libraries (bmcweb -lsystemd)
246target_link_libraries (bmcweb -lstdc++fs)
Ed Tanousd425c6f2018-05-16 10:20:11 -0700247target_link_libraries (bmcweb sdbusplus)
Ed Tanous1e439872018-05-18 11:48:52 -0700248target_link_libraries (bmcweb tinyxml2)
249install (TARGETS bmcweb DESTINATION bin)
250
251add_executable (getvideo src/getvideo_main.cpp)
252target_link_libraries (getvideo pthread)
Jason M. Billsc50fc5a2018-11-14 14:49:59 -0800253
254target_compile_definitions (
255 bmcweb PRIVATE
256 $<$<BOOL:${BMCWEB_ENABLE_KVM}>: -DBMCWEB_ENABLE_KVM>
257 $<$<BOOL:${BMCWEB_ENABLE_DBUS_REST}>: -DBMCWEB_ENABLE_DBUS_REST>
258 $<$<BOOL:${BMCWEB_ENABLE_REDFISH}>: -DBMCWEB_ENABLE_REDFISH>
259 $<$<BOOL:${BMCWEB_ENABLE_STATIC_HOSTING}>: -DBMCWEB_ENABLE_STATIC_HOSTING>
260 $<$<BOOL:${BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET}>: -DBMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET>
261 $<$<BOOL:${BMCWEB_INSECURE_DISABLE_CSRF_PREVENTION}>: -DBMCWEB_INSECURE_DISABLE_CSRF_PREVENTION>
262 $<$<BOOL:${BMCWEB_INSECURE_DISABLE_SSL}>: -DBMCWEB_INSECURE_DISABLE_SSL>
263 $<$<BOOL:${BMCWEB_INSECURE_DISABLE_XSS_PREVENTION}>: -DBMCWEB_INSECURE_DISABLE_XSS_PREVENTION>
264 $<$<BOOL:${BMCWEB_ENABLE_REDFISH_RAW_PECI}>: -DBMCWEB_ENABLE_REDFISH_RAW_PECI>
265 $<$<BOOL:${BMCWEB_ENABLE_REDFISH_CPU_LOG}>: -DBMCWEB_ENABLE_REDFISH_CPU_LOG>
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800266 $<$<BOOL:${BMCWEB_ENABLE_REDFISH_BMC_JOURNAL}>: -DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL>
Brad Bishopf5e906b2018-11-29 10:55:10 -0500267)