mirror of
				https://github.com/TheLartians/ModernCppStarter.git
				synced 2025-10-31 10:11:34 +01:00 
			
		
		
		
	replace example dependency with PackageProject.cmake
This commit is contained in:
		
							parent
							
								
									5f3c39b657
								
							
						
					
					
						commit
						df111c1104
					
				
					 2 changed files with 21 additions and 21 deletions
				
			
		|  | @ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) | ||||||
| 
 | 
 | ||||||
| # ---- Project ---- | # ---- Project ---- | ||||||
| 
 | 
 | ||||||
|  | # Note: update this to your new project's name and version | ||||||
| project(Greeter  | project(Greeter  | ||||||
|   VERSION 1.0 |   VERSION 1.0 | ||||||
|   LANGUAGES CXX |   LANGUAGES CXX | ||||||
|  | @ -20,23 +21,21 @@ endif() | ||||||
| FILE(GLOB_RECURSE headers "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") | FILE(GLOB_RECURSE headers "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") | ||||||
| FILE(GLOB_RECURSE sources "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp") | FILE(GLOB_RECURSE sources "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp") | ||||||
| 
 | 
 | ||||||
| # ---- Add dependencies via CPM (if required) ---- | # ---- Add dependencies via CPM ---- | ||||||
| # see https://github.com/TheLartians/CPM.cmake for more info | # see https://github.com/TheLartians/CPM.cmake for more info | ||||||
| 
 | 
 | ||||||
| include(cmake/CPM.cmake) | include(cmake/CPM.cmake) | ||||||
| 
 | 
 | ||||||
| # CPMAddPackage( | # PackageProject.cmake will be used to make our target installable | ||||||
| #   NAME cxxopts | CPMAddPackage( | ||||||
| #   GITHUB_REPOSITORY jarro2783/cxxopts |   NAME PackageProject.cmake | ||||||
| #   VERSION 2.2.0 |   GITHUB_REPOSITORY TheLartians/PackageProject.cmake | ||||||
| #   OPTIONS |   VERSION 1.0 | ||||||
| #     "CXXOPTS_BUILD_EXAMPLES Off" | ) | ||||||
| #     "CXXOPTS_BUILD_TESTS Off" |  | ||||||
| # ) |  | ||||||
| 
 | 
 | ||||||
| # ---- Create library ---- | # ---- Create library ---- | ||||||
| 
 | 
 | ||||||
| # Notes: | # Note: | ||||||
| # for single header libraries use `add_library(Greeter INTERFACE)` instead  | # for single header libraries use `add_library(Greeter INTERFACE)` instead  | ||||||
| # To create an executable use `add_executable(Greeter ${headers} ${sources})` | # To create an executable use `add_executable(Greeter ${headers} ${sources})` | ||||||
| add_library(Greeter ${headers} ${sources}) | add_library(Greeter ${headers} ${sources}) | ||||||
|  | @ -46,7 +45,7 @@ add_library(Greeter ${headers} ${sources}) | ||||||
| set_target_properties(Greeter PROPERTIES CXX_STANDARD 17) | set_target_properties(Greeter PROPERTIES CXX_STANDARD 17) | ||||||
| 
 | 
 | ||||||
| # Link dependencies (if required) | # Link dependencies (if required) | ||||||
| # target_link_libraries(Greeter cxxopts) | # target_link_libraries(Greeter PUBLIC cxxopts) | ||||||
| 
 | 
 | ||||||
| # Note: change PUBLIC to INTERFACE for single header libraries   | # Note: change PUBLIC to INTERFACE for single header libraries   | ||||||
| target_include_directories(Greeter | target_include_directories(Greeter | ||||||
|  | @ -58,12 +57,6 @@ target_include_directories(Greeter | ||||||
| # ---- Create an installable target ---- | # ---- Create an installable target ---- | ||||||
| # this allows users to install and find the library via `find_package()`. | # this allows users to install and find the library via `find_package()`. | ||||||
| 
 | 
 | ||||||
| CPMAddPackage( |  | ||||||
|   NAME PackageProject.cmake |  | ||||||
|   GITHUB_REPOSITORY TheLartians/PackageProject.cmake |  | ||||||
|   VERSION 1.0 |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| packageProject( | packageProject( | ||||||
|   NAME ${PROJECT_NAME} |   NAME ${PROJECT_NAME} | ||||||
|   VERSION ${PROJECT_VERSION} |   VERSION ${PROJECT_VERSION} | ||||||
|  |  | ||||||
							
								
								
									
										13
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								README.md
									
										
									
									
									
								
							|  | @ -21,7 +21,7 @@ This template is a collection from learnings of previous projects and should all | ||||||
| - Code coverage via [codecov](https://codecov.io) | - Code coverage via [codecov](https://codecov.io) | ||||||
| - Code formatting enforced by [clang-format](https://clang.llvm.org/docs/ClangFormat.html) via [Format.cmake](https://github.com/TheLartians/Format.cmake) | - Code formatting enforced by [clang-format](https://clang.llvm.org/docs/ClangFormat.html) via [Format.cmake](https://github.com/TheLartians/Format.cmake) | ||||||
| - Reproducible dependency management via [CPM.cmake](https://github.com/TheLartians/CPM.cmake) | - Reproducible dependency management via [CPM.cmake](https://github.com/TheLartians/CPM.cmake) | ||||||
| - Installable target with versioning information | - Installable target with versioning information via [PackageProject.cmake](https://github.com/TheLartians/PackageProject.cmake) | ||||||
| 
 | 
 | ||||||
| ## Usage | ## Usage | ||||||
| 
 | 
 | ||||||
|  | @ -80,9 +80,16 @@ See [Format.cmake](https://github.com/TheLartians/Format.cmake) for more options | ||||||
|     This approach should be compatible with any common C++ package manager without any user intervention, however at the cost of reproducible builds. |     This approach should be compatible with any common C++ package manager without any user intervention, however at the cost of reproducible builds. | ||||||
|     For more info, see the [CPM.cmake documentation](https://github.com/TheLartians/CPM.cmake). |     For more info, see the [CPM.cmake documentation](https://github.com/TheLartians/CPM.cmake). | ||||||
| 
 | 
 | ||||||
|   - How do I package my library / executable into an installer? |   - Can I configure and build my project offline? | ||||||
| 
 | 
 | ||||||
|     As there are a lot of possible options and configurations, this is not in the scope of this template. See the [CPack documentation](https://cmake.org/cmake/help/latest/module/CPack.html) for more info. |     Using CPM, all missing dependencies are downloaded at configure time. | ||||||
|  |     To avoid redundant downloads, it's recommended to set a CPM cache directory, e.g.: `export CPM_SOURCE_CACHE=$HOME/.cache/CPM`. | ||||||
|  |     This will also allow offline configurations if all dependencies are present. | ||||||
|  |     No internet connection is required for building. | ||||||
|  | 
 | ||||||
|  |   - Can I use CPack to create a package installer for my project? | ||||||
|  | 
 | ||||||
|  |     As there are a lot of possible options and configurations, this is not (yet) in the scope of this template. See the [CPack documentation](https://cmake.org/cmake/help/latest/module/CPack.html) for more information on setting up CPack installers. | ||||||
| 
 | 
 | ||||||
| ## Coming soon | ## Coming soon | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue