blob: 5ff08061ece0d3481ba83b342afd5eaa4764c2f8 [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)
10SET(HUNTER_STATUS_DEBUG ON)
11include("cmake/HunterGate.cmake")
12
13HunterGate(
14 URL "https://github.com/ruslo/hunter/archive/v0.16.31.tar.gz"
15 SHA1 "8fcc0a2d6206e1f2c6fc011e3e694e388d030b53"
16)
17
18option(BUILD_FOR_EMBEDDED "Build for device target" ON)
19
20project(bmc-webserver CXX C)
21
22set(CMAKE_CXX_STANDARD 14)
23set(CMAKE_CXX_STANDARD_REQUIRED ON)
24
25set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
26
27if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
28 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." )
29endif()
30
31# general
32option(BUILD_SHARED_LIBS "Build Pion as shared library" OFF)
33option(BUILD_UT "Enable Unit test" OFF)
34
35# Boost
36add_definitions(-DBOOST_ALL_NO_LIB)
37set(Boost_USE_STATIC_LIBS ON)
38hunter_add_package(Boost COMPONENTS system thread regex)
39find_package(Boost COMPONENTS system thread regex REQUIRED)
40
41#Openssl
Ed Tanous5f34a9c2017-02-28 12:35:13 -080042#hunter_add_package(OpenSSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -080043find_package(OpenSSL REQUIRED)
44if (NOT OPENSSL_FOUND)
45 message(FATAL_ERROR "Could not find OpenSSL")
46endif()
47include_directories(${OPENSSL_INCLUDE_DIR})
48
49# Crow
50include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
51
52#g3 logging
Ed Tanous5f34a9c2017-02-28 12:35:13 -080053option(ADD_FATAL_EXAMPLE "Disable g3 examples" OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080054add_subdirectory(g3log)
55include_directories(g3log/src)
56
57# Debug sanitizers
58find_package(Sanitizers)
59
Ed Tanousf9273472017-02-28 16:05:13 -080060# C++ GSL (Guideline support libraries)
61include_directories(GSL/include)
62
63set(WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanous5f34a9c2017-02-28 12:35:13 -080064
Ed Tanous904063f2017-03-02 16:48:24 -080065set(HDR_FILES
Ed Tanous5f34a9c2017-02-28 12:35:13 -080066 include/crow_g3_logger.hpp
67 include/ssl_key_handler.hpp
68 include/color_cout_g3_sink.hpp
Ed Tanous904063f2017-03-02 16:48:24 -080069 include/webassets.hpp
70)
71
72set(GENERATED_SRC_FILES
73 ${CMAKE_BINARY_DIR}/generated/webassets.cpp
74)
75
76set_source_files_properties(${GENERATED_SRC_FILES} PROPERTIES GENERATED TRUE)
77
78set(SRC_FILES
Ed Tanousf9273472017-02-28 16:05:13 -080079 src/token_authorization_middleware.cpp
80 src/base64.cpp
Ed Tanous904063f2017-03-02 16:48:24 -080081 ${GENERATED_SRC_FILES}
Ed Tanous5f34a9c2017-02-28 12:35:13 -080082)
83
Ed Tanousf9273472017-02-28 16:05:13 -080084set(UT_FILES
85 src/gtest_main.cpp
86 src/base64_test.cpp
87 src/token_authorization_middleware_test.cpp
88 ${CMAKE_BINARY_DIR}/generated/blns.hpp
89)
Ed Tanous5f34a9c2017-02-28 12:35:13 -080090
Ed Tanous904063f2017-03-02 16:48:24 -080091# avoid the "narrowing char to X" warning for negative numbers
92# TODO, make the python just do the right thing and turn the number negative
93# Background: char is faster than unsigned char once compiled, so it is used
94# extensively in the server for the "byte" type. Unfortunately, this means that
95# the call std::string s{0xFF} fails, because 0xFF narrows to a negative number
96# this line simply disables the warning, and the compiler does the right thing
97# we selectively only disable this warning on this specific file
98# http://stackoverflow.com/questions/28094263/create-array-of-chars-avoiding-narrowing
99set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-c++11-narrowing)
100
Ed Tanousf9273472017-02-28 16:05:13 -0800101# big list of naughty strings
102file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated")
103add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
104 COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/blns.txt ${CMAKE_BINARY_DIR}/generated/blns.hpp)
105
106# googletest
107#find_package(GTest REQUIRED)
108enable_testing()
109find_package(GTest REQUIRED)
110
Ed Tanous904063f2017-03-02 16:48:24 -0800111add_executable(unittest ${HDR_FILES} ${SRC_FILES} ${UT_FILES})
Ed Tanousf9273472017-02-28 16:05:13 -0800112target_link_libraries(unittest GTest::GTest GTest::Main)
113target_link_libraries(unittest Boost::boost Boost::system)
114target_link_libraries(unittest ${CMAKE_THREAD_LIBS_INIT})
115target_link_libraries(unittest OpenSSL::SSL OpenSSL::Crypto)
116target_link_libraries(unittest g3logger)
Ed Tanous904063f2017-03-02 16:48:24 -0800117add_dependencies(unittest packagestaticcpp)
118
119# web static assets
120add_subdirectory(static)
Ed Tanousf9273472017-02-28 16:05:13 -0800121
122# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800123add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800124target_link_libraries(bmcweb Boost::boost Boost::system)
125target_link_libraries(bmcweb ${CMAKE_THREAD_LIBS_INIT})
126target_link_libraries(bmcweb OpenSSL::SSL OpenSSL::Crypto)
127target_link_libraries(bmcweb g3logger)
Ed Tanous904063f2017-03-02 16:48:24 -0800128add_dependencies(bmcweb packagestaticcpp)
Ed Tanousf9273472017-02-28 16:05:13 -0800129
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800130include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800131
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800132# this needs to be at the end to make sure all includes are handled correctly
133get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
134execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py ${C_INCLUDE_DIRS})