|
1 |
| -# CMakeLists files in this project can |
2 |
| -# refer to the root source directory of the project as ${HELLO_SOURCE_DIR} and |
3 |
| -# to the root binary directory of the project as ${HELLO_BINARY_DIR}. |
| 1 | +cmake_minimum_required(VERSION 3.5.0) |
| 2 | +project(cpp-jwt) |
4 | 3 |
|
5 |
| -cmake_minimum_required (VERSION 2.8.11) |
6 |
| -project (cpp-jwt) |
| 4 | +option(CPP_JWT_BUILD_EXAMPLES "build examples" ON) |
| 5 | +option(CPP_JWT_BUILD_TESTS "build tests" ON) |
| 6 | +option(CPP_JWT_USE_VENDORED_NLOHMANN_JSON "use vendored json header" ON) |
7 | 7 |
|
8 |
| -#SET (CMAKE_CXX_COMPILER /usr/local/bin/g++) |
9 |
| -SET( CMAKE_CXX_FLAGS "-std=c++14 -Wall -Wextra" ) |
| 8 | +list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) |
| 9 | +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR}) |
10 | 10 |
|
11 |
| -include_directories (include) |
| 11 | +# only set compiler flags if we are the main project, otherwise let the main |
| 12 | +# project decide on the flags |
| 13 | +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 14 | + set(CMAKE_CXX_STANDARD 14) |
| 15 | + set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 16 | + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" |
| 17 | + MATCHES "Clang") |
| 18 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") |
| 19 | + endif() |
| 20 | + |
| 21 | + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
| 22 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") |
| 23 | + endif() |
| 24 | + |
| 25 | +endif() |
12 | 26 |
|
13 | 27 | find_package(OpenSSL REQUIRED)
|
14 |
| -include_directories(${OPENSSL_INCLUDE_DIR}) |
15 | 28 |
|
16 |
| -find_package(GTest REQUIRED) |
17 |
| -include_directories(${GTEST_INCLUDE_DIRS}) |
| 29 | +if(NOT CPP_JWT_USE_VENDORED_NLOHMANN_JSON) |
| 30 | + find_package(nlohmann_json REQUIRED) |
| 31 | +endif() |
| 32 | + |
| 33 | +# ############################################################################## |
| 34 | +# LIBRARY |
| 35 | +# ############################################################################## |
| 36 | + |
| 37 | +add_library(${PROJECT_NAME} INTERFACE) |
| 38 | +target_include_directories( |
| 39 | + ${PROJECT_NAME} |
| 40 | + INTERFACE $<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include> |
| 41 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 42 | + ${OpenSSL_INCLUDE_DIR}) |
| 43 | +target_link_libraries(${PROJECT_NAME} INTERFACE ${OpenSSL_LIBRARIES}) |
| 44 | +if(NOT CPP_JWT_USE_VENDORED_NLOHMANN_JSON) |
| 45 | + target_link_libraries(${PROJECT_NAME} INTERFACE nlohmann_json::nlohmann_json) |
| 46 | +else() |
| 47 | + add_definitions(-DCPP_JWT_USE_VENDORED_NLOHMANN_JSON) |
| 48 | +endif() |
| 49 | +target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_14) |
| 50 | + |
| 51 | +# ############################################################################## |
| 52 | +# TESTS |
| 53 | +# ############################################################################## |
| 54 | + |
| 55 | +if(CPP_JWT_BUILD_TESTS) |
| 56 | + find_package(GTest REQUIRED) |
| 57 | + include_directories(${GTEST_INCLUDE_DIRS}) |
| 58 | + enable_testing() |
| 59 | + # Recurse into the "Hello" and "Demo" subdirectories. This does not actually |
| 60 | + # cause another cmake executable to run. The same process will walk through |
| 61 | + # the project's entire directory structure. |
| 62 | + add_subdirectory(tests) |
| 63 | +endif() |
| 64 | + |
| 65 | +# ############################################################################## |
| 66 | +# EXAMPLES |
| 67 | +# ############################################################################## |
| 68 | + |
| 69 | +if(CPP_JWT_BUILD_EXAMPLES) |
| 70 | + add_subdirectory(examples) |
| 71 | +endif() |
18 | 72 |
|
19 |
| -enable_testing() |
| 73 | +# ############################################################################## |
| 74 | +# INSTALL |
| 75 | +# ############################################################################## |
20 | 76 |
|
21 |
| -# Recurse into the "Hello" and "Demo" subdirectories. This does not actually |
22 |
| -# cause another cmake executable to run. The same process will walk through |
23 |
| -# the project's entire directory structure. |
24 |
| -add_subdirectory (tests) |
| 77 | +include(GNUInstallDirs) |
| 78 | +install( |
| 79 | + TARGETS ${PROJECT_NAME} |
| 80 | + EXPORT ${PROJECT_NAME}_Targets |
| 81 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 82 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 83 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
25 | 84 |
|
26 |
| -add_subdirectory (examples) |
| 85 | +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/detail |
| 86 | + DESTINATION include/jwt) |
| 87 | +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/impl |
| 88 | + DESTINATION include/jwt) |
| 89 | +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/json |
| 90 | + DESTINATION include/jwt) |
| 91 | +install( |
| 92 | + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/ |
| 93 | + DESTINATION include/jwt |
| 94 | + FILES_MATCHING |
| 95 | + PATTERN "*.hpp") |
0 commit comments