blob: a0dd0d7e7d1697148d6caef3c4fee782149bac7b [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 Tanous911ac312017-08-15 09:37:42 -070027SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Werror -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)
Ed Tanousb4d29f42017-03-24 16:39:25 -070095
Ed Tanous904063f2017-03-02 16:48:24 -080096set(SRC_FILES
Ed Tanousf9273472017-02-28 16:05:13 -080097 src/base64.cpp
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
110 src/base64_test.cpp
111 src/token_authorization_middleware_test.cpp
112 src/security_headers_middleware_test.cpp
113 src/webassets_test.cpp
114 src/crow_getroutes_test.cpp
115 src/ast_jpeg_decoder_test.cpp
116 src/kvm_websocket_test.cpp
117 src/msan_test.cpp
118 src/ci_map_tests.cpp
119 src/ast_video_puller_test.cpp
120 ${CMAKE_BINARY_DIR}/generated/blns.hpp
121 )
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800122 # big list of naughty strings
123 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700124 COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns ${CMAKE_BINARY_DIR}/generated/blns.hpp)
Ed Tanous911ac312017-08-15 09:37:42 -0700125
126 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/blns.hpp
127 PROPERTIES GENERATED TRUE)
Ed Tanous38bdb982017-03-03 14:19:33 -0800128 # googletest
129 enable_testing()
Ed Tanous4c3cbc62017-05-16 09:17:42 -0700130
Ed Tanous911ac312017-08-15 09:37:42 -0700131 hunter_add_package(GTest)
132 find_package(GTest REQUIRED)
Ed Tanous01250f22017-04-18 17:49:51 -0700133 #find_package(GMock CONFIG REQUIRED)
Ed Tanous38bdb982017-03-03 14:19:33 -0800134
Ed Tanous911ac312017-08-15 09:37:42 -0700135 add_executable(webtest ${SRC_FILES} ${UT_FILES})
Ed Tanousc9b55212017-06-12 13:25:51 -0700136 target_link_libraries(webtest gmock gtest)
137 target_link_libraries(webtest pthread)
Ed Tanous911ac312017-08-15 09:37:42 -0700138 target_link_libraries(webtest boost-dbus)
Ed Tanousc9b55212017-06-12 13:25:51 -0700139 target_link_libraries(webtest ${OPENSSL_LIBRARIES})
140 target_link_libraries(webtest ${ZLIB_LIBRARIES})
141 target_link_libraries(webtest pam)
Ed Tanous911ac312017-08-15 09:37:42 -0700142 add_dependencies(webtest tinyxml2_static)
143 target_link_libraries(webtest tinyxml2_static)
144 target_link_libraries(webtest -lstdc++fs)
Ed Tanousc9b55212017-06-12 13:25:51 -0700145 add_test(webtest webtest "--gtest_output=xml:webtest.xml")
146
Ed Tanous911ac312017-08-15 09:37:42 -0700147endif(${BMCWEB_BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800148
Ed Tanous710adfc2017-10-24 17:04:52 -0700149install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/static/ DESTINATION share/www)
150
Ed Tanousf9273472017-02-28 16:05:13 -0800151# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800152add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous911ac312017-08-15 09:37:42 -0700153target_link_libraries(bmcweb boost-dbus)
Ed Tanous01250f22017-04-18 17:49:51 -0700154target_link_libraries(bmcweb pthread)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700155target_link_libraries(bmcweb ${OPENSSL_LIBRARIES})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800156target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanous4758d5b2017-06-06 15:28:13 -0700157target_link_libraries(bmcweb pam)
Ed Tanous911ac312017-08-15 09:37:42 -0700158target_link_libraries(bmcweb -lstdc++fs)
159add_dependencies(bmcweb tinyxml2_static)
160target_link_libraries(bmcweb tinyxml2_static)
161install(TARGETS bmcweb DESTINATION bin)
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700162
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700163add_executable(getvideo src/getvideo_main.cpp)
Ed Tanous01250f22017-04-18 17:49:51 -0700164target_link_libraries(getvideo pthread)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700165
Ed Tanous38bdb982017-03-03 14:19:33 -0800166# Visual Studio Code helper
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800167# this needs to be at the end to make sure all includes are handled correctly
Ed Tanous911ac312017-08-15 09:37:42 -0700168include(CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800169get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
Ed Tanous911ac312017-08-15 09:37:42 -0700170
171execute_process(
172 COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py
173 ${C_INCLUDE_DIRS}
174 ${CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS}
175 ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS}
176)