[CMake] How to build and link Externa Project with exported target

Michael Wild themiwi at gmail.com
Wed Mar 17 08:41:33 EDT 2010


On 17. Mar, 2010, at 13:17 , Nicola Brisotto wrote:

> Hi!
> I'm building a project that require a 3rd party library libqxmpp. Both project uses cmake 
> I want to build libqxmpp with ExternalProject_add, this the code I use:
> 
> ExternalProject_add(
> 	libqxmpp
> 	#no download, i'm using git submodule
> 	DOWNLOAD_COMMAND ""
> 	CMAKE_ARGS -DQT_QMAKE_EXECUTABLE=/devel/BIN/v4.6.1-git-phonon-dbg-release/bin/qmake -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
> 	SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/3rdparty/qxmpp-read-only-git/source
> )
> 
> The problem arise when I try to import a target from libqxmpp adding this to my project CMakeLists.txt:
> #Import libQXmppClient 
> include(${CMAKE_BINARY_DIR}/include/QXmppClient/QXmppClient.cmake)
> 
> Cmake cannot find QXmppClient.cmake because it will be created when I'll build the project.
> How can I solve this problem? Are there better solution to build and link an external project?
> 
> This is the libqxmpp snippet that export the target:
> 
> INSTALL(TARGETS QXmppClient EXPORT QXmppClient DESTINATION lib)
> INSTALL(EXPORT QXmppClient DESTINATION include/QXmppClient )
> 
> Nicola Brisotto
> vcard

There are two ways of getting around this:

1) create the IMPORTED targets yourself.

2) also build your main project wit a ExternalProject_Add and drive the whole thing from a "master-CMakeLists.txt"

The first one is probably easier to set up, but requires you to guess the installation names and paths correctly. The second option requires you to restructure your whole build system and adds considerable complexity due to the communication between your master-project and the external projects. For this communication I'd try the following:

- In the master project do all the feature-detection and setting of cache variables (such as options etc)
- Write a cache-initializer script to the binary tree
- Do all the ExternalProject_Add calls and specify the cache-initializer script with the -C option in CMAKE_ARGS

HTH

Michael


More information about the CMake mailing list