# This file contains a generic workaround to cause a list generated by # a generator expression to be expanded when used as the COMMAND to # add_custom_command() or add_custom_target(). # Using this workaround: # - include this file in CMakeLists.txt # - call expandable_command( [arg1] [arg2] ...) # - use the from above as the COMMAND to add_custom_target() # or add_custom_command(). # Example to execute # echo a generated list # code: # include(/path/to/expand_command.cmake) # expandable_command(cmdline echo $) # add_custom_target(echo ALL COMMAND ${cmdline} VERBATIM) # set_property(TARGET echo PROPERTY MSGLIST a generated list) if(NOT EXPAND_COMMAND_AS_SCRIPT) #==== This section is processed at configuration time when included if(COMMAND expandable_command) return() endif() set(EXPAND_COMMAND_SCRIPT "${CMAKE_CURRENT_LIST_FILE}") function(expandable_command retvar) set(cmdline ${ARGN}) string(REPLACE ";" "$" cmdline "${cmdline}") set(${retvar} "${CMAKE_COMMAND}" "-D" "EXPAND_COMMAND_AS_SCRIPT=TRUE" "-D" "EXPAND_COMMAND=${cmdline}" "-P" "${EXPAND_COMMAND_SCRIPT}" PARENT_SCOPE) endfunction(expandable_command) else() #==== This section is the command wrapper run at build time execute_process(COMMAND ${EXPAND_COMMAND} ERROR_VARIABLE error RESULT_VARIABLE result) set(stderr_type "") if(result) set(stderr_type FATAL_ERROR) endif() if(result OR error) message(${stderr_type} "${error}") endif() endif()