[CMake] Writing foo-config.cmake with find_dependency

Mateusz Loskot mateusz at loskot.net
Thu Oct 4 09:14:25 EDT 2018


On Mon, 1 Oct 2018 at 21:45, Mateusz Loskot <mateusz at loskot.net> wrote:
>
> The library has number of dependencies on third-party libraries,
> namely database access client libraries. I've reached the point
> where I need to 'list' those dependencies in soci-config.cmake [3]
> Namely, I need to make friend with find_dependency.
>
> In SOCI, I maintain number of Find-modules, eg. FindSQLite3.cmake,
> FindOracle.cmake, etc. Those are also an ancient CMake scripts,
> but I think my problem/question is orthogonal to rewriting those to
> target-aware modules or keep those old-style w/ FOO_LIBRARIES, etc.
>
> Now, if I have a custom `FindSQLite3.cmake` module and I do
> target_link_libraries(soci_sqlite3 PUBLIC ${SQLITE3_LIBRARIES})
> in CMakeLists.txt of the SOCI library, then in soci-config.cmake I do
> find_dependency(SQLite3)
> Is that correct?
>
> Now, am I supposed to deploy the FindSQLite3.cmake along
> soci-config.cmake to match the ${SQLITE3_LIBRARIES}?
> What if a user of SOCI (or even CMake distribution) comes with
> custom FindSQLite3.cmake which actually defines targets
> instead of old-style variables
> or defines SQLITE_LIBRARIES (without 3 in  SQLITE)?
>
> How to handle such situations?


Or, what to put into soci-config.cmake to screw things up the least,
to handle easiest scenario possible?

I'll appreciate any insights.

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net


More information about the CMake mailing list