Chris,
This is a common confusion, when you use find_package() to pull in Ceres:
find_package(Ceres REQUIRED)
message("CERES_LIBRARIES = ${CERES_LIBRARIES}")
You would see the output:
CERES_LIBRARIES = ceres
*However*, this does *not* refer to the compiled Ceres library: /usr/local/libceres.a/so (assuming you installed it there), but instead it is the *name* of a CMake imported target which gets declared when /usr/local/share/Ceres/CeresConfig.cmake is read, which is what happens when you call find_package(Ceres).
If you added the following:
get_target_property(CERES_IMPORTED_LIBS ${CERES_LIBRARIES} IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE)
message("CERES_IMPORTED_LIBS = ${CERES_IMPORTED_LIBS}”)
You would see any other public link libraries for your Ceres build (/usr/local/lib/libglog.so usually), similarly you can query for the actual libceres.a/so library that the imported CMake target represents.
The reason you are having an issue is that imported targets are *not* (re)exported when a project which imported them is exported. Somewhat annoyingly, instead what is exported is just the name of the imported target, with no other information. Hence when you exported Foo, you see ‘ceres’ in the list of link libraries. The issue is that in a project which imports Foo, CMake will interpret ‘ceres’ as meaning libceres.a/so if it exists on the path. This loses all information about other link libraries required that was present in the exported Ceres target.
The solution to this, is to add a find_package(Ceres QUIET) to your FooConfig.cmake, that way whenever anyone calls find_package(Foo), and FooConfig.cmake is called it will try and find Ceres (quietly, so no errors will be thrown - this is up to you, if Foo requires Ceres then remove QUIET - see my link below for a more expansive solution). This will result in CeresConfig.cmake being called (when building MyLib), and thus the ‘ceres’ target will be imported into the current project (MyLib in your example) - then everything should build fine, because now ‘ceres’ refers to the imported target, not just the compiled libceres.a/so library on its own.
As you’re actually the second person this week to ask me about this (although the first for Ceres), I will update the docs to add some info on this.
-Alex