From edf031370e255cd4506cd8a17d7ddda78e697ed2 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. --- Config.cmake.in | 5 ++++- package-config.cmake | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Config.cmake.in b/Config.cmake.in index ad10f7c87..16872f268 100644 --- a/Config.cmake.in +++ b/Config.cmake.in @@ -108,7 +108,10 @@ IF(COMMAND ADD_REQUIRED_DEPENDENCY) ENDFOREACH() ENDIF(COMMAND ADD_REQUIRED_DEPENDENCY) -include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") +@EXPR_PROJECT_NAME_ZERO_TARGET@ +if(NOT @PROJECT_NAME@_ZERO_TARGET) + include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") +endif() 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..f6f81018e 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(EXPR_PROJECT_NAME_ZERO_TARGET "SET(${PROJECT_NAME}_ZERO_TARGET FALSE)") +else() + SET(EXPR_PROJECT_NAME_ZERO_TARGET "SET(${PROJECT_NAME}_ZERO_TARGET TRUE)") +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: