-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure project layout to support use via CMake add_subdirectory (#…
…23) * Restructure project layout * build PRs on CI
- Loading branch information
Johannes Wolf
authored
Jan 18, 2021
1 parent
09e3ade
commit 6a4db60
Showing
8 changed files
with
71 additions
and
46 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
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,71 +1,91 @@ | ||
cmake_minimum_required(VERSION 3.12.4) | ||
|
||
set(PROJECT_NAME "keychain") | ||
project(${PROJECT_NAME}) | ||
project(keychain) | ||
|
||
option(BUILD_TESTS "Build tests for ${PROJECT_NAME}" OFF) | ||
|
||
if (MSVC) | ||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++11") | ||
else (MSVC) | ||
set (CMAKE_CXX_STANDARD 11) | ||
endif (MSVC) | ||
|
||
# enable compiler warnings | ||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") | ||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -pedantic") | ||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") | ||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W2 /WX") | ||
endif () | ||
add_library(${PROJECT_NAME}) | ||
target_include_directories(${PROJECT_NAME} | ||
PUBLIC | ||
"include" | ||
PRIVATE | ||
"src" | ||
"include/keychain") | ||
|
||
if (WIN32) | ||
add_definitions(-DKEYCHAIN_WINDOWS=1) | ||
set_target_properties(${PROJECT_NAME} | ||
PROPERTIES PUBLIC_HEADER "include/keychain/keychain.h") | ||
|
||
target_compile_features(${PROJECT_NAME} | ||
PUBLIC | ||
cxx_std_11) | ||
|
||
list(APPEND SOURCES "keychain_win.cpp") | ||
target_compile_options(${PROJECT_NAME} | ||
PRIVATE | ||
$<$<CXX_COMPILER_ID:MSVC>:/W2 /WX> | ||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -pedantic -Werror>) | ||
|
||
if (WIN32) | ||
target_compile_definitions(${PROJECT_NAME} | ||
PUBLIC | ||
-DKEYCHAIN_WINDOWS=1) | ||
|
||
list(APPEND KEYCHAIN_LIBRARIES crypt32) | ||
target_sources(${PROJECT_NAME} | ||
PRIVATE | ||
"src/keychain_win.cpp") | ||
|
||
target_link_libraries(${PROJECT_NAME} | ||
PRIVATE | ||
crypt32) | ||
elseif (APPLE) | ||
add_definitions(-DKEYCHAIN_MACOS=1) | ||
target_compile_definitions(${PROJECT_NAME} | ||
PUBLIC | ||
-DKEYCHAIN_MACOS=1) | ||
|
||
list(APPEND SOURCES "keychain_mac.cpp") | ||
target_sources(${PROJECT_NAME} | ||
PRIVATE | ||
"src/keychain_mac.cpp") | ||
|
||
find_library(COREFOUNDATION_LIBRARY CoreFoundation REQUIRED) | ||
list(APPEND KEYCHAIN_LIBRARIES ${COREFOUNDATION_LIBRARY}) | ||
|
||
find_library(SECURITY_LIBRARY Security REQUIRED) | ||
list(APPEND KEYCHAIN_LIBRARIES ${SECURITY_LIBRARY}) | ||
|
||
else (WIN32) # assuming Linux | ||
add_definitions(-DKEYCHAIN_LINUX=1) | ||
target_link_libraries(${PROJECT_NAME} | ||
PRIVATE | ||
${COREFOUNDATION_LIBRARY} | ||
${SECURITY_LIBRARY}) | ||
else () # assuming Linux | ||
target_compile_definitions(${PROJECT_NAME} | ||
PUBLIC | ||
-DKEYCHAIN_LINUX=1) | ||
|
||
list(APPEND SOURCES "keychain_linux.cpp") | ||
target_sources(${PROJECT_NAME} | ||
PRIVATE | ||
"src/keychain_linux.cpp") | ||
|
||
find_package(PkgConfig REQUIRED) | ||
pkg_check_modules(KEYCHAIN REQUIRED glib-2.0 libsecret-1) | ||
|
||
endif (WIN32) | ||
pkg_check_modules(GLIB2 IMPORTED_TARGET glib-2.0) | ||
pkg_check_modules(LIBSECRET IMPORTED_TARGET libsecret-1) | ||
|
||
add_library(${PROJECT_NAME} ${SOURCES}) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${KEYCHAIN_INCLUDE_DIRS}) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "keychain.h") | ||
target_link_libraries(${PROJECT_NAME} PUBLIC ${KEYCHAIN_LIBRARIES}) | ||
target_link_libraries(${PROJECT_NAME} | ||
PRIVATE | ||
PkgConfig::GLIB2 | ||
PkgConfig::LIBSECRET) | ||
endif () | ||
|
||
# Code Coverage Configuration | ||
option(CODE_COVERAGE "Enable coverage reporting" OFF) | ||
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") | ||
if (CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") | ||
set(COVERAGE_COMPILE_FLAGS "--coverage -g -O0") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILE_FLAGS}") | ||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \"--coverage\"") | ||
endif() | ||
endif() | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILE_FLAGS}") | ||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") | ||
endif () | ||
endif () | ||
|
||
install(TARGETS ${PROJECT_NAME} | ||
LIBRARY DESTINATION lib | ||
ARCHIVE DESTINATION lib | ||
PUBLIC_HEADER DESTINATION include/keychain) | ||
LIBRARY DESTINATION lib | ||
ARCHIVE DESTINATION lib | ||
PUBLIC_HEADER DESTINATION include/keychain) | ||
|
||
if (BUILD_TESTS) | ||
add_subdirectory("test") | ||
endif (BUILD_TESTS) | ||
endif () |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,5 +1,5 @@ | ||
#include "catch.hpp" | ||
#include "keychain.h" | ||
#include "keychain/keychain.h" | ||
|
||
using namespace keychain; | ||
|
||
|