mirror of
https://github.com/TheLartians/ModernCppStarter.git
synced 2025-08-31 22:21:13 +02:00
back to version 1.0
respect most review comments
This commit is contained in:
parent
4f309d5b79
commit
f158b9ca9c
3 changed files with 28 additions and 24 deletions
|
@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
# Note: update this to your new project's name and version
|
# Note: update this to your new project's name and version
|
||||||
project(
|
project(
|
||||||
Greeter
|
Greeter
|
||||||
VERSION 1.1
|
VERSION 1.0
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,12 +41,11 @@ CPMAddPackage(
|
||||||
# Note: If fmt is not imported, this is needed to prevent: CMake Error: install(EXPORT
|
# Note: If fmt is not imported, this is needed to prevent: CMake Error: install(EXPORT
|
||||||
# "GreeterTargets" ...) includes target "Greeter" which requires target "fmt" that is not in any
|
# "GreeterTargets" ...) includes target "Greeter" which requires target "fmt" that is not in any
|
||||||
# export set. see too https://gitlab.kitware.com/cmake/cmake/-/issues/15415
|
# export set. see too https://gitlab.kitware.com/cmake/cmake/-/issues/15415
|
||||||
set(FMT_VERSION 7.1.3)
|
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
NAME fmt
|
NAME fmt
|
||||||
GIT_TAG ${FMT_VERSION}
|
GIT_TAG 7.1.3
|
||||||
GITHUB_REPOSITORY fmtlib/fmt
|
GITHUB_REPOSITORY fmtlib/fmt # to get an installable target
|
||||||
# XXX OPTION "FMT_INSTALL YES"
|
OPTION "FMT_INSTALL YES"
|
||||||
)
|
)
|
||||||
|
|
||||||
# ---- Add source files ----
|
# ---- Add source files ----
|
||||||
|
@ -59,11 +58,11 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/
|
||||||
# ---- Create library ----
|
# ---- Create library ----
|
||||||
|
|
||||||
# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
|
# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
|
||||||
# target: add_library(Greeter INTERFACE)
|
# target! EITHER: add_library(Greeter INTERFACE) OR:
|
||||||
add_library(Greeter)
|
add_library(Greeter ${headers} ${sources})
|
||||||
target_compile_features(Greeter PUBLIC cxx_std_17)
|
|
||||||
|
|
||||||
target_sources(Greeter PRIVATE ${headers} ${sources})
|
set_target_properties(Greeter PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD})
|
||||||
|
# OR target_compile_features(Greeter PUBLIC cxx_std_17)
|
||||||
|
|
||||||
# being a cross-platform target, we enforce standards conformance on MSVC
|
# being a cross-platform target, we enforce standards conformance on MSVC
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
|
@ -94,5 +93,6 @@ packageProject(
|
||||||
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
|
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
|
||||||
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
|
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
|
||||||
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
|
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
|
||||||
# XXX DEPENDENCIES "fmt ${FMT_VERSION}"
|
# TODO COMPATIBILITY SameMajorVersion
|
||||||
|
DEPENDENCIES "fmt 7.1.3"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
project(
|
project(GreeterTests LANGUAGES CXX)
|
||||||
GreeterTests
|
|
||||||
VERSION 1.1
|
|
||||||
LANGUAGES CXX
|
|
||||||
)
|
|
||||||
|
|
||||||
# ---- Options ----
|
# ---- Options ----
|
||||||
|
|
||||||
|
@ -43,16 +39,16 @@ CPMAddPackage(
|
||||||
|
|
||||||
file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)
|
file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)
|
||||||
add_executable(GreeterTests ${sources})
|
add_executable(GreeterTests ${sources})
|
||||||
target_link_libraries(GreeterTests doctest Greeter::Greeter)
|
target_link_libraries(GreeterTests doctest::doctest Greeter::Greeter)
|
||||||
|
|
||||||
set_target_properties(GreeterTests PROPERTIES CXX_STANDARD 17)
|
set_target_properties(GreeterTests PROPERTIES CXX_STANDARD 17)
|
||||||
|
|
||||||
# enable compiler warnings
|
# enable compiler warnings
|
||||||
if(NOT TEST_INSTALLED_VERSION)
|
if(NOT TEST_INSTALLED_VERSION)
|
||||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||||
target_compile_options(Greeter PRIVATE -Wall -pedantic -Wextra -Werror)
|
target_compile_options(Greeter PUBLIC -Wall -Wpedantic -Wextra -Werror)
|
||||||
elseif(MSVC)
|
elseif(MSVC)
|
||||||
target_compile_options(Greeter PRIVATE /W4 /WX)
|
target_compile_options(Greeter PUBLIC /W4 /WX)
|
||||||
target_compile_definitions(GreeterTests PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS)
|
target_compile_definitions(GreeterTests PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
@ -63,13 +59,16 @@ enable_testing()
|
||||||
|
|
||||||
# Note: doctest and similar testing frameworks can automatically configure CMake tests For other
|
# Note: doctest and similar testing frameworks can automatically configure CMake tests For other
|
||||||
# testing frameworks add the tests target instead:
|
# testing frameworks add the tests target instead:
|
||||||
add_test(greeterTests GreeterTests)
|
if(DEFINED doctest_SOURCE_DIR)
|
||||||
# include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake) doctest_discover_tests(GreeterTests)
|
include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake)
|
||||||
# Warning: if doctest is imported with find_package() this will fail! CK
|
doctest_discover_tests(GreeterTests)
|
||||||
|
else()
|
||||||
|
add_test(greeterTests GreeterTests)
|
||||||
|
endif()
|
||||||
|
|
||||||
# ---- code coverage ----
|
# ---- code coverage ----
|
||||||
|
|
||||||
if(ENABLE_TEST_COVERAGE AND NOT TEST_INSTALLED_VERSION)
|
if(ENABLE_TEST_COVERAGE)
|
||||||
target_compile_options(Greeter PUBLIC -O0 -g -fprofile-arcs -ftest-coverage)
|
target_compile_options(Greeter PUBLIC -O0 -g -fprofile-arcs -ftest-coverage)
|
||||||
target_link_options(Greeter PUBLIC -fprofile-arcs -ftest-coverage)
|
target_link_options(Greeter PUBLIC -fprofile-arcs -ftest-coverage)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -16,8 +16,13 @@ TEST_CASE("Greeter") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Greeter version") {
|
TEST_CASE("Greeter version") {
|
||||||
static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.1"));
|
#if (__cpp_lib_starts_ends_with)
|
||||||
CHECK(std::string(GREETER_VERSION) == std::string("1.1"));
|
static_assert(std::string_view(GREETER_VERSION).starts_with("1.0")); // TBD C++20 only
|
||||||
|
CHECK(std::string(GREETER_VERSION).starts_with("1.0")); // SameMajorVersion
|
||||||
|
#else
|
||||||
|
static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0"));
|
||||||
|
CHECK(std::string(GREETER_VERSION) == std::string("1.0"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Greeter date") {
|
TEST_CASE("Greeter date") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue