Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR) |
| 2 | |
| 3 | cmake_policy(SET CMP0054 OLD) |
| 4 | |
| 5 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) |
| 6 | |
| 7 | message("${CMAKE_MODULE_PATH}") |
| 8 | |
| 9 | #set(HUNTER_ROOT /home/ed/hunter) |
| 10 | SET(HUNTER_STATUS_DEBUG ON) |
| 11 | include("cmake/HunterGate.cmake") |
| 12 | |
| 13 | HunterGate( |
| 14 | URL "https://github.com/ruslo/hunter/archive/v0.16.31.tar.gz" |
| 15 | SHA1 "8fcc0a2d6206e1f2c6fc011e3e694e388d030b53" |
| 16 | ) |
| 17 | |
| 18 | option(BUILD_FOR_EMBEDDED "Build for device target" ON) |
| 19 | |
| 20 | project(bmc-webserver CXX C) |
| 21 | |
| 22 | set(CMAKE_CXX_STANDARD 14) |
| 23 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 24 | |
| 25 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 26 | |
| 27 | if ( ${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." ) |
| 29 | endif() |
| 30 | |
| 31 | # general |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 32 | option(BUILD_SHARED_LIBS "Build as shared library" OFF) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 33 | option(BUILD_UT "Enable Unit test" OFF) |
| 34 | |
| 35 | # Boost |
| 36 | add_definitions(-DBOOST_ALL_NO_LIB) |
| 37 | set(Boost_USE_STATIC_LIBS ON) |
| 38 | hunter_add_package(Boost COMPONENTS system thread regex) |
| 39 | find_package(Boost COMPONENTS system thread regex REQUIRED) |
| 40 | |
| 41 | #Openssl |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 42 | #hunter_add_package(OpenSSL) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 43 | find_package(OpenSSL REQUIRED) |
| 44 | if (NOT OPENSSL_FOUND) |
| 45 | message(FATAL_ERROR "Could not find OpenSSL") |
| 46 | endif() |
| 47 | include_directories(${OPENSSL_INCLUDE_DIR}) |
| 48 | |
| 49 | # Crow |
| 50 | include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include) |
| 51 | |
| 52 | #g3 logging |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 53 | option(ADD_FATAL_EXAMPLE "Disable g3 examples" OFF) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 54 | add_subdirectory(g3log) |
| 55 | include_directories(g3log/src) |
| 56 | |
| 57 | # Debug sanitizers |
| 58 | find_package(Sanitizers) |
| 59 | |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 60 | # C++ GSL (Guideline support libraries) |
| 61 | include_directories(GSL/include) |
| 62 | |
| 63 | set(WEBSERVER_MAIN src/webserver_main.cpp) |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 64 | |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 65 | set(HDR_FILES |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 66 | include/crow_g3_logger.hpp |
| 67 | include/ssl_key_handler.hpp |
| 68 | include/color_cout_g3_sink.hpp |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 69 | include/webassets.hpp |
| 70 | ) |
| 71 | |
| 72 | set(GENERATED_SRC_FILES |
| 73 | ${CMAKE_BINARY_DIR}/generated/webassets.cpp |
| 74 | ) |
| 75 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 76 | if (CMAKE_COMPILER_IS_GNUCC) |
| 77 | execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion |
| 78 | OUTPUT_VARIABLE GCC_VERSION) |
| 79 | string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION}) |
| 80 | list(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR) |
| 81 | list(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR) |
| 82 | |
| 83 | message(STATUS ${GCC_MAJOR}) |
| 84 | message(STATUS ${GCC_MINOR}) |
| 85 | endif() |
| 86 | |
| 87 | |
| 88 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR GCC_VERSION VERSION_GREATER 5.0) |
| 89 | set_source_files_properties(${GENERATED_SRC_FILES} PROPERTIES GENERATED TRUE) |
| 90 | endif() |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 91 | |
| 92 | set(SRC_FILES |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 93 | src/token_authorization_middleware.cpp |
| 94 | src/base64.cpp |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 95 | ${GENERATED_SRC_FILES} |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 96 | ) |
| 97 | |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 98 | set(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 Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 104 | |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 105 | # avoid the "narrowing char to X" warning for negative numbers |
| 106 | # TODO, make the python just do the right thing and turn the number negative |
| 107 | # Background: char is faster than unsigned char once compiled, so it is used |
| 108 | # extensively in the server for the "byte" type. Unfortunately, this means that |
| 109 | # the call std::string s{0xFF} fails, because 0xFF narrows to a negative number |
| 110 | # this line simply disables the warning, and the compiler does the right thing |
| 111 | # we selectively only disable this warning on this specific file |
| 112 | # http://stackoverflow.com/questions/28094263/create-array-of-chars-avoiding-narrowing |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 113 | if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 114 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.0") |
| 115 | set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-c++11-narrowing) |
| 116 | endif() |
| 117 | elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 118 | set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-c++11-narrowing) |
| 119 | endif() |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 120 | |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 121 | # big list of naughty strings |
| 122 | file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated") |
| 123 | add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp |
| 124 | COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/blns.txt ${CMAKE_BINARY_DIR}/generated/blns.hpp) |
| 125 | |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 126 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 127 | # Unit Tests |
| 128 | if(${BUILD_UT}) |
| 129 | # 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) |
| 135 | target_link_libraries(unittest Boost::boost Boost::system) |
| 136 | target_link_libraries(unittest ${CMAKE_THREAD_LIBS_INIT}) |
| 137 | target_link_libraries(unittest OpenSSL::SSL OpenSSL::Crypto) |
| 138 | target_link_libraries(unittest g3logger) |
| 139 | add_dependencies(unittest packagestaticcpp) |
| 140 | endif(${BUILD_UT}) |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 141 | |
| 142 | # web static assets |
| 143 | add_subdirectory(static) |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 144 | |
| 145 | # bmcweb |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 146 | add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES}) |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 147 | target_link_libraries(bmcweb Boost::boost Boost::system) |
| 148 | target_link_libraries(bmcweb ${CMAKE_THREAD_LIBS_INIT}) |
| 149 | target_link_libraries(bmcweb OpenSSL::SSL OpenSSL::Crypto) |
| 150 | target_link_libraries(bmcweb g3logger) |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 151 | add_dependencies(bmcweb packagestaticcpp) |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 152 | |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 153 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 154 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 155 | # Visual Studio Code helper |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 156 | # this needs to be at the end to make sure all includes are handled correctly |
| 157 | get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) |
| 158 | execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py ${C_INCLUDE_DIRS}) |