Skip to content

Commit

Permalink
FairFindPackage2: Introduce find_package2_implicit_dependencies()
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisklein authored and ChristianTackeGSI committed May 20, 2021
1 parent ea10cdf commit 15a8f1f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/modules/FairFindPackage2.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,48 @@ macro(find_package2 qualifier pkgname)
unset(__old_cpp__)
endmacro()


#
# Loop over all remaining implicit dependencies and "find_package2" them.
#
macro(find_package2_implicit_dependencies)
cmake_parse_arguments(ARGS "" "" "EXCLUDE" ${ARGN})

set(__2_new_implicit__ ON)
while(__2_new_implicit__)
set(__2_new_implicit__ OFF)
foreach(dep IN LISTS PROJECT_PACKAGE_DEPENDENCIES)
if(NOT dep IN_LIST ARGS_EXCLUDE)
foreach(implicit IN LISTS ${dep}_PACKAGE_DEPENDENCIES)
if( NOT implicit IN_LIST PROJECT_PACKAGE_DEPENDENCIES
AND NOT implicit IN_LIST ARGS_EXCLUDE)
set(__2_new_implicit__ ON)
unset(__2_version__)
unset(__2_components__)
if(${dep}_${implicit}_VERSION)
set(__2_components__ VERSION ${${dep}_${implicit}_VERSION})
endif()
if(${dep}_${implicit}_COMPONENTS)
set(__2_components__ COMPONENTS ${${dep}_${implicit}_COMPONENTS})
endif()
if(dep IN_LIST PROJECT_INTERFACE_PACKAGE_DEPENDENCIES)
set(__2_qualifier__ PUBLIC)
else()
set(__2_qualifier__ PRIVATE)
endif()
find_package2(${__2_qualifier__} ${implicit} ${__2_version__} ${__2_components__} REQUIRED)
endif()
endforeach()
endif()
endforeach()
endwhile()
unset(__2_qualifier__)
unset(__2_new_implicit__)
unset(__2_version__)
unset(__2_components__)
endmacro()


# Add oneself as PRIVATE package if used from the @PROJECT_NAME@ package
if(@PROJECT_NAME@_FOUND)
list(APPEND PROJECT_PACKAGE_DEPENDENCIES @PROJECT_NAME@)
Expand Down
3 changes: 3 additions & 0 deletions tests/FairFindPackage2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ add_module_test(SUITE "find_package2" TEST "merge_requirements"

add_module_test(SUITE "fair_generate_package_dependencies" TEST "simple"
PREFIX_PATH ${pkgset1})

add_module_test(SUITE "find_package2_implicit_dependencies" TEST "simple"
PREFIX_PATH ${pkgset2})
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
################################################################################
# Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
# #
# This software is distributed under the terms of the #
# GNU Lesser General Public Licence (LGPL) version 3, #
# copied verbatim in the file "LICENSE" #
################################################################################

find_package2(PRIVATE A REQUIRED) # depends on B

assert_false(B_FOUND)

find_package2_implicit_dependencies()

assert_true(B_FOUND)

0 comments on commit 15a8f1f

Please sign in to comment.