From 90ad087ab9075cc9648df0623502da0caa44e971 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 11 Jun 2015 15:01:12 -0400 Subject: [PATCH] cmake: Fix --build for VS generators (#15609) The VS >= 10 generators need to parse the .sln file from the build directory to locate targets in subdirectories. This occurs after we change the working directory to the build tree. If a relative directory other than "." was given then we would change to it and also refer to the .sln file location with it. Fix this by converting the build tree to a full path always. This will also give a more informative error message when the directory does not exist. --- Source/cmakemain.cxx | 2 +- Tests/RunCMake/CommandLine/BuildDir.cmake | 1 + .../RunCMake/CommandLine/BuildDir/CMakeLists.txt | 5 +++++ Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 15 +++++++++++++++ .../RunCMake/CommandLine/build-bad-dir-result.txt | 1 + .../RunCMake/CommandLine/build-bad-dir-stderr.txt | 2 ++ 6 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/CommandLine/BuildDir.cmake create mode 100644 Tests/RunCMake/CommandLine/BuildDir/CMakeLists.txt create mode 100644 Tests/RunCMake/CommandLine/build-bad-dir-result.txt create mode 100644 Tests/RunCMake/CommandLine/build-bad-dir-stderr.txt diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index cc3073251..c94ffec06 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -420,7 +420,7 @@ static int do_build(int ac, char const* const* av) switch (doing) { case DoingDir: - dir = av[i]; + dir = cmSystemTools::CollapseFullPath(av[i]); doing = DoingNone; break; case DoingTarget: diff --git a/Tests/RunCMake/CommandLine/BuildDir.cmake b/Tests/RunCMake/CommandLine/BuildDir.cmake new file mode 100644 index 000000000..30030a783 --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir.cmake @@ -0,0 +1 @@ +add_subdirectory(BuildDir) diff --git a/Tests/RunCMake/CommandLine/BuildDir/CMakeLists.txt b/Tests/RunCMake/CommandLine/BuildDir/CMakeLists.txt new file mode 100644 index 000000000..20df108ef --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir/CMakeLists.txt @@ -0,0 +1,5 @@ +add_custom_command( + OUTPUT output.txt + COMMAND ${CMAKE_COMMAND} -E echo CustomCommand > output.txt + ) +add_custom_target(CustomTarget ALL DEPENDS output.txt) diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 416b94e7d..84d4cc904 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -28,9 +28,24 @@ run_cmake_command(build-no-cache ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}) run_cmake_command(build-no-generator ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-no-generator) +run_cmake_command(build-bad-dir + ${CMAKE_COMMAND} --build dir-does-not-exist) run_cmake_command(build-bad-generator ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-generator) +function(run_BuildDir) + # Use a single build tree for a few tests without cleaning. + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/BuildDir-build) + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + + run_cmake(BuildDir) + run_cmake_command(BuildDir--build ${CMAKE_COMMAND} -E chdir .. + ${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget) +endfunction() +run_BuildDir() + if(RunCMake_GENERATOR STREQUAL "Ninja") # Use a single build tree for a few tests without cleaning. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Build-build) diff --git a/Tests/RunCMake/CommandLine/build-bad-dir-result.txt b/Tests/RunCMake/CommandLine/build-bad-dir-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-bad-dir-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/build-bad-dir-stderr.txt b/Tests/RunCMake/CommandLine/build-bad-dir-stderr.txt new file mode 100644 index 000000000..d3f3d9ce0 --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-bad-dir-stderr.txt @@ -0,0 +1,2 @@ +^Error: [^ +]+/Tests/RunCMake/CommandLine/build-bad-dir-build/dir-does-not-exist is not a directory$