From ac9a5f4d943685f0b49b1a9d03f4e23238df0867 Mon Sep 17 00:00:00 2001 From: Petr Kmoch Date: Thu, 28 Mar 2013 10:10:13 -0400 Subject: [PATCH] ctest_build: Pass projectDir to GenerateBuildCommand This allows the ctest_build command's TARGET option to name a target in a subdirectory and still build properly with msbuild. Add test case covering use of ctest_build() with such a TARGET. --- Source/CTest/cmCTestBuildCommand.cxx | 3 ++- Tests/CMakeLists.txt | 14 ++++++++++++++ .../CTestBuildCommandProjectInSubdir.cmake.in | 12 ++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx index 5cb2a3738..1f63185c1 100644 --- a/Source/CTest/cmCTestBuildCommand.cxx +++ b/Source/CTest/cmCTestBuildCommand.cxx @@ -130,10 +130,11 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler() cmakeBuildConfiguration = config; } + std::string dir = this->CTest->GetCTestConfiguration("BuildDirectory"); std::string buildCommand = this->GlobalGenerator-> GenerateBuildCommand(cmakeMakeProgram, - cmakeProjectName, 0, + cmakeProjectName, dir.c_str(), cmakeBuildAdditionalFlags, cmakeBuildTarget, cmakeBuildConfiguration, true, false); cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 4eb2f9067..ad81fd678 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1660,6 +1660,20 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ # -S "${CMake_BINARY_DIR}/Tests/CTestScriptMode/CTestTestScriptMode.cmake" # ) + # A test for ctest_build() with targets in subdirectories + if(CMAKE_TEST_GENERATOR_TOOLSET) + set(CMAKE_TEST_GENERATOR_TOOLSET_SELECTION "-T;${CMAKE_TEST_GENERATOR_TOOLSET};") + else() + set(CMAKE_TEST_GENERATOR_TOOLSET_SELECTION) + endif() + configure_file("${CMake_SOURCE_DIR}/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in" + "${CMake_BINARY_DIR}/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake" @ONLY) + unset(CMAKE_TEST_GENERATOR_TOOLSET_SELECTION) + add_test(CTest.BuildCommand.ProjectInSubdir + ${CMAKE_CTEST_COMMAND} -S "${CMake_BINARY_DIR}/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake" + -DCMAKE_MAKE_PROGRAM:FILEPATH=${CMAKE_TEST_MAKEPROGRAM}) + list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CTestBuildCommandProjectInSubdir/Nested") + set(CTEST_TEST_UPDATE 1) if(CTEST_TEST_UPDATE) # Test CTest Update with Subversion diff --git a/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in b/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in new file mode 100644 index 000000000..ea48c780f --- /dev/null +++ b/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 2.8.10) + +set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/VSProjectInSubdir") +set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestBuildCommandProjectInSubdir/Nested") +set(CTEST_CMAKE_GENERATOR "@CMAKE_TEST_GENERATOR@") +set(CTEST_PROJECT_NAME "VSProjectInSubdir") +set(CTEST_BUILD_CONFIGURATION "@CTestTest_CONFIG@") + +ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY}) +ctest_start(Experimental) +ctest_configure(OPTIONS "@CMAKE_TEST_GENERATOR_TOOLSET_SELECTION@-DCMAKE_MAKE_PROGRAM:FILEPATH=@CMAKE_TEST_MAKEPROGRAM@") +ctest_build(TARGET test)