View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014370CMakeCMakepublic2013-08-21 13:042014-06-02 08:37
ReporterRobert Knight 
Assigned ToPeter Kuemmel 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSWindowsOS Version7
Product VersionCMake 2.8.11.2 
Target VersionFixed in VersionCMake 3.0 
Summary0014370: add_custom_command() commands run from incorrect directory with Ninja generator
DescriptionIn 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.

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}
)


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

#############################################
# 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


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.
TagsNo tags attached.
Attached Fileszip file icon workingdir.zip [^] (679 bytes) 2013-11-25 05:19

 Relationships

  Notes
(0034541)
Peter Kuemmel (developer)
2013-11-25 06:12

http://public.kitware.com/pipermail/cmake-commits/2013-November/017223.html [^]
(0036024)
Robert Maynard (manager)
2014-06-02 08:37

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2013-08-21 13:04 Robert Knight New Issue
2013-11-25 05:19 Peter Kuemmel Assigned To => Peter Kuemmel
2013-11-25 05:19 Peter Kuemmel Status new => assigned
2013-11-25 05:19 Peter Kuemmel File Added: workingdir.zip
2013-11-25 06:12 Peter Kuemmel Note Added: 0034541
2013-11-25 06:12 Peter Kuemmel Status assigned => resolved
2013-11-25 06:12 Peter Kuemmel Fixed in Version => CMake 3.0
2013-11-25 06:12 Peter Kuemmel Resolution open => fixed
2014-06-02 08:37 Robert Maynard Note Added: 0036024
2014-06-02 08:37 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team