From 7bd8cfb813e9bd19cebda92b280beb2deaf052d4 Mon Sep 17 00:00:00 2001 From: Andrey Pokrovskiy Date: Thu, 16 Apr 2015 21:42:19 -0700 Subject: [PATCH] ExternalProject: Allow generator expressions in initial cache options Use file(GENERATE) to write the initial cache file so that we can evaluate generator expressions. Use a per-config initial cache file name in case the content varies by configuration. --- Modules/ExternalProject.cmake | 11 ++++++----- .../ExternalProject/CMAKE_CACHE_ARGS-check.cmake | 2 +- Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS.cmake | 5 ++++- .../CMAKE_CACHE_DEFAULT_ARGS-check.cmake | 2 +- .../ExternalProject/CMAKE_CACHE_DEFAULT_ARGS.cmake | 5 ++++- .../ExternalProject/CMAKE_CACHE_mix-check.cmake | 2 +- Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix.cmake | 7 +++++-- 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 0c73d41a2..d91627028 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -113,6 +113,8 @@ Create custom targets to build projects in external trees overcome command line length limits. These arguments are :command:`set` using the ``FORCE`` argument, and therefore cannot be changed by the user. + Arguments may use + :manual:`generator expressions `. ``CMAKE_CACHE_DEFAULT_ARGS ...`` Initial default cache arguments, of the form ``-Dvar:string=on``. These arguments are written in a pre-load a script that populates @@ -121,6 +123,8 @@ Create custom targets to build projects in external trees These arguments can be used as default value that will be set if no previous value is found in the cache, and that the user can change later. + Arguments may use + :manual:`generator expressions `. Build step options are: @@ -1126,10 +1130,7 @@ function(_ep_write_initial_cache target_name script_filename script_initial_cach # Replace location tags. _ep_replace_location_tags(${target_name} script_initial_cache) # Write out the initial cache file to the location specified. - if(NOT EXISTS "${script_filename}.in") - file(WRITE "${script_filename}.in" "\@script_initial_cache\@\n") - endif() - configure_file("${script_filename}.in" "${script_filename}") + file(GENERATE OUTPUT "${script_filename}" CONTENT "${script_initial_cache}") endfunction() @@ -2054,7 +2055,7 @@ function(_ep_add_configure_command name) get_property(cmake_cache_default_args TARGET ${name} PROPERTY _EP_CMAKE_CACHE_DEFAULT_ARGS) if(cmake_cache_args OR cmake_cache_default_args) - set(_ep_cache_args_script "${tmp_dir}/${name}-cache.cmake") + set(_ep_cache_args_script "${tmp_dir}/${name}-cache-$.cmake") if(cmake_cache_args) _ep_command_line_to_initial_cache(script_initial_cache_force "${cmake_cache_args}" 1) endif() diff --git a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS-check.cmake b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS-check.cmake index c1e42043d..c350a63fc 100644 --- a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS-check.cmake +++ b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS-check.cmake @@ -1,4 +1,4 @@ -set(_cache_file "${RunCMake_TEST_BINARY_DIR}/tmp/FOO-cache.cmake") +set(_cache_file "${RunCMake_TEST_BINARY_DIR}/tmp/FOO-cache-Debug.cmake") if(NOT EXISTS "${_cache_file}") set(RunCMake_TEST_FAILED "Initial cache not created") diff --git a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS.cmake b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS.cmake index 5e37eece6..62b164040 100644 --- a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS.cmake +++ b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS.cmake @@ -1,5 +1,8 @@ +if(NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE Debug) +endif() include(ExternalProject) ExternalProject_Add(FOO TMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/tmp" DOWNLOAD_COMMAND "" - CMAKE_CACHE_ARGS "-DFOO:STRING=BAR") + CMAKE_CACHE_ARGS "-DFOO:STRING=$<1:BAR>$<0:BAD>") diff --git a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS-check.cmake b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS-check.cmake index ec1cafb1e..aeee11fa0 100644 --- a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS-check.cmake +++ b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS-check.cmake @@ -1,4 +1,4 @@ -set(_cache_file "${RunCMake_TEST_BINARY_DIR}/tmp/FOO-cache.cmake") +set(_cache_file "${RunCMake_TEST_BINARY_DIR}/tmp/FOO-cache-Debug.cmake") if(NOT EXISTS "${_cache_file}") set(RunCMake_TEST_FAILED "Initial cache not created") diff --git a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS.cmake b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS.cmake index 8e984706b..3a83dbe38 100644 --- a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS.cmake +++ b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS.cmake @@ -1,5 +1,8 @@ +if(NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE Debug) +endif() include(ExternalProject) ExternalProject_Add(FOO TMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/tmp" DOWNLOAD_COMMAND "" - CMAKE_CACHE_DEFAULT_ARGS "-DFOO:STRING=BAR") + CMAKE_CACHE_DEFAULT_ARGS "-DFOO:STRING=$<1:BAR>$<0:BAD>") diff --git a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix-check.cmake b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix-check.cmake index 2a07f27e5..04d49b9e4 100644 --- a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix-check.cmake +++ b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix-check.cmake @@ -1,4 +1,4 @@ -set(_cache_file "${RunCMake_TEST_BINARY_DIR}/tmp/FOO-cache.cmake") +set(_cache_file "${RunCMake_TEST_BINARY_DIR}/tmp/FOO-cache-Debug.cmake") if(NOT EXISTS "${_cache_file}") set(RunCMake_TEST_FAILED "Initial cache not created") diff --git a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix.cmake b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix.cmake index e7f26ae0a..192776ba7 100644 --- a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix.cmake +++ b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix.cmake @@ -1,6 +1,9 @@ +if(NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE Debug) +endif() include(ExternalProject) ExternalProject_Add(FOO TMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/tmp" DOWNLOAD_COMMAND "" - CMAKE_CACHE_ARGS "-DFOO:STRING=BAR" - CMAKE_CACHE_DEFAULT_ARGS "-DBAR:STRING=BAZ") + CMAKE_CACHE_ARGS "-DFOO:STRING=$<1:BAR>$<0:BAD>" + CMAKE_CACHE_DEFAULT_ARGS "-DBAR:STRING=$<1:BAZ>$<0:BAD>")