Skip to content

Commit

Permalink
GHI #11 Setup CMake for installing and packaging project
Browse files Browse the repository at this point in the history
  • Loading branch information
doodspav committed Mar 11, 2023
1 parent f7643ad commit 47ff661
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,10 @@ target_include_directories(
)

target_compile_features(patomic_patomic PUBLIC c_std_90)


# ---- Install Rules ----

if(NOT CMAKE_SKIP_INSTALL_RULES)
include(cmake/util/InstallRules.cmake)
endif()
1 change: 1 addition & 0 deletions cmake/util/InstallConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/patomicTargets.cmake")
77 changes: 77 additions & 0 deletions cmake/util/InstallRules.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
if(PROJECT_IS_TOP_LEVEL)
set(
CMAKE_INSTALL_INCLUDEDIR "include/patomic-${PROJECT_VERSION}"
CACHE PATH ""
)
endif()

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

# find_package(<package>) call for consumers to find this project
set(package patomic)

# copy header files to CMAKE_INSTALL_INCLUDEDIR
install(
DIRECTORY
"${PROJECT_SOURCE_DIR}/include/"
"${PROJECT_BINARY_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT patomic_Development
)

# copy target build output artifacts to OS dependent locations
install(
TARGETS patomic_patomic
EXPORT patomicTargets
RUNTIME #
COMPONENT patomic_Runtime
LIBRARY #
COMPONENT patomic_Runtime
NAMELINK_COMPONENT patomic_Development
ARCHIVE #
COMPONENT patomic_Development
INCLUDES #
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

# allow package maintainers to freely override the path for the configs
set(
patomic_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${package}"
CACHE PATH "CMake package config location relative to the install prefix"
)
mark_as_advanced(patomic_INSTALL_CMAKE_DIR)

# copy config file for find_package to find
install(
FILES "${PROJECT_SOURCE_DIR}/cmake/util/InstallConfig.cmake"
DESTINATION "${patomic_INSTALL_CMAKEDIR}"
RENAME "${package}Config.cmake"
COMPONENT patomic_Development
)

# create version file for consumer to check version in CMake
write_basic_package_version_file(
"${package}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)

# copy version file for find_package to find
install(
FILES "${PROJECT_BINARY_DIR}/${package}ConfigVersion.cmake"
DESTINATION "${patomic_INSTALL_CMAKEDIR}"
COMPONENT patomic_Development
)

# create core configuration file detailing targets for consumer
install(
EXPORT patomicTargets
NAMESPACE patomic::
DESTINATION "${patomic_INSTALL_CMAKEDIR}"
COMPONENT patomic_Development
)

# support packaging library
if(PROJECT_IS_TOP_LEVEL)
include(CPack)
endif()

0 comments on commit 47ff661

Please sign in to comment.