Escape file write expansion, and build up lists.

Escaped the @var@ in the file writes - this was being expanded at file
write and so not causing a reconfigure at the right time. I also took
care of build up lists of lists in the variables, especially important
for things like MPI_EXTRA_LIBRARY. Added some error checking, and use
the tmp_dir for initial cache file.
This commit is contained in:
Marcus D. Hanwell 2010-12-10 20:03:58 -05:00
parent 68cd3fe038
commit b316087c09
1 changed files with 25 additions and 12 deletions

View File

@ -554,23 +554,36 @@ function(_ep_write_initial_cache script_filename args)
# Write out values into an initial cache, that will be passed to CMake with -C
set(script_initial_cache "")
set(regex "^([^:]+):([^=]+)=(.*)$")
set(setArg "")
foreach(line ${args})
if("${line}" MATCHES "^-D")
if(setArg)
# This is required to build up lists in variables, or complete an entry
set(setArg "${setArg}${accumulator}\" CACHE ${type} \"Initial cache\" FORCE)")
set(script_initial_cache "${script_initial_cache}\n${setArg}")
set(accumulator "")
set(setArg "")
endif()
string(REGEX REPLACE "^-D" "" line ${line})
if("${line}" MATCHES "${regex}")
string(REGEX MATCH "${regex}" match "${line}")
set(name "${CMAKE_MATCH_1}")
set(type "${CMAKE_MATCH_2}")
set(value "${CMAKE_MATCH_3}")
set(setArg "set(${name} \"${value}\" CACHE ${type} \"Initial cache\" FORCE)")
set(script_initial_cache "${script_initial_cache}\n${setArg}")
set(setArg "set(${name} \"${value}")
else()
message(WARNING "Line '${line}' does not match regex. Ignoring.")
endif()
else()
# Assume this is a list to append to the last var
set(accumulator "${accumulator};${line}")
endif()
endforeach()
# 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")
file(WRITE "${script_filename}.in" "\@script_initial_cache\@\n")
endif()
configure_file("${script_filename}.in" "${script_filename}")
endfunction(_ep_write_initial_cache)
@ -1251,7 +1264,7 @@ function(_ep_add_configure_command name)
# If there are any CMAKE_CACHE_ARGS, write an initial cache and use it
get_property(cmake_cache_args TARGET ${name} PROPERTY _EP_CMAKE_CACHE_ARGS)
if(cmake_cache_args)
set(_ep_cache_args_script "${CMAKE_CURRENT_BINARY_DIR}/${name}-cache.cmake")
set(_ep_cache_args_script "${tmp_dir}/${name}-cache.cmake")
_ep_write_initial_cache("${_ep_cache_args_script}" "${cmake_cache_args}")
list(APPEND cmd "-C${_ep_cache_args_script}")
endif()
@ -1274,7 +1287,7 @@ function(_ep_add_configure_command name)
# Fixes issue http://public.kitware.com/Bug/view.php?id=10258
#
if(NOT EXISTS ${tmp_dir}/${name}-cfgcmd.txt.in)
file(WRITE ${tmp_dir}/${name}-cfgcmd.txt.in "cmd='@cmd@'\n")
file(WRITE ${tmp_dir}/${name}-cfgcmd.txt.in "cmd='\@cmd\@'\n")
endif()
configure_file(${tmp_dir}/${name}-cfgcmd.txt.in ${tmp_dir}/${name}-cfgcmd.txt)
list(APPEND file_deps ${tmp_dir}/${name}-cfgcmd.txt)