[CMake] Passing arguments to functions

Cedric Doucet cedric.doucet at inria.fr
Wed May 20 14:49:07 EDT 2015


Hello, 

I try to wrote a function DownloadThenInstall which calls the ExternalProject_Add function after havind defined useful variables like prefix, download_dir, etc. 

I would like to call it like this 
DownloadThenInstall(Eigen) 
to download and install the Eigen library (for example). 

But it doesn't work unless I change the call to 
DownloadThenInstall(${Eigen}) 

Below is the core of the function. 
In the first call of DownloadThenInstall, name and url are empty. 
In the second call of DownloadThenInstall, name and url have the right values. 

How could I modify my script in order to make the first call, DownloadThenInstall(Eigen), work? 

Thank you very much! 

Cédric 

-------------------- 



function(DownloadThenInstall LIBRARY_NAME) 




string(TOLOWER ${LIBRARY_NAME} LIBRARY_LOWERNAME) 
string(TOUPPER ${LIBRARY_NAME} LIBRARY_UPPERNAME) 




#=================================== 

# define useful variables for ExternalProject_Add 

#=================================== 

set(${LIBRARY_UPPERNAME}_PREFIX ${EXTERNAL_DIR}/${LIBRARY_LOWERNAME} ) 
set(${LIBRARY_UPPERNAME}_DOWNLOAD_DIR ${${LIBRARY_UPPERNAME}_PREFIX}/download) 
set(${LIBRARY_UPPERNAME}_SOURCE_DIR ${${LIBRARY_UPPERNAME}_PREFIX}/src) 
set(${LIBRARY_UPPERNAME}_BINARY_DIR ${${LIBRARY_UPPERNAME}_PREFIX}/build) 
set(${LIBRARY_UPPERNAME}_TMP_DIR ${${LIBRARY_UPPERNAME}_PREFIX}/tmp) 
set(${LIBRARY_UPPERNAME}_STAMP_DIR ${${LIBRARY_UPPERNAME}_PREFIX}/stamp) 
set(${LIBRARY_UPPERNAME}_INSTALL_DIR ${${LIBRARY_UPPERNAME}_PREFIX}/install) 



#==================================== 

# messages for debugging purpose (to be removed) 

#==================================== 

message(STATUS "name: ${LIBRARY_NAME}") 
message(STATUS "url: ${${LIBRARY_NAME}_URL}") 




#===================== 

# call to ExternalProject_Add 

#===================== 




endfunction(DownloadThenInstall) 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150520/f3cb4595/attachment.html>


More information about the CMake mailing list