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
diff --git a/cmake/CeresConfig.cmake.in b/cmake/CeresConfig.cmake.in index 9122881..1d0b012 100644 --- a/cmake/CeresConfig.cmake.in +++ b/cmake/CeresConfig.cmake.in
@@ -120,11 +120,11 @@ "${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 @@ "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.