[CMake] out-of-tree buildable libraries and find_package

Mueller-Roemer, Johannes Sebastian Johannes.Sebastian.Mueller-Roemer at igd.fraunhofer.de
Wed Nov 26 08:08:33 EST 2014


I have a project which uses a number of libraries, a bit like this:

CMakeLists.txt -> add_subdirectories, add_executable
Lib1 -> add_library
Lib2 -> add_library, links to/uses Lib1

As the libraries are individually useful I'd like to keep them individually buildable (i.e., out-of-tree). Obviously, Lib2 will then have to do a find_package(Lib1). However, the find_package will fail if it is built in-tree. I currently see three options:


1.       Protect the find_package() with if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)

2.       Use export(TARGETS) and export(PACKAGE), however this leads to warnings when using CMake 3

3.       Write an empty (or ALIAS-target only if using namespaces for the real config) ${PROJECT_NAME}-config.cmake to CMAKE_BINARY_DIR and add CMAKE_BINARY_DIR to CMAKE_PREFIX PATH in the root CMakeLists.txt

None of these really feels right. Are there better options? What is the cleanest solution?

--
Johannes S. Mueller-Roemer, MSc
Wiss. Mitarbeiter - Interactive Engineering Technologies (IET)

Fraunhofer-Institut für Graphische Datenverarbeitung IGD
Fraunhoferstr. 5  |  64283 Darmstadt  |  Germany
Tel +49 6151 155-606  |  Fax +49 6151 155-139
johannes.mueller-roemer at igd.fraunhofer.de  |  www.igd.fraunhofer.de

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141126/9c08f355/attachment-0001.html>


More information about the CMake mailing list