blob: 45dbb61f50266abd7e99e4d638d843baecd46504 [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)
Ed Tanous2daf6722018-08-23 11:27:23 -070013option (BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET "Enable host serial websocket" ON)
Andrew Geisslerd529ee22018-08-10 13:49:54 -070014option (BMCWEB_ENABLE_STATIC_HOSTING "Enable hosting of static files.
15 For example, redfish schema and webui files" ON)
Ed Tanous0fdddb12017-02-28 11:06:34 -080016
Ed Tanous1da66f72018-07-27 16:13:37 -070017option (
18 BMCWEB_ENABLE_REDFISH_RAW_PECI "Enable PECI transactions through redfish"
19 OFF
20)
21option (
22 BMCWEB_ENABLE_REDFISH_CPU_LOG
23 "Enable CPU log service transactions through redfish" OFF
24)
25
Ed Tanousbdd1c832018-10-12 11:00:30 -070026# Insecure options. Every option that starts with a BMCWEB_INSECURE flag should
Ed Tanous1e439872018-05-18 11:48:52 -070027# not be enabled by default for any platform, unless the author fully
28# comprehends the implications of doing so. In general, enabling these options
29# will cause security problems of varying degrees
Ed Tanousf0d73c22018-07-26 14:24:20 -070030option (BMCWEB_INSECURE_DISABLE_CSRF_PREVENTION "Disable CSRF prevention checks.
31 Should be set to OFF for production systems." OFF)
Ed Tanousf3d847c2017-06-12 16:01:42 -070032
Ed Tanousf0d73c22018-07-26 14:24:20 -070033option (BMCWEB_INSECURE_DISABLE_SSL "Disable SSL ports. Should be set to OFF for
34 production systems." OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080035
Ed Tanousf0d73c22018-07-26 14:24:20 -070036option (BMCWEB_INSECURE_DISABLE_AUTHENTICATION "Disable authentication on all
37 ports. Should be set to OFF for production systems" OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080038
Ed Tanous1e439872018-05-18 11:48:52 -070039option (BMCWEB_INSECURE_DISABLE_XSS_PREVENTION "Disable XSS preventions" OFF)
Ed Tanous0d485ef2017-05-23 09:23:53 -070040
Ed Tanous1e439872018-05-18 11:48:52 -070041project (bmc-webserver CXX)
42
43include (CTest)
44
45set (CMAKE_CXX_STANDARD 14)
46set (CMAKE_CXX_STANDARD_REQUIRED ON)
47
48set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
49
50set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall")
51
52set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
53set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
Ed Tanous3dac7492017-08-02 13:46:20 -070054
Ed Tanous0fdddb12017-02-28 11:06:34 -080055# general
Ed Tanous797d0c02018-08-07 10:22:35 -070056option (BMCWEB_BUILD_UT "Enable Unit test" OFF)
Ed Tanous8041f312017-04-03 09:47:01 -070057
Ed Tanous1ccd57c2017-03-21 13:15:58 -070058# security flags
Ed Tanousf0d73c22018-07-26 14:24:20 -070059set (SECURITY_FLAGS "\
Ed Tanous580f3722018-03-13 16:59:02 -070060 -fstack-protector-strong \
61 -fPIE \
62 -fPIC \
63 -D_FORTIFY_SOURCE=2 \
64 -Wformat \
Ed Tanousf0d73c22018-07-26 14:24:20 -070065 -Wformat-security")
Ed Tanous1e439872018-05-18 11:48:52 -070066set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SECURITY_FLAGS}")
Ed Tanousf0d73c22018-07-26 14:24:20 -070067set (
68 CMAKE_CXX_FLAGS_RELWITHDEBINFO
69 "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SECURITY_FLAGS}"
70)
Ed Tanous1e439872018-05-18 11:48:52 -070071set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}")
Ed Tanous3dac7492017-08-02 13:46:20 -070072
Ed Tanous580f3722018-03-13 16:59:02 -070073# Enable link time optimization This is a temporary workaround because
74# INTERPROCEDURAL_OPTIMIZATION isn't available until cmake 3.9. gcc-ar and gcc-
75# ranlib are wrappers around ar and ranlib which add the lto plugin to the
76# command line.
Ed Tanous1e439872018-05-18 11:48:52 -070077if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
78 if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
79 string (REGEX REPLACE "ar$" "gcc-ar" CMAKE_AR ${CMAKE_AR})
Ed Tanousf0d73c22018-07-26 14:24:20 -070080 string (
81 REGEX
82 REPLACE "ranlib$" "gcc-ranlib" CMAKE_RANLIB ${CMAKE_RANLIB}
83 )
Ed Tanous1e439872018-05-18 11:48:52 -070084 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
Ed Tanousf0d73c22018-07-26 14:24:20 -070088 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
Ed Tanous580f3722018-03-13 16:59:02 -070089 -fvisibility=hidden \
90 -fvisibility-inlines-hidden \
Ed Tanousf0d73c22018-07-26 14:24:20 -070091 -Wl,--exclude-libs,ALL")
Ed Tanous1e439872018-05-18 11:48:52 -070092 endif (NOT CMAKE_BUILD_TYPE MATCHES Debug)
93endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Borawski.Lukasz109799e2018-01-30 15:04:42 +010094
Ed Tanous1e439872018-05-18 11:48:52 -070095if (NOT ${YOCTO_DEPENDENCIES}) # Download and unpack googletest at configure
96 # time
97 configure_file (CMakeLists.txt.in 3rdparty/CMakeLists.txt)
Ed Tanousf0d73c22018-07-26 14:24:20 -070098 execute_process (
99 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
100 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty
101 )
102 execute_process (
103 COMMAND ${CMAKE_COMMAND} --build .
104 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty
105 )
Ed tanous7d95f5f2018-03-23 00:19:20 -0700106
Ed Tanous1e439872018-05-18 11:48:52 -0700107 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/prefix ${CMAKE_PREFIX_PATH})
108endif ()
Ed tanous7d95f5f2018-03-23 00:19:20 -0700109
Ed Tanous580f3722018-03-13 16:59:02 -0700110# add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanousd3a38062018-07-27 12:06:29 -0700111add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
Ed Tanous1e439872018-05-18 11:48:52 -0700112add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
113add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
114add_definitions (-DBOOST_ALL_NO_LIB)
115add_definitions (-DBOOST_NO_RTTI)
116add_definitions (-DBOOST_NO_TYPEID)
Ed tanous7d95f5f2018-03-23 00:19:20 -0700117
Ed Tanous1e439872018-05-18 11:48:52 -0700118find_package (Boost 1.66 REQUIRED)
119include_directories (${BOOST_SRC_DIR})
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700120
121# sdbusplus
Ed Tanous1e439872018-05-18 11:48:52 -0700122if (NOT ${YOCTO_DEPENDENCIES})
James Feista975e9f2018-08-08 14:03:49 -0700123 include_directories (${CMAKE_BINARY_DIR}/sdbusplus-src)
124 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
Ed Tanous1e439872018-05-18 11:48:52 -0700125endif ()
Ed Tanous0fdddb12017-02-28 11:06:34 -0800126
Ed Tanous580f3722018-03-13 16:59:02 -0700127# Openssl
Ed Tanous1e439872018-05-18 11:48:52 -0700128find_package (OpenSSL REQUIRED)
129include_directories (${OPENSSL_INCLUDE_DIR})
130message ("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
Ed Tanous0fdddb12017-02-28 11:06:34 -0800131
Ed Tanous55c7b7a2018-05-22 15:27:24 -0700132# bmcweb
Ed Tanous1e439872018-05-18 11:48:52 -0700133message ("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
134if (CMAKE_BUILD_TYPE MATCHES Debug)
135 message ("Logging disabled")
Ed Tanous55c7b7a2018-05-22 15:27:24 -0700136 add_definitions (-DBMCWEB_ENABLE_LOGGING)
137 add_definitions (-DBMCWEB_ENABLE_DEBUG)
Ed Tanous1e439872018-05-18 11:48:52 -0700138endif (CMAKE_BUILD_TYPE MATCHES Debug)
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700139
Andrew Geissler1f2fbf22018-07-17 07:57:30 -0700140if (NOT "${BMCWEB_INSECURE_DISABLE_SSL}")
Ed Tanousa434f2b2018-07-27 13:04:22 -0700141 add_definitions (-DBMCWEB_ENABLE_SSL)
Andrew Geissler1f2fbf22018-07-17 07:57:30 -0700142endif (NOT "${BMCWEB_INSECURE_DISABLE_SSL}")
Ed Tanous55c7b7a2018-05-22 15:27:24 -0700143include_directories (${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800144
Ed Tanous580f3722018-03-13 16:59:02 -0700145# Zlib
Ed Tanous1e439872018-05-18 11:48:52 -0700146find_package (ZLIB REQUIRED)
147include_directories (${ZLIB_INCLUDE_DIRS})
Ed Tanousf9273472017-02-28 16:05:13 -0800148
Ed Tanous4758d5b2017-06-06 15:28:13 -0700149# PAM
Ed Tanous1e439872018-05-18 11:48:52 -0700150option (WEBSERVER_ENABLE_PAM "enable pam authentication" ON)
151if ("${WEBSERVER_ENABLE_PAM}")
152 find_package (PAM REQUIRED)
153else ()
154 add_definitions ("-DWEBSERVER_DISABLE_PAM")
155endif ()
Ed Tanous911ac312017-08-15 09:37:42 -0700156
Ed Tanousf0d73c22018-07-26 14:24:20 -0700157add_definitions ("-Wno-attributes")
Jennifer Lee03346702018-05-23 14:05:20 -0700158# Copy pam-webserver to etc/pam.d
Ed Tanousf0d73c22018-07-26 14:24:20 -0700159install (
160 FILES ${CMAKE_CURRENT_SOURCE_DIR}/pam-webserver
161 DESTINATION /etc/pam.d/
162 RENAME webserver
163)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800164
Ed tanous7d95f5f2018-03-23 00:19:20 -0700165# tinyxml2
Ed Tanous1e439872018-05-18 11:48:52 -0700166find_package (tinyxml2 REQUIRED)
Ed tanous7d95f5f2018-03-23 00:19:20 -0700167
Ed Tanous1e439872018-05-18 11:48:52 -0700168set (WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700169
Ed Tanous1e439872018-05-18 11:48:52 -0700170include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
171include_directories (${CMAKE_CURRENT_SOURCE_DIR}/redfish-core/include)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700172
Ed Tanous1e439872018-05-18 11:48:52 -0700173file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include/bmcweb)
174configure_file (settings.hpp.in ${CMAKE_BINARY_DIR}/include/bmcweb/settings.hpp)
175include_directories (${CMAKE_BINARY_DIR}/include)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800176
Ed Tanousf0d73c22018-07-26 14:24:20 -0700177set (
178 SRC_FILES redfish-core/src/error_messages.cpp
179 redfish-core/src/utils/json_utils.cpp ${GENERATED_SRC_FILES}
180)
Ed Tanous93f987d2017-04-17 17:52:36 -0700181
Ed Tanous1e439872018-05-18 11:48:52 -0700182file (COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
Ed Tanous911ac312017-08-15 09:37:42 -0700183
Ed Tanous38bdb982017-03-03 14:19:33 -0800184# Unit Tests
Ed Tanous1e439872018-05-18 11:48:52 -0700185if (${BMCWEB_BUILD_UT})
Ed Tanousf0d73c22018-07-26 14:24:20 -0700186 set (
187 UT_FILES src/crow_test.cpp src/gtest_main.cpp
188 src/token_authorization_middleware_test.cpp
189 src/security_headers_middleware_test.cpp src/webassets_test.cpp
190 src/crow_getroutes_test.cpp src/ast_jpeg_decoder_test.cpp
191 src/kvm_websocket_test.cpp src/msan_test.cpp
192 src/ast_video_puller_test.cpp src/openbmc_jtag_rest_test.cpp
193 redfish-core/ut/privileges_test.cpp
194 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
195 ) # big list of naughty strings
196 add_custom_command (
197 OUTPUT ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
198 COMMAND
199 xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns
200 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
201 )
Ed Tanous1e439872018-05-18 11:48:52 -0700202
Ed Tanousf0d73c22018-07-26 14:24:20 -0700203 set_source_files_properties (
204 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp PROPERTIES GENERATED TRUE
205 )
Ed Tanous1e439872018-05-18 11:48:52 -0700206 enable_testing ()
207
208 add_executable (webtest ${SRC_FILES} ${UT_FILES})
209
210 find_package (GTest REQUIRED)
211 find_package (GMock REQUIRED)
212 target_link_libraries (webtest ${GTEST_LIBRARIES})
213 target_link_libraries (webtest ${GMOCK_LIBRARIES})
214
215 target_link_libraries (webtest pthread)
216 target_link_libraries (webtest ${OPENSSL_LIBRARIES})
217 target_link_libraries (webtest ${ZLIB_LIBRARIES})
218 target_link_libraries (webtest pam)
219 target_link_libraries (webtest tinyxml2)
Ed Tanousd425c6f2018-05-16 10:20:11 -0700220 target_link_libraries (webtest sdbusplus)
Ed Tanouse0625902018-05-16 13:35:08 -0700221 target_link_libraries (webtest -lsystemd)
Ed Tanous1e439872018-05-18 11:48:52 -0700222 target_link_libraries (webtest -lstdc++fs)
223 add_test (webtest webtest "--gtest_output=xml:webtest.xml")
224
225endif (${BMCWEB_BUILD_UT})
226
227install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www)
228
229# bmcweb
230add_executable (bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous1e439872018-05-18 11:48:52 -0700231target_link_libraries (bmcweb ${OPENSSL_LIBRARIES})
232target_link_libraries (bmcweb ${ZLIB_LIBRARIES})
233target_link_libraries (bmcweb pam)
234target_link_libraries (bmcweb -lsystemd)
235target_link_libraries (bmcweb -lstdc++fs)
Ed Tanousd425c6f2018-05-16 10:20:11 -0700236target_link_libraries (bmcweb sdbusplus)
Ed Tanous1e439872018-05-18 11:48:52 -0700237target_link_libraries (bmcweb tinyxml2)
238install (TARGETS bmcweb DESTINATION bin)
239
240add_executable (getvideo src/getvideo_main.cpp)
241target_link_libraries (getvideo pthread)