blob: 8d97d929b1bfc40378606da012d33f059195ba32 [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 -080011include("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
Ed Tanous38bdb982017-03-03 14:19:33 -080032option(BUILD_SHARED_LIBS "Build as shared library" OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080033option(BUILD_UT "Enable Unit test" OFF)
34
35# Boost
36add_definitions(-DBOOST_ALL_NO_LIB)
37set(Boost_USE_STATIC_LIBS ON)
Ed Tanous9b65f1f2017-03-07 15:17:13 -080038hunter_add_package(Boost COMPONENTS system thread)
39find_package(Boost REQUIRED system thread REQUIRED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080040
41#Openssl
Ed Tanous9b65f1f2017-03-07 15:17:13 -080042hunter_add_package(OpenSSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -080043find_package(OpenSSL REQUIRED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080044
45# Crow
Ed Tanous9b65f1f2017-03-07 15:17:13 -080046add_definitions(-DCROW_ENABLE_SSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -080047include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous9b65f1f2017-03-07 15:17:13 -080048#add_subdirectory(crow)
Ed Tanous0fdddb12017-02-28 11:06:34 -080049
50#g3 logging
Ed Tanous5f34a9c2017-02-28 12:35:13 -080051option(ADD_FATAL_EXAMPLE "Disable g3 examples" OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080052add_subdirectory(g3log)
53include_directories(g3log/src)
54
Ed Tanous9b65f1f2017-03-07 15:17:13 -080055#Zlib
56#hunter_add_package(ZLIB)
57#find_package(ZLIB REQUIRED)
58
Ed Tanous0fdddb12017-02-28 11:06:34 -080059# Debug sanitizers
60find_package(Sanitizers)
61
Ed Tanousf9273472017-02-28 16:05:13 -080062# C++ GSL (Guideline support libraries)
Ed Tanous9b65f1f2017-03-07 15:17:13 -080063include_directories(gsl-lite/include)
Ed Tanousf9273472017-02-28 16:05:13 -080064
65set(WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanous5f34a9c2017-02-28 12:35:13 -080066
Ed Tanous904063f2017-03-02 16:48:24 -080067set(HDR_FILES
Ed Tanous5f34a9c2017-02-28 12:35:13 -080068 include/crow_g3_logger.hpp
69 include/ssl_key_handler.hpp
70 include/color_cout_g3_sink.hpp
Ed Tanous904063f2017-03-02 16:48:24 -080071 include/webassets.hpp
72)
73
74set(GENERATED_SRC_FILES
75 ${CMAKE_BINARY_DIR}/generated/webassets.cpp
76)
77
Ed Tanous38bdb982017-03-03 14:19:33 -080078if (CMAKE_COMPILER_IS_GNUCC)
79 execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
80 OUTPUT_VARIABLE GCC_VERSION)
81 string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION})
82 list(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR)
83 list(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR)
84
85 message(STATUS ${GCC_MAJOR})
86 message(STATUS ${GCC_MINOR})
87endif()
88
Ed Tanous9b65f1f2017-03-07 15:17:13 -080089set_source_files_properties(${GENERATED_SRC_FILES} PROPERTIES GENERATED TRUE)
Ed Tanous904063f2017-03-02 16:48:24 -080090
91set(SRC_FILES
Ed Tanousf9273472017-02-28 16:05:13 -080092 src/token_authorization_middleware.cpp
93 src/base64.cpp
Ed Tanous904063f2017-03-02 16:48:24 -080094 ${GENERATED_SRC_FILES}
Ed Tanous5f34a9c2017-02-28 12:35:13 -080095)
96
Ed Tanousf9273472017-02-28 16:05:13 -080097set(UT_FILES
98 src/gtest_main.cpp
99 src/base64_test.cpp
100 src/token_authorization_middleware_test.cpp
101 ${CMAKE_BINARY_DIR}/generated/blns.hpp
102)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800103
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800104file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated")
105
Ed Tanous904063f2017-03-02 16:48:24 -0800106# avoid the "narrowing char to X" warning for negative numbers
107# TODO, make the python just do the right thing and turn the number negative
108# Background: char is faster than unsigned char once compiled, so it is used
109# extensively in the server for the "byte" type. Unfortunately, this means that
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800110# the call std::string s{0xFF} fails, because 0xFF narrows to a negative number.
111# This line simply disables the warning, and the compiler does the right thing
Ed Tanous904063f2017-03-02 16:48:24 -0800112# we selectively only disable this warning on this specific file
113# http://stackoverflow.com/questions/28094263/create-array-of-chars-avoiding-narrowing
Ed Tanous38bdb982017-03-03 14:19:33 -0800114if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
115 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.0")
116 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-c++11-narrowing)
117 endif()
118elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
119 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-c++11-narrowing)
120endif()
Ed Tanous904063f2017-03-02 16:48:24 -0800121
Ed Tanous38bdb982017-03-03 14:19:33 -0800122# Unit Tests
123if(${BUILD_UT})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800124
125 # big list of naughty strings
126 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
127 COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/blns.txt ${CMAKE_BINARY_DIR}/generated/blns.hpp)
128
Ed Tanous38bdb982017-03-03 14:19:33 -0800129 # googletest
130 enable_testing()
131 find_package(GTest REQUIRED)
132
133 add_executable(unittest ${HDR_FILES} ${SRC_FILES} ${UT_FILES})
134 target_link_libraries(unittest GTest::GTest GTest::Main)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800135 target_link_libraries(unittest ${Boost_LIBRARIES} Boost::system)
Ed Tanous38bdb982017-03-03 14:19:33 -0800136 target_link_libraries(unittest ${CMAKE_THREAD_LIBS_INIT})
137 target_link_libraries(unittest OpenSSL::SSL OpenSSL::Crypto)
138 target_link_libraries(unittest g3logger)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800139 #target_link_libraries(unittest zlib)
Ed Tanous38bdb982017-03-03 14:19:33 -0800140 add_dependencies(unittest packagestaticcpp)
141endif(${BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800142
143# web static assets
144add_subdirectory(static)
Ed Tanousf9273472017-02-28 16:05:13 -0800145
146# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800147add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800148target_link_libraries(bmcweb ${Boost_LIBRARIES} Boost::system)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800149target_link_libraries(bmcweb ${CMAKE_THREAD_LIBS_INIT})
150target_link_libraries(bmcweb OpenSSL::SSL OpenSSL::Crypto)
151target_link_libraries(bmcweb g3logger)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800152target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanous904063f2017-03-02 16:48:24 -0800153add_dependencies(bmcweb packagestaticcpp)
Ed Tanousf9273472017-02-28 16:05:13 -0800154
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800155include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800156
Ed Tanous38bdb982017-03-03 14:19:33 -0800157# Visual Studio Code helper
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800158# this needs to be at the end to make sure all includes are handled correctly
159get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
160execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py ${C_INCLUDE_DIRS})