[cmake-developers] [CMake 0014370]: add_custom_command() commands run from incorrect directory with Ninja generator

Mantis Bug Tracker mantis at public.kitware.com
Wed Aug 21 13:04:51 EDT 2013


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=14370 
====================================================================== 
Reported By:                Robert Knight
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   14370
Category:                   CMake
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2013-08-21 13:04 EDT
Last Modified:              2013-08-21 13:04 EDT
====================================================================== 
Summary:                    add_custom_command() commands run from incorrect
directory with Ninja generator
Description: 
In the following project, if using the Ninja generator on Windows the first
post-build command runs in the directory that Ninja is run from, not the
directory specified by WORKING_DIRECTORY.  The second post-build command runs in
the correct directory.

Both commands run in the correct directory when using the NMake Makefiles
generator.

<pre>
project(ninja-generator-test)

set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/foo)
file(MAKE_DIRECTORY ${TEST_DIR})

add_executable(test test.cpp)

# this file is created in the directory
# that ninja is run from
add_custom_command(TARGET test
  POST_BUILD
  COMMAND "${CMAKE_COMMAND}" -E touch foo.txt
  WORKING_DIRECTORY ${TEST_DIR}
)

# this file is created in the correct directory
add_custom_command(TARGET test
  POST_BUILD
  COMMAND "${CMAKE_COMMAND}" -E touch foo2.txt
  WORKING_DIRECTORY ${TEST_DIR}
)
</pre>

The generated Ninja output in build.ninja for the test target is:

<pre>
#############################################
# Link the executable test.exe

build test.exe: CXX_EXECUTABLE_LINKER CMakeFiles\test.dir\test.obj
  FLAGS = /DWIN32 /D_WINDOWS /W3 /GR /EHsc /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1
  LINK_FLAGS = /machine:X86  /debug /INCREMENTAL /subsystem:console
  LINK_LIBRARIES = kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib
ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib
  POST_BUILD = cmd.exe /c cd C:\Users\Win7-VM\mendeley\misc\ninja-test\build\foo
&& "C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -E touch foo.txt && cd
C:\Users\Win7-VM\mendeley\misc\ninja-test\build\foo && "C:\Program Files
(x86)\CMake 2.8\bin\cmake.exe" -E touch foo2.txt
  PRE_LINK = cd .
  TARGET_IMPLIB = test.lib
  TARGET_PDB = test.pdb
</pre>

Here the first post-build command uses 'cmd.exe /c cd' to switch to the target
dir which has no effect and the second uses plain 'cd' which does.

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2013-08-21 13:04 Robert Knight  New Issue                                    
======================================================================




More information about the cmake-developers mailing list