blob: cccc3c03326aa42093851f789e1903a7e910bf5f [file] [log] [blame]
Ed Tanous0fdddb12017-02-28 11:06:34 -08001cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR)
2
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})
Ed Tanous911ac312017-08-15 09:37:42 -07006message(CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH})
Ed Tanous0fdddb12017-02-28 11:06:34 -08007
Ed Tanous911ac312017-08-15 09:37:42 -07008option(BUILD_STATIC_LIBS "Built static libraries" ON)
Ed Tanous465b12a2018-02-06 16:30:36 -08009option(YOCTO_DEPENDENCIES "Use YOCTO depedencies system" OFF)
Ed Tanous2d02dcd2017-05-15 12:25:30 -070010option(HUNTER_ENABLED "Enable hunter package pulling" OFF)
Ed Tanous911ac312017-08-15 09:37:42 -070011
Ed Tanous1ccd57c2017-03-21 13:15:58 -070012include("cmake/HunterGate.cmake")
Ed Tanous0fdddb12017-02-28 11:06:34 -080013HunterGate(
Ed Tanouscfbe25d2017-05-23 16:34:35 -070014 URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz"
15 SHA1 "baf9c8cc4f65306f0e442b5419967b4c4c04589a"
Ed Tanous0fdddb12017-02-28 11:06:34 -080016)
17
Ed Tanous0fdddb12017-02-28 11:06:34 -080018project(bmc-webserver CXX C)
19
Ed Tanousf3d847c2017-06-12 16:01:42 -070020include( CTest )
21
Ed Tanous0fdddb12017-02-28 11:06:34 -080022set(CMAKE_CXX_STANDARD 14)
23set(CMAKE_CXX_STANDARD_REQUIRED ON)
24
25set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
26
Ed Tanousc963aa42017-10-27 16:00:19 -070027SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall")
Ed Tanous0d485ef2017-05-23 09:23:53 -070028
Ed Tanous3dac7492017-08-02 13:46:20 -070029SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
30SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
31
Ed Tanous0fdddb12017-02-28 11:06:34 -080032# general
Ed Tanous911ac312017-08-15 09:37:42 -070033option(BMCWEB_BUILD_UT "Enable Unit test" ON)
Ed Tanous8041f312017-04-03 09:47:01 -070034
Ed Tanous1ccd57c2017-03-21 13:15:58 -070035# security flags
Ed Tanous911ac312017-08-15 09:37:42 -070036SET(SECURITY_FLAGS " -fstack-protector-strong -fPIE -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security")
37SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SECURITY_FLAGS}" )
38SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SECURITY_FLAGS}" )
Ed Tanous7f935f82018-01-25 11:40:21 -080039SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}" )
Ed Tanous3dac7492017-08-02 13:46:20 -070040
Borawski.Lukasz109799e2018-01-30 15:04:42 +010041if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
42 # Enable link time optimization
43 # This is a temporary workaround because INTERPROCEDURAL_OPTIMIZATION isn't available until cmake 3.9.
44 # gcc-ar and gcc-ranlib are wrappers around ar and ranlib which add the lto plugin to the command line.
45 STRING(REGEX REPLACE "ar$" "gcc-ar" CMAKE_AR ${CMAKE_AR})
46 STRING(REGEX REPLACE "ranlib$" "gcc-ranlib" CMAKE_RANLIB ${CMAKE_RANLIB})
47 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -fno-fat-lto-objects")
48
49 # Reduce the binary size by removing unnecessary dynamic symbol table entries
50 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -Wl,--exclude-libs,ALL")
51endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
52
Borawski.Lukasz6aa32622018-01-30 15:04:42 +010053if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
54 # Enable link time optimization
55 # This is a temporary workaround because INTERPROCEDURAL_OPTIMIZATION isn't available until cmake 3.9.
56 # gcc-ar and gcc-ranlib are wrappers around ar and ranlib which add the lto plugin to the command line.
57 STRING(REGEX REPLACE "ar$" "gcc-ar" CMAKE_AR ${CMAKE_AR})
58 STRING(REGEX REPLACE "ranlib$" "gcc-ranlib" CMAKE_RANLIB ${CMAKE_RANLIB})
59 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -fno-fat-lto-objects")
60
61 # Reduce the binary size by removing unnecessary dynamic symbol table entries
62 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -Wl,--exclude-libs,ALL")
63endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
64
Ed Tanous1ccd57c2017-03-21 13:15:58 -070065#add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanous01250f22017-04-18 17:49:51 -070066add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
67add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080068add_definitions(-DBOOST_ALL_NO_LIB)
Ed Tanous3dac7492017-08-02 13:46:20 -070069add_definitions(-DBOOST_NO_RTTI)
70add_definitions(-DBOOST_NO_TYPEID)
Ed Tanous0d485ef2017-05-23 09:23:53 -070071#set(Boost_USE_STATIC_LIBS ON)
Ed Tanouseb1b8622017-04-25 14:11:46 -070072hunter_add_package(Boost)
Ed Tanous911ac312017-08-15 09:37:42 -070073find_package(Boost)
Ed Tanouse2fc45a2017-04-26 09:19:10 -070074include_directories(${Boost_INCLUDE_DIRS})
Ed Tanous0fdddb12017-02-28 11:06:34 -080075
76#Openssl
Ed Tanous2d02dcd2017-05-15 12:25:30 -070077hunter_add_package(OpenSSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -080078find_package(OpenSSL REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -070079include_directories(${OPENSSL_INCLUDE_DIR})
Ed Tanous0d485ef2017-05-23 09:23:53 -070080message("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
Ed Tanous0fdddb12017-02-28 11:06:34 -080081
Ed Tanous8041f312017-04-03 09:47:01 -070082# Crow
Ed Tanous4c3cbc62017-05-16 09:17:42 -070083#add_definitions(-DCROW_DISABLE_LOGGING)
Ed Tanous8041f312017-04-03 09:47:01 -070084add_definitions(-DCROW_ENABLE_SSL)
85include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -080086
Ed Tanous9b65f1f2017-03-07 15:17:13 -080087#Zlib
Ed Tanous7d3dba42017-04-05 13:04:39 -070088hunter_add_package(ZLIB)
89find_package(ZLIB REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -070090include_directories(${ZLIB_INCLUDE_DIRS})
Ed Tanousf9273472017-02-28 16:05:13 -080091
Ed Tanous911ac312017-08-15 09:37:42 -070092#tinyxml2
Ed Tanous465b12a2018-02-06 16:30:36 -080093if(NOT ${YOCTO_DEPENDENCIES})
94 add_subdirectory(tinyxml2)
95else()
96 find_package(tinyxml2 REQUIRED)
97endif()
Ed Tanous4758d5b2017-06-06 15:28:13 -070098# PAM
Ed Tanous911ac312017-08-15 09:37:42 -070099option(WEBSERVER_ENABLE_PAM "enable pam authentication" ON)
100if ("${WEBSERVER_ENABLE_PAM}")
101 find_package(PAM REQUIRED)
102else()
103 add_definitions("-DWEBSERVER_DISABLE_PAM")
104endif()
105
Ed Tanous4758d5b2017-06-06 15:28:13 -0700106
Ed Tanousc9b55212017-06-12 13:25:51 -0700107# Boost-dbus
Ed Tanous911ac312017-08-15 09:37:42 -0700108set(BOOST_DBUS_BUILD_UT ${BMCWEB_BUILD_UT})
Ed Tanous465b12a2018-02-06 16:30:36 -0800109if(NOT ${YOCTO_DEPENDENCIES})
110 add_subdirectory(boost-dbus)
111else()
112 find_package(boost-dbus REQUIRED)
113endif()
Ed Tanousf9273472017-02-28 16:05:13 -0800114set(WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800115
Ed Tanous12a002d2017-05-15 11:59:16 -0700116# the webassets file has a non-ideal beahvior, where it loads binary data into a std::string
117# due to the way crow is constructed. This causes GCC warnings. Filter them out.
Ed Tanousb4d29f42017-03-24 16:39:25 -0700118if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Ed Tanous12a002d2017-05-15 11:59:16 -0700119 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700120 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-narrowing)
Ed Tanous12a002d2017-05-15 11:59:16 -0700121 endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700122endif()
123
Ed Tanous911ac312017-08-15 09:37:42 -0700124include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Borawski.Lukasz86e1b662018-01-19 14:22:14 +0100125include_directories(${CMAKE_CURRENT_SOURCE_DIR}/redfish-core/include)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700126
Ed Tanous904063f2017-03-02 16:48:24 -0800127set(SRC_FILES
Ed Tanous904063f2017-03-02 16:48:24 -0800128 ${GENERATED_SRC_FILES}
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800129)
130
Ed Tanous93f987d2017-04-17 17:52:36 -0700131file(COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
132
Ed Tanous911ac312017-08-15 09:37:42 -0700133file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/generated)
134
Ed Tanous38bdb982017-03-03 14:19:33 -0800135# Unit Tests
Ed Tanous911ac312017-08-15 09:37:42 -0700136if(${BMCWEB_BUILD_UT})
137 set(UT_FILES
Borawski.Lukaszaecb47a2018-01-25 12:14:14 +0100138 redfish-core/ut/privileges_test.cpp
Ed Tanous911ac312017-08-15 09:37:42 -0700139 src/crow_test.cpp
140 src/gtest_main.cpp
Ed Tanous911ac312017-08-15 09:37:42 -0700141 src/token_authorization_middleware_test.cpp
142 src/security_headers_middleware_test.cpp
143 src/webassets_test.cpp
144 src/crow_getroutes_test.cpp
145 src/ast_jpeg_decoder_test.cpp
146 src/kvm_websocket_test.cpp
147 src/msan_test.cpp
148 src/ci_map_tests.cpp
149 src/ast_video_puller_test.cpp
150 ${CMAKE_BINARY_DIR}/generated/blns.hpp
151 )
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800152 # big list of naughty strings
153 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700154 COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns ${CMAKE_BINARY_DIR}/generated/blns.hpp)
Ed Tanous911ac312017-08-15 09:37:42 -0700155
156 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/blns.hpp
157 PROPERTIES GENERATED TRUE)
Ed Tanous38bdb982017-03-03 14:19:33 -0800158 # googletest
159 enable_testing()
Ed Tanous4c3cbc62017-05-16 09:17:42 -0700160
Ed Tanous911ac312017-08-15 09:37:42 -0700161 hunter_add_package(GTest)
162 find_package(GTest REQUIRED)
Ed Tanous01250f22017-04-18 17:49:51 -0700163 #find_package(GMock CONFIG REQUIRED)
Ed Tanous38bdb982017-03-03 14:19:33 -0800164
Ed Tanous911ac312017-08-15 09:37:42 -0700165 add_executable(webtest ${SRC_FILES} ${UT_FILES})
Ed Tanousc9b55212017-06-12 13:25:51 -0700166 target_link_libraries(webtest gmock gtest)
167 target_link_libraries(webtest pthread)
Ed Tanous911ac312017-08-15 09:37:42 -0700168 target_link_libraries(webtest boost-dbus)
Ed Tanousc9b55212017-06-12 13:25:51 -0700169 target_link_libraries(webtest ${OPENSSL_LIBRARIES})
170 target_link_libraries(webtest ${ZLIB_LIBRARIES})
171 target_link_libraries(webtest pam)
Borawski.Lukasz109799e2018-01-30 15:04:42 +0100172 target_link_libraries(webtest tinyxml2)
Ed Tanous911ac312017-08-15 09:37:42 -0700173 target_link_libraries(webtest -lstdc++fs)
Ed Tanousc9b55212017-06-12 13:25:51 -0700174 add_test(webtest webtest "--gtest_output=xml:webtest.xml")
175
Ed Tanous911ac312017-08-15 09:37:42 -0700176endif(${BMCWEB_BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800177
Ed Tanous710adfc2017-10-24 17:04:52 -0700178install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www)
179
Ed Tanousf9273472017-02-28 16:05:13 -0800180# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800181add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous911ac312017-08-15 09:37:42 -0700182target_link_libraries(bmcweb boost-dbus)
Ed Tanous01250f22017-04-18 17:49:51 -0700183target_link_libraries(bmcweb pthread)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700184target_link_libraries(bmcweb ${OPENSSL_LIBRARIES})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800185target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanous4758d5b2017-06-06 15:28:13 -0700186target_link_libraries(bmcweb pam)
Vernon Mauery168792a2018-01-26 13:42:54 -0800187target_link_libraries(bmcweb -lsystemd)
Ed Tanous911ac312017-08-15 09:37:42 -0700188target_link_libraries(bmcweb -lstdc++fs)
Borawski.Lukasz109799e2018-01-30 15:04:42 +0100189target_link_libraries(bmcweb tinyxml2)
Ed Tanous911ac312017-08-15 09:37:42 -0700190install(TARGETS bmcweb DESTINATION bin)
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700191
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700192add_executable(getvideo src/getvideo_main.cpp)
Ed Tanous01250f22017-04-18 17:49:51 -0700193target_link_libraries(getvideo pthread)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700194
Ed Tanous38bdb982017-03-03 14:19:33 -0800195# Visual Studio Code helper
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800196# this needs to be at the end to make sure all includes are handled correctly
Ed Tanous911ac312017-08-15 09:37:42 -0700197include(CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800198get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
Ed Tanous911ac312017-08-15 09:37:42 -0700199
200execute_process(
201 COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py
202 ${C_INCLUDE_DIRS}
203 ${CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS}
204 ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS}
205)