Skip to content

Commit

Permalink
InstallBasicPackageFiles: Fix subtle bug of OVERRIDE_MODULE_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro committed Mar 29, 2024
1 parent 4e9a2ba commit bcef0c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to this project are documented in this file.

### Fixed
- Fix the barrier logic for threads synchronization (https://github.com/ami-iit/bipedal-locomotion-framework/pull/811)
- InstallBasicPackageFiles: Fix bug of OVERRIDE_MODULE_PATH that corrupt CMAKE_MODULE_PATH values set by blf transitive dependencies (https://github.com/ami-iit/bipedal-locomotion-framework/pull/827)

### Removed

Expand Down
17 changes: 10 additions & 7 deletions cmake/InstallBasicPackageFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
# :command:`install` commands, otherwise <Name> is used.
#
# If the ``OVERRIDE_MODULE_PATH`` is set, the autogenerated ``<Name>Config.cmake``
# file temporarily overrides the ``CMAKE_MODULE_PATH`` with the specified paths.
# file temporarily prepends the ``CMAKE_MODULE_PATH`` with the specified paths.

#=============================================================================
# Copyright 2013 Istituto Italiano di Tecnologia (IIT)
Expand Down Expand Up @@ -576,13 +576,11 @@ ${_compatibility_vars}
endif()

unset(PACKAGE_DEPENDENCIES)
set(_overridden_module_path_list "")
if(DEFINED _IBPF_DEPENDENCIES)
set(PACKAGE_DEPENDENCIES "#### Expanded from @PACKAGE_DEPENDENCIES@ by install_basic_package_files() ####\n\ninclude(CMakeFindDependencyMacro)\n")

if (DEFINED _IBPF_OVERRIDE_MODULE_PATH)

string(APPEND PACKAGE_DEPENDENCIES "set(CMAKE_MODULE_PATH_BK_${_IBPF_VARS_PREFIX} \${CMAKE_MODULE_PATH})\n")
set(_overridden_module_path "")
foreach(_path ${_IBPF_OVERRIDE_MODULE_PATH})

if (IS_ABSOLUTE ${_path})
Expand All @@ -592,9 +590,12 @@ ${_compatibility_vars}
endif()

file(RELATIVE_PATH _relative_path ${CMAKE_INSTALL_PREFIX} ${_absolute_module_path})
string(APPEND _overridden_module_path " \${PACKAGE_PREFIX_DIR}/${_relative_path}")
string(APPEND _overridden_module_path_list ";\${PACKAGE_PREFIX_DIR}/${_relative_path}")
endforeach()
string(APPEND PACKAGE_DEPENDENCIES "set(CMAKE_MODULE_PATH${_overridden_module_path})\n")
string(APPEND PACKAGE_DEPENDENCIES "foreach(overridden_module_path ${_overridden_module_path_list})\n")
string(APPEND PACKAGE_DEPENDENCIES " list(PREPEND CMAKE_MODULE_PATH \${overridden_module_path})\n")
string(APPEND PACKAGE_DEPENDENCIES "endforeach()\n")

# If OVERRIDE_MODULE_PATH is used, then if a dependency is not found find_dependency will
# halt the execution of the <package>config.cmake script, never restoring the original
# value of CMAKE_MODULE_PATH. For this reason, in this case we just use find_package
Expand Down Expand Up @@ -654,7 +655,9 @@ endif()
endif()

if(DEFINED _IBPF_OVERRIDE_MODULE_PATH)
string(APPEND PACKAGE_DEPENDENCIES "set(CMAKE_MODULE_PATH \${CMAKE_MODULE_PATH_BK_${_IBPF_VARS_PREFIX}})\n")
string(APPEND PACKAGE_DEPENDENCIES "foreach(overridden_module_path ${_overridden_module_path_list})\n")
string(APPEND PACKAGE_DEPENDENCIES " list(REMOVE_ITEM CMAKE_MODULE_PATH \${overridden_module_path})\n")
string(APPEND PACKAGE_DEPENDENCIES "endforeach()\n")
endif()

set(PACKAGE_DEPENDENCIES "${PACKAGE_DEPENDENCIES}\n###############################################################################\n")
Expand Down

0 comments on commit bcef0c1

Please sign in to comment.