ExternalProject: Allow generator expressions with LOG_* options (#15287)

Use file(GENERATE) to write the logging wrapper scripts to evaluate
generator expressions.  Use a per-config script names in case the
content varies by configuration.
This commit is contained in:
Andrey Pokrovskiy 2015-04-20 23:28:21 -07:00 committed by Brad King
parent 7bd8cfb813
commit 0273ef1469
3 changed files with 15 additions and 5 deletions

View File

@ -106,6 +106,8 @@ Create custom targets to build projects in external trees
:manual:`CMake Options <cmake(1)>`. Arguments in the form :manual:`CMake Options <cmake(1)>`. Arguments in the form
``-Dvar:string=on`` are always passed to the command line, and ``-Dvar:string=on`` are always passed to the command line, and
therefore cannot be changed by the user. therefore cannot be changed by the user.
Arguments may use
:manual:`generator expressions <cmake-generator-expressions(7)>`.
``CMAKE_CACHE_ARGS <arg>...`` ``CMAKE_CACHE_ARGS <arg>...``
Initial cache arguments, of the form ``-Dvar:string=on``. Initial cache arguments, of the form ``-Dvar:string=on``.
These arguments are written in a pre-load a script that populates These arguments are written in a pre-load a script that populates
@ -271,6 +273,9 @@ specifies to run ``make`` and then ``echo done`` during the build step.
Whether the current working directory is preserved between commands is Whether the current working directory is preserved between commands is
not defined. Behavior of shell operators like ``&&`` is not defined. not defined. Behavior of shell operators like ``&&`` is not defined.
Arguments to ``<step>_COMMAND`` or ``COMMAND`` options may use
:manual:`generator expressions <cmake-generator-expressions(7)>`.
.. command:: ExternalProject_Get_Property .. command:: ExternalProject_Get_Property
The ``ExternalProject_Get_Property`` function retrieves external project The ``ExternalProject_Get_Property`` function retrieves external project
@ -1303,14 +1308,14 @@ endif()
endif() endif()
endforeach() endforeach()
set(code "${code}set(command \"${cmd}\")${code_execute_process}") set(code "${code}set(command \"${cmd}\")${code_execute_process}")
file(WRITE ${stamp_dir}/${name}-${step}-impl.cmake "${code}") file(GENERATE OUTPUT "${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake" CONTENT "${code}")
set(command ${CMAKE_COMMAND} "-Dmake=\${make}" "-Dconfig=\${config}" -P ${stamp_dir}/${name}-${step}-impl.cmake) set(command ${CMAKE_COMMAND} "-Dmake=\${make}" "-Dconfig=\${config}" -P ${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake)
endif() endif()
# Wrap the command in a script to log output to files. # Wrap the command in a script to log output to files.
set(script ${stamp_dir}/${name}-${step}.cmake) set(script ${stamp_dir}/${name}-${step}-$<CONFIG>.cmake)
set(logbase ${stamp_dir}/${name}-${step}) set(logbase ${stamp_dir}/${name}-${step})
file(WRITE ${script} " set(code "
${code_cygpath_make} ${code_cygpath_make}
set(command \"${command}\") set(command \"${command}\")
execute_process( execute_process(
@ -1331,6 +1336,7 @@ else()
message(STATUS \"\${msg}\") message(STATUS \"\${msg}\")
endif() endif()
") ")
file(GENERATE OUTPUT "${script}" CONTENT "${code}")
set(command ${CMAKE_COMMAND} ${make} ${config} -P ${script}) set(command ${CMAKE_COMMAND} ${make} ${config} -P ${script})
set(${cmd_var} "${command}" PARENT_SCOPE) set(${cmd_var} "${command}" PARENT_SCOPE)
endfunction() endfunction()

View File

@ -6,7 +6,7 @@ ExternalProject_Add(Subdir1
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Subdir1 SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Subdir1
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/Subdir1 BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/Subdir1
CMAKE_ARGS -DNORMAL_VAR=NORMAL_VALUE CMAKE_ARGS -DNORMAL_VAR=NORMAL_VALUE -DGENEX_VAR=$<1:GENEX_VALUE>
LOG_CONFIGURE 1 LOG_CONFIGURE 1
BUILD_COMMAND "" BUILD_COMMAND ""

View File

@ -4,3 +4,7 @@ project(Subdir1 NONE)
if(NOT "${NORMAL_VAR}" STREQUAL "NORMAL_VALUE") if(NOT "${NORMAL_VAR}" STREQUAL "NORMAL_VALUE")
message(SEND_ERROR "NORMAL_VAR != 'NORMAL_VALUE'") message(SEND_ERROR "NORMAL_VAR != 'NORMAL_VALUE'")
endif() endif()
if(NOT "${GENEX_VAR}" STREQUAL "GENEX_VALUE")
message(SEND_ERROR "GENEX_VAR != 'GENEX_VALUE'")
endif()