View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014353CMakeCCMakepublic2013-08-13 04:122016-06-10 14:31
Assigned ToKitware Robot 
PlatformWindowsOSOS Version
Product VersionCMake 
Target VersionFixed in Version 
Summary0014353: list expansion from generator expression in custom command
Descriptionthe below example breaks when spaces are in the argument lists.

for the release configuration everything works as expected as the argument list contains just a single entry. but for the debug configuration $<1:something something dark side> is inserted into the argument list.

this is very urgend as CMake does offer no other way to set different arguments to the custom commands depending on the configuration!

set(SCM_ARGS_A something)
set(SCM_ARGS_B something something dark side)

add_custom_command(OUTPUT ${CUDA_NVCC_OUTPUT_FILE}
                               COMMAND ${SCM_CUDA_NVCC_COMMAND}
                                   ARGS $<$<CONFIG:Release>:${SCM_ARGS_A}>
                                        $<$<CONFIG:Debug>:${SCM_ARGS_B }>
                                        -o \"${CUDA_NVCC_OUTPUT_FILE}\"
                               MAIN_DEPENDENCY ${input_file}
                               DEPENDS ${input_file}
                               COMMENT "NVCC compiling (${input_file_name}):")
TagsNo tags attached.
Attached Files? file icon expand_command.cmake [^] (1,643 bytes) 2015-04-20 12:32

related to 0014352closedStephen Kelly CMake crashing with white space in generator expression 
related to 0015586closed Add support for lists inside generator expressions 

chrislu (reporter)
2013-08-13 04:33

more basic:

$<0:something> -> OK
$<0:something dark> -> $<0:something dark> added to command arguments.
Stephen Kelly (developer)
2013-08-13 08:07

Generally, things are easier if you provide sscce code with bugs: [^]

If you provide only a snippet which depends on CUDA, I have to create my own sscce and that's not necessarily showing the same problem as you have.

Here is my testcase, which seems to work fine:

 cmake_minimum_required(VERSION 2.8)

 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/main.out
                    COMMAND dd
                        ARGS if=${CMAKE_CURRENT_SOURCE_DIR}/main.cpp of=${CMAKE_CURRENT_BINARY_DIR}/main.out
                        "$<$<CONFIG:Debug>:some thing>"
                    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

 add_library(foo SHARED main.cpp
chrislu (reporter)
2013-08-14 04:15


cmake_minimum_required(VERSION 2.8)

set (SCM_CUDA_NVCC_OPTIONS --cl-version 2010 CACHE STRING "schism cuda internal" FORCE)

set(SCM_CUDA_NVCC_OPTIONS_DEBUG -Xcompiler A,B,C,D CACHE STRING "schism cuda internal" FORCE)
set(SCM_CUDA_NVCC_OPTIONS_RELEASE --optimize 3 -Xcompiler E,F,G,H CACHE STRING "schism cuda internal" FORCE)


add_custom_command(OUTPUT ${CUDA_NVCC_OUTPUT_FILE}
                   COMMAND nvcc.exe
                       ARGS $<$<CONFIG:Release>:${SCM_CUDA_NVCC_OPTIONS_RELEASE}>
                            -o \"${CUDA_NVCC_OUTPUT_FILE}\"
                   MAIN_DEPENDENCY ${input_file}
                   DEPENDS ${input_file}
                   COMMENT "NVCC compiling (${input_file_name}):")


add_executable(foo main.cpp ${CUDA_NVCC_OUTPUT_FILE})

the problem here is the same as described originally. generate a visual studio project and look for the nvcc line:

nvcc.exe $<0:--optimize 3 -Xcompiler E,F,G,H> $<1:-Xcompiler A,B,C,D> --cl-version 2010 -o "" ""

now with your example:
                       ARGS "$<$<CONFIG:Release>:${SCM_CUDA_NVCC_OPTIONS_RELEASE}>"

the nvcc line reads:

nvcc.exe --optimize;3;-Xcompiler;E,F,G,H --cl-version 2010 -o "" ""

UNUSABLE! the added ; break the command line. i also tried add the "" to the SCM_CUDA_NVCC_OPTIONS_DEBUG variables which are then transported to the command line, which is also UNUSABLE.

please advise.
Stephen Kelly (developer)
2013-08-14 04:27

Here's a simpler example:

set(things raindrops windows kittens mittens)

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/main.out
                    COMMAND dd
                        ARGS if=${CMAKE_CURRENT_SOURCE_DIR}/main.cpp of=${CMAKE_CURRENT_BINARY_DIR}/main.out
                        "$<JOIN:$<$<CONFIG:Debug>:${things}>, >"
                    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

add_library(foo SHARED main.cpp


 "$<JOIN:$<$<CONFIG:Debug>:${things}>, >"

can also be simplified to

"$<JOIN:${things}, >"

This results in dd if=/home/stephen/dev/src/playground/cmake/main.cpp of=/home/stephen/dev/src/playground/cmake/build/main.out raindrops\ windows\ kittens\ mittens on the command line, which is not what you want.

The problem is known, but there's no one working on a fix: [^]
Stephen Kelly (developer)
2013-08-14 04:37

The workarounds available are either:

1) Use file(GENERATE) to generate a script and execute the script instead.
2) Use file(GENERATE) to a response file, if the tool supports it, as was done here:;a=commitdiff;h=9ce60ff50 [^]

file(GENERATE) is new in CMake 2.8.12.
chrislu (reporter)
2013-08-14 07:59

ok, but how is this a feature request?

and how can something so simple be made so awesomely difficult? how many years now are devs asking to set arguments etc. depending on the build configuration?

Stephen Kelly (developer)
2013-08-14 08:09

Of course, another workaround is to put the config-genex on each element in the list.

set(things $<$<CONFIG:Debug>:raindrops> $<$<CONFIG:Debug>:windows> $<$<CONFIG:Release>:kittens> $<$<CONFIG:Release>:mittens>)

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/main.out
                    COMMAND dd
                        ARGS if=${CMAKE_CURRENT_SOURCE_DIR}/main.cpp of=${CMAKE_CURRENT_BINARY_DIR}/main.out
# "$<JOIN:$<$<CONFIG:Debug>:${things}>, >"
                    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

That might be something that works for your CUDA case, I don't know.
chrislu (reporter)
2013-08-15 06:14

what is the real problem here?

are the genex not evaluated correctly or is there something wrong much deeper. if its a simple fix point me to the location and maybe i can hack my local version to do what it is supposed to do.
Stephen Kelly (developer)
2013-08-15 06:18

See the thread linked in 0014353:0033712.
arlbranch (reporter)
2015-04-20 12:39

Since this pops up on the mailing list periodically, I've attached a (hopefully) generic workaround to get generator expression generated lists expanded in the COMMAND of add_custom_target() and add_custom_command().

==== Example use: =====


expandable_command(echocmd echo gcc
    -o someprog
add_custom_target(echo ALL
    COMMAND ${echocmd}
    COMMENT "Building target echo"
    "/path/a" "/path/b" "/path/c")

====== End Example =======

Note that echo doesn't care whether the arguments are passed as separate arguments or a single string, so you have to check the verbose output (make VERBOSE=1 or ninja -v) to see that this does the right thing.
Kitware Robot (administrator)
2016-06-10 14:29

Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2013-08-13 04:12 chrislu New Issue
2013-08-13 04:33 chrislu Note Added: 0033700
2013-08-13 08:07 Stephen Kelly Note Added: 0033702
2013-08-13 09:13 Brad King Relationship added related to 0014352
2013-08-14 03:16 chrislu Note Added: 0033710
2013-08-14 03:20 Stephen Kelly Status new => resolved
2013-08-14 03:20 Stephen Kelly Resolution open => no change required
2013-08-14 03:20 Stephen Kelly Assigned To => Stephen Kelly
2013-08-14 04:15 chrislu Note Added: 0033711
2013-08-14 04:15 chrislu Status resolved => feedback
2013-08-14 04:15 chrislu Resolution no change required => reopened
2013-08-14 04:16 chrislu Note Deleted: 0033710
2013-08-14 04:27 Stephen Kelly Note Added: 0033712
2013-08-14 04:29 Stephen Kelly Assigned To Stephen Kelly =>
2013-08-14 04:29 Stephen Kelly Priority urgent => normal
2013-08-14 04:29 Stephen Kelly Severity block => feature
2013-08-14 04:29 Stephen Kelly Status feedback => backlog
2013-08-14 04:29 Stephen Kelly OS Windows 7 =>
2013-08-14 04:29 Stephen Kelly OS Version x64 =>
2013-08-14 04:29 Stephen Kelly Summary generator expression $<1:...> and $<0:...> fail with white space in provided strings. => list expansion from generator expression in custom command
2013-08-14 04:37 Stephen Kelly Note Added: 0033713
2013-08-14 07:59 chrislu Note Added: 0033714
2013-08-14 08:09 Stephen Kelly Note Added: 0033715
2013-08-15 06:14 chrislu Note Added: 0033717
2013-08-15 06:18 Stephen Kelly Note Added: 0033718
2015-04-20 12:32 arlbranch File Added: expand_command.cmake
2015-04-20 12:39 arlbranch Note Added: 0038558
2015-05-26 10:55 Nils Gladitz Relationship added related to 0015586
2016-06-10 14:29 Kitware Robot Note Added: 0042348
2016-06-10 14:29 Kitware Robot Status backlog => resolved
2016-06-10 14:29 Kitware Robot Resolution reopened => moved
2016-06-10 14:29 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed

Copyright © 2000 - 2018 MantisBT Team