Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the no-target case. #403

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Handle the no-target case.
It is done through a COMPUTE_TARGETS_LIST in package-config.cmake
Targets are gathered by going through the root and the subdirectories
of the root and collect the BUILDSYSTEM_TARGET property.
From this list, standard targets are removed.

Then if there is no user target the <package-name>Target.cmake file
is not generated and not included in the Config.cmake.in file.
olivier-stasse committed Jun 13, 2020
commit ddd3630d1f7e02945ba90a3b344858619781ac79
7 changes: 5 additions & 2 deletions Config.cmake.in
Original file line number Diff line number Diff line change
@@ -97,7 +97,10 @@ IF(COMMAND ADD_REQUIRED_DEPENDENCY)
ENDFOREACH()
ENDIF(COMMAND ADD_REQUIRED_DEPENDENCY)

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
@VALID_TARGETS_EXPORT_NAME@
if(${VALID_TARGETS_EXPORT_NAME})
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
endif(${VALID_TARGETS_EXPORT_NAME})

@PACKAGE_EXTRA_MACROS@
67 changes: 65 additions & 2 deletions package-config.cmake
Original file line number Diff line number Diff line change
@@ -87,6 +87,60 @@ MACRO(ADD_PROJECT_DEPENDENCY)
set(_PACKAGE_CONFIG_DEPENDENCIES_FIND_DEPENDENCY "${_PACKAGE_CONFIG_DEPENDENCIES_FIND_DEPENDENCY}" CACHE INTERNAL "")
ENDMACRO()

# COMPUTE_TARGETS_LIST
# -------------------
# This macro creates a list of targets based on the targets
# for each directory. It creates a list of targets called TARGETS_LIST
# The macro is searching across the subdirectories of the root and
# the root itself.
#
MACRO(COMPUTE_TARGETS_LIST)
###
set(TARGETS_LIST )

# Search subdirectories of the root
get_property(subdirs_list
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
PROPERTY SUBDIRECTORIES)

# Put the root itself in the list
LIST(APPEND subdirs_list ${CMAKE_CURRENT_SOURCE_DIR})


# For each subdirectory
foreach (_varsubdir ${subdirs_list})

# Get the list of targets
get_property(_variableNames
DIRECTORY ${_varsubdir}
PROPERTY BUILDSYSTEM_TARGETS)
list (SORT _variableNames)

# Append each target to the list of targets
foreach (_variableName ${_variableNames})
LIST(APPEND TARGETS_LIST ${_variableName})
endforeach()

endforeach()

# Standard targets
SET( STD_TARGETS_TO_FILTER Continuous ContinuousBuild ContinuousConfigure
ContinuousCoverage ContinuousMemCheck ContinuousStart ContinuousSubmit
ContinuousTest ContinuousUpdate Experimental ExperimentalBuild
ExperimentalConfigure ExperimentalCoverage ExperimentalMemCheck
ExperimentalStart ExperimentalSubmit ExperimentalTest ExperimentalUpdate
Nightly NightlyBuild NightlyConfigure NightlyCoverage NightlyMemCheck
NightlyMemoryCheck NightlyStart NightlySubmit NightlyTest NightlyUpdate
build_tests dist dist_tarbz2 dist_targz dist_tarxz distcheck distclean
distdir distorig doc reinstall release uninstall)

# Removing standard targets
list(REMOVE_ITEM TARGETS_LIST ${STD_TARGETS_TO_FILTER})

# Set the number of targets
list(LENGTH TARGETS_LIST TARGETS_LIST_LENGTH)

ENDMACRO()

# SETUP_PROJECT_PACKAGE_FINALIZE
# -------------
@@ -152,6 +206,12 @@ if(_PKG_CONFIG_REQUIRES)
endforeach()
list(REMOVE_DUPLICATES _PKG_CONFIG_REQUIRES_LIST)
endif(_PKG_CONFIG_REQUIRES)

COMPUTE_TARGETS_LIST()
if(TARGETS_LIST_LENGTH)
SET(VALID_TARGETS_EXPORT_NAME "SET(VALID_TARGETS_EXPORT_NAME TRUE)")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the scope of variable VALID_TARGETS_EXPORT_NAME in the configured Config.cmake ? Will it interfere with previous included config files ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

endif(TARGETS_LIST_LENGTH)

configure_package_config_file(
"cmake/Config.cmake.in"
"${PROJECT_CONFIG}"
@@ -168,9 +228,12 @@ install(

# Config
# * <prefix>/lib/cmake/Foo/FooTargets.cmake
install(
if(TARGETS_LIST_LENGTH)
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${CONFIG_INSTALL_DIR}"
)
)
endif(TARGETS_LIST_LENGTH)

ENDMACRO(SETUP_PROJECT_PACKAGE_FINALIZE)