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