-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from gocarlos/master
build: improve cmake scripts
- Loading branch information
Showing
9 changed files
with
270 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: CMake | ||
|
||
on: [push] | ||
|
||
env: | ||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) | ||
BUILD_TYPE: RelWithDebInfo | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [windows-latest, ubuntu-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- uses: actions/setup-python@v1 | ||
with: | ||
python-version: "3.x" | ||
|
||
- name: Install tools (Linux) | ||
if: startsWith(runner.os, 'Linux') | ||
run: | | ||
sudo apt-get install python3-setuptools python3-wheel python3-pip | ||
shell: bash | ||
|
||
- name: Install conan (Linux) | ||
if: startsWith(runner.os, 'Linux') | ||
run: | | ||
sudo pip3 install conan --upgrade | ||
shell: bash | ||
|
||
- name: Install conan (Windows) | ||
if: startsWith(runner.os, 'Windows') | ||
run: | | ||
pip3 install conan --upgrade | ||
shell: bash | ||
|
||
- name: Create Build Environment | ||
run: cmake -E make_directory ${{runner.workspace}}/build | ||
|
||
- name: Install conan profile | ||
working-directory: ${{runner.workspace}}/build | ||
run: conan profile new default --detect | ||
|
||
- name: Use cpp 11 (Linux) | ||
if: startsWith(runner.os, 'Linux') | ||
run: | | ||
conan profile update settings.compiler.libcxx=libstdc++11 default | ||
shell: bash | ||
|
||
- name: Install conan dependencies | ||
working-directory: ${{runner.workspace}}/build | ||
run: conan install $GITHUB_WORKSPACE --build missing | ||
shell: bash | ||
|
||
- name: Configure CMake | ||
shell: bash | ||
working-directory: ${{runner.workspace}}/build | ||
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE | ||
|
||
- name: Build | ||
working-directory: ${{runner.workspace}}/build | ||
shell: bash | ||
run: cmake --build . --config $BUILD_TYPE | ||
|
||
- name: Test | ||
working-directory: ${{runner.workspace}}/build | ||
shell: bash | ||
run: ctest --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,95 @@ | ||
# CMakeLists files in this project can | ||
# refer to the root source directory of the project as ${HELLO_SOURCE_DIR} and | ||
# to the root binary directory of the project as ${HELLO_BINARY_DIR}. | ||
cmake_minimum_required(VERSION 3.5.0) | ||
project(cpp-jwt) | ||
|
||
cmake_minimum_required (VERSION 2.8.11) | ||
project (cpp-jwt) | ||
option(CPP_JWT_BUILD_EXAMPLES "build examples" ON) | ||
option(CPP_JWT_BUILD_TESTS "build tests" ON) | ||
option(CPP_JWT_USE_VENDORED_NLOHMANN_JSON "use vendored json header" ON) | ||
|
||
#SET (CMAKE_CXX_COMPILER /usr/local/bin/g++) | ||
SET( CMAKE_CXX_FLAGS "-std=c++14 -Wall -Wextra" ) | ||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) | ||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
include_directories (include) | ||
# only set compiler flags if we are the main project, otherwise let the main | ||
# project decide on the flags | ||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) | ||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" | ||
MATCHES "Clang") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") | ||
endif() | ||
|
||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") | ||
endif() | ||
|
||
endif() | ||
|
||
find_package(OpenSSL REQUIRED) | ||
include_directories(${OPENSSL_INCLUDE_DIR}) | ||
|
||
find_package(GTest REQUIRED) | ||
include_directories(${GTEST_INCLUDE_DIRS}) | ||
if(NOT CPP_JWT_USE_VENDORED_NLOHMANN_JSON) | ||
find_package(nlohmann_json REQUIRED) | ||
endif() | ||
|
||
# ############################################################################## | ||
# LIBRARY | ||
# ############################################################################## | ||
|
||
add_library(${PROJECT_NAME} INTERFACE) | ||
target_include_directories( | ||
${PROJECT_NAME} | ||
INTERFACE $<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
${OpenSSL_INCLUDE_DIR}) | ||
target_link_libraries(${PROJECT_NAME} INTERFACE ${OpenSSL_LIBRARIES}) | ||
if(NOT CPP_JWT_USE_VENDORED_NLOHMANN_JSON) | ||
target_link_libraries(${PROJECT_NAME} INTERFACE nlohmann_json::nlohmann_json) | ||
else() | ||
add_definitions(-DCPP_JWT_USE_VENDORED_NLOHMANN_JSON) | ||
endif() | ||
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_14) | ||
|
||
# ############################################################################## | ||
# TESTS | ||
# ############################################################################## | ||
|
||
if(CPP_JWT_BUILD_TESTS) | ||
find_package(GTest REQUIRED) | ||
include_directories(${GTEST_INCLUDE_DIRS}) | ||
enable_testing() | ||
# Recurse into the "Hello" and "Demo" subdirectories. This does not actually | ||
# cause another cmake executable to run. The same process will walk through | ||
# the project's entire directory structure. | ||
add_subdirectory(tests) | ||
endif() | ||
|
||
# ############################################################################## | ||
# EXAMPLES | ||
# ############################################################################## | ||
|
||
if(CPP_JWT_BUILD_EXAMPLES) | ||
add_subdirectory(examples) | ||
endif() | ||
|
||
enable_testing() | ||
# ############################################################################## | ||
# INSTALL | ||
# ############################################################################## | ||
|
||
# Recurse into the "Hello" and "Demo" subdirectories. This does not actually | ||
# cause another cmake executable to run. The same process will walk through | ||
# the project's entire directory structure. | ||
add_subdirectory (tests) | ||
include(GNUInstallDirs) | ||
install( | ||
TARGETS ${PROJECT_NAME} | ||
EXPORT ${PROJECT_NAME}_Targets | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
|
||
add_subdirectory (examples) | ||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/detail | ||
DESTINATION include/jwt) | ||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/impl | ||
DESTINATION include/jwt) | ||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/json | ||
DESTINATION include/jwt) | ||
install( | ||
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/ | ||
DESTINATION include/jwt | ||
FILES_MATCHING | ||
PATTERN "*.hpp") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[requires] | ||
gtest/1.10.0 | ||
nlohmann_json/3.7.0 | ||
openssl/1.1.1d | ||
|
||
[generators] | ||
cmake_find_package | ||
cmake_paths | ||
|
||
[options] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
|
||
include_directories(${OPENSSL_INCLUDE_DIR}) | ||
|
||
SET(CERT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rsa_256") | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCERT_ROOT_DIR=\"\\\"${CERT_ROOT_DIR}\\\"\"") | ||
set(CERT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rsa_256") | ||
set(CMAKE_CXX_FLAGS | ||
"${CMAKE_CXX_FLAGS} -DCERT_ROOT_DIR=\"\\\"${CERT_ROOT_DIR}\\\"\"") | ||
|
||
add_executable(simple_ex1 simple_ex1.cc) | ||
target_link_libraries(simple_ex1 ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES}) | ||
add_test(NAME simple_ex1 COMMAND ./simple_ex1 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
target_link_libraries(simple_ex1 ${PROJECT_NAME}) | ||
add_test( | ||
NAME simple_ex1 | ||
COMMAND ./simple_ex1 | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
add_executable(simple_ex2 simple_ex2.cc) | ||
target_link_libraries(simple_ex2 ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES}) | ||
add_test(NAME simple_ex2 COMMAND ./simple_ex2 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
target_link_libraries(simple_ex2 ${PROJECT_NAME}) | ||
add_test( | ||
NAME simple_ex2 | ||
COMMAND ./simple_ex2 | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
add_executable(simple_ex3_rsa simple_ex3_rsa.cc) | ||
target_link_libraries(simple_ex3_rsa ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES}) | ||
add_test(NAME simple_ex3_rsa COMMAND ./simple_ex3_rsa WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
target_link_libraries(simple_ex3_rsa ${PROJECT_NAME}) | ||
add_test( | ||
NAME simple_ex3_rsa | ||
COMMAND ./simple_ex3_rsa | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,69 @@ | ||
|
||
include_directories(${OPENSSL_INCLUDE_DIR}) | ||
|
||
SET(CERT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/certs") | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCERT_ROOT_DIR=\"\\\"${CERT_ROOT_DIR}\\\"\"") | ||
set(CERT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/certs") | ||
set(CMAKE_CXX_FLAGS | ||
"${CMAKE_CXX_FLAGS} -DCERT_ROOT_DIR=\"\\\"${CERT_ROOT_DIR}\\\"\"") | ||
|
||
add_executable(test_jwt_object test_jwt_object.cc) | ||
target_link_libraries(test_jwt_object ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES}) | ||
add_test(NAME test_jwt_object COMMAND ./test_jwt_object WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
target_link_libraries(test_jwt_object ${GTest_LIBRARIES} ${PROJECT_NAME}) | ||
target_include_directories(test_jwt_object PRIVATE ${GTEST_INCLUDE_DIRS} | ||
${GTest_INCLUDE_DIRS}) | ||
add_test( | ||
NAME test_jwt_object | ||
COMMAND ./test_jwt_object | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
add_executable(test_jwt_encode test_jwt_encode.cc) | ||
target_link_libraries(test_jwt_encode ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES}) | ||
add_test(NAME test_jwt_encode COMMAND ./test_jwt_encode WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
target_link_libraries(test_jwt_encode ${GTest_LIBRARIES} ${PROJECT_NAME}) | ||
target_include_directories(test_jwt_encode PRIVATE ${GTEST_INCLUDE_DIRS} | ||
${GTest_INCLUDE_DIRS}) | ||
add_test( | ||
NAME test_jwt_encode | ||
COMMAND ./test_jwt_encode | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
add_executable(test_jwt_decode test_jwt_decode.cc) | ||
target_link_libraries(test_jwt_decode ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES}) | ||
add_test(NAME test_jwt_decode COMMAND ./test_jwt_decode WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
target_link_libraries(test_jwt_decode ${GTest_LIBRARIES} ${PROJECT_NAME}) | ||
target_include_directories(test_jwt_decode PRIVATE ${GTEST_INCLUDE_DIRS} | ||
${GTest_INCLUDE_DIRS}) | ||
add_test( | ||
NAME test_jwt_decode | ||
COMMAND ./test_jwt_decode | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
add_executable(test_jwt_decode_verifiy test_jwt_decode_verifiy.cc) | ||
target_link_libraries(test_jwt_decode_verifiy ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES}) | ||
add_test(NAME test_jwt_decode_verifiy COMMAND ./test_jwt_decode_verifiy WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
target_link_libraries(test_jwt_decode_verifiy ${GTest_LIBRARIES} | ||
${PROJECT_NAME}) | ||
target_include_directories(test_jwt_decode_verifiy | ||
PRIVATE ${GTEST_INCLUDE_DIRS} ${GTest_INCLUDE_DIRS}) | ||
add_test( | ||
NAME test_jwt_decode_verifiy | ||
COMMAND ./test_jwt_decode_verifiy | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
add_executable(test_jwt_decode_verifiy_with_exception test_jwt_decode_verifiy_with_exception.cc) | ||
target_link_libraries(test_jwt_decode_verifiy_with_exception ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES}) | ||
add_test(NAME test_jwt_decode_verifiy_with_exception COMMAND ./test_jwt_decode_verifiy_with_exception WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
add_executable(test_jwt_decode_verifiy_with_exception | ||
test_jwt_decode_verifiy_with_exception.cc) | ||
target_link_libraries(test_jwt_decode_verifiy_with_exception ${GTest_LIBRARIES} | ||
${PROJECT_NAME}) | ||
target_include_directories(test_jwt_decode_verifiy_with_exception | ||
PRIVATE ${GTEST_INCLUDE_DIRS} ${GTest_INCLUDE_DIRS}) | ||
add_test( | ||
NAME test_jwt_decode_verifiy_with_exception | ||
COMMAND ./test_jwt_decode_verifiy_with_exception | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
add_executable(test_jwt_rsa test_jwt_rsa.cc) | ||
target_link_libraries(test_jwt_rsa ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES} ) | ||
add_test(NAME test_jwt_rsa COMMAND ./test_jwt_rsa WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
target_link_libraries(test_jwt_rsa ${GTest_LIBRARIES} ${PROJECT_NAME}) | ||
target_include_directories(test_jwt_rsa PRIVATE ${GTEST_INCLUDE_DIRS} | ||
${GTest_INCLUDE_DIRS}) | ||
add_test( | ||
NAME test_jwt_rsa | ||
COMMAND ./test_jwt_rsa | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
add_executable(test_jwt_es test_jwt_es.cc) | ||
target_link_libraries(test_jwt_es ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES}) | ||
add_test(NAME test_jwt_es COMMAND ./test_jwt_es WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
target_link_libraries(test_jwt_es ${GTest_LIBRARIES} ${PROJECT_NAME}) | ||
target_include_directories(test_jwt_es PRIVATE ${GTEST_INCLUDE_DIRS} | ||
${GTest_INCLUDE_DIRS}) | ||
add_test( | ||
NAME test_jwt_es | ||
COMMAND ./test_jwt_es | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |