mirror of
https://github.com/TheLartians/ModernCppStarter.git
synced 2025-08-31 22:21:13 +02:00
move packaging to extra file
This commit is contained in:
parent
bf392d6ae3
commit
9d8879ed88
3 changed files with 47 additions and 44 deletions
|
@ -58,46 +58,4 @@ target_include_directories(Greeter
|
||||||
# ---- Create an installable target ----
|
# ---- Create an installable target ----
|
||||||
# this allows users install and find the library via `find_package(Greeter)`.
|
# this allows users install and find the library via `find_package(Greeter)`.
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
include(cmake/packaging.cmake)
|
||||||
|
|
||||||
write_basic_package_version_file(
|
|
||||||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
|
||||||
VERSION ${PROJECT_VERSION}
|
|
||||||
COMPATIBILITY AnyNewerVersion
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
TARGETS ${PROJECT_NAME}
|
|
||||||
EXPORT ${PROJECT_NAME}Targets
|
|
||||||
LIBRARY DESTINATION lib/${PROJECT_NAME}-${PROJECT_VERSION} COMPONENT Runtime
|
|
||||||
ARCHIVE DESTINATION lib/${PROJECT_NAME}-${PROJECT_VERSION} COMPONENT Development
|
|
||||||
RUNTIME DESTINATION bin/${PROJECT_NAME}-${PROJECT_VERSION} COMPONENT Runtime
|
|
||||||
PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} COMPONENT Development
|
|
||||||
BUNDLE DESTINATION bin COMPONENT Runtime
|
|
||||||
)
|
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
|
||||||
|
|
||||||
configure_package_config_file(
|
|
||||||
"${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in"
|
|
||||||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
|
||||||
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
EXPORT ${PROJECT_NAME}Targets
|
|
||||||
DESTINATION lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
FILES
|
|
||||||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
|
||||||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
|
||||||
DESTINATION
|
|
||||||
lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
DIRECTORY ${PROJECT_SOURCE_DIR}/include/
|
|
||||||
DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
|
|
||||||
)
|
|
||||||
|
|
|
@ -21,6 +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
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -77,6 +78,7 @@ See [Format.cmake](https://github.com/TheLartians/Format.cmake) for more options
|
||||||
If problems do arise, they can always opt-out by defining `CPM_USE_LOCAL_PACKAGES`, which will override all calls to `CPMAddPackage` with `find_package`.
|
If problems do arise, they can always opt-out by defining `CPM_USE_LOCAL_PACKAGES`, which will override all calls to `CPMAddPackage` with `find_package`.
|
||||||
If you are using `CPMFindPackage` instead of `CPMAddPackage`, CPM will always try to use `find_package` to add packages.
|
If you are using `CPMFindPackage` instead of `CPMAddPackage`, CPM will always try to use `find_package` to add packages.
|
||||||
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).
|
||||||
|
|
||||||
- How do I package my library / executable into an installer?
|
- How do I package my library / executable into an installer?
|
||||||
|
|
||||||
|
@ -84,4 +86,4 @@ See [Format.cmake](https://github.com/TheLartians/Format.cmake) for more options
|
||||||
|
|
||||||
## Coming soon
|
## Coming soon
|
||||||
|
|
||||||
- Script to automatically adjust this template for new projects
|
- Script to automatically adjust the template for new projects
|
||||||
|
|
43
cmake/packaging.cmake
Normal file
43
cmake/packaging.cmake
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
write_basic_package_version_file(
|
||||||
|
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
COMPATIBILITY AnyNewerVersion
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
TARGETS ${PROJECT_NAME}
|
||||||
|
EXPORT ${PROJECT_NAME}Targets
|
||||||
|
LIBRARY DESTINATION lib/${PROJECT_NAME}-${PROJECT_VERSION} COMPONENT Runtime
|
||||||
|
ARCHIVE DESTINATION lib/${PROJECT_NAME}-${PROJECT_VERSION} COMPONENT Development
|
||||||
|
RUNTIME DESTINATION bin/${PROJECT_NAME}-${PROJECT_VERSION} COMPONENT Runtime
|
||||||
|
PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} COMPONENT Development
|
||||||
|
BUNDLE DESTINATION bin COMPONENT Runtime
|
||||||
|
)
|
||||||
|
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
configure_package_config_file(
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/Config.cmake.in"
|
||||||
|
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||||
|
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
EXPORT ${PROJECT_NAME}Targets
|
||||||
|
DESTINATION lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||||
|
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||||
|
DESTINATION
|
||||||
|
lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
DIRECTORY ${PROJECT_SOURCE_DIR}/include/
|
||||||
|
DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
|
||||||
|
)
|
Loading…
Add table
Add a link
Reference in a new issue