MantisBT - CMake
View Issue Details
0015935CMakeCMakepublic2016-01-26 05:322016-06-10 14:31
Kiron 
Kitware Robot 
normalfeaturealways
closedmoved 
 
 
0015935: Custom command post-genex ;-list expansion
When an $<0:...> generator expression in a COMMAND argument of add_custom_command (and add_custom_target) the Visual Studio generator generates an invalid command "".

When using a normal variable which is empty or not set, the COMMAND argument is just ignored.
Create a file called CMakeLists.txt with the following content in an empty directory:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
cmake_policy(VERSION 3.0)

project(EmptyGenExCommand LANGUAGES CXX VERSION 0.0.1.0)

set(_stamp ${CMAKE_BINARY_DIR}/foo.stamp)
add_custom_command(OUTPUT ${_stamp}
    COMMAND $<$<BOOL:$<TARGET_PROPERTY:foo,FOOCMD>>:$<TARGET_PROPERTY:foo,FOOCMD>>
    COMMAND ${CMAKE_COMMAND} -E echo foo is done
    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
add_custom_target(foo ALL DEPENDS ${_stamp})
#set_property(TARGET foo PROPERTY FOOCMD ${CMAKE_COMMAND} -E sleep 1)
Tested with cmake version 3.4.3 under Windows 7 64 bit.

When using the Visual Studio generator the vcxproj contains:

  <ItemGroup>
    <CustomBuild Include="...">
      [...]
      <Command ...>setlocal
cd S:\abc
if %errorlevel% neq 0 goto :cmEnd
S:
if %errorlevel% neq 0 goto :cmEnd
""
if %errorlevel% neq 0 goto :cmEnd

When trying to execute "" the following error from cmd.exe is generated:

'""' is not recognized as an internal or external command,
operable program or batch file.

Also when setting the FOOCMD property to an actual command (e.g.: set_property(TARGET foo PROPERTY FOOCMD ${CMAKE_COMMAND} -E sleep 1)) it will not work, since it evaluates to "C:\Program Files (x86)\CMake\bin\cmake.exe";"-E";"sleep";"1" or with quotes in the set_property command it evaluates to "C:\Program Files (x86)\CMake\bin\cmake.exe -E sleep 1".
No tags attached.
Issue History
2016-01-26 05:32KironNew Issue
2016-01-26 10:15Brad KingNote Added: 0040328
2016-01-26 10:16Brad KingSeverityminor => feature
2016-01-26 10:16Brad KingStatusnew => backlog
2016-01-26 10:16Brad KingSummaryEmpty generator expression in COMMAND leads to "" => Custom command post-genex ;-list expansion
2016-06-10 14:29Kitware RobotNote Added: 0042922
2016-06-10 14:29Kitware RobotStatusbacklog => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0040328)
Brad King   
2016-01-26 10:15   
This is expected. The elimination of unquoted empty arguments is done by the CMake language during configuration. At that stage the generator expression is not evaluated. The command and number of arguments becomes fixed. Generator expressions can be used within each argument but no ;-list splitting is done on the results. A new feature/genex/syntax would be needed to enable post-evaluation argument expansion.

Side note:

> cmake_policy(VERSION 3.0)

This is implied by the cmake_minimum_required call and so does not need to be called explicitly.
(0042922)
Kitware Robot   
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.