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) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 10 | #SET(HUNTER_STATUS_DEBUG ON) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 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 |
Ed Tanous | c4771fb | 2017-03-13 13:39:49 -0700 | [diff] [blame^] | 36 | add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 37 | add_definitions(-DBOOST_ALL_NO_LIB) |
| 38 | set(Boost_USE_STATIC_LIBS ON) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 39 | hunter_add_package(Boost COMPONENTS system thread) |
| 40 | find_package(Boost REQUIRED system thread REQUIRED) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 41 | |
| 42 | #Openssl |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 43 | hunter_add_package(OpenSSL) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 44 | find_package(OpenSSL REQUIRED) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 45 | |
| 46 | # Crow |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 47 | add_definitions(-DCROW_ENABLE_SSL) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 48 | include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 49 | #add_subdirectory(crow) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 50 | |
| 51 | #g3 logging |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 52 | option(ADD_FATAL_EXAMPLE "Disable g3 examples" OFF) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 53 | add_subdirectory(g3log) |
| 54 | include_directories(g3log/src) |
| 55 | |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 56 | #Zlib |
| 57 | #hunter_add_package(ZLIB) |
| 58 | #find_package(ZLIB REQUIRED) |
| 59 | |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 60 | # Debug sanitizers |
| 61 | find_package(Sanitizers) |
| 62 | |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 63 | # C++ GSL (Guideline support libraries) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 64 | include_directories(gsl-lite/include) |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 65 | |
| 66 | set(WEBSERVER_MAIN src/webserver_main.cpp) |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 67 | |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 68 | set(HDR_FILES |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 69 | include/crow_g3_logger.hpp |
| 70 | include/ssl_key_handler.hpp |
| 71 | include/color_cout_g3_sink.hpp |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 72 | include/webassets.hpp |
| 73 | ) |
| 74 | |
| 75 | set(GENERATED_SRC_FILES |
| 76 | ${CMAKE_BINARY_DIR}/generated/webassets.cpp |
| 77 | ) |
| 78 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 79 | if (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}) |
| 88 | endif() |
| 89 | |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 90 | set_source_files_properties(${GENERATED_SRC_FILES} PROPERTIES GENERATED TRUE) |
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 | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 105 | file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated") |
| 106 | |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 107 | # 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 Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 111 | # 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 Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 113 | # we selectively only disable this warning on this specific file |
| 114 | # http://stackoverflow.com/questions/28094263/create-array-of-chars-avoiding-narrowing |
Ed Tanous | c4771fb | 2017-03-13 13:39:49 -0700 | [diff] [blame^] | 115 | if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 116 | set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-c++11-narrowing) |
Ed Tanous | c4771fb | 2017-03-13 13:39:49 -0700 | [diff] [blame^] | 117 | endif() |
| 118 | if("${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 Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 122 | endif() |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 123 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 124 | # Unit Tests |
| 125 | if(${BUILD_UT}) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 126 | |
| 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 Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 131 | # 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 Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 137 | target_link_libraries(unittest ${Boost_LIBRARIES} Boost::system) |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 138 | target_link_libraries(unittest ${CMAKE_THREAD_LIBS_INIT}) |
| 139 | target_link_libraries(unittest OpenSSL::SSL OpenSSL::Crypto) |
| 140 | target_link_libraries(unittest g3logger) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 141 | #target_link_libraries(unittest zlib) |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 142 | add_dependencies(unittest packagestaticcpp) |
| 143 | endif(${BUILD_UT}) |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 144 | |
| 145 | # web static assets |
| 146 | add_subdirectory(static) |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 147 | |
| 148 | # bmcweb |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 149 | add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES}) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 150 | target_link_libraries(bmcweb ${Boost_LIBRARIES} Boost::system) |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 151 | target_link_libraries(bmcweb ${CMAKE_THREAD_LIBS_INIT}) |
| 152 | target_link_libraries(bmcweb OpenSSL::SSL OpenSSL::Crypto) |
| 153 | target_link_libraries(bmcweb g3logger) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 154 | target_link_libraries(bmcweb ${ZLIB_LIBRARIES}) |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 155 | add_dependencies(bmcweb packagestaticcpp) |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 156 | |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 157 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 158 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 159 | # Visual Studio Code helper |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 160 | # this needs to be at the end to make sure all includes are handled correctly |
| 161 | get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) |
| 162 | execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py ${C_INCLUDE_DIRS}) |