blob: 1c4435eec5b6ac1fe4124e72be13d1299a6f21ec [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})
6
7message("${CMAKE_MODULE_PATH}")
8
Ed Tanous93f987d2017-04-17 17:52:36 -07009SET(BUILD_SHARED_LIBRARIES OFF)
10
Ed Tanous9b65f1f2017-03-07 15:17:13 -080011#SET(HUNTER_STATUS_DEBUG ON)
Ed Tanous2d02dcd2017-05-15 12:25:30 -070012option(HUNTER_ENABLED "Enable hunter package pulling" OFF)
Ed Tanousa1e077c2017-04-25 12:42:19 -070013#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
14#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
Ed Tanous1ccd57c2017-03-21 13:15:58 -070015include("cmake/HunterGate.cmake")
Ed Tanous0fdddb12017-02-28 11:06:34 -080016HunterGate(
Ed Tanouscfbe25d2017-05-23 16:34:35 -070017 URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz"
18 SHA1 "baf9c8cc4f65306f0e442b5419967b4c4c04589a"
Ed Tanous0fdddb12017-02-28 11:06:34 -080019)
20
Ed Tanous0fdddb12017-02-28 11:06:34 -080021project(bmc-webserver CXX C)
22
Ed Tanousf3d847c2017-06-12 16:01:42 -070023include( CTest )
24
Ed Tanous0fdddb12017-02-28 11:06:34 -080025set(CMAKE_CXX_STANDARD 14)
26set(CMAKE_CXX_STANDARD_REQUIRED ON)
27
28set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
29
Ed Tanouseb1b8622017-04-25 14:11:46 -070030if (MSAN)
31 if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
32 message(FATAL_ERROR "Cannot enable MSAN unless using Clang")
33 endif()
34
35 if (ASAN)
36 message(FATAL_ERROR "ASAN and MSAN are mutually exclusive")
37 endif()
38
39 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSAN_CXX_FLAGS}")
40 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSAN_LINKER_EXE_FLAGS}")
41
42 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
43 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
44 set(OPENSSL_NO_ASM "1")
45 set(LIBC++ ON)
Ed Tanousf0226cd2017-05-16 12:35:38 -070046endif(MSAN)
Ed Tanouseb1b8622017-04-25 14:11:46 -070047
48if (ASAN)
49 if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
50 message(FATAL_ERROR "Cannot enable ASAN unless using Clang")
51 endif()
52
53 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
54 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
55 set(OPENSSL_NO_ASM "1")
Ed Tanousf0226cd2017-05-16 12:35:38 -070056endif(ASAN)
Ed Tanouseb1b8622017-04-25 14:11:46 -070057
58if (GCOV)
59 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
60 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
Ed Tanousf0226cd2017-05-16 12:35:38 -070061endif(GCOV)
Ed Tanouseb1b8622017-04-25 14:11:46 -070062
Ed Tanous0fdddb12017-02-28 11:06:34 -080063if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
64 message( FATAL_ERROR "In-source builds not allowed. Please make a new directory (usually called build) and run CMake from there. You may need to remove CMakeCache.txt." )
65endif()
66
Ed Tanouseb1b8622017-04-25 14:11:46 -070067if(LIBC++)
68 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
69 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
70 if (MSAN)
71 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/home/ed/libcxx_msan/include -I/home/ed/libcxx_msan/include/c++/v1")
72 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/home/ed/libcxx_msan/lib -Wl,-rpath,I/home/ed/libcxx_msan/lib")
73 endif(MSAN)
74endif(LIBC++)
75
Ed Tanous0d485ef2017-05-23 09:23:53 -070076#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall")
77
Ed Tanous0fdddb12017-02-28 11:06:34 -080078# general
Ed Tanous38bdb982017-03-03 14:19:33 -080079option(BUILD_SHARED_LIBS "Build as shared library" OFF)
Ed Tanous93f987d2017-04-17 17:52:36 -070080option(BUILD_UT "Enable Unit test" ON)
Ed Tanous0fdddb12017-02-28 11:06:34 -080081
Ed Tanous8041f312017-04-03 09:47:01 -070082# This needs to be before the crow and other module includes so headers get overriden correctly
83include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
84
Ed Tanous1ccd57c2017-03-21 13:15:58 -070085# security flags
86#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong -fPIE -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security" )
87#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now")
88
Ed Tanous0fdddb12017-02-28 11:06:34 -080089# Boost
Ed Tanousa1e077c2017-04-25 12:42:19 -070090#add_definitions(-DBOOST_NO_RTTI -DBOOST_NO_TYPEID)
91
Ed Tanous1ccd57c2017-03-21 13:15:58 -070092#add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanous01250f22017-04-18 17:49:51 -070093add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
94add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080095add_definitions(-DBOOST_ALL_NO_LIB)
Ed Tanous0d485ef2017-05-23 09:23:53 -070096#set(Boost_USE_STATIC_LIBS ON)
Ed Tanouseb1b8622017-04-25 14:11:46 -070097hunter_add_package(Boost)
Ed Tanous2d02dcd2017-05-15 12:25:30 -070098find_package(Boost REQUIRED)
Ed Tanouse2fc45a2017-04-26 09:19:10 -070099include_directories(${Boost_INCLUDE_DIRS})
Ed Tanous0fdddb12017-02-28 11:06:34 -0800100
101#Openssl
Ed Tanous2d02dcd2017-05-15 12:25:30 -0700102hunter_add_package(OpenSSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800103find_package(OpenSSL REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700104include_directories(${OPENSSL_INCLUDE_DIR})
Ed Tanous0d485ef2017-05-23 09:23:53 -0700105message("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
Ed Tanous0fdddb12017-02-28 11:06:34 -0800106
Ed Tanous0fdddb12017-02-28 11:06:34 -0800107#g3 logging
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700108# G3logger does some unfortunate compile options, so cheat a little bit and copy/paste
Ed Tanousd91df922017-05-12 17:00:32 -0700109set(LOG_SRC ${CMAKE_CURRENT_SOURCE_DIR}/g3log)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700110
111file(GLOB_RECURSE SRC_FILES ${LOG_SRC}/*.cpp ${LOG_SRC}/*.ipp)
112file(GLOB_RECURSE HEADER_FILES ${LOG_SRC}/*.hpp)
113
114IF (MSVC OR MINGW)
Ed Tanousa1e077c2017-04-25 12:42:19 -0700115 list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_unix.cpp)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700116ELSE()
Ed Tanousa1e077c2017-04-25 12:42:19 -0700117 list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_windows.cpp ${LOG_SRC}/g3log/stacktrace_windows.hpp ${LOG_SRC}/stacktrace_windows.cpp)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700118ENDIF (MSVC OR MINGW)
119
120# Create the g3log library
121include_directories(${LOG_SRC})
Ed Tanous8041f312017-04-03 09:47:01 -0700122
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700123add_library(g3logger ${SRC_FILES})
Ed Tanousdc7b6792017-05-12 15:55:51 -0700124set_target_properties(g3logger PROPERTIES LINKER_LANGUAGE CXX)
Ed Tanous9140a672017-04-24 17:01:32 -0700125# clean up some warnings in files we don't own
Ed Tanous7d3dba42017-04-05 13:04:39 -0700126if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
127 set_source_files_properties(g3log/src/logcapture.cpp PROPERTIES COMPILE_FLAGS -Wno-braced-scalar-init)
128 set_source_files_properties(g3log/src/filesink.cpp PROPERTIES COMPILE_FLAGS -Wno-braced-scalar-init)
129 set_source_files_properties(g3log/src/logworker.cpp PROPERTIES COMPILE_FLAGS -Wno-braced-scalar-init)
130endif()
131
Ed Tanous93f987d2017-04-17 17:52:36 -0700132#lib jpeg
133set(BUILD_STATIC ON)
134#include_directories(libjpeg)
135#include_directories(${CMAKE_CURRENT_BINARY_DIR}/libjpeg)
136#add_subdirectory(libjpeg)
137
Ed Tanous8041f312017-04-03 09:47:01 -0700138
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700139# dbus
Ed Tanous2d02dcd2017-05-15 12:25:30 -0700140hunter_add_package(dbus)
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700141find_package(dbus REQUIRED) # Include functions provided by PkgConfig module.
Ed Tanouse4e67cc2017-05-12 16:10:59 -0700142include_directories(${DBUS_INCLUDE_DIRS})
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700143
Ed Tanous8041f312017-04-03 09:47:01 -0700144# Crow
Ed Tanous4c3cbc62017-05-16 09:17:42 -0700145#add_definitions(-DCROW_DISABLE_LOGGING)
Ed Tanous8041f312017-04-03 09:47:01 -0700146add_definitions(-DCROW_ENABLE_SSL)
147include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800148
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800149#Zlib
Ed Tanous7d3dba42017-04-05 13:04:39 -0700150hunter_add_package(ZLIB)
151find_package(ZLIB REQUIRED)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700152include_directories(${ZLIB_INCLUDE_DIRS})
Ed Tanousf9273472017-02-28 16:05:13 -0800153
Ed Tanous4758d5b2017-06-06 15:28:13 -0700154
155# PAM
156find_package(PAM REQUIRED)
157
Ed Tanousc9b55212017-06-12 13:25:51 -0700158# Boost-dbus
159add_subdirectory(boost-dbus)
160include_directories(boost-dbus/include)
161
Ed Tanousf9273472017-02-28 16:05:13 -0800162set(WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800163
Ed Tanous904063f2017-03-02 16:48:24 -0800164set(HDR_FILES
Ed Tanous8041f312017-04-03 09:47:01 -0700165 include/crow/g3_logger.hpp
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800166 include/ssl_key_handler.hpp
167 include/color_cout_g3_sink.hpp
Ed Tanous904063f2017-03-02 16:48:24 -0800168)
169
170set(GENERATED_SRC_FILES
171 ${CMAKE_BINARY_DIR}/generated/webassets.cpp
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700172 ${CMAKE_BINARY_DIR}/generated/webassets.hpp
Ed Tanous904063f2017-03-02 16:48:24 -0800173)
174
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700175include_directories(${CMAKE_BINARY_DIR}/generated)
176
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800177set_source_files_properties(${GENERATED_SRC_FILES} PROPERTIES GENERATED TRUE)
Ed Tanous904063f2017-03-02 16:48:24 -0800178
Ed Tanous12a002d2017-05-15 11:59:16 -0700179# the webassets file has a non-ideal beahvior, where it loads binary data into a std::string
180# due to the way crow is constructed. This causes GCC warnings. Filter them out.
Ed Tanousb4d29f42017-03-24 16:39:25 -0700181if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Ed Tanous12a002d2017-05-15 11:59:16 -0700182 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700183 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-narrowing)
Ed Tanous12a002d2017-05-15 11:59:16 -0700184 endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
Ed Tanousb4d29f42017-03-24 16:39:25 -0700185endif()
186
187
Ed Tanous904063f2017-03-02 16:48:24 -0800188set(SRC_FILES
Ed Tanousf9273472017-02-28 16:05:13 -0800189 src/base64.cpp
Ed Tanous904063f2017-03-02 16:48:24 -0800190 ${GENERATED_SRC_FILES}
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800191)
192
Ed Tanousf9273472017-02-28 16:05:13 -0800193set(UT_FILES
Ed Tanous9140a672017-04-24 17:01:32 -0700194 src/crow_test.cpp
Ed Tanousf9273472017-02-28 16:05:13 -0800195 src/gtest_main.cpp
196 src/base64_test.cpp
197 src/token_authorization_middleware_test.cpp
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700198 src/security_headers_middleware_test.cpp
199 src/webassets_test.cpp
200 src/crow_getroutes_test.cpp
Ed Tanous93f987d2017-04-17 17:52:36 -0700201 src/ast_jpeg_decoder_test.cpp
Ed Tanous9140a672017-04-24 17:01:32 -0700202 src/kvm_websocket_test.cpp
203 src/test_utils.cpp
Ed Tanous01250f22017-04-18 17:49:51 -0700204 src/msan_test.cpp
Ed Tanous9140a672017-04-24 17:01:32 -0700205 src/ci_map_tests.cpp
Ed Tanouse2fc45a2017-04-26 09:19:10 -0700206 src/ast_video_puller_test.cpp
Ed Tanousf9273472017-02-28 16:05:13 -0800207 ${CMAKE_BINARY_DIR}/generated/blns.hpp
208)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800209
Ed Tanous93f987d2017-04-17 17:52:36 -0700210
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800211file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated")
212
Ed Tanous93f987d2017-04-17 17:52:36 -0700213file(COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
214
Ed Tanous38bdb982017-03-03 14:19:33 -0800215# Unit Tests
216if(${BUILD_UT})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800217 # big list of naughty strings
218 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700219 COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/test_resources/blns ${CMAKE_BINARY_DIR}/generated/blns.hpp)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800220
Ed Tanous38bdb982017-03-03 14:19:33 -0800221 # googletest
222 enable_testing()
Ed Tanous4c3cbc62017-05-16 09:17:42 -0700223
Ed Tanous01250f22017-04-18 17:49:51 -0700224 #hunter_add_package(GTest)
225 add_subdirectory(googletest)
226 #find_package(GMock CONFIG REQUIRED)
Ed Tanous38bdb982017-03-03 14:19:33 -0800227
Ed Tanousc9b55212017-06-12 13:25:51 -0700228 add_executable(webtest ${HDR_FILES} ${SRC_FILES} ${UT_FILES})
229 target_link_libraries(webtest gmock gtest)
230 target_link_libraries(webtest pthread)
231 target_link_libraries(webtest g3logger)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700232
Ed Tanousc9b55212017-06-12 13:25:51 -0700233 target_link_libraries(webtest ${OPENSSL_LIBRARIES})
234 target_link_libraries(webtest ${ZLIB_LIBRARIES})
235 target_link_libraries(webtest pam)
236 add_dependencies(webtest packagestaticcpp)
237 add_test(webtest webtest "--gtest_output=xml:webtest.xml")
238
Ed Tanous38bdb982017-03-03 14:19:33 -0800239endif(${BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800240
241# web static assets
242add_subdirectory(static)
Ed Tanousf9273472017-02-28 16:05:13 -0800243
Ed Tanousc9b55212017-06-12 13:25:51 -0700244
Ed Tanousf9273472017-02-28 16:05:13 -0800245# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800246add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous01250f22017-04-18 17:49:51 -0700247target_link_libraries(bmcweb pthread)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800248target_link_libraries(bmcweb g3logger)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700249target_link_libraries(bmcweb ${OPENSSL_LIBRARIES})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800250target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanousdc7b6792017-05-12 15:55:51 -0700251target_link_libraries(bmcweb ${DBUS_LIBRARIES})
Ed Tanous4758d5b2017-06-06 15:28:13 -0700252target_link_libraries(bmcweb pam)
Ed Tanousf0226cd2017-05-16 12:35:38 -0700253add_dependencies(bmcweb packagestaticcpp)
Ed Tanous12a002d2017-05-15 11:59:16 -0700254install (TARGETS bmcweb DESTINATION bin)
Ed Tanouscc5a37f2017-05-11 10:27:23 -0700255
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700256add_executable(getvideo src/getvideo_main.cpp)
Ed Tanous01250f22017-04-18 17:49:51 -0700257target_link_libraries(getvideo pthread)
Ed Tanousd5f39992017-04-18 13:41:22 -0700258target_link_libraries(getvideo g3logger)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700259
Ed Tanous38bdb982017-03-03 14:19:33 -0800260# Visual Studio Code helper
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800261# this needs to be at the end to make sure all includes are handled correctly
Ed Tanous93f987d2017-04-17 17:52:36 -0700262
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800263get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
Ed Tanouscfbe25d2017-05-23 16:34:35 -0700264execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py ${C_INCLUDE_DIRS})