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

Nicola Brisotto nicolabrisotto at gmail.com
Fri Apr 16 12:28:55 EDT 2010


Hi Mike,
I'm back to this topic because the second solution create some problem with qt-creator parser of cmake project. If I import the project I have no source file loaded so the solution is not ok for me.
The first solution,  "create the IMPORTED targets myself", means that I have to put something like the code below in my main CMakeList.txt?

#QXmppClient.cmake:
# Generated by CMake 2.8.0

IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5)
   MESSAGE(FATAL_ERROR "CMake >= 2.6.0 required")
ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5)
CMAKE_POLICY(PUSH)
CMAKE_POLICY(VERSION 2.6)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------

# Commands may need to know the format version.
SET(CMAKE_IMPORT_FILE_VERSION 1)

# Create imported target QXmppClient
ADD_LIBRARY(QXmppClient STATIC IMPORTED)

# Load information for each installed configuration.
GET_FILENAME_COMPONENT(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
FILE(GLOB CONFIG_FILES "${_DIR}/QXmppClient-*.cmake")
FOREACH(f ${CONFIG_FILES})
  INCLUDE(${f})
ENDFOREACH(f)

# Commands beyond this point should not need to know the version.
SET(CMAKE_IMPORT_FILE_VERSION)
CMAKE_POLICY(POP)



#QXmppClient-release.cmake 
#----------------------------------------------------------------
# Generated CMake target import file for configuration "Release".
#----------------------------------------------------------------

# Commands may need to know the format version.
SET(CMAKE_IMPORT_FILE_VERSION 1)

# Compute the installation prefix relative to this file.
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)

# Import target "QXmppClient" for configuration "Release"
SET_PROPERTY(TARGET QXmppClient APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
SET_TARGET_PROPERTIES(QXmppClient PROPERTIES
  IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
  IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE "/devel/BIN/v4.6.1-git-phonon-dbg-release/lib/QtGui.framework;-framework Carbon;-framework AppKit;/devel/BIN/v4.6.1-git-phonon-dbg-release/lib/QtXml.framework;/devel/BIN/v4.6.1-git-phonon-dbg-release/lib/QtNetwork.framework;/devel/BIN/v4.6.1-git-phonon-dbg-release/lib/QtCore.framework;/usr/lib/libz.dylib;-framework ApplicationServices"
  IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/libQXmppClient.a"
  )

# Cleanup temporary variables.
SET(_IMPORT_PREFIX)

# Commands beyond this point should not need to know the version.
SET(CMAKE_IMPORT_FILE_VERSION)


On Mar 17, 2010, at 13:41 , Michael Wild wrote:

> 
> 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

Nicola Brisotto
vcard

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100416/31ddd3ff/attachment-0001.htm>


More information about the CMake mailing list