execute_program breaks command line at +arg
execute_program breaks command line at +arg
Reproducible with CMake 3.10.1 and 3.8.0 on Windows with VS2017.
I define custom command which executes xxd
utility.
The xxd
utility supports this curious -s
argument which takes [+][-]seek
value to
start at
<seek>
bytes abs. (or +: rel.) infile offset.
Here is my custom command defined:
add_custom_command(OUTPUT zones.h
COMMAND ${XXD} -i -s +${zones_bytes} ${CMAKE_SOURCE_DIR}/zones.csv zones.h
COMMENT "Compiling zones.csv to zones.h")
CMake successfully configures my build and generates VS2017 solution:
D:\tmp\execute_program_command_args\_build>cmake ..
-- Building for: Visual Studio 15 2017
-- The CXX compiler identification is MSVC 19.12.25834.0
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.12.25827/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.12.25827/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- zones_result=0
-- zones_error=
-- zones_bytes=146
-- Configuring done
-- Generating done
-- Build files have been written to: D:/tmp/execute_program_command_args/_build
Then, I try to build:
D:\tmp\execute_program_command_args\_build>cmake --build .
Microsoft (R) Build Engine version 15.5.180.51428 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 2018-01-11 13:48:26.
Project "D:\tmp\execute_program_command_args\_build\ALL_BUILD.vcxproj" on node 1 (default targets).
Project "D:\tmp\execute_program_command_args\_build\ALL_BUILD.vcxproj" (1) is building "D:\tmp\execute_program_command_args\_build\ZERO_CHECK.vcxproj" (2) on node 1 (default targets).
PrepareForBuild:
Creating directory "Win32\Debug\ZERO_CHECK\".
Creating directory "D:\tmp\execute_program_command_args\_build\Debug\".
Creating directory "Win32\Debug\ZERO_CHECK\ZERO_CHECK.tlog\".
InitializeBuildStatus:
Creating "Win32\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
CustomBuild:
Checking Build System
CMake does not need to re-run because D:/tmp/execute_program_command_args/_build/CMakeFiles/generate.stamp is up-to-date.
FinalizeBuildStatus:
Deleting file "Win32\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild".
Touching "Win32\Debug\ZERO_CHECK\ZERO_CHECK.tlog\ZERO_CHECK.lastbuildstate".
Done Building Project "D:\tmp\execute_program_command_args\_build\ZERO_CHECK.vcxproj" (default targets).
Project "D:\tmp\execute_program_command_args\_build\ALL_BUILD.vcxproj" (1) is building "D:\tmp\execute_program_command_args\_build\mytest.vcxproj" (3) on node 1 (default targets).
PrepareForBuild:
Creating directory "mytest.dir\Debug\".
Creating directory "mytest.dir\Debug\mytest.tlog\".
InitializeBuildStatus:
Creating "mytest.dir\Debug\mytest.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
CustomBuild:
Building Custom Rule D:/tmp/execute_program_command_args/CMakeLists.txt
CMake does not need to re-run because D:/tmp/execute_program_command_args/_build/CMakeFiles/generate.stamp is up-to-date.
Compiling zones.csv to zones.h
...
and here at the "Compiling zones.csv to zones.h" step, Excel is being launched loading zones.csv
file.
I noticed, that CMake generates the .vcxproj
with <Command>
element and inserts newline just after the [+][-]seek
argument of xxd
utility.
D:\tmp\execute_program_command_args\_build>grep -C 1 xxd mytest.vcxproj
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">setlocal
"C:\Program Files (x86)\GnuWin32\bin\xxd.exe" -i -s +146
D:/tmp/execute_program_command_args/zones.csv zones.h
--
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">setlocal
"C:\Program Files (x86)\GnuWin32\bin\xxd.exe" -i -s +146
D:/tmp/execute_program_command_args/zones.csv zones.h
--
<Command Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">setlocal
"C:\Program Files (x86)\GnuWin32\bin\xxd.exe" -i -s +146
D:/tmp/execute_program_command_args/zones.csv zones.h
--
<Command Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">setlocal
"C:\Program Files (x86)\GnuWin32\bin\xxd.exe" -i -s +146
D:/tmp/execute_program_command_args/zones.csv zones.h
If I remove the +${zones_bytes}
argument from my add_custom_command
completely, regenerate the project, it builds without launching Excel, as expected.
If I replace +${zones_bytes}
with verbatim +146
, everything builds fine too.
D:\tmp\execute_program_command_args\_build>grep -C 1 xxd mytest.vcxproj
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">setlocal
"C:\Program Files (x86)\GnuWin32\bin\xxd.exe" -i -s +146 D:/tmp/execute_program_command_args/zones.csv zones.h
if %errorlevel% neq 0 goto :cmEnd
--
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">setlocal
"C:\Program Files (x86)\GnuWin32\bin\xxd.exe" -i -s +146 D:/tmp/execute_program_command_args/zones.csv zones.h
if %errorlevel% neq 0 goto :cmEnd
--
<Command Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">setlocal
"C:\Program Files (x86)\GnuWin32\bin\xxd.exe" -i -s +146 D:/tmp/execute_program_command_args/zones.csv zones.h
if %errorlevel% neq 0 goto :cmEnd
--
<Command Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">setlocal
"C:\Program Files (x86)\GnuWin32\bin\xxd.exe" -i -s +146 D:/tmp/execute_program_command_args/zones.csv zones.h
if %errorlevel% neq 0 goto :cmEnd
I attach test project that can be used to reproduce the issue, with CMake generated output included.