Skip to content

Commit

Permalink
replace example dependency with PackageProject.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLartians committed Apr 14, 2020
1 parent 5f3c39b commit df111c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
29 changes: 11 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

# ---- Project ----

# Note: update this to your new project's name and version
project(Greeter
VERSION 1.0
LANGUAGES CXX
Expand All @@ -20,23 +21,21 @@ endif()
FILE(GLOB_RECURSE headers "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
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

include(cmake/CPM.cmake)

# CPMAddPackage(
# NAME cxxopts
# GITHUB_REPOSITORY jarro2783/cxxopts
# VERSION 2.2.0
# OPTIONS
# "CXXOPTS_BUILD_EXAMPLES Off"
# "CXXOPTS_BUILD_TESTS Off"
# )
# PackageProject.cmake will be used to make our target installable
CPMAddPackage(
NAME PackageProject.cmake
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
VERSION 1.0
)

# ---- Create library ----

# Notes:
# Note:
# for single header libraries use `add_library(Greeter INTERFACE)` instead
# To create an executable use `add_executable(Greeter ${headers} ${sources})`
add_library(Greeter ${headers} ${sources})
Expand All @@ -46,24 +45,18 @@ add_library(Greeter ${headers} ${sources})
set_target_properties(Greeter PROPERTIES CXX_STANDARD 17)

# Link dependencies (if required)
# target_link_libraries(Greeter cxxopts)
# target_link_libraries(Greeter PUBLIC cxxopts)

# Note: change PUBLIC to INTERFACE for single header libraries
target_include_directories(Greeter
PUBLIC
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

# ---- Create an installable target ----
# 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(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)
- Installable target with versioning information
- Installable target with versioning information via [PackageProject.cmake](https://github.com/TheLartians/PackageProject.cmake)

## Usage

Expand Down Expand Up @@ -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.
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

Expand Down

0 comments on commit df111c1

Please sign in to comment.