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 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 12 | |
| 13 | #SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") |
| 14 | |
| 15 | #SET(MSAN_CXX_FLAGS "-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -stdlib=libc++ -I/home/ed/libcxx_msan/include -I/home/ed/libcxx_msan/include/c++/v1") |
| 16 | #SET(MSAN_LINKER_EXE_FLAGS "${MSAN_CXX_FLAGS} -lc++abi -L/home/ed/libcxx_msan/lib") |
| 17 | include("cmake/HunterGate.cmake") |
| 18 | #HunterGate( |
| 19 | # URL "https://github.com/ruslo/hunter/archive/v0.16.31.tar.gz" |
| 20 | # SHA1 "8fcc0a2d6206e1f2c6fc011e3e694e388d030b53" |
| 21 | #) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 22 | HunterGate( |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 23 | URL "https://github.com/ruslo/hunter/archive/v0.18.16.tar.gz" |
| 24 | SHA1 "6cbca2b0e7605ad8ea22ee3527850996436f71b8" |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 25 | ) |
| 26 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 27 | |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 28 | option(BUILD_FOR_EMBEDDED "Build for device target" ON) |
| 29 | |
| 30 | project(bmc-webserver CXX C) |
| 31 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 32 | SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${MSAN_CXX_FLAGS}") |
| 33 | SET(CMAKE_EXE_LINKER_FLAGS "${MSAN_LINKER_EXE_FLAGS}") |
| 34 | |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 35 | set(CMAKE_CXX_STANDARD 14) |
| 36 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 37 | |
| 38 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 39 | |
| 40 | if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} ) |
| 41 | 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." ) |
| 42 | endif() |
| 43 | |
| 44 | # general |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 45 | option(BUILD_SHARED_LIBS "Build as shared library" OFF) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 46 | option(BUILD_UT "Enable Unit test" OFF) |
| 47 | |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 48 | # This needs to be before the crow and other module includes so headers get overriden correctly |
| 49 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) |
| 50 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 51 | # security flags |
| 52 | #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong -fPIE -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security" ) |
| 53 | #SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now") |
| 54 | |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 55 | # Boost |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 56 | #add_definitions(-DBOOST_ASIO_ENABLE_HANDLER_TRACKING) |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 57 | #add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 58 | add_definitions(-DBOOST_ALL_NO_LIB) |
| 59 | set(Boost_USE_STATIC_LIBS ON) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 60 | hunter_add_package(Boost COMPONENTS system thread) |
| 61 | find_package(Boost REQUIRED system thread REQUIRED) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 62 | |
| 63 | #Openssl |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 64 | hunter_add_package(OpenSSL) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 65 | find_package(OpenSSL REQUIRED) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 66 | |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 67 | |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 68 | |
| 69 | #g3 logging |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 70 | # G3logger does some unfortunate compile options, so cheat a little bit and copy/paste |
| 71 | |
| 72 | set(LOG_SRC ${CMAKE_CURRENT_SOURCE_DIR}/g3log/src) |
| 73 | |
| 74 | file(GLOB_RECURSE SRC_FILES ${LOG_SRC}/*.cpp ${LOG_SRC}/*.ipp) |
| 75 | file(GLOB_RECURSE HEADER_FILES ${LOG_SRC}/*.hpp) |
| 76 | |
| 77 | IF (MSVC OR MINGW) |
| 78 | list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_unix.cpp) |
| 79 | ELSE() |
| 80 | list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_windows.cpp ${LOG_SRC}/g3log/stacktrace_windows.hpp ${LOG_SRC}/stacktrace_windows.cpp) |
| 81 | ENDIF (MSVC OR MINGW) |
| 82 | |
| 83 | # Create the g3log library |
| 84 | include_directories(${LOG_SRC}) |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 85 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 86 | add_library(g3logger ${SRC_FILES}) |
| 87 | set_target_properties(g3logger PROPERTIES |
| 88 | LINKER_LANGUAGE CXX |
| 89 | OUTPUT_NAME g3logger |
| 90 | CLEAN_DIRECT_OUTPUT 1) |
| 91 | target_link_libraries(g3logger ${PLATFORM_LINK_LIBRIES}) |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 92 | |
| 93 | |
| 94 | # Crow |
| 95 | add_definitions(-DCROW_ENABLE_SSL) |
| 96 | include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include) |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 97 | |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 98 | #Zlib |
| 99 | #hunter_add_package(ZLIB) |
| 100 | #find_package(ZLIB REQUIRED) |
| 101 | |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 102 | # C++ GSL (Guideline support libraries) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 103 | include_directories(gsl-lite/include) |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 104 | |
| 105 | set(WEBSERVER_MAIN src/webserver_main.cpp) |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 106 | |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 107 | set(HDR_FILES |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 108 | include/crow/g3_logger.hpp |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 109 | include/ssl_key_handler.hpp |
| 110 | include/color_cout_g3_sink.hpp |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 111 | include/webassets.hpp |
| 112 | ) |
| 113 | |
| 114 | set(GENERATED_SRC_FILES |
| 115 | ${CMAKE_BINARY_DIR}/generated/webassets.cpp |
| 116 | ) |
| 117 | |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 118 | set_source_files_properties(${GENERATED_SRC_FILES} PROPERTIES GENERATED TRUE) |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 119 | |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 120 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 121 | if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) |
| 122 | set_source_files_properties(${CMAKE_BINARY_DIR}/generated/webassets.cpp PROPERTIES COMPILE_FLAGS -Wno-narrowing) |
| 123 | endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) |
| 124 | endif() |
| 125 | |
| 126 | |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 127 | set(SRC_FILES |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 128 | src/token_authorization_middleware.cpp |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 129 | src/security_headers_middleware.cpp |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 130 | src/base64.cpp |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 131 | ${GENERATED_SRC_FILES} |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 132 | ) |
| 133 | |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 134 | set(UT_FILES |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 135 | src/crowtest/crow_unittest.cpp |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 136 | src/gtest_main.cpp |
| 137 | src/base64_test.cpp |
| 138 | src/token_authorization_middleware_test.cpp |
| 139 | ${CMAKE_BINARY_DIR}/generated/blns.hpp |
| 140 | ) |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 141 | |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 142 | file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated") |
| 143 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 144 | # Unit Tests |
| 145 | if(${BUILD_UT}) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 146 | # big list of naughty strings |
| 147 | add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/generated/blns.hpp |
| 148 | COMMAND xxd -i ${CMAKE_CURRENT_SOURCE_DIR}/src/blns.txt ${CMAKE_BINARY_DIR}/generated/blns.hpp) |
| 149 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 150 | # googletest |
| 151 | enable_testing() |
| 152 | find_package(GTest REQUIRED) |
| 153 | |
| 154 | add_executable(unittest ${HDR_FILES} ${SRC_FILES} ${UT_FILES}) |
| 155 | target_link_libraries(unittest GTest::GTest GTest::Main) |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 156 | target_link_libraries(unittest Boost::system Boost::thread) |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 157 | target_link_libraries(unittest ${CMAKE_THREAD_LIBS_INIT}) |
| 158 | target_link_libraries(unittest OpenSSL::SSL OpenSSL::Crypto) |
| 159 | target_link_libraries(unittest g3logger) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 160 | #target_link_libraries(unittest zlib) |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 161 | add_dependencies(unittest packagestaticcpp) |
| 162 | endif(${BUILD_UT}) |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 163 | |
| 164 | # web static assets |
| 165 | add_subdirectory(static) |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 166 | |
| 167 | # bmcweb |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 168 | add_executable(bmcweb ${WEBSERVER_MAIN} ${HDR_FILES} ${SRC_FILES}) |
Ed Tanous | 8041f31 | 2017-04-03 09:47:01 -0700 | [diff] [blame] | 169 | target_link_libraries(bmcweb Boost::system Boost::thread) |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 170 | target_link_libraries(bmcweb ${CMAKE_THREAD_LIBS_INIT}) |
| 171 | target_link_libraries(bmcweb OpenSSL::SSL OpenSSL::Crypto) |
| 172 | target_link_libraries(bmcweb g3logger) |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 173 | target_link_libraries(bmcweb ${ZLIB_LIBRARIES}) |
Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 174 | add_dependencies(bmcweb packagestaticcpp) |
Ed Tanous | f927347 | 2017-02-28 16:05:13 -0800 | [diff] [blame] | 175 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 176 | # bmcweb |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 177 | add_executable(udpclient src/udpclient.cpp) |
| 178 | |
| 179 | target_link_libraries(udpclient Boost::system) |
| 180 | target_link_libraries(udpclient ${CMAKE_THREAD_LIBS_INIT}) |
| 181 | |
| 182 | |
| 183 | add_executable(getvideo src/getvideo_main.cpp) |
| 184 | |
Ed Tanous | 38bdb98 | 2017-03-03 14:19:33 -0800 | [diff] [blame] | 185 | # Visual Studio Code helper |
Ed Tanous | 5f34a9c | 2017-02-28 12:35:13 -0800 | [diff] [blame] | 186 | # this needs to be at the end to make sure all includes are handled correctly |
| 187 | get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 188 | execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py ${C_INCLUDE_DIRS}) |