Merge topic 'cmake-dir-args' into release-3.23

d2e9478321 Tests: Add RunCMake.CommandLine ExplicitiDirs explicit work directory
78e8f11456 cmake: Correct regression in `-B <dir> <src_dir>`
4091d5c58c Tests: Verify RunCMake.CommandLine ExplicitDirs source/build dirs
1b97f8f35c Tests: Clarify RunCMake.CommandLine ExplicitDirs case names

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !7030
This commit is contained in:
Brad King
2022-03-03 16:46:21 +00:00
committed by Kitware Robot
50 changed files with 85 additions and 31 deletions

View File

@@ -1556,7 +1556,7 @@ bool cmake::SetDirectoriesFromFile(const std::string& arg)
// This function is called multiple times with the same path
if (is_source_dir) {
this->SetHomeDirectoryViaCommandLine(listPath, HomeDirArgStyle::Plain);
if (!no_build_tree) {
if (no_build_tree) {
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
this->SetHomeOutputDirectory(cwd);
}

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirsMissing'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirsMissing/build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirsMissing'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirsMissing/build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirsMissing'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirsMissing/build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -0,0 +1,2 @@
-- CMAKE_SOURCE_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs'
-- CMAKE_BINARY_DIR='[^']*/Tests/RunCMake/CommandLine/ExplicitDirs-build'

View File

@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 3.14)
project(ExplicitDirs NONE)
message(STATUS "CMAKE_SOURCE_DIR='${CMAKE_SOURCE_DIR}'")
message(STATUS "CMAKE_BINARY_DIR='${CMAKE_BINARY_DIR}'")
add_custom_command(
OUTPUT output1.txt
COMMAND ${CMAKE_COMMAND} -E echo CustomCommand > output1.txt

View File

@@ -132,7 +132,7 @@ project(ExplicitDirsMissing LANGUAGES NONE)
]=])
set(RunCMake_TEST_SOURCE_DIR "${source_dir}")
set(RunCMake_TEST_BINARY_DIR "${source_dir}")
run_cmake_with_options(no-S-B -DFOO=BAR)
run_cmake_with_options(ExplicitDirs-no-S-B -DFOO=BAR)
file(WRITE ${source_dir}/CMakeLists.txt [=[
cmake_minimum_required(VERSION 3.13)
@@ -140,66 +140,75 @@ project(ExplicitDirsMissing LANGUAGES NONE)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "CWD used as binary dir")
endif()
message(STATUS "CMAKE_SOURCE_DIR='${CMAKE_SOURCE_DIR}'")
message(STATUS "CMAKE_BINARY_DIR='${CMAKE_BINARY_DIR}'")
]=])
file(REMOVE_RECURSE "${source_dir}/build")
# Test with a setup where binary_dir won't be created by `run_cmake_with_options`
run_cmake_with_options(S-arg-build-dir-not-created -S ${source_dir} build/)
run_cmake_with_options(S-arg-reverse-build-dir-not-created build/ -S${source_dir} )
run_cmake_with_options(ExplicitDirs-S-arg-build-dir-not-created -S ${source_dir} build/)
run_cmake_with_options(ExplicitDirs-S-arg-reverse-build-dir-not-created build/ -S${source_dir} )
file(REMOVE_RECURSE "${source_dir}/build")
file(MAKE_DIRECTORY "${source_dir}/build")
run_cmake_with_options(S-arg-build-dir-empty -S ${source_dir} build/)
run_cmake_with_options(ExplicitDirs-S-arg-build-dir-empty -S ${source_dir} build/)
set(source_dir ${RunCMake_SOURCE_DIR}/ExplicitDirs)
set(binary_dir ${RunCMake_BINARY_DIR}/ExplicitDirs-build)
set(working_dir ${RunCMake_BINARY_DIR}/ExplicitDirs-cwd)
set(RunCMake_TEST_SOURCE_DIR "${source_dir}")
set(RunCMake_TEST_BINARY_DIR "${binary_dir}")
file(MAKE_DIRECTORY "${working_dir}")
set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${working_dir}")
file(REMOVE_RECURSE "${binary_dir}")
run_cmake_with_options(S-arg -S ${source_dir} ${binary_dir})
run_cmake_with_options(S-arg-reverse-order ${binary_dir} -S${source_dir} )
run_cmake_with_options(S-no-arg -S )
run_cmake_with_options(S-no-arg2 -S -T)
run_cmake_with_raw_args(S-no-arg3 [[-S ""]])
run_cmake_with_options(S-B -S ${source_dir} -B ${binary_dir})
run_cmake_with_options(S-B-extra-path -S ${source_dir} -B ${binary_dir} /extra/path/)
run_cmake_with_raw_args(S-B-non-path "-S \"${source_dir}\" -B \"${binary_dir}\" \"\"")
run_cmake_with_raw_args(S-B-non-path2 "-S \"${source_dir}\" \"\" -B \"${binary_dir}\"")
run_cmake_with_options(ExplicitDirs-S-arg -S ${source_dir} ${binary_dir})
run_cmake_with_options(ExplicitDirs-S-arg-reverse-order ${binary_dir} -S${source_dir} )
run_cmake_with_options(ExplicitDirs-S-no-arg -S )
run_cmake_with_options(ExplicitDirs-S-no-arg2 -S -T)
run_cmake_with_raw_args(ExplicitDirs-S-no-arg3 [[-S ""]])
run_cmake_with_options(ExplicitDirs-S-B -S ${source_dir} -B ${binary_dir})
run_cmake_with_options(ExplicitDirs-S-B-extra-path -S ${source_dir} -B ${binary_dir} /extra/path/)
run_cmake_with_raw_args(ExplicitDirs-S-B-non-path "-S \"${source_dir}\" -B \"${binary_dir}\" \"\"")
run_cmake_with_raw_args(ExplicitDirs-S-B-non-path2 "-S \"${source_dir}\" \"\" -B \"${binary_dir}\"")
file(REMOVE_RECURSE "${binary_dir}/other_dir")
file(MAKE_DIRECTORY "${binary_dir}/other_dir")
file(WRITE "${binary_dir}/other_dir/CMakeLists.txt" [=[ ]=])
run_cmake_with_options(S-S-same -S ${source_dir} -S ${source_dir} -B ${binary_dir})
run_cmake_with_options(S-S-differs -S ${binary_dir}/other_dir -S ${source_dir} -B ${binary_dir})
run_cmake_with_options(S-implicit-same -S ${source_dir} ${source_dir} -B ${binary_dir})
run_cmake_with_options(S-implicit-differs -S ${source_dir} ${binary_dir}/other_dir -B ${binary_dir})
run_cmake_with_options(S-implicit-differs2 ${binary_dir}/other_dir -S ${source_dir} -B ${binary_dir})
run_cmake_with_options(S-implicit-differs3 ${binary_dir}/other_dir ${source_dir} -B ${binary_dir})
run_cmake_with_options(S-S-Sdiffers -S ${binary_dir}/other_dir1 -S ${binary_dir}/other_dir2 -S ${source_dir} -B ${binary_dir})
run_cmake_with_options(S-S-Simplicit ${binary_dir}/other_dir1 ${binary_dir}/other_dir2 ${source_dir} -B ${binary_dir})
run_cmake_with_options(ExplicitDirs-S-S-same -S ${source_dir} -S ${source_dir} -B ${binary_dir})
run_cmake_with_options(ExplicitDirs-S-S-differs -S ${binary_dir}/other_dir -S ${source_dir} -B ${binary_dir})
run_cmake_with_options(ExplicitDirs-S-implicit-same -S ${source_dir} ${source_dir} -B ${binary_dir})
run_cmake_with_options(ExplicitDirs-S-implicit-differs -S ${source_dir} ${binary_dir}/other_dir -B ${binary_dir})
run_cmake_with_options(ExplicitDirs-S-implicit-differs2 ${binary_dir}/other_dir -S ${source_dir} -B ${binary_dir})
run_cmake_with_options(ExplicitDirs-S-implicit-differs3 ${binary_dir}/other_dir ${source_dir} -B ${binary_dir})
run_cmake_with_options(ExplicitDirs-S-S-Sdiffers -S ${binary_dir}/other_dir1 -S ${binary_dir}/other_dir2 -S ${source_dir} -B ${binary_dir})
run_cmake_with_options(ExplicitDirs-S-S-Simplicit ${binary_dir}/other_dir1 ${binary_dir}/other_dir2 ${source_dir} -B ${binary_dir})
# make sure that -B can explicitly construct build directories
file(REMOVE_RECURSE "${binary_dir}")
run_cmake_with_options(B-arg -B ${binary_dir} ${source_dir})
run_cmake_with_options(ExplicitDirs-B-arg -B ${binary_dir} ${source_dir})
file(REMOVE_RECURSE "${binary_dir}")
run_cmake_with_options(B-arg-reverse-order ${source_dir} -B${binary_dir})
run_cmake_with_options(B-no-arg -B )
run_cmake_with_options(B-no-arg2 -B -T)
run_cmake_with_raw_args(B-no-arg3 [[-B ""]])
run_cmake_with_options(ExplicitDirs-B-arg-reverse-order ${source_dir} -B${binary_dir})
run_cmake_with_options(ExplicitDirs-B-no-arg -B )
run_cmake_with_options(ExplicitDirs-B-no-arg2 -B -T)
run_cmake_with_raw_args(ExplicitDirs-B-no-arg3 [[-B ""]])
file(REMOVE_RECURSE "${binary_dir}")
run_cmake_with_options(B-S -B${binary_dir} -S${source_dir})
run_cmake_with_options(B-S-extra-path -B${binary_dir} -S${source_dir} /extra/path/)
run_cmake_with_options(ExplicitDirs-B-S -B${binary_dir} -S${source_dir})
run_cmake_with_options(ExplicitDirs-B-S-extra-path -B${binary_dir} -S${source_dir} /extra/path/)
unset(RunCMake_TEST_COMMAND_WORKING_DIRECTORY)
message("copied to ${RunCMake_TEST_BINARY_DIR}/initial-cache.txt")
file(COPY ${RunCMake_SOURCE_DIR}/C_buildsrcdir/initial-cache.txt DESTINATION ${RunCMake_TEST_BINARY_DIR})
# CMAKE_BINARY_DIR should be determined by -B if specified, and CMAKE_SOURCE_DIR determined by -S if specified.
# Path to initial-cache.txt is relative to the $PWD, which is normally set to ${RunCMake_TEST_BINARY_DIR}.
run_cmake_with_options(C_buildsrcdir -B DummyBuildDir -S ${RunCMake_SOURCE_DIR}/C_buildsrcdir/src -C initial-cache.txt)
run_cmake_with_options(ExplicitDirs-C_buildsrcdir -B DummyBuildDir -S ${RunCMake_SOURCE_DIR}/C_buildsrcdir/src -C initial-cache.txt)
# Test that full path works, too.
run_cmake_with_options(C_buildsrcdir -B DummyBuildDir -S ${RunCMake_SOURCE_DIR}/C_buildsrcdir/src -C ${RunCMake_TEST_BINARY_DIR}/initial-cache.txt)
run_cmake_with_options(ExplicitDirs-C_buildsrcdir -B DummyBuildDir -S ${RunCMake_SOURCE_DIR}/C_buildsrcdir/src -C ${RunCMake_TEST_BINARY_DIR}/initial-cache.txt)
run_cmake_with_options(ExplicitDirs-C_buildsrcdir -B DummyBuildDir ${RunCMake_SOURCE_DIR}/C_buildsrcdir/src -C ${RunCMake_TEST_BINARY_DIR}/initial-cache.txt)
endfunction()
run_ExplicitDirs()