[cmake-developers] [CMake 0015935]: Empty generator expression in COMMAND leads to ""

Mantis Bug Tracker mantis at public.kitware.com
Tue Jan 26 05:32:40 EST 2016


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=15935 
====================================================================== 
Reported By:                Kiron
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15935
Category:                   CMake
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2016-01-26 05:32 EST
Last Modified:              2016-01-26 05:32 EST
====================================================================== 
Summary:                    Empty generator expression in COMMAND leads to ""
Description: 
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.

Steps to Reproduce: 
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)

Additional Information: 
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".
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2016-01-26 05:32 Kiron          New Issue                                    
======================================================================



More information about the cmake-developers mailing list