[CMake] file(DOWNLOAD ...) at build time

Eric Noulard eric.noulard at gmail.com
Mon Mar 11 14:11:23 EDT 2013


2013/3/11 Luc J. Bourhis <luc_j_bourhis at mac.com>:
> David Cole-2 wrote
>> The simplest way is to make a “download only” ExternalProject, by using
>> something like:
>> [...]
>> ExternalProject does all that for you, and even extracts tarballs and
>> moves them into the SOURCE_DIR for you, which you can see if you poke
>> around enough underneath the hood.
>
> The problem is that the file to download is a RPM and ExternalProject does
> not know how to handle it.
>
>
> David Cole-2 wrote
>> Alternatively, you could use add_custom_command to run a CMake script at
>> build time that does the file(DOWNLOAD.
>>
>>     add_custom_command(COMMAND ${CMAKE_COMMAND} -P
>>
>>       ${CMAKE_CURRENT_SOURCE_DIR}/download.cmake)
>>
>> And then in download.cmake:
>>
>>     file(DOWNLOAD .....)
>
> As far as I understand, ExternalProject_Add creates the equivalent of
> download.cmake and then use the -P trick. Would there be a way to put the
> download.cmake inline the calling CMake script? Like a "heredoc"?

not "really" but you can generate the download.cmake file:

inside you CMakeLists.txt you can write something like:

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/download.cmake "file(DOWNLOAD ...)")
add_custom_command(COMMAND ${CMAKE_COMMAND} -P
       ${CMAKE_CURRENT_BINARY_DIR}/download.cmake


the "file(WRITE ...)" will write ${CMAKE_CURRENT_BINARY_DIR}/download.cmake
at CMake time and then you custom command will invoke it using cmake -P
at build time.

If you want to write a possibly complex "download.cmake" file then
you can use file(APPEND  ${CMAKE_CURRENT_BINARY_DIR}/download.cmake ...)


-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org


More information about the CMake mailing list