blob: 0a6e3ec247a0a46322cf3944f0ca34ae0f0b1c09 [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
Ed Tanousc4771fb2017-03-13 13:39:49 -070036add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
Ed Tanous0fdddb12017-02-28 11:06:34 -080037add_definitions(-DBOOST_ALL_NO_LIB)
38set(Boost_USE_STATIC_LIBS ON)
Ed Tanous9b65f1f2017-03-07 15:17:13 -080039hunter_add_package(Boost COMPONENTS system thread)
40find_package(Boost REQUIRED system thread REQUIRED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080041
42#Openssl
Ed Tanous9b65f1f2017-03-07 15:17:13 -080043hunter_add_package(OpenSSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -080044find_package(OpenSSL REQUIRED)
Ed Tanous0fdddb12017-02-28 11:06:34 -080045
46# Crow
Ed Tanous9b65f1f2017-03-07 15:17:13 -080047add_definitions(-DCROW_ENABLE_SSL)
Ed Tanous0fdddb12017-02-28 11:06:34 -080048include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
Ed Tanous9b65f1f2017-03-07 15:17:13 -080049#add_subdirectory(crow)
Ed Tanous0fdddb12017-02-28 11:06:34 -080050
51#g3 logging
Ed Tanous5f34a9c2017-02-28 12:35:13 -080052option(ADD_FATAL_EXAMPLE "Disable g3 examples" OFF)
Ed Tanous0fdddb12017-02-28 11:06:34 -080053add_subdirectory(g3log)
54include_directories(g3log/src)
55
Ed Tanous9b65f1f2017-03-07 15:17:13 -080056#Zlib
57#hunter_add_package(ZLIB)
58#find_package(ZLIB REQUIRED)
59
Ed Tanous0fdddb12017-02-28 11:06:34 -080060# Debug sanitizers
61find_package(Sanitizers)
62
Ed Tanousf9273472017-02-28 16:05:13 -080063# C++ GSL (Guideline support libraries)
Ed Tanous9b65f1f2017-03-07 15:17:13 -080064include_directories(gsl-lite/include)
Ed Tanousf9273472017-02-28 16:05:13 -080065
66set(WEBSERVER_MAIN src/webserver_main.cpp)
Ed Tanous5f34a9c2017-02-28 12:35:13 -080067
Ed Tanous904063f2017-03-02 16:48:24 -080068set(HDR_FILES
Ed Tanous5f34a9c2017-02-28 12:35:13 -080069 include/crow_g3_logger.hpp
70 include/ssl_key_handler.hpp
71 include/color_cout_g3_sink.hpp
Ed Tanous904063f2017-03-02 16:48:24 -080072 include/webassets.hpp
73)
74
75set(GENERATED_SRC_FILES
76 ${CMAKE_BINARY_DIR}/generated/webassets.cpp
77)
78
Ed Tanous38bdb982017-03-03 14:19:33 -080079if (CMAKE_COMPILER_IS_GNUCC)
80 execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
81 OUTPUT_VARIABLE GCC_VERSION)
82 string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION})
83 list(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR)
84 list(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR)
85
86 message(STATUS ${GCC_MAJOR})
87 message(STATUS ${GCC_MINOR})
88endif()
89
Ed Tanous9b65f1f2017-03-07 15:17:13 -080090set_source_files_properties(${GENERATED_SRC_FILES} PROPERTIES GENERATED TRUE)
Ed Tanous904063f2017-03-02 16:48:24 -080091
92set(SRC_FILES
Ed Tanousf9273472017-02-28 16:05:13 -080093 src/token_authorization_middleware.cpp
94 src/base64.cpp
Ed Tanous904063f2017-03-02 16:48:24 -080095 ${GENERATED_SRC_FILES}
Ed Tanous5f34a9c2017-02-28 12:35:13 -080096)
97
Ed Tanousf9273472017-02-28 16:05:13 -080098set(UT_FILES
99 src/gtest_main.cpp
100 src/base64_test.cpp
101 src/token_authorization_middleware_test.cpp
102 ${CMAKE_BINARY_DIR}/generated/blns.hpp
103)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800104
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800105file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated")
106
Ed Tanous904063f2017-03-02 16:48:24 -0800107# avoid the "narrowing char to X" warning for negative numbers
108# TODO, make the python just do the right thing and turn the number negative
109# Background: char is faster than unsigned char once compiled, so it is used
110# extensively in the server for the "byte" type. Unfortunately, this means that
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800111# the call std::string s{0xFF} fails, because 0xFF narrows to a negative number.
112# This line simply disables the warning, and the compiler does the right thing
Ed Tanous904063f2017-03-02 16:48:24 -0800113# we selectively only disable this warning on this specific file
114# http://stackoverflow.com/questions/28094263/create-array-of-chars-avoiding-narrowing
Ed Tanousc4771fb2017-03-13 13:39:49 -0700115if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Ed Tanous38bdb982017-03-03 14:19:33 -0800116 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-c++11-narrowing)
Ed Tanousc4771fb2017-03-13 13:39:49 -0700117endif()
118if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
119 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.2)
120 set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-narrowing)
121 endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.2)
Ed Tanous38bdb982017-03-03 14:19:33 -0800122endif()
Ed Tanous904063f2017-03-02 16:48:24 -0800123
Ed Tanous38bdb982017-03-03 14:19:33 -0800124# Unit Tests
125if(${BUILD_UT})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800126
127 # big list of naughty strings
128 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp
129 COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/blns.txt ${CMAKE_BINARY_DIR}/generated/blns.hpp)
130
Ed Tanous38bdb982017-03-03 14:19:33 -0800131 # googletest
132 enable_testing()
133 find_package(GTest REQUIRED)
134
135 add_executable(unittest ${HDR_FILES} ${SRC_FILES} ${UT_FILES})
136 target_link_libraries(unittest GTest::GTest GTest::Main)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800137 target_link_libraries(unittest ${Boost_LIBRARIES} Boost::system)
Ed Tanous38bdb982017-03-03 14:19:33 -0800138 target_link_libraries(unittest ${CMAKE_THREAD_LIBS_INIT})
139 target_link_libraries(unittest OpenSSL::SSL OpenSSL::Crypto)
140 target_link_libraries(unittest g3logger)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800141 #target_link_libraries(unittest zlib)
Ed Tanous38bdb982017-03-03 14:19:33 -0800142 add_dependencies(unittest packagestaticcpp)
143endif(${BUILD_UT})
Ed Tanous904063f2017-03-02 16:48:24 -0800144
145# web static assets
146add_subdirectory(static)
Ed Tanousf9273472017-02-28 16:05:13 -0800147
148# bmcweb
Ed Tanous904063f2017-03-02 16:48:24 -0800149add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES})
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800150target_link_libraries(bmcweb ${Boost_LIBRARIES} Boost::system)
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800151target_link_libraries(bmcweb ${CMAKE_THREAD_LIBS_INIT})
152target_link_libraries(bmcweb OpenSSL::SSL OpenSSL::Crypto)
153target_link_libraries(bmcweb g3logger)
Ed Tanous9b65f1f2017-03-07 15:17:13 -0800154target_link_libraries(bmcweb ${ZLIB_LIBRARIES})
Ed Tanous904063f2017-03-02 16:48:24 -0800155add_dependencies(bmcweb packagestaticcpp)
Ed Tanousf9273472017-02-28 16:05:13 -0800156
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800157include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Ed Tanous0fdddb12017-02-28 11:06:34 -0800158
Ed Tanous38bdb982017-03-03 14:19:33 -0800159# Visual Studio Code helper
Ed Tanous5f34a9c2017-02-28 12:35:13 -0800160# this needs to be at the end to make sure all includes are handled correctly
161get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
162execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py ${C_INCLUDE_DIRS})