blob: 6f841ba3a63caad7f16bc5dc8bccb5f54f8b92cc [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
9#set(HUNTER_ROOT /home/ed/hunter)
Ed Tanous9b65f1f2017-03-07 15:17:13 -080010#SET(HUNTER_STATUS_DEBUG ON)
Ed Tanous0fdddb12017-02-28 11:06:34 -080011
Ed Tanous1ccd57c2017-03-21 13:15:58 -070012
13#SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls")
14
15#SET(MSAN_CXX_FLAGS "-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -stdlib=libc++ -I/home/ed/libcxx_msan/include -I/home/ed/libcxx_msan/include/c++/v1")
16#SET(MSAN_LINKER_EXE_FLAGS "${MSAN_CXX_FLAGS} -lc++abi -L/home/ed/libcxx_msan/lib")
17include("cmake/HunterGate.cmake")
18#HunterGate(
19# URL "https://github.com/ruslo/hunter/archive/v0.16.31.tar.gz"
20# SHA1 "8fcc0a2d6206e1f2c6fc011e3e694e388d030b53"
21#)
Ed Tanous0fdddb12017-02-28 11:06:34 -080022HunterGate(
Ed Tanous1ccd57c2017-03-21 13:15:58 -070023 URL "https://github.com/ruslo/hunter/archive/v0.18.16.tar.gz"
24 SHA1 "6cbca2b0e7605ad8ea22ee3527850996436f71b8"
Ed Tanous0fdddb12017-02-28 11:06:34 -080025)
26
Ed Tanous1ccd57c2017-03-21 13:15:58 -070027
Ed Tanous0fdddb12017-02-28 11:06:34 -080028option(BUILD_FOR_EMBEDDED "Build for device target" ON)
29
30project(bmc-webserver CXX C)
31
Ed Tanous1ccd57c2017-03-21 13:15:58 -070032SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${MSAN_CXX_FLAGS}")
33SET(CMAKE_EXE_LINKER_FLAGS "${MSAN_LINKER_EXE_FLAGS}")
34
Ed Tanous0fdddb12017-02-28 11:06:34 -080035set(CMAKE_CXX_STANDARD 14)
36set(CMAKE_CXX_STANDARD_REQUIRED ON)
37
38set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
39
40if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
41 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." )
42endif()
43
44# general
Ed Tanous38bdb982017-03-03 14:19:33 -080045option(BUILD_SHARED_LIBS "Build as shared library" OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080046option(BUILD_UT "Enable Unit test" OFF)
47
Ed Tanous8041f312017-04-03 09:47:01 -070048# This needs to be before the crow and other module includes so headers get overriden correctly
49include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
50
Ed Tanous1ccd57c2017-03-21 13:15:58 -070051# security flags
52#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong -fPIE -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security" )
53#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now")
54
Ed Tanous0fdddb12017-02-28 11:06:34 -080055# Boost
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070056#add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
Ed Tanous1ccd57c2017-03-21 13:15:58 -070057#add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanous8041f312017-04-03 09:47:01 -070058#add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
Ed Tanous0fdddb12017-02-28 11:06:34 -080059add_definitions(-DBOOST_ALL_NO_LIB)
60set(Boost_USE_STATIC_LIBS ON)
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070061hunter_add_package(Boost COMPONENTS system thread iostreams)
62find_package(Boost REQUIRED system thread iostreams REQUIRED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080063
64#Openssl
Ed Tanous9b65f1f2017-03-07 15:17:13 -080065hunter_add_package(OpenSSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -080066find_package(OpenSSL REQUIRED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080067
Ed Tanous8041f312017-04-03 09:47:01 -070068
Ed Tanous0fdddb12017-02-28 11:06:34 -080069
70#g3 logging
Ed Tanous1ccd57c2017-03-21 13:15:58 -070071# G3logger does some unfortunate compile options, so cheat a little bit and copy/paste
72
73set(LOG_SRC ${CMAKE_CURRENT_SOURCE_DIR}/g3log/src)
74
75file(GLOB_RECURSE SRC_FILES ${LOG_SRC}/*.cpp ${LOG_SRC}/*.ipp)
76file(GLOB_RECURSE HEADER_FILES ${LOG_SRC}/*.hpp)
77
78IF (MSVC OR MINGW)
79 list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_unix.cpp)
80ELSE()
81 list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_windows.cpp ${LOG_SRC}/g3log/stacktrace_windows.hpp ${LOG_SRC}/stacktrace_windows.cpp)
82ENDIF (MSVC OR MINGW)
83
84# Create the g3log library
85include_directories(${LOG_SRC})
Ed Tanous8041f312017-04-03 09:47:01 -070086
Ed Tanous1ccd57c2017-03-21 13:15:58 -070087add_library(g3logger ${SRC_FILES})
88set_target_properties(g3logger PROPERTIES
89 LINKER_LANGUAGE CXX
90 OUTPUT_NAME g3logger
91 CLEAN_DIRECT_OUTPUT 1)
92target_link_libraries(g3logger ${PLATFORM_LINK_LIBRIES})
Ed Tanous8041f312017-04-03 09:47:01 -070093
94
95# Crow
96add_definitions(-DCROW_ENABLE_SSL)
97include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -080098
Ed Tanous9b65f1f2017-03-07 15:17:13 -080099#Zlib
100#hunter_add_package(ZLIB)
101#find_package(ZLIB REQUIRED)
102
Ed Tanousf9273472017-02-28 16:05:13 -0800103# C++ GSL (Guideline support libraries)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800104include_directories(gsl-lite/include)
Ed Tanousf9273472017-02-28 16:05:13 -0800105
106set(WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800107
Ed Tanous904063f2017-03-02 16:48:24 -0800108set(HDR_FILES
Ed Tanous8041f312017-04-03 09:47:01 -0700109 include/crow/g3_logger.hpp
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800110 include/ssl_key_handler.hpp
111 include/color_cout_g3_sink.hpp
Ed Tanous904063f2017-03-02 16:48:24 -0800112)
113
114set(GENERATED_SRC_FILES
115 ${CMAKE_BINARY_DIR}/generated/webassets.cpp
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700116 ${CMAKE_BINARY_DIR}/generated/webassets.hpp
Ed Tanous904063f2017-03-02 16:48:24 -0800117)
118
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700119include_directories(${CMAKE_BINARY_DIR}/generated)
120
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800121set_source_files_properties(${GENERATED_SRC_FILES} PROPERTIES GENERATED TRUE)
Ed Tanous904063f2017-03-02 16:48:24 -0800122
Ed Tanousb4d29f42017-03-24 16:39:25 -0700123if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
124 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
125 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-narrowing)
126 endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
127endif()
128
129
Ed Tanous904063f2017-03-02 16:48:24 -0800130set(SRC_FILES
Ed Tanousf9273472017-02-28 16:05:13 -0800131 src/token_authorization_middleware.cpp
Ed Tanous8041f312017-04-03 09:47:01 -0700132 src/security_headers_middleware.cpp
Ed Tanousf9273472017-02-28 16:05:13 -0800133 src/base64.cpp
Ed Tanous904063f2017-03-02 16:48:24 -0800134 ${GENERATED_SRC_FILES}
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800135)
136
Ed Tanousf9273472017-02-28 16:05:13 -0800137set(UT_FILES
Ed Tanous8041f312017-04-03 09:47:01 -0700138 src/crowtest/crow_unittest.cpp
Ed Tanousf9273472017-02-28 16:05:13 -0800139 src/gtest_main.cpp
140 src/base64_test.cpp
141 src/token_authorization_middleware_test.cpp
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700142 src/security_headers_middleware_test.cpp
143 src/webassets_test.cpp
144 src/crow_getroutes_test.cpp
Ed Tanousf9273472017-02-28 16:05:13 -0800145 ${CMAKE_BINARY_DIR}/generated/blns.hpp
146)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800147
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800148file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated")
149
Ed Tanous38bdb982017-03-03 14:19:33 -0800150# Unit Tests
151if(${BUILD_UT})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800152 # big list of naughty strings
153 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
154 COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/blns.txt ${CMAKE_BINARY_DIR}/generated/blns.hpp)
155
Ed Tanous38bdb982017-03-03 14:19:33 -0800156 # googletest
157 enable_testing()
158 find_package(GTest REQUIRED)
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700159 find_package(GMock REQUIRED)
Ed Tanous38bdb982017-03-03 14:19:33 -0800160
161 add_executable(unittest ${HDR_FILES} ${SRC_FILES} ${UT_FILES})
Ed Tanousb4a7bfa2017-04-04 17:23:00 -0700162 target_link_libraries(unittest ${GMOCK_BOTH_LIBRARIES})
163 target_link_libraries(unittest Boost::system Boost::thread Boost::iostreams)
Ed Tanous38bdb982017-03-03 14:19:33 -0800164 target_link_libraries(unittest ${CMAKE_THREAD_LIBS_INIT})
165 target_link_libraries(unittest OpenSSL::SSL OpenSSL::Crypto)
166 target_link_libraries(unittest g3logger)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800167 #target_link_libraries(unittest zlib)
Ed Tanous38bdb982017-03-03 14:19:33 -0800168 add_dependencies(unittest packagestaticcpp)
169endif(${BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800170
171# web static assets
172add_subdirectory(static)
Ed Tanousf9273472017-02-28 16:05:13 -0800173
174# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800175add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous8041f312017-04-03 09:47:01 -0700176target_link_libraries(bmcweb Boost::system Boost::thread)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800177target_link_libraries(bmcweb ${CMAKE_THREAD_LIBS_INIT})
178target_link_libraries(bmcweb OpenSSL::SSL OpenSSL::Crypto)
179target_link_libraries(bmcweb g3logger)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800180target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanous904063f2017-03-02 16:48:24 -0800181add_dependencies(bmcweb packagestaticcpp)
Ed Tanousf9273472017-02-28 16:05:13 -0800182
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700183# bmcweb
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700184add_executable(udpclient src/udpclient.cpp)
185
186target_link_libraries(udpclient Boost::system)
187target_link_libraries(udpclient ${CMAKE_THREAD_LIBS_INIT})
188
189
190add_executable(getvideo src/getvideo_main.cpp)
191
Ed Tanous38bdb982017-03-03 14:19:33 -0800192# Visual Studio Code helper
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800193# this needs to be at the end to make sure all includes are handled correctly
194get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700195execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py ${C_INCLUDE_DIRS})