Skip to content

Commit cbe9a65

Browse files
authored
InstallBasicPackageFiles: Fix bug of OVERRIDE_MODULE_PATH that corrupt CMAKE_MODULE_PATH values set by blf transitive dependencies
1 parent 2dbf5db commit cbe9a65

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

cmake/InstallBasicPackageFiles.cmake

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
# :command:`install` commands, otherwise <Name> is used.
212212
#
213213
# If the ``OVERRIDE_MODULE_PATH`` is set, the autogenerated ``<Name>Config.cmake``
214-
# file temporarily overrides the ``CMAKE_MODULE_PATH`` with the specified paths.
214+
# file temporarily prepends the ``CMAKE_MODULE_PATH`` with the specified paths.
215215

216216
#=============================================================================
217217
# Copyright 2013 Istituto Italiano di Tecnologia (IIT)
@@ -576,13 +576,11 @@ ${_compatibility_vars}
576576
endif()
577577

578578
unset(PACKAGE_DEPENDENCIES)
579+
set(_overridden_module_path_list "")
579580
if(DEFINED _IBPF_DEPENDENCIES)
580581
set(PACKAGE_DEPENDENCIES "#### Expanded from @PACKAGE_DEPENDENCIES@ by install_basic_package_files() ####\n\ninclude(CMakeFindDependencyMacro)\n")
581582

582583
if (DEFINED _IBPF_OVERRIDE_MODULE_PATH)
583-
584-
string(APPEND PACKAGE_DEPENDENCIES "set(CMAKE_MODULE_PATH_BK_${_IBPF_VARS_PREFIX} \${CMAKE_MODULE_PATH})\n")
585-
set(_overridden_module_path "")
586584
foreach(_path ${_IBPF_OVERRIDE_MODULE_PATH})
587585

588586
if (IS_ABSOLUTE ${_path})
@@ -592,9 +590,12 @@ ${_compatibility_vars}
592590
endif()
593591

594592
file(RELATIVE_PATH _relative_path ${CMAKE_INSTALL_PREFIX} ${_absolute_module_path})
595-
string(APPEND _overridden_module_path " \${PACKAGE_PREFIX_DIR}/${_relative_path}")
593+
string(APPEND _overridden_module_path_list ";\${PACKAGE_PREFIX_DIR}/${_relative_path}")
596594
endforeach()
597-
string(APPEND PACKAGE_DEPENDENCIES "set(CMAKE_MODULE_PATH${_overridden_module_path})\n")
595+
string(APPEND PACKAGE_DEPENDENCIES "foreach(overridden_module_path ${_overridden_module_path_list})\n")
596+
string(APPEND PACKAGE_DEPENDENCIES " list(PREPEND CMAKE_MODULE_PATH \${overridden_module_path})\n")
597+
string(APPEND PACKAGE_DEPENDENCIES "endforeach()\n")
598+
598599
# If OVERRIDE_MODULE_PATH is used, then if a dependency is not found find_dependency will
599600
# halt the execution of the <package>config.cmake script, never restoring the original
600601
# value of CMAKE_MODULE_PATH. For this reason, in this case we just use find_package
@@ -654,7 +655,9 @@ endif()
654655
endif()
655656

656657
if(DEFINED _IBPF_OVERRIDE_MODULE_PATH)
657-
string(APPEND PACKAGE_DEPENDENCIES "set(CMAKE_MODULE_PATH \${CMAKE_MODULE_PATH_BK_${_IBPF_VARS_PREFIX}})\n")
658+
string(APPEND PACKAGE_DEPENDENCIES "foreach(overridden_module_path ${_overridden_module_path_list})\n")
659+
string(APPEND PACKAGE_DEPENDENCIES " list(REMOVE_ITEM CMAKE_MODULE_PATH \${overridden_module_path})\n")
660+
string(APPEND PACKAGE_DEPENDENCIES "endforeach()\n")
658661
endif()
659662

660663
set(PACKAGE_DEPENDENCIES "${PACKAGE_DEPENDENCIES}\n###############################################################################\n")
@@ -709,3 +712,4 @@ endif()
709712
FILE "${_targets_filename}"
710713
COMPONENT ${_IBPF_COMPONENT})
711714
endfunction()
715+

0 commit comments

Comments
 (0)