diff --git a/CMakeLists.txt b/CMakeLists.txt index 087d8b9..e348e4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,5 @@ +cmake_minimum_required(VERSION 3.14) + set(PACKAGE_PROJECT_ROOT_PATH "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "The path to the PackageProject directory" @@ -10,7 +12,7 @@ function(packageProject) cmake_parse_arguments( PROJECT "" - "NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;VERSION_HEADER;NAMESPACE;DISABLE_VERSION_SUFFIX" + "NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;VERSION_HEADER;NAMESPACE;DISABLE_VERSION_SUFFIX;ARCH_INDEPENDENT" "DEPENDENCIES" ${ARGN} ) @@ -55,46 +57,79 @@ function(packageProject) target_include_directories( ${PROJECT_NAME} ${VISIBILITY} "$" ) - install(DIRECTORY ${PROJECT_VERSION_INCLUDE_DIR}/ DESTINATION ${PROJECT_INCLUDE_DESTINATION}) + install( + DIRECTORY ${PROJECT_VERSION_INCLUDE_DIR}/ + DESTINATION ${PROJECT_INCLUDE_DESTINATION} + COMPONENT "${PROJECT_NAME}_Development" + ) + endif() + + set(wbpvf_extra_args "") + if(NOT DEFINED PROJECT_ARCH_INDEPENDENT) + get_target_property(target_type "${PROJECT_NAME}" TYPE) + if(TYPE STREQUAL "INTERFACE_LIBRARY") + set(PROJECT_ARCH_INDEPENDENT YES) + endif() + endif() + + if(PROJECT_ARCH_INDEPENDENT) + set(wbpvf_extra_args ARCH_INDEPENDENT) endif() write_basic_package_version_file( "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" VERSION ${PROJECT_VERSION} - COMPATIBILITY ${PROJECT_COMPATIBILITY} + COMPATIBILITY ${PROJECT_COMPATIBILITY} ${wbpvf_extra_args} ) install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX} - COMPONENT Runtime + COMPONENT "${PROJECT_NAME}_Runtime" + NAMELINK_COMPONENT "${PROJECT_NAME}_Development" ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX} - COMPONENT Development + COMPONENT "${PROJECT_NAME}_Development" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX} - COMPONENT Runtime + COMPONENT "${PROJECT_NAME}_Runtime" BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX} - COMPONENT Runtime - PUBLIC_HEADER DESTINATION ${PROJECT_INCLUDE_DESTINATION} COMPONENT Development + COMPONENT "${PROJECT_NAME}_Runtime" + PUBLIC_HEADER DESTINATION ${PROJECT_INCLUDE_DESTINATION} COMPONENT "${PROJECT_NAME}_Development" + INCLUDES + DESTINATION "${PROJECT_INCLUDE_DESTINATION}" ) - configure_package_config_file( - ${PACKAGE_PROJECT_ROOT_PATH}/Config.cmake.in "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX} + set("${PROJECT_NAME}_INSTALL_CMAKEDIR" + "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}" + CACHE PATH "CMake package config location relative to the install prefix" + ) + + mark_as_advanced("${PROJECT_NAME}_INSTALL_CMAKEDIR") + + configure_file( + ${PACKAGE_PROJECT_ROOT_PATH}/Config.cmake.in + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY ) install( EXPORT ${PROJECT_NAME}Targets - DESTINATION lib/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX} + DESTINATION "${${PROJECT_NAME}_INSTALL_CMAKEDIR}" NAMESPACE ${PROJECT_NAMESPACE} + COMPONENT "${PROJECT_NAME}_Development" ) - install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - DESTINATION lib/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX} + install( + FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + DESTINATION "${${PROJECT_NAME}_INSTALL_CMAKEDIR}" + COMPONENT "${PROJECT_NAME}_Development" ) - install(DIRECTORY ${PROJECT_INCLUDE_DIR}/ DESTINATION ${PROJECT_INCLUDE_DESTINATION}) + install( + DIRECTORY ${PROJECT_INCLUDE_DIR}/ + DESTINATION ${PROJECT_INCLUDE_DESTINATION} + COMPONENT "${PROJECT_NAME}_Development" + ) set(${PROJECT_NAME}_VERSION ${PROJECT_VERSION} diff --git a/Config.cmake.in b/Config.cmake.in index ee34db7..15f626a 100644 --- a/Config.cmake.in +++ b/Config.cmake.in @@ -1,5 +1,3 @@ -@PACKAGE_INIT@ - include(CMakeFindDependencyMacro) string(REGEX MATCHALL "[^;]+" SEPARATE_DEPENDENCIES "@PROJECT_DEPENDENCIES@") @@ -10,4 +8,3 @@ foreach(dependency ${SEPARATE_DEPENDENCIES}) endforeach() include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") -check_required_components("@PROJECT_NAME@") diff --git a/README.md b/README.md index 194a36f..41e9783 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ packageProject( COMPATIBILITY AnyNewerVersion # (optional) option to disable the versioning of install destinations DISABLE_VERSION_SUFFIX YES + # (optional) option to ignore target architecture for package resolution + # defaults to YES for header only (i.e. INTERFACE) libraries + ARCH_INDEPENDENT YES ) ```