blob: e9cfad7737278f244f71eee04bd64934df818dbb [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 Tanous0fdddb12017-02-28 11:06:34 -08009
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}" )
39SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${SECURITY_FLAGS}" )
Ed Tanous3dac7492017-08-02 13:46:20 -070040
Ed Tanous1ccd57c2017-03-21 13:15:58 -070041#add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanous01250f22017-04-18 17:49:51 -070042add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
43add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080044add_definitions(-DBOOST_ALL_NO_LIB)
Ed Tanous3dac7492017-08-02 13:46:20 -070045add_definitions(-DBOOST_NO_RTTI)
46add_definitions(-DBOOST_NO_TYPEID)
Ed Tanous0d485ef2017-05-23 09:23:53 -070047#set(Boost_USE_STATIC_LIBS ON)
Ed Tanouseb1b8622017-04-25 14:11:46 -070048hunter_add_package(Boost)
Ed Tanous911ac312017-08-15 09:37:42 -070049find_package(Boost)
Ed Tanouse2fc45a2017-04-26 09:19:10 -070050include_directories(${Boost_INCLUDE_DIRS})
Ed Tanous0fdddb12017-02-28 11:06:34 -080051
52#Openssl
Ed Tanous2d02dcd2017-05-15 12:25:30 -070053hunter_add_package(OpenSSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -080054find_package(OpenSSL REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -070055include_directories(${OPENSSL_INCLUDE_DIR})
Ed Tanous0d485ef2017-05-23 09:23:53 -070056message("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
Ed Tanous0fdddb12017-02-28 11:06:34 -080057
Ed Tanous8041f312017-04-03 09:47:01 -070058# Crow
Ed Tanous4c3cbc62017-05-16 09:17:42 -070059#add_definitions(-DCROW_DISABLE_LOGGING)
Ed Tanous8041f312017-04-03 09:47:01 -070060add_definitions(-DCROW_ENABLE_SSL)
61include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -080062
Ed Tanous9b65f1f2017-03-07 15:17:13 -080063#Zlib
Ed Tanous7d3dba42017-04-05 13:04:39 -070064hunter_add_package(ZLIB)
65find_package(ZLIB REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -070066include_directories(${ZLIB_INCLUDE_DIRS})
Ed Tanousf9273472017-02-28 16:05:13 -080067
Ed Tanous911ac312017-08-15 09:37:42 -070068#tinyxml2
69add_subdirectory(tinyxml2)
Ed Tanous4758d5b2017-06-06 15:28:13 -070070
71# PAM
Ed Tanous911ac312017-08-15 09:37:42 -070072option(WEBSERVER_ENABLE_PAM "enable pam authentication" ON)
73if ("${WEBSERVER_ENABLE_PAM}")
74 find_package(PAM REQUIRED)
75else()
76 add_definitions("-DWEBSERVER_DISABLE_PAM")
77endif()
78
Ed Tanous4758d5b2017-06-06 15:28:13 -070079
Ed Tanousc9b55212017-06-12 13:25:51 -070080# Boost-dbus
Ed Tanous911ac312017-08-15 09:37:42 -070081set(BOOST_DBUS_BUILD_UT ${BMCWEB_BUILD_UT})
82add_subdirectory(boost-dbus)
Ed Tanousc9b55212017-06-12 13:25:51 -070083
Ed Tanousf9273472017-02-28 16:05:13 -080084set(WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanous5f34a9c2017-02-28 12:35:13 -080085
Ed Tanous12a002d2017-05-15 11:59:16 -070086# the webassets file has a non-ideal beahvior, where it loads binary data into a std::string
87# due to the way crow is constructed. This causes GCC warnings. Filter them out.
Ed Tanousb4d29f42017-03-24 16:39:25 -070088if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Ed Tanous12a002d2017-05-15 11:59:16 -070089 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
Ed Tanousb4d29f42017-03-24 16:39:25 -070090 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-narrowing)
Ed Tanous12a002d2017-05-15 11:59:16 -070091 endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
Ed Tanousb4d29f42017-03-24 16:39:25 -070092endif()
93
Ed Tanous911ac312017-08-15 09:37:42 -070094include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Borawski.Lukasz86e1b662018-01-19 14:22:14 +010095include_directories(${CMAKE_CURRENT_SOURCE_DIR}/redfish-core/include)
Ed Tanousb4d29f42017-03-24 16:39:25 -070096
Ed Tanous904063f2017-03-02 16:48:24 -080097set(SRC_FILES
Ed Tanous904063f2017-03-02 16:48:24 -080098 ${GENERATED_SRC_FILES}
Ed Tanous5f34a9c2017-02-28 12:35:13 -080099)
100
Ed Tanous93f987d2017-04-17 17:52:36 -0700101file(COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
102
Ed Tanous911ac312017-08-15 09:37:42 -0700103file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/generated)
104
Ed Tanous38bdb982017-03-03 14:19:33 -0800105# Unit Tests
Ed Tanous911ac312017-08-15 09:37:42 -0700106if(${BMCWEB_BUILD_UT})
107 set(UT_FILES
108 src/crow_test.cpp
109 src/gtest_main.cpp
Ed Tanous911ac312017-08-15 09:37:42 -0700110 src/token_authorization_middleware_test.cpp
111 src/security_headers_middleware_test.cpp
112 src/webassets_test.cpp
113 src/crow_getroutes_test.cpp
114 src/ast_jpeg_decoder_test.cpp
115 src/kvm_websocket_test.cpp
116 src/msan_test.cpp
117 src/ci_map_tests.cpp
118 src/ast_video_puller_test.cpp
119 ${CMAKE_BINARY_DIR}/generated/blns.hpp
120 )
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800121 # big list of naughty strings
122 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700123 COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns ${CMAKE_BINARY_DIR}/generated/blns.hpp)
Ed Tanous911ac312017-08-15 09:37:42 -0700124
125 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/blns.hpp
126 PROPERTIES GENERATED TRUE)
Ed Tanous38bdb982017-03-03 14:19:33 -0800127 # googletest
128 enable_testing()
Ed Tanous4c3cbc62017-05-16 09:17:42 -0700129
Ed Tanous911ac312017-08-15 09:37:42 -0700130 hunter_add_package(GTest)
131 find_package(GTest REQUIRED)
Ed Tanous01250f22017-04-18 17:49:51 -0700132 #find_package(GMock CONFIG REQUIRED)
Ed Tanous38bdb982017-03-03 14:19:33 -0800133
Ed Tanous911ac312017-08-15 09:37:42 -0700134 add_executable(webtest ${SRC_FILES} ${UT_FILES})
Ed Tanousc9b55212017-06-12 13:25:51 -0700135 target_link_libraries(webtest gmock gtest)
136 target_link_libraries(webtest pthread)
Ed Tanous911ac312017-08-15 09:37:42 -0700137 target_link_libraries(webtest boost-dbus)
Ed Tanousc9b55212017-06-12 13:25:51 -0700138 target_link_libraries(webtest ${OPENSSL_LIBRARIES})
139 target_link_libraries(webtest ${ZLIB_LIBRARIES})
140 target_link_libraries(webtest pam)
Ed Tanous911ac312017-08-15 09:37:42 -0700141 add_dependencies(webtest tinyxml2_static)
142 target_link_libraries(webtest tinyxml2_static)
143 target_link_libraries(webtest -lstdc++fs)
Ed Tanousc9b55212017-06-12 13:25:51 -0700144 add_test(webtest webtest "--gtest_output=xml:webtest.xml")
145
Ed Tanous911ac312017-08-15 09:37:42 -0700146endif(${BMCWEB_BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800147
Ed Tanous710adfc2017-10-24 17:04:52 -0700148install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www)
149
Ed Tanousf9273472017-02-28 16:05:13 -0800150# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800151add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous911ac312017-08-15 09:37:42 -0700152target_link_libraries(bmcweb boost-dbus)
Ed Tanous01250f22017-04-18 17:49:51 -0700153target_link_libraries(bmcweb pthread)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700154target_link_libraries(bmcweb ${OPENSSL_LIBRARIES})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800155target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanous4758d5b2017-06-06 15:28:13 -0700156target_link_libraries(bmcweb pam)
Ed Tanous911ac312017-08-15 09:37:42 -0700157target_link_libraries(bmcweb -lstdc++fs)
158add_dependencies(bmcweb tinyxml2_static)
159target_link_libraries(bmcweb tinyxml2_static)
160install(TARGETS bmcweb DESTINATION bin)
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700161
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700162add_executable(getvideo src/getvideo_main.cpp)
Ed Tanous01250f22017-04-18 17:49:51 -0700163target_link_libraries(getvideo pthread)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700164
Ed Tanous38bdb982017-03-03 14:19:33 -0800165# Visual Studio Code helper
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800166# this needs to be at the end to make sure all includes are handled correctly
Ed Tanous911ac312017-08-15 09:37:42 -0700167include(CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800168get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
Ed Tanous911ac312017-08-15 09:37:42 -0700169
170execute_process(
171 COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py
172 ${C_INCLUDE_DIRS}
173 ${CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS}
174 ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS}
175)