mirror of
				https://github.com/TheLartians/ModernCppStarter.git
				synced 2025-10-31 02:01:33 +01:00 
			
		
		
		
	cleanup build files
use strict -std=c++20 update cmake-format config file
This commit is contained in:
		
							parent
							
								
									1aad14a6fa
								
							
						
					
					
						commit
						7f36b7cb86
					
				
					 12 changed files with 70 additions and 164 deletions
				
			
		|  | @ -5,10 +5,6 @@ format: | |||
| 
 | ||||
| parse: | ||||
|   additional_commands: | ||||
|     cpmdeclarepackage: | ||||
|       spelling: CPMDeclarePackage | ||||
|     cpmusepackagelock: | ||||
|       spelling: CPMUsePackageLock | ||||
|     cpmaddpackage: | ||||
|       pargs: | ||||
|         nargs: '*' | ||||
|  | @ -44,10 +40,16 @@ parse: | |||
|         flags: [] | ||||
|       spelling: CPMFindPackage | ||||
|       kwargs: *cpmaddpackagekwargs | ||||
|     packageproject: | ||||
|     cpmdeclarepackage: | ||||
|       pargs: | ||||
|         nargs: '*' | ||||
|         flags: [] | ||||
|       spelling: CPMDeclarePackage | ||||
|       kwargs: *cpmaddpackagekwargs | ||||
|     packageproject: | ||||
|       pargs: | ||||
|         nargs: '*' | ||||
|         flags: [NO_VERSION_SUFFIX] | ||||
|       spelling: packageProject | ||||
|       kwargs: | ||||
|         NAME: 1 | ||||
|  | @ -59,3 +61,12 @@ parse: | |||
|         COMPATIBILITY: 1 | ||||
|         VERSION_HEADER: 1 | ||||
|         DEPENDENCIES: + | ||||
|     cpmusepackagelock: | ||||
|       pargs: 1 | ||||
|       spelling: CPMUsePackageLock | ||||
|     cpmregisterpackage: | ||||
|       pargs: 1 | ||||
|       spelling: CPMRegisterPackage | ||||
|     cpmgetpackageversion: | ||||
|       pargs: 2 | ||||
|       spelling: CPMGetPackageVersion | ||||
|  |  | |||
							
								
								
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -1,4 +1,4 @@ | |||
| root/ | ||||
| stagedir/ | ||||
| build/ | ||||
| /build* | ||||
| /.vscode | ||||
|  |  | |||
|  | @ -20,6 +20,8 @@ endif() | |||
| 
 | ||||
| # ---- Project settings ---- | ||||
| 
 | ||||
| option(BUILD_SHARED_LIBS "Create shared libraries if ON" OFF) | ||||
| 
 | ||||
| if(NOT DEFINED CMAKE_CXX_STANDARD) | ||||
|   set(CMAKE_CXX_STANDARD 20) | ||||
|   set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||||
|  | @ -60,11 +62,11 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS source/*.cpp) | |||
| 
 | ||||
| # Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface | ||||
| # target! EITHER: add_library(Greeter INTERFACE) OR: | ||||
| add_library(Greeter SHARED ${headers} ${sources}) | ||||
| add_library(Greeter ${headers} ${sources}) | ||||
| 
 | ||||
| # EITHER: | ||||
| set_target_properties(Greeter PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD}) | ||||
| # OR: target_compile_features(Greeter PUBLIC cxx_std_17) | ||||
| # OR: target_compile_features(Greeter PUBLIC cxx_std_20) | ||||
| 
 | ||||
| # being a cross-platform target, we enforce standards conformance on MSVC EITHER: | ||||
| # target_compile_options(Greeter PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive>") OR: | ||||
|  |  | |||
							
								
								
									
										22
									
								
								GNUmakefile
									
										
									
									
									
								
							
							
						
						
									
										22
									
								
								GNUmakefile
									
										
									
									
									
								
							|  | @ -1,8 +1,11 @@ | |||
| # | ||||
| # CURDIR=$(/bin/pwd) | ||||
| # | ||||
| # GENERATOR="Unix Makefiles" | ||||
| GENERATOR=Ninja | ||||
| # On UNIX one can use the DESTDIR mechanism in order to relocate the whole installation. | ||||
| DESTDIR?=${CURDIR}/stagedir | ||||
| export DESTDIR | ||||
| 
 | ||||
| # GENERATOR?="Unix Makefiles" | ||||
| GENERATOR?=Ninja | ||||
| 
 | ||||
| export CPM_SOURCE_CACHE=${HOME}/.cache/CPM | ||||
| export CPM_USE_LOCAL_PACKAGES=1 | ||||
|  | @ -12,8 +15,11 @@ export CPM_USE_LOCAL_PACKAGES=1 | |||
| # the default target does just all | ||||
| all: | ||||
| 
 | ||||
| clean: | ||||
| 	find . -type d -name build | xargs rm -rf | ||||
| 
 | ||||
| distclean: clean | ||||
| 	rm -rf build root | ||||
| 	rm -rf build ${DESTDIR} | ||||
| 
 | ||||
| # update CPM.cmake | ||||
| update: | ||||
|  | @ -27,18 +33,18 @@ lock: standalone all | |||
| 
 | ||||
| # install the library | ||||
| install: | ||||
| 	cmake -S . -B build/install -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${CURDIR}/root -DCMAKE_INSTALL_PREFIX=${CURDIR}/root -DCMAKE_CXX_STANDARD=20 # --trace-expand | ||||
| 	cmake -S . -B build/install -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${DESTDIR} # --trace-expand | ||||
| 	cmake --build build/install --target install | ||||
| 
 | ||||
| # test the library | ||||
| test: install | ||||
| 	cmake -S test -B build/test -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${CURDIR}/root -DTEST_INSTALLED_VERSION=1 | ||||
| 	cmake -S test -B build/test -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${DESTDIR} -DTEST_INSTALLED_VERSION=1 | ||||
| 	cmake --build build/test | ||||
| 	cmake --build build/test --target test | ||||
| 
 | ||||
| # all together | ||||
| all: test | ||||
| 	cmake -S all -B build/all -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${CURDIR}/root -DTEST_INSTALLED_VERSION=1 -DENABLE_TEST_COVERAGE=1 | ||||
| 	cmake -S all -B build/all -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${DESTDIR} -DTEST_INSTALLED_VERSION=1 -DENABLE_TEST_COVERAGE=1 | ||||
| 	cmake --build build/all | ||||
| 	cmake --build build/all --target test | ||||
| 	cmake --build build/all --target GenerateDocs | ||||
|  | @ -51,7 +57,7 @@ format: distclean | |||
| 	find . -name '*.h' | xargs clang-format -i | ||||
| 
 | ||||
| standalone: | ||||
| 	cmake -S standalone -B build/standalone -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${CURDIR}/root -DCMAKE_EXPORT_COMPILE_COMMANDS=1 | ||||
| 	cmake -S standalone -B build/standalone -G "${GENERATOR}" -DCMAKE_PREFIX_PATH=${DESTDIR} -DCMAKE_EXPORT_COMPILE_COMMANDS=1 | ||||
| 	cmake --build build/standalone --target all | ||||
| 
 | ||||
| # check the library | ||||
|  |  | |||
|  | @ -3,69 +3,17 @@ | |||
| # Ccache.cmake | ||||
| CPMDeclarePackage( | ||||
|   Ccache.cmake | ||||
|   NAME | ||||
|   Ccache.cmake | ||||
|   VERSION | ||||
|   1.2.1 | ||||
|   GITHUB_REPOSITORY | ||||
|   TheLartians/Ccache.cmake | ||||
| ) | ||||
| # cxxopts | ||||
| CPMDeclarePackage( | ||||
|   cxxopts | ||||
|   NAME | ||||
|   cxxopts | ||||
|   VERSION | ||||
|   2.2.0 | ||||
|   GITHUB_REPOSITORY | ||||
|   jarro2783/cxxopts | ||||
|   OPTIONS | ||||
|   "CXXOPTS_BUILD_EXAMPLES Off" | ||||
|   "CXXOPTS_BUILD_TESTS Off" | ||||
| ) | ||||
| # Greeter (unversioned) CPMDeclarePackage(Greeter local directory ) PackageProject.cmake | ||||
| CPMDeclarePackage( | ||||
|   PackageProject.cmake | ||||
|   NAME | ||||
|   PackageProject.cmake | ||||
|   VERSION | ||||
|   1.4.1 | ||||
|   GITHUB_REPOSITORY | ||||
|   TheLartians/PackageProject.cmake | ||||
| ) | ||||
| # fmt | ||||
| CPMDeclarePackage( | ||||
|   fmt | ||||
|   NAME | ||||
|   fmt | ||||
|   GIT_TAG | ||||
|   7.1.3 | ||||
|   GITHUB_REPOSITORY | ||||
|   fmtlib/fmt | ||||
|   OPTIONS | ||||
|   "FMT_INSTALL YES" | ||||
| ) | ||||
| # doctest | ||||
| CPMDeclarePackage( | ||||
|   doctest | ||||
|   NAME | ||||
|   doctest | ||||
|   GIT_TAG | ||||
|   2.4.5 | ||||
|   GITHUB_REPOSITORY | ||||
|   onqtam/doctest | ||||
|   NAME Ccache.cmake | ||||
|   VERSION 1.2.1 | ||||
|   GITHUB_REPOSITORY TheLartians/Ccache.cmake | ||||
| ) | ||||
| # Format.cmake | ||||
| CPMDeclarePackage( | ||||
|   Format.cmake | ||||
|   NAME | ||||
|   Format.cmake | ||||
|   VERSION | ||||
|   1.6 | ||||
|   GITHUB_REPOSITORY | ||||
|   TheLartians/Format.cmake | ||||
|   OPTIONS | ||||
|   "FORMAT_CHECK_CMAKE ON" | ||||
|   NAME Format.cmake | ||||
|   VERSION 1.6 | ||||
|   GITHUB_REPOSITORY TheLartians/Format.cmake | ||||
|   OPTIONS "FORMAT_CHECK_CMAKE ON" | ||||
| ) | ||||
| # MCSS (unversioned) CPMDeclarePackage(MCSS NAME MCSS GIT_TAG | ||||
| # 42d4a9a48f31f5df6e246c948403b54b50574a2a DOWNLOAD_ONLY YES GITHUB_REPOSITORY mosra/m.css ) | ||||
|  |  | |||
|  | @ -9,6 +9,12 @@ endif() | |||
| include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) | ||||
| CPMUsePackageLock(package-lock.cmake) | ||||
| 
 | ||||
| if(NOT DEFINED CMAKE_CXX_STANDARD) | ||||
|   set(CMAKE_CXX_STANDARD 20) | ||||
|   set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||||
|   set(CMAKE_CXX_EXTENSIONS NO) | ||||
| endif() | ||||
| 
 | ||||
| # option: default not set | ||||
| set(USE_STATIC_ANALYZER | ||||
|     "" | ||||
|  |  | |||
|  | @ -3,22 +3,7 @@ | |||
| # PackageProject.cmake | ||||
| CPMDeclarePackage( | ||||
|   PackageProject.cmake | ||||
|   NAME | ||||
|   PackageProject.cmake | ||||
|   VERSION | ||||
|   1.4.1 | ||||
|   GITHUB_REPOSITORY | ||||
|   TheLartians/PackageProject.cmake | ||||
| ) | ||||
| # fmt | ||||
| CPMDeclarePackage( | ||||
|   fmt | ||||
|   NAME | ||||
|   fmt | ||||
|   GIT_TAG | ||||
|   7.1.3 | ||||
|   GITHUB_REPOSITORY | ||||
|   fmtlib/fmt | ||||
|   OPTIONS | ||||
|   "FMT_INSTALL YES" | ||||
|   NAME PackageProject.cmake | ||||
|   VERSION 1.4.1 | ||||
|   GITHUB_REPOSITORY TheLartians/PackageProject.cmake | ||||
| ) | ||||
|  |  | |||
|  | @ -26,10 +26,12 @@ file(GLOB sources CONFIGURE_DEPENDS source/*.cpp) | |||
| 
 | ||||
| add_executable(GreeterStandalone ${sources}) | ||||
| 
 | ||||
| # TODO: why rename in this way? | ||||
| set_target_properties(GreeterStandalone PROPERTIES CXX_STANDARD 17 OUTPUT_NAME "Greeter") | ||||
| # TODO: why rename in this way? Seems only for CI with GitHub actions! CK | ||||
| set_target_properties( | ||||
|   GreeterStandalone PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD} OUTPUT_NAME "Greeter" | ||||
| ) | ||||
| 
 | ||||
| # WORKAROUND for ALIAS target is missing error! CK | ||||
| # WORKAROUND missing ALIAS target error! CK | ||||
| if(NOT TARGET cxxopts::cxxopts) | ||||
|   add_library(cxxopts::cxxopts ALIAS cxxopts) | ||||
| endif() | ||||
|  |  | |||
|  | @ -3,45 +3,7 @@ | |||
| # Ccache.cmake | ||||
| CPMDeclarePackage( | ||||
|   Ccache.cmake | ||||
|   NAME | ||||
|   Ccache.cmake | ||||
|   VERSION | ||||
|   1.2.1 | ||||
|   GITHUB_REPOSITORY | ||||
|   TheLartians/Ccache.cmake | ||||
| ) | ||||
| # cxxopts | ||||
| CPMDeclarePackage( | ||||
|   cxxopts | ||||
|   NAME | ||||
|   cxxopts | ||||
|   VERSION | ||||
|   2.2.0 | ||||
|   GITHUB_REPOSITORY | ||||
|   jarro2783/cxxopts | ||||
|   OPTIONS | ||||
|   "CXXOPTS_BUILD_EXAMPLES Off" | ||||
|   "CXXOPTS_BUILD_TESTS Off" | ||||
| ) | ||||
| # Greeter (unversioned) CPMDeclarePackage(Greeter local directory ) PackageProject.cmake | ||||
| CPMDeclarePackage( | ||||
|   PackageProject.cmake | ||||
|   NAME | ||||
|   PackageProject.cmake | ||||
|   VERSION | ||||
|   1.4.1 | ||||
|   GITHUB_REPOSITORY | ||||
|   TheLartians/PackageProject.cmake | ||||
| ) | ||||
| # fmt | ||||
| CPMDeclarePackage( | ||||
|   fmt | ||||
|   NAME | ||||
|   fmt | ||||
|   GIT_TAG | ||||
|   7.1.3 | ||||
|   GITHUB_REPOSITORY | ||||
|   fmtlib/fmt | ||||
|   OPTIONS | ||||
|   "FMT_INSTALL YES" | ||||
|   NAME Ccache.cmake | ||||
|   VERSION 1.2.1 | ||||
|   GITHUB_REPOSITORY TheLartians/Ccache.cmake | ||||
| ) | ||||
|  |  | |||
|  | @ -41,8 +41,9 @@ 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 20) | ||||
| # EITHER: | ||||
| set_target_properties(GreeterTests PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD}) | ||||
| # OR: target_compile_features(GreeterTests PUBLIC cxx_std_20) | ||||
| 
 | ||||
| # enable compiler warnings | ||||
| if(NOT TEST_INSTALLED_VERSION) | ||||
|  |  | |||
|  | @ -3,32 +3,15 @@ | |||
| # Ccache.cmake | ||||
| CPMDeclarePackage( | ||||
|   Ccache.cmake | ||||
|   NAME | ||||
|   Ccache.cmake | ||||
|   VERSION | ||||
|   1.2.1 | ||||
|   GITHUB_REPOSITORY | ||||
|   TheLartians/Ccache.cmake | ||||
| ) | ||||
| # doctest | ||||
| CPMDeclarePackage( | ||||
|   doctest | ||||
|   NAME | ||||
|   doctest | ||||
|   GIT_TAG | ||||
|   2.4.5 | ||||
|   GITHUB_REPOSITORY | ||||
|   onqtam/doctest | ||||
|   NAME Ccache.cmake | ||||
|   VERSION 1.2.1 | ||||
|   GITHUB_REPOSITORY TheLartians/Ccache.cmake | ||||
| ) | ||||
| # Format.cmake | ||||
| CPMDeclarePackage( | ||||
|   Format.cmake | ||||
|   NAME | ||||
|   Format.cmake | ||||
|   VERSION | ||||
|   1.6 | ||||
|   GITHUB_REPOSITORY | ||||
|   TheLartians/Format.cmake | ||||
|   OPTIONS | ||||
|   "FORMAT_CHECK_CMAKE ON" | ||||
|   NAME Format.cmake | ||||
|   VERSION 1.6 | ||||
|   GITHUB_REPOSITORY TheLartians/Format.cmake | ||||
|   OPTIONS "FORMAT_CHECK_CMAKE ON" | ||||
| ) | ||||
|  |  | |||
|  | @ -16,7 +16,7 @@ TEST_CASE("Greeter") { | |||
| } | ||||
| 
 | ||||
| TEST_CASE("Greeter version") { | ||||
| #if (__cpp_lib_starts_ends_with) | ||||
| #if ((__cplusplus >= 201907L) || __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 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue