blob: 70e56fd00f48201af276f3f6c52c8f21e5cb80d0 [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
Ed Tanous3eb2f352018-12-20 12:30:45 -080012 '/kvm/0'. Video is from the BMC's '/dev/video' device." ON)
Joseph Reynolds7a777f52018-11-07 22:01:31 -060013option (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
Jason M. Billsd53dd412019-02-12 17:16:22 -080030 Redfish. Paths are under '/redfish/v1/Systems/system/LogServices/CpuLog/
Joseph Reynolds7a777f52018-11-07 22:01:31 -060031 Actions/Oem/CpuLog.SendRawPeci'." OFF)
32option (BMCWEB_ENABLE_REDFISH_CPU_LOG "Enable CPU log service transactions
33 through Redfish. Paths are under
Jason M. Billsd53dd412019-02-12 17:16:22 -080034 '/redfish/v1/Systems/system/LogServices/CpuLog'." OFF)
Gunnar Mills603a6642019-01-21 17:03:51 -060035option (BMCWEB_ENABLE_REDFISH_ONE_CHASSIS "Enable Redfish to assume only one
36 chassis is present. All sensors will be assumed to be under this
37 chassis. The chassis path is '/redfish/v1/Chassis/chassis'." OFF)
Ed Tanous1da66f72018-07-27 16:13:37 -070038
Ed Tanousbdd1c832018-10-12 11:00:30 -070039# Insecure options. Every option that starts with a BMCWEB_INSECURE flag should
Ed Tanous1e439872018-05-18 11:48:52 -070040# not be enabled by default for any platform, unless the author fully
41# comprehends the implications of doing so. In general, enabling these options
42# will cause security problems of varying degrees
Ed Tanousf0d73c22018-07-26 14:24:20 -070043option (BMCWEB_INSECURE_DISABLE_CSRF_PREVENTION "Disable CSRF prevention checks.
44 Should be set to OFF for production systems." OFF)
Ed Tanousf3d847c2017-06-12 16:01:42 -070045
Ed Tanousf0d73c22018-07-26 14:24:20 -070046option (BMCWEB_INSECURE_DISABLE_SSL "Disable SSL ports. Should be set to OFF for
47 production systems." OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080048
Ed Tanousf0d73c22018-07-26 14:24:20 -070049option (BMCWEB_INSECURE_DISABLE_AUTHENTICATION "Disable authentication on all
50 ports. Should be set to OFF for production systems" OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080051
Ed Tanous1e439872018-05-18 11:48:52 -070052option (BMCWEB_INSECURE_DISABLE_XSS_PREVENTION "Disable XSS preventions" OFF)
Ed Tanous0d485ef2017-05-23 09:23:53 -070053
Ed Tanous1e439872018-05-18 11:48:52 -070054project (bmc-webserver CXX)
55
56include (CTest)
57
Ed Tanous62288742018-10-16 14:58:20 -070058set (CMAKE_CXX_STANDARD 17)
Ed Tanous1e439872018-05-18 11:48:52 -070059set (CMAKE_CXX_STANDARD_REQUIRED ON)
60
61set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
62
Ed Tanousb01bf292019-03-25 19:25:26 +000063set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall")
Ed Tanous1e439872018-05-18 11:48:52 -070064
65set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
66set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
Ed Tanous3dac7492017-08-02 13:46:20 -070067
Ed Tanous0fdddb12017-02-28 11:06:34 -080068# general
Ed Tanous797d0c02018-08-07 10:22:35 -070069option (BMCWEB_BUILD_UT "Enable Unit test" OFF)
Ed Tanous8041f312017-04-03 09:47:01 -070070
Ed Tanous1ccd57c2017-03-21 13:15:58 -070071# security flags
Ed Tanousf0d73c22018-07-26 14:24:20 -070072set (SECURITY_FLAGS "\
Ed Tanous580f3722018-03-13 16:59:02 -070073 -fstack-protector-strong \
74 -fPIE \
75 -fPIC \
76 -D_FORTIFY_SOURCE=2 \
77 -Wformat \
Ed Tanousf0d73c22018-07-26 14:24:20 -070078 -Wformat-security")
Ed Tanous1e439872018-05-18 11:48:52 -070079set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SECURITY_FLAGS}")
Ed Tanousf0d73c22018-07-26 14:24:20 -070080set (
81 CMAKE_CXX_FLAGS_RELWITHDEBINFO
82 "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SECURITY_FLAGS}"
83)
Ed Tanous1e439872018-05-18 11:48:52 -070084set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}")
Ed Tanous3dac7492017-08-02 13:46:20 -070085
Ed Tanous580f3722018-03-13 16:59:02 -070086# Enable link time optimization This is a temporary workaround because
87# INTERPROCEDURAL_OPTIMIZATION isn't available until cmake 3.9. gcc-ar and gcc-
88# ranlib are wrappers around ar and ranlib which add the lto plugin to the
89# command line.
Ed Tanous1e439872018-05-18 11:48:52 -070090if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
91 if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
92 string (REGEX REPLACE "ar$" "gcc-ar" CMAKE_AR ${CMAKE_AR})
Ed Tanousf0d73c22018-07-26 14:24:20 -070093 string (
94 REGEX
95 REPLACE "ranlib$" "gcc-ranlib" CMAKE_RANLIB ${CMAKE_RANLIB}
96 )
Ed Tanous1e439872018-05-18 11:48:52 -070097 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -fno-fat-lto-objects")
Borawski.Lukasz109799e2018-01-30 15:04:42 +010098
Ed Tanous1e439872018-05-18 11:48:52 -070099 # Reduce the binary size by removing unnecessary dynamic symbol table
100 # entries
Ed Tanousf0d73c22018-07-26 14:24:20 -0700101 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
Ed Tanous580f3722018-03-13 16:59:02 -0700102 -fvisibility=hidden \
103 -fvisibility-inlines-hidden \
Ed Tanousf0d73c22018-07-26 14:24:20 -0700104 -Wl,--exclude-libs,ALL")
Ed Tanous1e439872018-05-18 11:48:52 -0700105 endif (NOT CMAKE_BUILD_TYPE MATCHES Debug)
106endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Borawski.Lukasz109799e2018-01-30 15:04:42 +0100107
Ed Tanous1e439872018-05-18 11:48:52 -0700108if (NOT ${YOCTO_DEPENDENCIES}) # Download and unpack googletest at configure
109 # time
110 configure_file (CMakeLists.txt.in 3rdparty/CMakeLists.txt)
Ed Tanousf0d73c22018-07-26 14:24:20 -0700111 execute_process (
112 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
113 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty
114 )
115 execute_process (
116 COMMAND ${CMAKE_COMMAND} --build .
117 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty
118 )
Ed tanous7d95f5f2018-03-23 00:19:20 -0700119
Ed Tanous1e439872018-05-18 11:48:52 -0700120 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/prefix ${CMAKE_PREFIX_PATH})
121endif ()
Ed tanous7d95f5f2018-03-23 00:19:20 -0700122
Ed Tanous580f3722018-03-13 16:59:02 -0700123# add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanousd3a38062018-07-27 12:06:29 -0700124add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
Ed Tanous39e77502019-03-04 17:35:53 -0800125add_definitions (-DBOOST_BEAST_USE_STD_STRING_VIEW)
Ed Tanous1e439872018-05-18 11:48:52 -0700126add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
127add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
Ed Tanouse278c182019-03-13 16:23:37 -0700128add_definitions (-DBOOST_ASIO_NO_DEPRECATED)
Ed Tanous1e439872018-05-18 11:48:52 -0700129add_definitions (-DBOOST_ALL_NO_LIB)
130add_definitions (-DBOOST_NO_RTTI)
131add_definitions (-DBOOST_NO_TYPEID)
Ed Tanousc85eb8b2018-10-16 14:59:20 -0700132add_definitions (-DBOOST_COROUTINES_NO_DEPRECATION_WARNING)
Ed tanous7d95f5f2018-03-23 00:19:20 -0700133
Ed Tanous1e439872018-05-18 11:48:52 -0700134find_package (Boost 1.66 REQUIRED)
135include_directories (${BOOST_SRC_DIR})
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700136
137# sdbusplus
Ed Tanous1e439872018-05-18 11:48:52 -0700138if (NOT ${YOCTO_DEPENDENCIES})
James Feista975e9f2018-08-08 14:03:49 -0700139 include_directories (${CMAKE_BINARY_DIR}/sdbusplus-src)
140 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
Ed Tanous1e439872018-05-18 11:48:52 -0700141endif ()
Ed Tanous0fdddb12017-02-28 11:06:34 -0800142
Ed Tanous580f3722018-03-13 16:59:02 -0700143# Openssl
Ed Tanous1e439872018-05-18 11:48:52 -0700144find_package (OpenSSL REQUIRED)
145include_directories (${OPENSSL_INCLUDE_DIR})
146message ("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
Ed Tanous0fdddb12017-02-28 11:06:34 -0800147
Ed Tanous55c7b7a2018-05-22 15:27:24 -0700148# bmcweb
Ed Tanous1e439872018-05-18 11:48:52 -0700149message ("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
150if (CMAKE_BUILD_TYPE MATCHES Debug)
151 message ("Logging disabled")
Ed Tanous55c7b7a2018-05-22 15:27:24 -0700152 add_definitions (-DBMCWEB_ENABLE_LOGGING)
153 add_definitions (-DBMCWEB_ENABLE_DEBUG)
Ed Tanous1e439872018-05-18 11:48:52 -0700154endif (CMAKE_BUILD_TYPE MATCHES Debug)
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700155
Andrew Geissler1f2fbf22018-07-17 07:57:30 -0700156if (NOT "${BMCWEB_INSECURE_DISABLE_SSL}")
Ed Tanousa434f2b2018-07-27 13:04:22 -0700157 add_definitions (-DBMCWEB_ENABLE_SSL)
Andrew Geissler1f2fbf22018-07-17 07:57:30 -0700158endif (NOT "${BMCWEB_INSECURE_DISABLE_SSL}")
Ed Tanous55c7b7a2018-05-22 15:27:24 -0700159include_directories (${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800160
Ed Tanous580f3722018-03-13 16:59:02 -0700161# Zlib
Ed Tanous1e439872018-05-18 11:48:52 -0700162find_package (ZLIB REQUIRED)
163include_directories (${ZLIB_INCLUDE_DIRS})
Ed Tanousf9273472017-02-28 16:05:13 -0800164
Ed Tanous4758d5b2017-06-06 15:28:13 -0700165# PAM
Ed Tanous1e439872018-05-18 11:48:52 -0700166option (WEBSERVER_ENABLE_PAM "enable pam authentication" ON)
167if ("${WEBSERVER_ENABLE_PAM}")
168 find_package (PAM REQUIRED)
169else ()
170 add_definitions ("-DWEBSERVER_DISABLE_PAM")
171endif ()
Ed Tanous911ac312017-08-15 09:37:42 -0700172
Ed Tanousf0d73c22018-07-26 14:24:20 -0700173add_definitions ("-Wno-attributes")
Jennifer Lee03346702018-05-23 14:05:20 -0700174# Copy pam-webserver to etc/pam.d
Ed Tanousf0d73c22018-07-26 14:24:20 -0700175install (
176 FILES ${CMAKE_CURRENT_SOURCE_DIR}/pam-webserver
177 DESTINATION /etc/pam.d/
178 RENAME webserver
179)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800180
Ed tanous7d95f5f2018-03-23 00:19:20 -0700181# tinyxml2
Ed Tanous1e439872018-05-18 11:48:52 -0700182find_package (tinyxml2 REQUIRED)
Ed tanous7d95f5f2018-03-23 00:19:20 -0700183
Ed Tanous1e439872018-05-18 11:48:52 -0700184set (WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700185
Ed Tanous1e439872018-05-18 11:48:52 -0700186include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
187include_directories (${CMAKE_CURRENT_SOURCE_DIR}/redfish-core/include)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700188
Ed Tanous1e439872018-05-18 11:48:52 -0700189file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include/bmcweb)
Ed Tanous1e439872018-05-18 11:48:52 -0700190include_directories (${CMAKE_BINARY_DIR}/include)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800191
Ed Tanousf0d73c22018-07-26 14:24:20 -0700192set (
193 SRC_FILES redfish-core/src/error_messages.cpp
194 redfish-core/src/utils/json_utils.cpp ${GENERATED_SRC_FILES}
195)
Ed Tanous93f987d2017-04-17 17:52:36 -0700196
Ed Tanous1e439872018-05-18 11:48:52 -0700197file (COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
Ed Tanous911ac312017-08-15 09:37:42 -0700198
Ed Tanous38bdb982017-03-03 14:19:33 -0800199# Unit Tests
Ed Tanous1e439872018-05-18 11:48:52 -0700200if (${BMCWEB_BUILD_UT})
Ed Tanousf0d73c22018-07-26 14:24:20 -0700201 set (
202 UT_FILES src/crow_test.cpp src/gtest_main.cpp
203 src/token_authorization_middleware_test.cpp
204 src/security_headers_middleware_test.cpp src/webassets_test.cpp
205 src/crow_getroutes_test.cpp src/ast_jpeg_decoder_test.cpp
206 src/kvm_websocket_test.cpp src/msan_test.cpp
207 src/ast_video_puller_test.cpp src/openbmc_jtag_rest_test.cpp
208 redfish-core/ut/privileges_test.cpp
209 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
210 ) # big list of naughty strings
211 add_custom_command (
212 OUTPUT ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
213 COMMAND
214 xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns
215 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
216 )
Ed Tanous1e439872018-05-18 11:48:52 -0700217
Ed Tanousf0d73c22018-07-26 14:24:20 -0700218 set_source_files_properties (
219 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp PROPERTIES GENERATED TRUE
220 )
Ed Tanous1e439872018-05-18 11:48:52 -0700221 enable_testing ()
222
223 add_executable (webtest ${SRC_FILES} ${UT_FILES})
224
225 find_package (GTest REQUIRED)
226 find_package (GMock REQUIRED)
227 target_link_libraries (webtest ${GTEST_LIBRARIES})
228 target_link_libraries (webtest ${GMOCK_LIBRARIES})
229
230 target_link_libraries (webtest pthread)
231 target_link_libraries (webtest ${OPENSSL_LIBRARIES})
232 target_link_libraries (webtest ${ZLIB_LIBRARIES})
233 target_link_libraries (webtest pam)
234 target_link_libraries (webtest tinyxml2)
Ed Tanousd425c6f2018-05-16 10:20:11 -0700235 target_link_libraries (webtest sdbusplus)
Ed Tanouse0625902018-05-16 13:35:08 -0700236 target_link_libraries (webtest -lsystemd)
Ed Tanous1e439872018-05-18 11:48:52 -0700237 target_link_libraries (webtest -lstdc++fs)
238 add_test (webtest webtest "--gtest_output=xml:webtest.xml")
239
240endif (${BMCWEB_BUILD_UT})
241
242install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www)
243
244# bmcweb
245add_executable (bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous1e439872018-05-18 11:48:52 -0700246target_link_libraries (bmcweb ${OPENSSL_LIBRARIES})
247target_link_libraries (bmcweb ${ZLIB_LIBRARIES})
248target_link_libraries (bmcweb pam)
Brad Bishop79ba46f2018-11-29 10:57:31 -0500249target_link_libraries (bmcweb -latomic)
Ed Tanous1e439872018-05-18 11:48:52 -0700250target_link_libraries (bmcweb -lsystemd)
251target_link_libraries (bmcweb -lstdc++fs)
Ed Tanousd425c6f2018-05-16 10:20:11 -0700252target_link_libraries (bmcweb sdbusplus)
Ed Tanous1e439872018-05-18 11:48:52 -0700253target_link_libraries (bmcweb tinyxml2)
254install (TARGETS bmcweb DESTINATION bin)
255
Jason M. Billsc50fc5a2018-11-14 14:49:59 -0800256target_compile_definitions (
257 bmcweb PRIVATE
258 $<$<BOOL:${BMCWEB_ENABLE_KVM}>: -DBMCWEB_ENABLE_KVM>
259 $<$<BOOL:${BMCWEB_ENABLE_DBUS_REST}>: -DBMCWEB_ENABLE_DBUS_REST>
260 $<$<BOOL:${BMCWEB_ENABLE_REDFISH}>: -DBMCWEB_ENABLE_REDFISH>
261 $<$<BOOL:${BMCWEB_ENABLE_STATIC_HOSTING}>: -DBMCWEB_ENABLE_STATIC_HOSTING>
262 $<$<BOOL:${BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET}>: -DBMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET>
263 $<$<BOOL:${BMCWEB_INSECURE_DISABLE_CSRF_PREVENTION}>: -DBMCWEB_INSECURE_DISABLE_CSRF_PREVENTION>
264 $<$<BOOL:${BMCWEB_INSECURE_DISABLE_SSL}>: -DBMCWEB_INSECURE_DISABLE_SSL>
265 $<$<BOOL:${BMCWEB_INSECURE_DISABLE_XSS_PREVENTION}>: -DBMCWEB_INSECURE_DISABLE_XSS_PREVENTION>
266 $<$<BOOL:${BMCWEB_ENABLE_REDFISH_RAW_PECI}>: -DBMCWEB_ENABLE_REDFISH_RAW_PECI>
267 $<$<BOOL:${BMCWEB_ENABLE_REDFISH_CPU_LOG}>: -DBMCWEB_ENABLE_REDFISH_CPU_LOG>
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800268 $<$<BOOL:${BMCWEB_ENABLE_REDFISH_BMC_JOURNAL}>: -DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL>
Gunnar Mills603a6642019-01-21 17:03:51 -0600269 $<$<BOOL:${BMCWEB_ENABLE_REDFISH_ONE_CHASSIS}>: -DBMCWEB_ENABLE_REDFISH_ONE_CHASSIS>
Brad Bishopf5e906b2018-11-29 10:55:10 -0500270)