From ec4a43aebc5e0c6dcc3caf5a74163df1f1fb67b1 Mon Sep 17 00:00:00 2001 From: Olivier Stasse Date: Thu, 18 Jun 2020 16:43:24 +0200 Subject: [PATCH] Handle no-target case through a user information. Lean implementation. --- Config.cmake.in | 2 +- package-config.cmake | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Config.cmake.in b/Config.cmake.in index ad10f7c87..f7c4ad195 100644 --- a/Config.cmake.in +++ b/Config.cmake.in @@ -108,7 +108,7 @@ IF(COMMAND ADD_REQUIRED_DEPENDENCY) ENDFOREACH() ENDIF(COMMAND ADD_REQUIRED_DEPENDENCY) -include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") +@INCLUDE_TARGETS_FILE@ foreach(component ${@PROJECT_NAME@_FIND_COMPONENTS}) set(comp_file "${CMAKE_CURRENT_LIST_DIR}/${component}Config.cmake") diff --git a/package-config.cmake b/package-config.cmake index 8d7ae8349..b60bab36d 100644 --- a/package-config.cmake +++ b/package-config.cmake @@ -154,6 +154,13 @@ if(_PKG_CONFIG_REQUIRES) endforeach() list(REMOVE_DUPLICATES _PKG_CONFIG_REQUIRES_LIST) endif(_PKG_CONFIG_REQUIRES) + +if(NOT ${PROJECT_NAME}_ZERO_TARGET) + SET(INCLUDE_TARGETS_FILE "include(\"\${CMAKE_CURRENT_LIST_DIR}/${TARGETS_EXPORT_NAME}.cmake\")") +else() + SET(INCLUDE_TARGETS_FILE "# Package with no targets") +endif() + configure_package_config_file( "cmake/Config.cmake.in" "${PROJECT_CONFIG}" @@ -170,11 +177,14 @@ install( # Config # * /lib/cmake/Foo/FooTargets.cmake -install( +if(NOT ${PROJECT_NAME}_ZERO_TARGET) + install( EXPORT "${TARGETS_EXPORT_NAME}" NAMESPACE "${namespace}" DESTINATION "${CONFIG_INSTALL_DIR}" -) + ) +endif() + ENDMACRO(SETUP_PROJECT_PACKAGE_FINALIZE) #.rst: