mirror of
https://github.com/TheLartians/ModernCppStarter.git
synced 2025-08-30 21:51:12 +02:00
Merge branch 'master' into develop
This commit is contained in:
commit
9d1c7413f0
7 changed files with 27 additions and 38 deletions
|
@ -29,17 +29,13 @@ include(cmake/CPM.cmake)
|
|||
CPMUsePackageLock(package-lock.cmake)
|
||||
|
||||
# PackageProject.cmake will be used to make our target installable
|
||||
CPMAddPackage(
|
||||
NAME PackageProject.cmake
|
||||
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
|
||||
VERSION 1.5.0
|
||||
)
|
||||
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.4.1")
|
||||
|
||||
CPMAddPackage(
|
||||
NAME fmt
|
||||
GIT_TAG 7.1.3
|
||||
GITHUB_REPOSITORY fmtlib/fmt # to get an installable target
|
||||
OPTIONS "FMT_INSTALL YES"
|
||||
GITHUB_REPOSITORY fmtlib/fmt
|
||||
OPTIONS "FMT_INSTALL YES" # create an installable target
|
||||
)
|
||||
|
||||
# ---- Add source files ----
|
||||
|
@ -52,19 +48,18 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS source/*.cpp)
|
|||
# ---- Create library ----
|
||||
|
||||
# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
|
||||
# target! EITHER: add_library(Greeter INTERFACE) OR:
|
||||
# target: add_library(Greeter INTERFACE)
|
||||
add_library(Greeter ${headers} ${sources})
|
||||
set_target_properties(Greeter PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD})
|
||||
|
||||
# for SameMajorVersion upgrade stategie
|
||||
set_target_properties(Greeter PROPERTIES SOVERSION 1 VERSION ${PROJECT_VERSION})
|
||||
|
||||
# being a cross-platform target, we enforce standards conformance on MSVC:
|
||||
# being a cross-platform target, we enforce standards conformance on MSVC
|
||||
target_compile_options(Greeter PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive>")
|
||||
|
||||
# Link dependencies EITHER:
|
||||
target_link_libraries(Greeter PRIVATE $<BUILD_INTERFACE:fmt::fmt-header-only>)
|
||||
# OR: target_link_libraries(Greeter PUBLIC fmt::fmt)
|
||||
# Link dependencies
|
||||
target_link_libraries(Greeter PUBLIC fmt::fmt)
|
||||
|
||||
set(INCLUDE_INSTALL_DIR include/${PROJECT_NAME}-${PROJECT_VERSION})
|
||||
target_include_directories(
|
||||
|
@ -96,5 +91,5 @@ packageProject(
|
|||
INCLUDE_DESTINATION ${INCLUDE_INSTALL_DIR}
|
||||
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
|
||||
COMPATIBILITY SameMajorVersion
|
||||
# Note: not needed DEPENDENCIES "fmt 7.1.3"
|
||||
DEPENDENCIES "fmt 7.1.3"
|
||||
)
|
||||
|
|
|
@ -34,7 +34,10 @@ This template is the result of learnings from many previous projects and should
|
|||
|
||||
### Adjust the template to your needs
|
||||
|
||||
- Use this repo [as a template](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) and replace all occurrences of "Greeter" in the relevant CMakeLists.txt with the name of your project
|
||||
- Use this repo [as a template](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template).
|
||||
- Replace all occurrences of "Greeter" in the relevant CMakeLists.txt with the name of your project
|
||||
- Capitalization matters here: `Greeter` means the name of the project, while `greeter` is used in file names.
|
||||
- Remember to rename the `include/greeter` directory to use your project's lowercase name and update all relevant `#include`s accordingly.
|
||||
- Replace the source files with your own
|
||||
- For header-only libraries: see the comments in [CMakeLists.txt](CMakeLists.txt)
|
||||
- Add [your project's codecov token](https://docs.codecov.io/docs/quick-start) to your project's github secrets under `CODECOV_TOKEN`
|
||||
|
|
|
@ -12,4 +12,4 @@ enable_testing()
|
|||
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../standalone standalone)
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../test test)
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../documentation documentation)
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../documentation documentation)
|
|
@ -1,4 +1,4 @@
|
|||
set(CPM_DOWNLOAD_VERSION 0.30.0)
|
||||
set(CPM_DOWNLOAD_VERSION 0.31.0)
|
||||
|
||||
if(CPM_SOURCE_CACHE)
|
||||
# Expand relative path. This is important if the provided path contains a tilde (~)
|
||||
|
|
|
@ -11,12 +11,7 @@ include(../cmake/tools.cmake)
|
|||
include(../cmake/CPM.cmake)
|
||||
CPMUsePackageLock(package-lock.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME cxxopts
|
||||
GITHUB_REPOSITORY jarro2783/cxxopts
|
||||
VERSION 2.2.0
|
||||
OPTIONS "CXXOPTS_BUILD_EXAMPLES Off" "CXXOPTS_BUILD_TESTS Off"
|
||||
)
|
||||
CPMAddPackage("gh:jarro2783/cxxopts@2.2.0")
|
||||
|
||||
CPMAddPackage(NAME Greeter SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
|
||||
|
||||
|
|
|
@ -20,11 +20,7 @@ include(../cmake/tools.cmake)
|
|||
include(../cmake/CPM.cmake)
|
||||
CPMUsePackageLock(package-lock.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME doctest
|
||||
GITHUB_REPOSITORY onqtam/doctest
|
||||
GIT_TAG 2.4.5
|
||||
)
|
||||
CPMAddPackage("gh:onqtam/doctest#2.4.5")
|
||||
|
||||
if(TEST_INSTALLED_VERSION)
|
||||
find_package(Greeter ${PROJECT_VERSION} REQUIRED)
|
||||
|
@ -45,12 +41,13 @@ CPMAddPackage(
|
|||
file(GLOB sources CONFIGURE_DEPENDS source/*.cpp)
|
||||
add_executable(GreeterTests ${sources})
|
||||
target_link_libraries(GreeterTests doctest::doctest Greeter::Greeter)
|
||||
set_target_properties(GreeterTests PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD})
|
||||
|
||||
set_target_properties(GreeterTests PROPERTIES CXX_STANDARD 17)
|
||||
|
||||
# enable compiler warnings
|
||||
if(NOT TEST_INSTALLED_VERSION)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
target_compile_options(Greeter PUBLIC -Wall -Wextra -Werror)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
target_compile_options(Greeter PUBLIC -Wall -Wpedantic -Wextra -Werror)
|
||||
elseif(MSVC)
|
||||
target_compile_options(Greeter PUBLIC /W4 /WX)
|
||||
target_compile_definitions(GreeterTests PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS)
|
||||
|
@ -61,7 +58,11 @@ endif()
|
|||
|
||||
enable_testing()
|
||||
|
||||
add_test(NAME greeterTests COMMAND GreeterTests -s false)
|
||||
# Note: doctest and similar testing frameworks can automatically configure CMake tests. For other
|
||||
# testing frameworks add the tests target instead: add_test(NAME greeterTests COMMAND GreeterTests)
|
||||
|
||||
include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake)
|
||||
doctest_discover_tests(GreeterTests)
|
||||
|
||||
# ---- code coverage ----
|
||||
|
||||
|
|
|
@ -14,11 +14,6 @@ TEST_CASE("Greeter") {
|
|||
}
|
||||
|
||||
TEST_CASE("Greeter version") {
|
||||
#if (__cpp_lib_starts_ends_with)
|
||||
static_assert(std::string_view(GREETER_VERSION).starts_with("1")); // TBD C++20 only
|
||||
CHECK(std::string(GREETER_VERSION).starts_with("1")); // SameMajorVersion
|
||||
#else
|
||||
static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0.1"));
|
||||
CHECK(std::string(GREETER_VERSION) == std::string("1.0.1"));
|
||||
#endif
|
||||
static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0"));
|
||||
CHECK(std::string(GREETER_VERSION) == std::string("1.0"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue