blob: ce0006b3c1ecc859dcc5641feef2f0dc1e76faec [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 Tanousf0d73c22018-07-26 14:24:20 -070013option (BMCWEB_ENABLE_PHOSPHOR_WEBUI "Enable webui interfaces; Requires
Ed Tanous1e439872018-05-18 11:48:52 -070014 DBUS_REST interfaces" ON)
Ed Tanous0fdddb12017-02-28 11:06:34 -080015
Ed Tanous1e439872018-05-18 11:48:52 -070016# Insecure options. Every option that starts with a BMCWEB_INSECURE flag should
17# not be enabled by default for any platform, unless the author fully
18# comprehends the implications of doing so. In general, enabling these options
19# will cause security problems of varying degrees
Ed Tanousf0d73c22018-07-26 14:24:20 -070020option (BMCWEB_INSECURE_DISABLE_CSRF_PREVENTION "Disable CSRF prevention checks.
21 Should be set to OFF for production systems." OFF)
Ed Tanousf3d847c2017-06-12 16:01:42 -070022
Ed Tanousf0d73c22018-07-26 14:24:20 -070023option (BMCWEB_INSECURE_DISABLE_SSL "Disable SSL ports. Should be set to OFF for
24 production systems." OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080025
Ed Tanousf0d73c22018-07-26 14:24:20 -070026option (BMCWEB_INSECURE_DISABLE_AUTHENTICATION "Disable authentication on all
27 ports. Should be set to OFF for production systems" OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080028
Ed Tanous1e439872018-05-18 11:48:52 -070029option (BMCWEB_INSECURE_DISABLE_XSS_PREVENTION "Disable XSS preventions" OFF)
Ed Tanous0d485ef2017-05-23 09:23:53 -070030
Ed Tanous1e439872018-05-18 11:48:52 -070031project (bmc-webserver CXX)
32
33include (CTest)
34
35set (CMAKE_CXX_STANDARD 14)
36set (CMAKE_CXX_STANDARD_REQUIRED ON)
37
38set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
39
40set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall")
41
42set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
43set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
Ed Tanous3dac7492017-08-02 13:46:20 -070044
Ed Tanous0fdddb12017-02-28 11:06:34 -080045# general
Ed Tanous1e439872018-05-18 11:48:52 -070046option (BMCWEB_BUILD_UT "Enable Unit test" ON)
Ed Tanous8041f312017-04-03 09:47:01 -070047
Ed Tanous1ccd57c2017-03-21 13:15:58 -070048# security flags
Ed Tanousf0d73c22018-07-26 14:24:20 -070049set (SECURITY_FLAGS "\
Ed Tanous580f3722018-03-13 16:59:02 -070050 -fstack-protector-strong \
51 -fPIE \
52 -fPIC \
53 -D_FORTIFY_SOURCE=2 \
54 -Wformat \
Ed Tanousf0d73c22018-07-26 14:24:20 -070055 -Wformat-security")
Ed Tanous1e439872018-05-18 11:48:52 -070056set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SECURITY_FLAGS}")
Ed Tanousf0d73c22018-07-26 14:24:20 -070057set (
58 CMAKE_CXX_FLAGS_RELWITHDEBINFO
59 "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SECURITY_FLAGS}"
60)
Ed Tanous1e439872018-05-18 11:48:52 -070061set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}")
Ed Tanous3dac7492017-08-02 13:46:20 -070062
Ed Tanous580f3722018-03-13 16:59:02 -070063# Enable link time optimization This is a temporary workaround because
64# INTERPROCEDURAL_OPTIMIZATION isn't available until cmake 3.9. gcc-ar and gcc-
65# ranlib are wrappers around ar and ranlib which add the lto plugin to the
66# command line.
Ed Tanous1e439872018-05-18 11:48:52 -070067if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
68 if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
69 string (REGEX REPLACE "ar$" "gcc-ar" CMAKE_AR ${CMAKE_AR})
Ed Tanousf0d73c22018-07-26 14:24:20 -070070 string (
71 REGEX
72 REPLACE "ranlib$" "gcc-ranlib" CMAKE_RANLIB ${CMAKE_RANLIB}
73 )
Ed Tanous1e439872018-05-18 11:48:52 -070074 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -fno-fat-lto-objects")
Borawski.Lukasz109799e2018-01-30 15:04:42 +010075
Ed Tanous1e439872018-05-18 11:48:52 -070076 # Reduce the binary size by removing unnecessary dynamic symbol table
77 # entries
Ed Tanousf0d73c22018-07-26 14:24:20 -070078 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
Ed Tanous580f3722018-03-13 16:59:02 -070079 -fvisibility=hidden \
80 -fvisibility-inlines-hidden \
Ed Tanousf0d73c22018-07-26 14:24:20 -070081 -Wl,--exclude-libs,ALL")
Ed Tanous1e439872018-05-18 11:48:52 -070082 endif (NOT CMAKE_BUILD_TYPE MATCHES Debug)
83endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Borawski.Lukasz109799e2018-01-30 15:04:42 +010084
Ed Tanous1e439872018-05-18 11:48:52 -070085if (NOT ${YOCTO_DEPENDENCIES}) # Download and unpack googletest at configure
86 # time
87 configure_file (CMakeLists.txt.in 3rdparty/CMakeLists.txt)
Ed Tanousf0d73c22018-07-26 14:24:20 -070088 execute_process (
89 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
90 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty
91 )
92 execute_process (
93 COMMAND ${CMAKE_COMMAND} --build .
94 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty
95 )
Ed tanous7d95f5f2018-03-23 00:19:20 -070096
Ed Tanous1e439872018-05-18 11:48:52 -070097 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/prefix ${CMAKE_PREFIX_PATH})
98endif ()
Ed tanous7d95f5f2018-03-23 00:19:20 -070099
Ed Tanous580f3722018-03-13 16:59:02 -0700100# add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanous1e439872018-05-18 11:48:52 -0700101add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
102add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
103add_definitions (-DBOOST_ALL_NO_LIB)
104add_definitions (-DBOOST_NO_RTTI)
105add_definitions (-DBOOST_NO_TYPEID)
Ed tanous7d95f5f2018-03-23 00:19:20 -0700106
Ed Tanous1e439872018-05-18 11:48:52 -0700107find_package (Boost 1.66 REQUIRED)
108include_directories (${BOOST_SRC_DIR})
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700109
110# sdbusplus
Ed Tanous1e439872018-05-18 11:48:52 -0700111if (NOT ${YOCTO_DEPENDENCIES})
Ed Tanousf0d73c22018-07-26 14:24:20 -0700112 include_directories (
113 ${CMAKE_BINARY_DIR}/sdbusplus-src ${CMAKE_BINARY_DIR}/prefix/include
114 )
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700115
Ed Tanous1e439872018-05-18 11:48:52 -0700116 set (WANT_TRANSACTION 0)
117
Ed Tanousf0d73c22018-07-26 14:24:20 -0700118 configure_file (
119 ${CMAKE_BINARY_DIR}/sdbusplus-src/sdbusplus/server.hpp.in
120 ${CMAKE_BINARY_DIR}/prefix/include/sdbusplus/server.hpp @ONLY
121 )
122 configure_file (
123 ${CMAKE_BINARY_DIR}/sdbusplus-src/sdbusplus/bus.hpp.in
124 ${CMAKE_BINARY_DIR}/prefix/include/sdbusplus/bus.hpp @ONLY
125 )
Ed Tanous1e439872018-05-18 11:48:52 -0700126endif ()
Ed Tanous0fdddb12017-02-28 11:06:34 -0800127
Ed Tanous580f3722018-03-13 16:59:02 -0700128# Openssl
Ed Tanous1e439872018-05-18 11:48:52 -0700129find_package (OpenSSL REQUIRED)
130include_directories (${OPENSSL_INCLUDE_DIR})
131message ("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
Ed Tanous0fdddb12017-02-28 11:06:34 -0800132
Ed Tanous55c7b7a2018-05-22 15:27:24 -0700133# bmcweb
Ed Tanous1e439872018-05-18 11:48:52 -0700134message ("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
135if (CMAKE_BUILD_TYPE MATCHES Debug)
136 message ("Logging disabled")
Ed Tanous55c7b7a2018-05-22 15:27:24 -0700137 add_definitions (-DBMCWEB_ENABLE_LOGGING)
138 add_definitions (-DBMCWEB_ENABLE_DEBUG)
Ed Tanous1e439872018-05-18 11:48:52 -0700139endif (CMAKE_BUILD_TYPE MATCHES Debug)
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700140
Andrew Geissler1f2fbf22018-07-17 07:57:30 -0700141if (NOT "${BMCWEB_INSECURE_DISABLE_SSL}")
Ed Tanousf0d73c22018-07-26 14:24:20 -0700142 add_definitions (-DCROW_ENABLE_SSL)
Andrew Geissler1f2fbf22018-07-17 07:57:30 -0700143endif (NOT "${BMCWEB_INSECURE_DISABLE_SSL}")
Ed Tanous55c7b7a2018-05-22 15:27:24 -0700144include_directories (${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800145
Ed Tanous580f3722018-03-13 16:59:02 -0700146# Zlib
Ed Tanous1e439872018-05-18 11:48:52 -0700147find_package (ZLIB REQUIRED)
148include_directories (${ZLIB_INCLUDE_DIRS})
Ed Tanousf9273472017-02-28 16:05:13 -0800149
Ed Tanous4758d5b2017-06-06 15:28:13 -0700150# PAM
Ed Tanous1e439872018-05-18 11:48:52 -0700151option (WEBSERVER_ENABLE_PAM "enable pam authentication" ON)
152if ("${WEBSERVER_ENABLE_PAM}")
153 find_package (PAM REQUIRED)
154else ()
155 add_definitions ("-DWEBSERVER_DISABLE_PAM")
156endif ()
Ed Tanous911ac312017-08-15 09:37:42 -0700157
Ed Tanousf0d73c22018-07-26 14:24:20 -0700158add_definitions ("-Wno-attributes")
Jennifer Lee03346702018-05-23 14:05:20 -0700159# Copy pam-webserver to etc/pam.d
Ed Tanousf0d73c22018-07-26 14:24:20 -0700160install (
161 FILES ${CMAKE_CURRENT_SOURCE_DIR}/pam-webserver
162 DESTINATION /etc/pam.d/
163 RENAME webserver
164)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800165
Ed tanous7d95f5f2018-03-23 00:19:20 -0700166# tinyxml2
Ed Tanous1e439872018-05-18 11:48:52 -0700167find_package (tinyxml2 REQUIRED)
Ed tanous7d95f5f2018-03-23 00:19:20 -0700168
Ed Tanous1e439872018-05-18 11:48:52 -0700169set (WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700170
Ed Tanous1e439872018-05-18 11:48:52 -0700171include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
172include_directories (${CMAKE_CURRENT_SOURCE_DIR}/redfish-core/include)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700173
Ed Tanous1e439872018-05-18 11:48:52 -0700174file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include/bmcweb)
175configure_file (settings.hpp.in ${CMAKE_BINARY_DIR}/include/bmcweb/settings.hpp)
176include_directories (${CMAKE_BINARY_DIR}/include)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800177
Ed Tanousf0d73c22018-07-26 14:24:20 -0700178set (
179 SRC_FILES redfish-core/src/error_messages.cpp
180 redfish-core/src/utils/json_utils.cpp ${GENERATED_SRC_FILES}
181)
Ed Tanous93f987d2017-04-17 17:52:36 -0700182
Ed Tanous1e439872018-05-18 11:48:52 -0700183file (COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
Ed Tanous911ac312017-08-15 09:37:42 -0700184
Ed Tanous38bdb982017-03-03 14:19:33 -0800185# Unit Tests
Ed Tanous1e439872018-05-18 11:48:52 -0700186if (${BMCWEB_BUILD_UT})
Ed Tanousf0d73c22018-07-26 14:24:20 -0700187 set (
188 UT_FILES src/crow_test.cpp src/gtest_main.cpp
189 src/token_authorization_middleware_test.cpp
190 src/security_headers_middleware_test.cpp src/webassets_test.cpp
191 src/crow_getroutes_test.cpp src/ast_jpeg_decoder_test.cpp
192 src/kvm_websocket_test.cpp src/msan_test.cpp
193 src/ast_video_puller_test.cpp src/openbmc_jtag_rest_test.cpp
194 redfish-core/ut/privileges_test.cpp
195 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
196 ) # big list of naughty strings
197 add_custom_command (
198 OUTPUT ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
199 COMMAND
200 xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns
201 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp
202 )
Ed Tanous1e439872018-05-18 11:48:52 -0700203
Ed Tanousf0d73c22018-07-26 14:24:20 -0700204 set_source_files_properties (
205 ${CMAKE_BINARY_DIR}/include/bmcweb/blns.hpp PROPERTIES GENERATED TRUE
206 )
Ed Tanous1e439872018-05-18 11:48:52 -0700207
208 enable_testing ()
209
210 add_executable (webtest ${SRC_FILES} ${UT_FILES})
211
212 find_package (GTest REQUIRED)
213 find_package (GMock REQUIRED)
214 target_link_libraries (webtest ${GTEST_LIBRARIES})
215 target_link_libraries (webtest ${GMOCK_LIBRARIES})
216
217 target_link_libraries (webtest pthread)
218 target_link_libraries (webtest ${OPENSSL_LIBRARIES})
219 target_link_libraries (webtest ${ZLIB_LIBRARIES})
220 target_link_libraries (webtest pam)
221 target_link_libraries (webtest tinyxml2)
Ed Tanousd425c6f2018-05-16 10:20:11 -0700222 target_link_libraries (webtest sdbusplus)
Ed Tanouse0625902018-05-16 13:35:08 -0700223 target_link_libraries (webtest -lsystemd)
Ed Tanous1e439872018-05-18 11:48:52 -0700224 target_link_libraries (webtest -lstdc++fs)
225 add_test (webtest webtest "--gtest_output=xml:webtest.xml")
226
227endif (${BMCWEB_BUILD_UT})
228
229install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www)
230
231# bmcweb
232add_executable (bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
233target_link_libraries (bmcweb pthread)
234target_link_libraries (bmcweb ${OPENSSL_LIBRARIES})
235target_link_libraries (bmcweb ${ZLIB_LIBRARIES})
236target_link_libraries (bmcweb pam)
237target_link_libraries (bmcweb -lsystemd)
238target_link_libraries (bmcweb -lstdc++fs)
Ed Tanousd425c6f2018-05-16 10:20:11 -0700239target_link_libraries (bmcweb sdbusplus)
Ed Tanous1e439872018-05-18 11:48:52 -0700240target_link_libraries (bmcweb tinyxml2)
241install (TARGETS bmcweb DESTINATION bin)
242
243add_executable (getvideo src/getvideo_main.cpp)
244target_link_libraries (getvideo pthread)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700245
Ed Tanous580f3722018-03-13 16:59:02 -0700246# Visual Studio Code helper this needs to be at the end to make sure all
247# includes are handled correctly
Ed Tanous1e439872018-05-18 11:48:52 -0700248include (CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs)
Ed Tanousf0d73c22018-07-26 14:24:20 -0700249get_property (
250 C_INCLUDE_DIRS
251 DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
252 PROPERTY INCLUDE_DIRECTORIES
253)
Ed Tanous911ac312017-08-15 09:37:42 -0700254
Ed Tanous1e439872018-05-18 11:48:52 -0700255execute_process (
Ed Tanousf0d73c22018-07-26 14:24:20 -0700256 COMMAND
257 python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py
258 ${C_INCLUDE_DIRS} ${CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS}
259 ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS}
Ed Tanous1e439872018-05-18 11:48:52 -0700260)