From 275ad5406459d0540d700a74de1be3870ad0a737 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. Uses variable PROJECT_EXPORT_NO_TARGET Documentation for the variable. From SET to set --- Config.cmake.in | 2 +- base.cmake | 7 +++++++ package-config.cmake | 14 ++++++++++++-- 3 files changed, 20 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/base.cmake b/base.cmake index 3f075dcad..06c98c2a0 100644 --- a/base.cmake +++ b/base.cmake @@ -76,6 +76,13 @@ # This tells jrl-cmakemodules that you are using export functionalities so it will # hook the installation of your configuration files. Defaults to false # +# .. variable:: PROJECT_EXPORT_NO_TARGET +# +# This tells jrl-cmakemodules that there is no targets in the project. +# However the export functionalities are still provided to detect the +# project properties. Not setting this variable when no target is present +# will result in an error. +# # Macros # ------ # diff --git a/package-config.cmake b/package-config.cmake index 8d7ae8349..b75028cba 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_EXPORT_NO_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_EXPORT_NO_TARGET) + install( EXPORT "${TARGETS_EXPORT_NAME}" NAMESPACE "${namespace}" DESTINATION "${CONFIG_INSTALL_DIR}" -) + ) +endif() + ENDMACRO(SETUP_PROJECT_PACKAGE_FINALIZE) #.rst: