mirror of
				https://github.com/TheLartians/ModernCppStarter.git
				synced 2025-10-31 02:01:33 +01:00 
			
		
		
		
	changes acording review comments
update to current PackageProject version 1.5.0 too
This commit is contained in:
		
							parent
							
								
									f76aa76a81
								
							
						
					
					
						commit
						b483a1eb5a
					
				
					 4 changed files with 11 additions and 30 deletions
				
			
		|  | @ -27,12 +27,9 @@ include(cmake/CPM.cmake) | |||
| CPMAddPackage( | ||||
|   NAME PackageProject.cmake | ||||
|   GITHUB_REPOSITORY TheLartians/PackageProject.cmake | ||||
|   VERSION 1.4.1 | ||||
|   VERSION 1.5.0 | ||||
| ) | ||||
| 
 | ||||
| # 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 | ||||
| # export set.  see too https://gitlab.kitware.com/cmake/cmake/-/issues/15415 | ||||
| CPMAddPackage( | ||||
|   NAME fmt | ||||
|   GIT_TAG 7.1.3 | ||||
|  | @ -53,14 +50,12 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/ | |||
| # target: add_library(Greeter INTERFACE) | ||||
| add_library(Greeter ${headers} ${sources}) | ||||
| 
 | ||||
| # EITHER: set_target_properties(Greeter PROPERTIES CXX_STANDARD 17) # OR: | ||||
| target_compile_features(Greeter PUBLIC cxx_std_17) | ||||
| set_target_properties(Greeter PROPERTIES CXX_STANDARD 17) | ||||
| 
 | ||||
| # 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: | ||||
| # Link dependencies | ||||
| target_link_libraries(Greeter PUBLIC fmt::fmt) | ||||
| 
 | ||||
| target_include_directories( | ||||
|  | @ -84,6 +79,6 @@ packageProject( | |||
|   INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} | ||||
|   VERSION_HEADER "${VERSION_HEADER_LOCATION}" | ||||
|   COMPATIBILITY ExactVersion | ||||
|   # TBD COMPATIBILITY SameMajorVersion | ||||
|   COMPATIBILITY SameMajorVersion | ||||
|   DEPENDENCIES "fmt 7.1.3" | ||||
| ) | ||||
|  |  | |||
|  | @ -8,8 +8,6 @@ | |||
| 
 | ||||
| // NOLINTNEXTLINE(modernize-use-trailing-return-type)
 | ||||
| int main(int argc, char** argv) { | ||||
|   // prevent warning: initialization of 'languages' with static storage duration may throw an
 | ||||
|   // exception that cannot be caught [cert-err58-cpp]
 | ||||
|   const std::unordered_map<std::string, greeter::LanguageCode> languages{ | ||||
|       {"en", greeter::LanguageCode::EN}, | ||||
|       {"de", greeter::LanguageCode::DE}, | ||||
|  | @ -17,8 +15,6 @@ int main(int argc, char** argv) { | |||
|       {"fr", greeter::LanguageCode::FR}, | ||||
|   }; | ||||
| 
 | ||||
|   // prevent warning: do not use pointer arithmetic
 | ||||
|   // [cppcoreguidelines-pro-bounds-pointer-arithmetic]
 | ||||
|   cxxopts::Options options(*argv, "A program to welcome the world!"); | ||||
| 
 | ||||
|   std::string language; | ||||
|  | @ -40,7 +36,6 @@ int main(int argc, char** argv) { | |||
|     return 0; | ||||
|   } | ||||
| 
 | ||||
|   // prevent warning: do not use 'else' after 'return' [readability-else-after-return]
 | ||||
|   if (result["version"].as<bool>()) { | ||||
|     std::cout << "Greeter, version " << GREETER_VERSION << std::endl; | ||||
|     return 0; | ||||
|  |  | |||
|  | @ -1,6 +1,10 @@ | |||
| cmake_minimum_required(VERSION 3.14 FATAL_ERROR) | ||||
| 
 | ||||
| project(GreeterTests LANGUAGES CXX) | ||||
| project( | ||||
|   GreeterTests | ||||
|   VERSION 1.0 | ||||
|   LANGUAGES CXX | ||||
| ) | ||||
| 
 | ||||
| # ---- Options ---- | ||||
| 
 | ||||
|  | @ -22,7 +26,7 @@ CPMAddPackage( | |||
| ) | ||||
| 
 | ||||
| if(TEST_INSTALLED_VERSION) | ||||
|   find_package(Greeter ${PROJECT_VERSION} REQUIRED) | ||||
|   find_package(Greeter ${PROJECT_VERSION} EXACT REQUIRED) | ||||
| else() | ||||
|   CPMAddPackage(NAME Greeter SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..) | ||||
| endif() | ||||
|  | @ -40,7 +44,6 @@ CPMAddPackage( | |||
| file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp) | ||||
| add_executable(GreeterTests ${sources}) | ||||
| target_link_libraries(GreeterTests doctest::doctest Greeter::Greeter) | ||||
| 
 | ||||
| set_target_properties(GreeterTests PROPERTIES CXX_STANDARD 17) | ||||
| 
 | ||||
| # enable compiler warnings | ||||
|  | @ -57,14 +60,7 @@ endif() | |||
| 
 | ||||
| enable_testing() | ||||
| 
 | ||||
| # Note: doctest and similar testing frameworks can automatically configure CMake tests For other | ||||
| # testing frameworks add the tests target instead: | ||||
| if(DEFINED doctest_SOURCE_DIR) | ||||
|   include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake) | ||||
|   doctest_discover_tests(GreeterTests) | ||||
| else() | ||||
|   add_test(greeterTests GreeterTests) | ||||
| endif() | ||||
| add_test(NAME greeterTests COMMAND GreeterTests) | ||||
| 
 | ||||
| # ---- code coverage ---- | ||||
| 
 | ||||
|  |  | |||
|  | @ -16,11 +16,6 @@ TEST_CASE("Greeter") { | |||
| } | ||||
| 
 | ||||
| TEST_CASE("Greeter version") { | ||||
| #if (__cpp_lib_starts_ends_with) | ||||
|   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 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue