blob: 5cb1a04ddffc68ddb85e1887e981d5e123df19c4 [file] [log] [blame]
Ed tanous7d95f5f2018-03-23 00:19:20 -07001cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
Ed Tanous0fdddb12017-02-28 11:06:34 -08002
Ed Tanouscfbe25d2017-05-23 16:34:35 -07003cmake_policy(SET CMP0054 NEW)
4
Ed Tanous0fdddb12017-02-28 11:06:34 -08005set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
6
Ed Tanous911ac312017-08-15 09:37:42 -07007option(BUILD_STATIC_LIBS "Built static libraries" ON)
Ed Tanous465b12a2018-02-06 16:30:36 -08008option(YOCTO_DEPENDENCIES "Use YOCTO depedencies system" OFF)
Ed Tanous911ac312017-08-15 09:37:42 -07009
Ed tanous7d95f5f2018-03-23 00:19:20 -070010project(bmc-webserver CXX)
Ed Tanous0fdddb12017-02-28 11:06:34 -080011
Ed Tanous580f3722018-03-13 16:59:02 -070012include(CTest)
Ed Tanousf3d847c2017-06-12 16:01:42 -070013
Ed Tanous0fdddb12017-02-28 11:06:34 -080014set(CMAKE_CXX_STANDARD 14)
15set(CMAKE_CXX_STANDARD_REQUIRED ON)
16
17set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
18
Ed Tanousc963aa42017-10-27 16:00:19 -070019SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall")
Ed Tanous0d485ef2017-05-23 09:23:53 -070020
Ed Tanous3dac7492017-08-02 13:46:20 -070021SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
22SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
23
Ed Tanous0fdddb12017-02-28 11:06:34 -080024# general
Ed Tanous911ac312017-08-15 09:37:42 -070025option(BMCWEB_BUILD_UT "Enable Unit test" ON)
Ed Tanous8041f312017-04-03 09:47:01 -070026
Ed Tanous1ccd57c2017-03-21 13:15:58 -070027# security flags
Ed Tanous580f3722018-03-13 16:59:02 -070028SET(
29 SECURITY_FLAGS
30 "\
31 -fstack-protector-strong \
32 -fPIE \
33 -fPIC \
34 -D_FORTIFY_SOURCE=2 \
35 -Wformat \
36 -Wformat-security"
37 )
38SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SECURITY_FLAGS}")
39SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO
40 "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SECURITY_FLAGS}")
41SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}")
Ed Tanous3dac7492017-08-02 13:46:20 -070042
Ed Tanous580f3722018-03-13 16:59:02 -070043# Enable link time optimization This is a temporary workaround because
44# INTERPROCEDURAL_OPTIMIZATION isn't available until cmake 3.9. gcc-ar and gcc-
45# ranlib are wrappers around ar and ranlib which add the lto plugin to the
46# command line.
47if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Ed Tanousac093312018-03-16 13:53:05 -070048 if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
Borawski.Lukasz109799e2018-01-30 15:04:42 +010049 STRING(REGEX REPLACE "ar$" "gcc-ar" CMAKE_AR ${CMAKE_AR})
50 STRING(REGEX REPLACE "ranlib$" "gcc-ranlib" CMAKE_RANLIB ${CMAKE_RANLIB})
51 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -fno-fat-lto-objects")
52
Ed Tanous580f3722018-03-13 16:59:02 -070053 # Reduce the binary size by removing unnecessary dynamic symbol table
54 # entries
55 SET(
56 CMAKE_CXX_FLAGS
57 "${CMAKE_CXX_FLAGS} \
58 -fvisibility=hidden \
59 -fvisibility-inlines-hidden \
60 -Wl,--exclude-libs,ALL"
61 )
Ed Tanousac093312018-03-16 13:53:05 -070062 endif(NOT CMAKE_BUILD_TYPE MATCHES Debug)
Ed Tanous580f3722018-03-13 16:59:02 -070063endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Borawski.Lukasz109799e2018-01-30 15:04:42 +010064
Ed tanous7d95f5f2018-03-23 00:19:20 -070065if(NOT ${YOCTO_DEPENDENCIES}) # Download and unpack googletest at configure time
Ed Tanousaa2e59c2018-04-12 12:17:20 -070066 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.in
67 3rdparty/CMakeLists.txt)
Ed tanous7d95f5f2018-03-23 00:19:20 -070068 execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
69 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty)
70 execute_process(COMMAND ${CMAKE_COMMAND} --build .
71 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty)
72
73 set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/prefix ${CMAKE_PREFIX_PATH})
74endif()
75
Ed Tanous580f3722018-03-13 16:59:02 -070076# add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanous01250f22017-04-18 17:49:51 -070077add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
78add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080079add_definitions(-DBOOST_ALL_NO_LIB)
Ed Tanous3dac7492017-08-02 13:46:20 -070080add_definitions(-DBOOST_NO_RTTI)
81add_definitions(-DBOOST_NO_TYPEID)
Ed tanous7d95f5f2018-03-23 00:19:20 -070082
Ed Tanouse0d918b2018-03-27 17:41:04 -070083find_package(Boost 1.66 REQUIRED)
84include_directories(${BOOST_SRC_DIR})
Ed Tanousaa2e59c2018-04-12 12:17:20 -070085
86# sdbusplus
87if(NOT ${YOCTO_DEPENDENCIES})
88 include_directories(${CMAKE_BINARY_DIR}/sdbusplus-src
89 ${CMAKE_BINARY_DIR}/prefix/include)
90 set(WANT_TRANSACTION 0)
91
92 configure_file(${CMAKE_BINARY_DIR}/sdbusplus-src/sdbusplus/server.hpp.in
93 ${CMAKE_BINARY_DIR}/prefix/include/sdbusplus/server.hpp @ONLY)
94 configure_file(${CMAKE_BINARY_DIR}/sdbusplus-src/sdbusplus/bus.hpp.in
95 ${CMAKE_BINARY_DIR}/prefix/include/sdbusplus/bus.hpp @ONLY)
96endif()
Ed Tanous0fdddb12017-02-28 11:06:34 -080097
Ed Tanous580f3722018-03-13 16:59:02 -070098# Openssl
Ed Tanous0fdddb12017-02-28 11:06:34 -080099find_package(OpenSSL REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700100include_directories(${OPENSSL_INCLUDE_DIR})
Ed Tanous0d485ef2017-05-23 09:23:53 -0700101message("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
Ed Tanous0fdddb12017-02-28 11:06:34 -0800102
Ed Tanousac093312018-03-16 13:53:05 -0700103# Crow
104message("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
105if(CMAKE_BUILD_TYPE MATCHES Debug)
106 message("Logging disabled")
107 add_definitions(-DCROW_ENABLE_LOGGING)
108 add_definitions(-DCROW_ENABLE_DEBUG)
109endif(CMAKE_BUILD_TYPE MATCHES Debug)
110
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700111#add_definitions(-DCROW_ENABLE_LOGGING)
112#add_definitions(-DCROW_ENABLE_DEBUG)
113
Ed Tanous8041f312017-04-03 09:47:01 -0700114add_definitions(-DCROW_ENABLE_SSL)
Ed Tanous580f3722018-03-13 16:59:02 -0700115include_directories(${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800116
Ed Tanous580f3722018-03-13 16:59:02 -0700117# Zlib
Ed Tanous7d3dba42017-04-05 13:04:39 -0700118find_package(ZLIB REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700119include_directories(${ZLIB_INCLUDE_DIRS})
Ed Tanousf9273472017-02-28 16:05:13 -0800120
Ed Tanous4758d5b2017-06-06 15:28:13 -0700121# PAM
Ed Tanous911ac312017-08-15 09:37:42 -0700122option(WEBSERVER_ENABLE_PAM "enable pam authentication" ON)
Ed Tanous580f3722018-03-13 16:59:02 -0700123if("${WEBSERVER_ENABLE_PAM}")
124 find_package(PAM REQUIRED)
Ed Tanous911ac312017-08-15 09:37:42 -0700125else()
Ed Tanous580f3722018-03-13 16:59:02 -0700126 add_definitions("-DWEBSERVER_DISABLE_PAM")
Ed Tanous911ac312017-08-15 09:37:42 -0700127endif()
128
Ed tanous7d95f5f2018-03-23 00:19:20 -0700129add_definitions("-Wno-attributes")
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800130
Ed tanous7d95f5f2018-03-23 00:19:20 -0700131# tinyxml2
132find_package(tinyxml2 REQUIRED)
133
134set(WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700135
Ed Tanous911ac312017-08-15 09:37:42 -0700136include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Borawski.Lukasz86e1b662018-01-19 14:22:14 +0100137include_directories(${CMAKE_CURRENT_SOURCE_DIR}/redfish-core/include)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700138
Kowalski, Kamilf4c4dcf2018-01-29 14:55:35 +0100139set(SRC_FILES
140 redfish-core/src/error_messages.cpp
Kowalski, Kamil77dd8812018-04-03 10:15:14 +0200141 redfish-core/src/utils/json_utils.cpp
Kowalski, Kamilf4c4dcf2018-01-29 14:55:35 +0100142 ${GENERATED_SRC_FILES}
143)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800144
Ed Tanous93f987d2017-04-17 17:52:36 -0700145file(COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
146
Ed Tanous911ac312017-08-15 09:37:42 -0700147file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/generated)
148
Ed Tanous38bdb982017-03-03 14:19:33 -0800149# Unit Tests
Ed Tanous911ac312017-08-15 09:37:42 -0700150if(${BMCWEB_BUILD_UT})
Ed Tanous580f3722018-03-13 16:59:02 -0700151 set(UT_FILES
Ed Tanous580f3722018-03-13 16:59:02 -0700152 src/crow_test.cpp
153 src/gtest_main.cpp
154 src/token_authorization_middleware_test.cpp
155 src/security_headers_middleware_test.cpp
156 src/webassets_test.cpp
157 src/crow_getroutes_test.cpp
158 src/ast_jpeg_decoder_test.cpp
159 src/kvm_websocket_test.cpp
160 src/msan_test.cpp
Ed Tanous580f3722018-03-13 16:59:02 -0700161 src/ast_video_puller_test.cpp
162 ${CMAKE_BINARY_DIR}/generated/blns.hpp) # big list of naughty strings
163 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
164 COMMAND
165 xxd -i
166 ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns
167 ${CMAKE_BINARY_DIR}/generated/blns.hpp)
Ed Tanous4c3cbc62017-05-16 09:17:42 -0700168
Ed Tanous580f3722018-03-13 16:59:02 -0700169 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/blns.hpp
170 PROPERTIES
171 GENERATED
172 TRUE) # googletest
173 enable_testing()
Ed Tanous38bdb982017-03-03 14:19:33 -0800174
Ed Tanous580f3722018-03-13 16:59:02 -0700175 add_executable(webtest ${SRC_FILES} ${UT_FILES})
Ed tanous7d95f5f2018-03-23 00:19:20 -0700176
177 find_package(GTest REQUIRED)
178 find_package(GMock REQUIRED)
179 target_link_libraries(webtest ${GTEST_LIBRARIES})
180 target_link_libraries(webtest ${GMOCK_LIBRARIES})
181
Ed Tanous580f3722018-03-13 16:59:02 -0700182 target_link_libraries(webtest pthread)
Ed Tanous580f3722018-03-13 16:59:02 -0700183 target_link_libraries(webtest ${OPENSSL_LIBRARIES})
184 target_link_libraries(webtest ${ZLIB_LIBRARIES})
185 target_link_libraries(webtest pam)
186 target_link_libraries(webtest tinyxml2)
187 target_link_libraries(webtest -lstdc++fs)
188 add_test(webtest webtest "--gtest_output=xml:webtest.xml")
Ed Tanousc9b55212017-06-12 13:25:51 -0700189
Ed Tanous911ac312017-08-15 09:37:42 -0700190endif(${BMCWEB_BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800191
Ed Tanous710adfc2017-10-24 17:04:52 -0700192install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www)
193
Ed Tanousf9273472017-02-28 16:05:13 -0800194# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800195add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous01250f22017-04-18 17:49:51 -0700196target_link_libraries(bmcweb pthread)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700197target_link_libraries(bmcweb ${OPENSSL_LIBRARIES})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800198target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanous4758d5b2017-06-06 15:28:13 -0700199target_link_libraries(bmcweb pam)
Vernon Mauery168792a2018-01-26 13:42:54 -0800200target_link_libraries(bmcweb -lsystemd)
Ed Tanous911ac312017-08-15 09:37:42 -0700201target_link_libraries(bmcweb -lstdc++fs)
Borawski.Lukasz109799e2018-01-30 15:04:42 +0100202target_link_libraries(bmcweb tinyxml2)
Ed Tanousaa2e59c2018-04-12 12:17:20 -0700203target_link_libraries(bmcweb sdbusplus)
Ed Tanous911ac312017-08-15 09:37:42 -0700204install(TARGETS bmcweb DESTINATION bin)
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700205
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700206add_executable(getvideo src/getvideo_main.cpp)
Ed Tanous01250f22017-04-18 17:49:51 -0700207target_link_libraries(getvideo pthread)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700208
Ed Tanous580f3722018-03-13 16:59:02 -0700209# Visual Studio Code helper this needs to be at the end to make sure all
210# includes are handled correctly
Ed Tanous911ac312017-08-15 09:37:42 -0700211include(CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs)
Ed Tanous580f3722018-03-13 16:59:02 -0700212get_property(C_INCLUDE_DIRS
213 DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
214 PROPERTY INCLUDE_DIRECTORIES)
Ed Tanous911ac312017-08-15 09:37:42 -0700215
Ed Tanous580f3722018-03-13 16:59:02 -0700216execute_process(COMMAND
217 python3
218 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py
219 ${C_INCLUDE_DIRS}
220 ${CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS}
221 ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS})