[CMake] Linking with an external project also built with CMake

Wojtek Mamrak wmamrak at gmail.com
Fri Sep 18 06:03:20 EDT 2015


Or you can export ExternalLib directly from the build tree.

export(TARGETS ExternalLib FILE
"${PROJECT_BINARY_DIR}/ExternalLibTargets.cmake")

configure_file("${PROJECT_SOURCE_DIR}/ExternalLibConfig.cmake"
"${PROJECT_BINARY_DIR}/ExternalLibConfig.cmake")

export(PACKAGE ExternalLib)

with ExternalLibConfig.cmake having something like:

include("ExternalLibTargets.cmake")

regards

2015-09-17 22:52 GMT+02:00 Tamás Kenéz <tamas.kenez at gmail.com>:
> 1. There is a (semi-)automatic way: you can export the targets of
> ExternalLib with install(EXPORT...) from its CMakeLists.txt. In the simplest
> cases you can use the generated export file as a config module:
>
>     install(TARGETS ... EXPORT externallib ...)
>     install(EXPORT externallib FILE externallib-config.cmake ...)
>
> Of course you also need to set the appropriate properties of the targets of
> ExternalLib by using the target_* commands.
>
> 2. (Another option) If you build the ExternalLib in the same project, its
> targets will be available in the main project.
>
> On Thu, Sep 17, 2015 at 6:25 PM, Saad Khattak <saadrustam at gmail.com> wrote:
>>
>> Hello,
>>
>> I have a project ExternalLib that uses CMake to build its libraries. I
>> then have my own project (separate from the external library) that needs to
>> include ExternalLib's headers and link with its libraries. ExternalLib does
>> not have a find_package module.
>>
>> Since ExternalLib is also built using CMake, is there no 'automatic' way
>> to have CMake figure out where the source files and library files are (since
>> CMake built them in the first place)? That is, I want to avoid writing a
>> find_package module for ExternalLib and since I have to build it using CMake
>> anyway, I was hoping there would be some way to automatically fill in the
>> correct paths for the libraries and source file directories in MyProject
>> which also uses CMake.
>>
>> Thanks,
>> Saad
>>
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more
>> information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/cmake
>
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake


More information about the CMake mailing list