[CMake] How to build and link Externa Project with exported target
Michael Wild
themiwi at gmail.com
Fri Mar 19 11:01:21 EDT 2010
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-work at 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
>>
More information about the CMake
mailing list