Re: [CMake] How to build and link Externa Project with exported target
Say your project is called foo, you could do something like this: # Mark variables to be included in the cache-init script # The variables must already exist in the cache. function(foo_add_cache_init_vars) get_property(is_defined GLOBAL PROPERTY FOO_CACHE_INIT_VARIABLES DEFINED) if(NOT is_defined) define_property(GLOBAL PROPERTY FOO_CACHE_INIT_VARIABLES BRIEF_DOCS Variables to be written to the cache initialization script FULL_DOCS The variables will be used to initialize external projects ) endif() set_property(GLOBAL APPEND PROPERTY FOO_CACHE_INIT_VARIABLES ${ARGN}) endif() # Write the cache initializer script function(foo_write_cache_init_script outfile) get_property(is_set GLOBAL PROPERTY FOO_CACHE_INIT_VARIABLES SET) if(NOT is_set) message(FATAL_ERROR You must call foo_add_cache_init_var before calling this function) endif() get_property(varnames GLOBAL PROPERTY FOO_CACHE_INIT_VARIABLES) set(text # Automatically generated, do not edit!\n) foreach(var IN LISTS varnames) get_property(vartype CACHE ${var} PROPERTY TYPE) get_property(varhelp CACHE ${var} PROPERTY HELPSTRING) set(text ${text}set(${var} \${${var}}\ CACHE ${vartype} \${varhelp}\)\n) endforeach() file(WRITE ${outfile} ${text}) endfunction() # here goes the real stuff foo_add_cache_init_vars( CMAKE_C_COMPILER CMAKE_CXX_COMPILER CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT CMAKE_VERBOSE_MAKEFILE # ... ) foreach(config _DEBUG _RELEASE _MINSIZEREL _RELWITHDEBINFO) foo_add_cache_init_vars( CMAKE_C_FLAGS${config} CMAKE_CXX_FLAGS${config} CMAKE_MODULE_LINKER_FLAGS${config} CMAKE_SHARED_LINKER_FLAGS${config} # ... ) endforeach() foo_write_cache_init_script(${CMAKE_BINARY_DIR}/ExternalCacheInitScript.cmake) I haven't tested it, but something along these lines should work. HTH Michael On 19. Mar, 2010, at 15:11 , Nicola Brisotto wrote: Hi, the solution with a master CMakeLists.txt works well but now I don't know how to write wrapper for OPTION and SET functions, can you give me an example? I'm quite new to cmake so another question is: what is the diffence between create a xxx-config and the file I create with INSTALL(EXPORT QXmppClient DESTINATION include/QXmppClient ) ? They seem to do the same thing but probably I'm missing something Nicola Brisotto On Wed, Mar 17, 2010 at 8:44 PM, Alexander Neundorf a.neundorf-w...@gmx.net wrote: On Wednesday 17 March 2010, Michael Wild wrote: On 17. Mar, 2010, at 15:43 , Luigi Calori wrote: ... Is this ExternalProject_Add feature really used/developed? I find it really nice but a little scared of weather it will be really supported and improved. I have done some patching on it but not know if there is a group of user/developer eventually interested to submit mods to It is actively used and developed, but also relatively new. If you have improvements, it's best to create a tracker item with a patch and description there and post the link to the item on this list. Yes. And git support for it would be a really nice thing to have :-) Alex ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] How to build and link Externa Project with exported target
Hi, the solution with a master CMakeLists.txt works well but now I don't know how to write wrapper for OPTION and SET functions, can you give me an example? I'm quite new to cmake so another question is: what is the diffence between create a xxx-config and the file I create with INSTALL(EXPORT QXmppClient DESTINATION include/QXmppClient ) ? They seem to do the same thing but probably I'm missing something Nicola Brisotto On Wed, Mar 17, 2010 at 8:44 PM, Alexander Neundorf a.neundorf-w...@gmx.net wrote: On Wednesday 17 March 2010, Michael Wild wrote: On 17. Mar, 2010, at 15:43 , Luigi Calori wrote: ... Is this ExternalProject_Add feature really used/developed? I find it really nice but a little scared of weather it will be really supported and improved. I have done some patching on it but not know if there is a group of user/developer eventually interested to submit mods to It is actively used and developed, but also relatively new. If you have improvements, it's best to create a tracker item with a patch and description there and post the link to the item on this list. Yes. And git support for it would be a really nice thing to have :-) Alex ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
[CMake] How to build and link Externa Project with exported target
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 ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] How to build and link Externa Project with exported target
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 ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] How to build and link Externa Project with exported target
Hi Michael and Nicola, I'm in a similar situation as I' m trying to build up a cmake based dependency builder for OpenSceneGraph based projects: So I' m really interested in any best practice advice 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 ) Means there is a way to instruct ExternalProject_add to download from GIT repos? I was not aware of and starting to hack it to add... let me know if one is available: I have already added Bazaar download similarly to SVN ... so if there is a way to share hacking on it 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 ) Sorry my ignorance, this is part of the install step of 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 This suggestion is really interesting:the purpouse is to let any config options in the master projects to be passed to the slaves? Have you any examples? I came up with a schema like 2: any project is built as external, dependencies are resolved by ExternalProject_Add and I have used CMAKE_ARGS to communicate settings: As most of cmake projects were based on FindXXX stuff for finding deps, I have overridden the necessary modules in order to make the projects find the good components at configure time. As I did not yet need a lot of interactive customization, I just passed common parameters using CMAKE_ARGS Would not something similar work for you: keep your project separate from libqxmpp, add to it a find_package(QXmppClient) then build a master project where you do: 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 ) ExternalProject_Add(your_project_name DEPENDS libqxmpp DOWNLOAD_COMMAND SOURCE_DIR ${CMAKE_SOURCE_DIR}/your project subsource dir INSTALL_DIR ${CMAKE_INSTALL_PREFIX} HTH Luigi ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] How to build and link Externa Project with exported target
On 17. Mar, 2010, at 14:37 , Luigi Calori wrote: Hi Michael and Nicola, I'm in a similar situation as I' m trying to build up a cmake based dependency builder for OpenSceneGraph based projects: So I' m really interested in any best practice advice 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 ) Means there is a way to instruct ExternalProject_add to download from GIT repos? I was not aware of and starting to hack it to add... let me know if one is available: I have already added Bazaar download similarly to SVN ... so if there is a way to share hacking on it He's not downloading with CMake, he just told git that in this directory is a submodule. The user has then to fetch it himself with one command: http://git.wiki.kernel.org/index.php/GitSubmoduleTutorial [...] 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 This suggestion is really interesting:the purpouse is to let any config options in the master projects to be passed to the slaves? Have you any examples? You could pass every single cache variable using -D in CMAKE_ARGS, but that becomes pretty tedious very soon... Currently I don't have any example, sorry. I came up with a schema like 2: any project is built as external, dependencies are resolved by ExternalProject_Add and I have used CMAKE_ARGS to communicate settings: As most of cmake projects were based on FindXXX stuff for finding deps, I have overridden the necessary modules in order to make the projects find the good components at configure time. That's what you could do with the cache-initialization script, no need to override the FindXXX modules. If more than one of the external projects use the same FindXXX module, do it in the master and then communicate the results using the initializer script. This way the user can easily override the results during the configure-step and get consistent results in all the sub-projects. Only thing that has me worried is when the user aborts the build, changes the settings in the master cache and then restarts the build. You'd need to somehow set up correct dependencies... If sub-project B does a FIND_PACKAGE(A REQUIRED) and A is built as another sub-project, then you can specify A_DIR to the B project containing the path to the directory containing its A-config.cmake. Michael ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] How to build and link Externa Project with exported target
[...] He's not downloading with CMake, he just told git that in this directory is a submodule. The user has then to fetch it himself with one command: http://git.wiki.kernel.org/index.php/GitSubmoduleTutorial Sorry ... no git expert at all my point was just to hack ExternalProject_add to let specify different download ways, apart from URL, SVN_REPOSITORY and mine BZR_REPOSITORY would like to have also GIT_REPOSITORY and HG_REPOSITORY [...] 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 This suggestion is really interesting:the purpouse is to let any config options in the master projects to be passed to the slaves? Have you any examples? You could pass every single cache variable using -D in CMAKE_ARGS, but that becomes pretty tedious very soon... Currently I don't have any example, sorry. from http://www.cmake.org/cmake/help/cmake-2-8-docs.html#opt:-Cinitial-cache seems that what you are suggesting is not passing the master cache to the slaves, but to build a selection of variables and build a script in a different format Do you suggesto to pass the same script to ALL the subprojects? I' ll try to find some examples of that usage.seems useful I came up with a schema like 2: any project is built as external, dependencies are resolved by ExternalProject_Add and I have used CMAKE_ARGS to communicate settings: As most of cmake projects were based on FindXXX stuff for finding deps, I have overridden the necessary modules in order to make the projects find the good components at configure time. That's what you could do with the cache-initialization script, no need to override the FindXXX modules. If more than one of the external projects use the same FindXXX module, do it in the master and then communicate the results using the initializer script. This way the user can easily override the results during the configure-step and get consistent results in all the sub-projects. Only thing that has me worried is when the user aborts the build, changes the settings in the master cache and then restarts the build. You'd need to somehow set up correct dependencies... If the cache-initialization script is single, then would be good that all the slave projects file_depends on that but do not know how to set a file dependency on the configure step of ExternalProject_Add If sub-project B does a FIND_PACKAGE(A REQUIRED) and A is built as another sub-project, then you can specify A_DIR to the B project containing the path to the directory containing its A-config.cmake. Yes, that would be good unfortunately not so many cmake projects builds xxx-config.cmake in their build-install process It would be nice to have good examples of usages: this could be a standard way of building dependencies throug cmake . Is this ExternalProject_Add feature really used/developed? I find it really nice but a little scared of weather it will be really supported and improved. I have done some patching on it but not know if there is a group of user/developer eventually interested to submit mods to Thanks Luigi ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] How to build and link Externa Project with exported target
On Wednesday 17 March 2010, Michael Wild wrote: On 17. Mar, 2010, at 15:43 , Luigi Calori wrote: ... Is this ExternalProject_Add feature really used/developed? I find it really nice but a little scared of weather it will be really supported and improved. I have done some patching on it but not know if there is a group of user/developer eventually interested to submit mods to It is actively used and developed, but also relatively new. If you have improvements, it's best to create a tracker item with a patch and description there and post the link to the item on this list. Yes. And git support for it would be a really nice thing to have :-) Alex ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake