0

I have two versions of the Ceres solver installed. One is in /opt/local/lib and the other is in /usr/local/lib/ and I am using cmake to build an application that uses the latter. In my build subdirectory the following works fine:

cmake -DCeres_DIR=/usr/local/lib/cmake/Ceres/ ..

I would rather specify the correct path in the CMakeLists.txt file as described in this post, but the following fails:

find_package(Ceres PATHS /usr/local/lib/cmake/Ceres)

When I do this, cmake complains since it finds the wrong CeresConfig.cmake file which was built using a different version of Eigen:

CMake Error at /opt/local/lib/cmake/Ceres/CeresConfig.cmake:85 (message):
  Failed to find Ceres - Found Eigen dependency, but the version of Eigen
  found (3.4.0) does not exactly match the version of Eigen Ceres was
  compiled with (3.3.9).
  ....

Clearly is it using the Ceres installation in /opt/local/lib not /usr/local/lib. Why isn't the PATHS specification working in this case?

wcochran
  • 10,089
  • 6
  • 61
  • 69
  • 1
    Have you cleared CMake cache (`CMakeCache.txt`) before your new attempt? Also, you could add option `NO_DEFAULT_PATH` to the `find_package` call, so CMake won't search the package elsewhere except the `PATHS`. – Tsyvarev Sep 29 '21 at 07:17
  • `NO_DEFAULT_PATH` did the trick. I didn't see this documented. --thanks! Add as answer and I'll check it. – wcochran Sep 29 '21 at 14:02
  • Actually, the behavior of `NO_DEFAULT_PATH` is follows: **Without** `NO_DEFAULT_PATH`, CMake firstly checks the package under `PATHS`. If CMake cannot find the package here, then it searches under some predefined locations. **With** `NO_DEFAULT_PATH`, CMake checkes the package under `PATHS`. If it cannot find the package their, then it reports an error. So, `NO_DEFAULT_PATH` simply cannot help you to find one package instead of another: it can only help you to **not find** an unwanted package. BTW, the option is documented here: https://cmake.org/cmake/help/latest/command/find_package.html – Tsyvarev Sep 29 '21 at 14:10
  • @Tsyvarev I don't understand why it didn't first find it under `/usr/local` then -- according to the behavior you describe it should. Actually, according to the docs, looking at the `PATHS` is the ninth step! – wcochran Sep 29 '21 at 15:23

0 Answers0