blob: 1be970a3e76f6dac6874fe52a23b40f9558dae9d [file] [log] [blame]
Ed Tanous0fdddb12017-02-28 11:06:34 -08001cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR)
2
3cmake_policy(SET CMP0054 OLD)
4
5set(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 Tanous0fdddb12017-02-28 11:06:34 -080012
Ed Tanous9140a672017-04-24 17:01:32 -070013#SET(MSAN_CXX_FLAGS "-fsanitize=memory -stdlib=libc++ -I/home/ed/libcxx_msan/include -I/home/ed/libcxx_msan/include/c++/v1")
14#SET(MSAN_LINKER_EXE_FLAGS "${MSAN_CXX_FLAGS} -lc++abi -L/home/ed/libcxx_msan/lib -Wl,-rpath,I/home/ed/libcxx_msan/lib")
Ed Tanous1ccd57c2017-03-21 13:15:58 -070015
Ed Tanous01250f22017-04-18 17:49:51 -070016#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSAN_CXX_FLAGS}")
17#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSAN_LINKER_EXE_FLAGS}")
18
Ed Tanous9140a672017-04-24 17:01:32 -070019# Debug information
20SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fno-omit-frame-pointer")
Ed Tanous01250f22017-04-18 17:49:51 -070021
Ed Tanous1ccd57c2017-03-21 13:15:58 -070022include("cmake/HunterGate.cmake")
23#HunterGate(
24# URL "https://github.com/ruslo/hunter/archive/v0.16.31.tar.gz"
25# SHA1 "8fcc0a2d6206e1f2c6fc011e3e694e388d030b53"
26#)
Ed Tanous0fdddb12017-02-28 11:06:34 -080027HunterGate(
Ed Tanous1ccd57c2017-03-21 13:15:58 -070028 URL "https://github.com/ruslo/hunter/archive/v0.18.16.tar.gz"
29 SHA1 "6cbca2b0e7605ad8ea22ee3527850996436f71b8"
Ed Tanous0fdddb12017-02-28 11:06:34 -080030)
31
Ed Tanous1ccd57c2017-03-21 13:15:58 -070032
Ed Tanous0fdddb12017-02-28 11:06:34 -080033option(BUILD_FOR_EMBEDDED "Build for device target" ON)
34
35project(bmc-webserver CXX C)
36
37set(CMAKE_CXX_STANDARD 14)
38set(CMAKE_CXX_STANDARD_REQUIRED ON)
39
40set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
41
42if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
43 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." )
44endif()
45
46# general
Ed Tanous38bdb982017-03-03 14:19:33 -080047option(BUILD_SHARED_LIBS "Build as shared library" OFF)
Ed Tanous93f987d2017-04-17 17:52:36 -070048option(BUILD_UT "Enable Unit test" ON)
Ed Tanous0fdddb12017-02-28 11:06:34 -080049
Ed Tanous8041f312017-04-03 09:47:01 -070050# This needs to be before the crow and other module includes so headers get overriden correctly
51include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
52
Ed Tanous1ccd57c2017-03-21 13:15:58 -070053# security flags
54#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong -fPIE -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security" )
55#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now")
56
Ed Tanous0fdddb12017-02-28 11:06:34 -080057# Boost
Ed Tanous1ccd57c2017-03-21 13:15:58 -070058#add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanous01250f22017-04-18 17:49:51 -070059add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
60add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080061add_definitions(-DBOOST_ALL_NO_LIB)
62set(Boost_USE_STATIC_LIBS ON)
Ed Tanous9140a672017-04-24 17:01:32 -070063hunter_add_package(Boost COMPONENTS system)
64find_package(Boost COMPONENTS system)
Ed Tanous0fdddb12017-02-28 11:06:34 -080065
66#Openssl
Ed Tanous9b65f1f2017-03-07 15:17:13 -080067hunter_add_package(OpenSSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -080068find_package(OpenSSL REQUIRED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080069
Ed Tanous0fdddb12017-02-28 11:06:34 -080070#g3 logging
Ed Tanous1ccd57c2017-03-21 13:15:58 -070071# G3logger does some unfortunate compile options, so cheat a little bit and copy/paste
Ed Tanous1ccd57c2017-03-21 13:15:58 -070072set(LOG_SRC ${CMAKE_CURRENT_SOURCE_DIR}/g3log/src)
73
74file(GLOB_RECURSE SRC_FILES ${LOG_SRC}/*.cpp ${LOG_SRC}/*.ipp)
75file(GLOB_RECURSE HEADER_FILES ${LOG_SRC}/*.hpp)
76
77IF (MSVC OR MINGW)
78 list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_unix.cpp)
79ELSE()
80 list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_windows.cpp ${LOG_SRC}/g3log/stacktrace_windows.hpp ${LOG_SRC}/stacktrace_windows.cpp)
81ENDIF (MSVC OR MINGW)
82
83# Create the g3log library
84include_directories(${LOG_SRC})
Ed Tanous8041f312017-04-03 09:47:01 -070085
Ed Tanous1ccd57c2017-03-21 13:15:58 -070086add_library(g3logger ${SRC_FILES})
Ed Tanous9140a672017-04-24 17:01:32 -070087# clean up some warnings in files we don't own
Ed Tanous7d3dba42017-04-05 13:04:39 -070088if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
89 set_source_files_properties(g3log/src/logcapture.cpp PROPERTIES COMPILE_FLAGS -Wno-braced-scalar-init)
90 set_source_files_properties(g3log/src/filesink.cpp PROPERTIES COMPILE_FLAGS -Wno-braced-scalar-init)
91 set_source_files_properties(g3log/src/logworker.cpp PROPERTIES COMPILE_FLAGS -Wno-braced-scalar-init)
92endif()
93
Ed Tanous1ccd57c2017-03-21 13:15:58 -070094set_target_properties(g3logger PROPERTIES
95 LINKER_LANGUAGE CXX
96 OUTPUT_NAME g3logger
97 CLEAN_DIRECT_OUTPUT 1)
98target_link_libraries(g3logger ${PLATFORM_LINK_LIBRIES})
Ed Tanous8041f312017-04-03 09:47:01 -070099
Ed Tanous93f987d2017-04-17 17:52:36 -0700100#lib jpeg
101set(BUILD_STATIC ON)
102#include_directories(libjpeg)
103#include_directories(${CMAKE_CURRENT_BINARY_DIR}/libjpeg)
104#add_subdirectory(libjpeg)
105
Ed Tanous8041f312017-04-03 09:47:01 -0700106
107# Crow
Ed Tanous9140a672017-04-24 17:01:32 -0700108add_definitions(-DCROW_DISABLE_LOGGING)
Ed Tanous8041f312017-04-03 09:47:01 -0700109add_definitions(-DCROW_ENABLE_SSL)
110include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800111
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800112#Zlib
Ed Tanous7d3dba42017-04-05 13:04:39 -0700113hunter_add_package(ZLIB)
114find_package(ZLIB REQUIRED)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800115
Ed Tanousf9273472017-02-28 16:05:13 -0800116# C++ GSL (Guideline support libraries)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800117include_directories(gsl-lite/include)
Ed Tanousf9273472017-02-28 16:05:13 -0800118
119set(WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800120
Ed Tanous904063f2017-03-02 16:48:24 -0800121set(HDR_FILES
Ed Tanous8041f312017-04-03 09:47:01 -0700122 include/crow/g3_logger.hpp
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800123 include/ssl_key_handler.hpp
124 include/color_cout_g3_sink.hpp
Ed Tanous904063f2017-03-02 16:48:24 -0800125)
126
127set(GENERATED_SRC_FILES
128 ${CMAKE_BINARY_DIR}/generated/webassets.cpp
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700129 ${CMAKE_BINARY_DIR}/generated/webassets.hpp
Ed Tanous904063f2017-03-02 16:48:24 -0800130)
131
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700132include_directories(${CMAKE_BINARY_DIR}/generated)
133
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800134set_source_files_properties(${GENERATED_SRC_FILES} PROPERTIES GENERATED TRUE)
Ed Tanous904063f2017-03-02 16:48:24 -0800135
Ed Tanousb4d29f42017-03-24 16:39:25 -0700136if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
137 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
138 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-narrowing)
139 endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
140endif()
141
142
Ed Tanous904063f2017-03-02 16:48:24 -0800143set(SRC_FILES
Ed Tanousf9273472017-02-28 16:05:13 -0800144 src/token_authorization_middleware.cpp
Ed Tanous8041f312017-04-03 09:47:01 -0700145 src/security_headers_middleware.cpp
Ed Tanousf9273472017-02-28 16:05:13 -0800146 src/base64.cpp
Ed Tanous904063f2017-03-02 16:48:24 -0800147 ${GENERATED_SRC_FILES}
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800148)
149
Ed Tanousf9273472017-02-28 16:05:13 -0800150set(UT_FILES
Ed Tanous7d3dba42017-04-05 13:04:39 -0700151 g3log/test_unit/test_cpp_future_concepts.cpp
152 g3log/test_unit/tester_sharedlib.cpp
153 # TODO(ed) figure out why this unit test has a main function in it
154 #g3log/test_unit/test_filechange.cpp
155 g3log/test_unit/testing_helpers.h
156 #TODO(ed)
157 #g3log/test_unit/test_linux_dynamic_loaded_sharedlib.cpp
158 #g3log/test_unit/test_sink.cpp
159 g3log/test_unit/test_concept_sink.cpp
160 g3log/test_unit/test_crashhandler_windows.cpp
161 g3log/test_unit/tester_sharedlib.h
162 g3log/test_unit/testing_helpers.cpp
163 g3log/test_unit/test_io.cpp
164 g3log/test_unit/test_message.cpp
Ed Tanous9140a672017-04-24 17:01:32 -0700165 src/crow_test.cpp
Ed Tanousf9273472017-02-28 16:05:13 -0800166 src/gtest_main.cpp
167 src/base64_test.cpp
168 src/token_authorization_middleware_test.cpp
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700169 src/security_headers_middleware_test.cpp
170 src/webassets_test.cpp
171 src/crow_getroutes_test.cpp
Ed Tanous93f987d2017-04-17 17:52:36 -0700172 src/ast_jpeg_decoder_test.cpp
Ed Tanous9140a672017-04-24 17:01:32 -0700173 src/kvm_websocket_test.cpp
174 src/test_utils.cpp
Ed Tanous01250f22017-04-18 17:49:51 -0700175 src/msan_test.cpp
Ed Tanous9140a672017-04-24 17:01:32 -0700176 src/ci_map_tests.cpp
Ed Tanous01250f22017-04-18 17:49:51 -0700177
Ed Tanousf9273472017-02-28 16:05:13 -0800178 ${CMAKE_BINARY_DIR}/generated/blns.hpp
179)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800180
Ed Tanous93f987d2017-04-17 17:52:36 -0700181
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800182file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated")
183
Ed Tanous93f987d2017-04-17 17:52:36 -0700184file(COPY src/test_resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
185
Ed Tanous38bdb982017-03-03 14:19:33 -0800186# Unit Tests
187if(${BUILD_UT})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800188 # big list of naughty strings
189 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
190 COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/blns.txt ${CMAKE_BINARY_DIR}/generated/blns.hpp)
191
Ed Tanous38bdb982017-03-03 14:19:33 -0800192 # googletest
193 enable_testing()
Ed Tanous01250f22017-04-18 17:49:51 -0700194 #hunter_add_package(GTest)
195 add_subdirectory(googletest)
196 #find_package(GMock CONFIG REQUIRED)
Ed Tanous38bdb982017-03-03 14:19:33 -0800197
198 add_executable(unittest ${HDR_FILES} ${SRC_FILES} ${UT_FILES})
Ed Tanous01250f22017-04-18 17:49:51 -0700199 target_link_libraries(unittest gmock gtest)
200 target_link_libraries(unittest pthread)
Ed Tanous38bdb982017-03-03 14:19:33 -0800201 target_link_libraries(unittest OpenSSL::SSL OpenSSL::Crypto)
202 target_link_libraries(unittest g3logger)
Ed Tanous7d3dba42017-04-05 13:04:39 -0700203 target_link_libraries(unittest ${ZLIB_LIBRARIES})
Ed Tanous38bdb982017-03-03 14:19:33 -0800204 add_dependencies(unittest packagestaticcpp)
205endif(${BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800206
207# web static assets
208add_subdirectory(static)
Ed Tanousf9273472017-02-28 16:05:13 -0800209
210# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800211add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous01250f22017-04-18 17:49:51 -0700212target_link_libraries(bmcweb pthread)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800213target_link_libraries(bmcweb OpenSSL::SSL OpenSSL::Crypto)
Ed Tanous9140a672017-04-24 17:01:32 -0700214target_link_libraries(bmcweb Boost::system)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800215target_link_libraries(bmcweb g3logger)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800216target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanous904063f2017-03-02 16:48:24 -0800217add_dependencies(bmcweb packagestaticcpp)
Ed Tanousf9273472017-02-28 16:05:13 -0800218
Ed Tanous93f987d2017-04-17 17:52:36 -0700219# udpclient
Ed Tanous9140a672017-04-24 17:01:32 -0700220#add_executable(udpclient src/udpclient.cpp)
221#target_link_libraries(udpclient pthread)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700222
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700223add_executable(getvideo src/getvideo_main.cpp)
Ed Tanous01250f22017-04-18 17:49:51 -0700224target_link_libraries(getvideo pthread)
Ed Tanousd5f39992017-04-18 13:41:22 -0700225target_link_libraries(getvideo g3logger)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700226
Ed Tanous38bdb982017-03-03 14:19:33 -0800227# Visual Studio Code helper
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800228# this needs to be at the end to make sure all includes are handled correctly
Ed Tanous93f987d2017-04-17 17:52:36 -0700229
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800230get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
Ed Tanous01250f22017-04-18 17:49:51 -0700231execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py ${C_INCLUDE_DIRS})