Do not discard caller's CMAKE_MODULE_PATH

Ceres CMake package configuration relies on several own find modules
(e.g., for SuiteSparse and METIS). To allow CMake to discover additional
find modules, the CMAKE_MODULE_PATH variable must be updated to include
the directories containing the corresponding find modules.

Previously, before updating CMAKE_MODULE_PATH, Ceres stored the
variable's initial value and then completely replaced it by the
directory containing Ceres's modules. However, a find_dependency failure
would cause an early return preventing CMAKE_MODULE_PATH to be restored.
Thus, any initial user changes to CMAKE_MODULE_PATH would be lost.

Now, instead of completely replacing the CMAKE_MODULE_PATH value we only
prepend additional directories. An early return no longer has a
destructive effect on CMAKE_MODULE_PATH. In a failure case,
CMAKE_MODULE_PATH still contains caller's initial set of directories and
an additional path prepended by Ceres.

Fixes #1024

Change-Id: I80d92a5dff9f3cff651f950c4f8d04ece008b44b
This commit is contained in:
Sergiu Deitsch
2025-02-19 22:50:15 +01:00
parent af39e3b9ee
commit 46b4b3b002
+10 -10
View File
@@ -120,11 +120,11 @@ get_filename_component(CERES_CURRENT_CONFIG_DIR
"${CMAKE_CURRENT_LIST_FILE}" PATH)
if (CERES_WAS_INSTALLED)
# Reset CMake module path to the installation directory of this
# script, thus we will use the FindPackage() scripts shipped with
# Ceres to find Ceres' dependencies, even if the user has equivalently
# named FindPackage() scripts in their project.
set(CMAKE_MODULE_PATH ${CERES_CURRENT_CONFIG_DIR})
# Update the CMake module path to include the installation directory of this
# script, thus we will use the FindPackage() scripts shipped with Ceres to
# find Ceres' dependencies, even if the user has equivalently named
# FindPackage() scripts in their project.
list(PREPEND CMAKE_MODULE_PATH ${CERES_CURRENT_CONFIG_DIR})
# Build the absolute root install directory as a relative path
# (determined when Ceres was configured & built) from the current
@@ -155,11 +155,11 @@ else(CERES_WAS_INSTALLED)
"directory: ${CERES_EXPORTED_BUILD_DIR} does not exist.")
endif()
# Reset CMake module path to the cmake directory in the Ceres source
# tree which was exported, thus we will use the FindPackage() scripts shipped
# with Ceres to find Ceres' dependencies, even if the user has equivalently
# named FindPackage() scripts in their project.
set(CMAKE_MODULE_PATH ${CERES_EXPORTED_SOURCE_DIR}/cmake)
# Update the CMake module path to include the cmake directory in the Ceres
# source tree which was exported, thus we will use the FindPackage() scripts
# shipped with Ceres to find Ceres' dependencies, even if the user has
# equivalently named FindPackage() scripts in their project.
list(PREPEND CMAKE_MODULE_PATH ${CERES_EXPORTED_SOURCE_DIR}/cmake)
endif(CERES_WAS_INSTALLED)
# Set the version.