From 8bb908b1084b5db1a6f8197a4d26b67984587ee4 Mon Sep 17 00:00:00 2001 From: Tamas Kenez Date: Mon, 5 Oct 2015 22:12:30 +0200 Subject: [PATCH] Document and test CMAKE_[CURRENT_](BINARY|SOURCE)_DIR in script mode --- Help/variable/CMAKE_BINARY_DIR.rst | 5 +++++ Help/variable/CMAKE_CURRENT_BINARY_DIR.rst | 5 +++++ Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst | 5 +++++ Help/variable/CMAKE_SOURCE_DIR.rst | 5 +++++ Tests/RunCMake/CommandLine/P_working-dir.cmake | 14 ++++++++++++++ Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 1 + 6 files changed, 35 insertions(+) create mode 100644 Tests/RunCMake/CommandLine/P_working-dir.cmake diff --git a/Help/variable/CMAKE_BINARY_DIR.rst b/Help/variable/CMAKE_BINARY_DIR.rst index f8dd8ab8d..3b323b7ae 100644 --- a/Help/variable/CMAKE_BINARY_DIR.rst +++ b/Help/variable/CMAKE_BINARY_DIR.rst @@ -6,3 +6,8 @@ The path to the top level of the build tree. This is the full path to the top level of the current CMake build tree. For an in-source build, this would be the same as :variable:`CMAKE_SOURCE_DIR`. + +When run in -P script mode, CMake sets the variables +:variable:`CMAKE_BINARY_DIR`, :variable:`CMAKE_SOURCE_DIR`, +:variable:`CMAKE_CURRENT_BINARY_DIR` and +:variable:`CMAKE_CURRENT_SOURCE_DIR` to the current working directory. diff --git a/Help/variable/CMAKE_CURRENT_BINARY_DIR.rst b/Help/variable/CMAKE_CURRENT_BINARY_DIR.rst index cc3b63987..40496b5d9 100644 --- a/Help/variable/CMAKE_CURRENT_BINARY_DIR.rst +++ b/Help/variable/CMAKE_CURRENT_BINARY_DIR.rst @@ -8,3 +8,8 @@ processed by cmake. Each directory added by :command:`add_subdirectory` will create a binary directory in the build tree, and as it is being processed this variable will be set. For in-source builds this is the current source directory being processed. + +When run in -P script mode, CMake sets the variables +:variable:`CMAKE_BINARY_DIR`, :variable:`CMAKE_SOURCE_DIR`, +:variable:`CMAKE_CURRENT_BINARY_DIR` and +:variable:`CMAKE_CURRENT_SOURCE_DIR` to the current working directory. diff --git a/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst b/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst index db063a4b7..c1b755a0e 100644 --- a/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst +++ b/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst @@ -5,3 +5,8 @@ The path to the source directory currently being processed. This the full path to the source directory that is currently being processed by cmake. + +When run in -P script mode, CMake sets the variables +:variable:`CMAKE_BINARY_DIR`, :variable:`CMAKE_SOURCE_DIR`, +:variable:`CMAKE_CURRENT_BINARY_DIR` and +:variable:`CMAKE_CURRENT_SOURCE_DIR` to the current working directory. diff --git a/Help/variable/CMAKE_SOURCE_DIR.rst b/Help/variable/CMAKE_SOURCE_DIR.rst index 3df0226dc..416fbe1a8 100644 --- a/Help/variable/CMAKE_SOURCE_DIR.rst +++ b/Help/variable/CMAKE_SOURCE_DIR.rst @@ -6,3 +6,8 @@ The path to the top level of the source tree. This is the full path to the top level of the current CMake source tree. For an in-source build, this would be the same as :variable:`CMAKE_BINARY_DIR`. + +When run in -P script mode, CMake sets the variables +:variable:`CMAKE_BINARY_DIR`, :variable:`CMAKE_SOURCE_DIR`, +:variable:`CMAKE_CURRENT_BINARY_DIR` and +:variable:`CMAKE_CURRENT_SOURCE_DIR` to the current working directory. diff --git a/Tests/RunCMake/CommandLine/P_working-dir.cmake b/Tests/RunCMake/CommandLine/P_working-dir.cmake new file mode 100644 index 000000000..4ea029382 --- /dev/null +++ b/Tests/RunCMake/CommandLine/P_working-dir.cmake @@ -0,0 +1,14 @@ +if(NOT IS_DIRECTORY "${EXPECTED_WORKING_DIR}") + message(FATAL_ERROR "EXPECTED_WORKING_DIR is not a directory: ${EXPECTED_WORKING_DIR}") +endif() + +foreach(d CMAKE_BINARY_DIR CMAKE_CURRENT_BINARY_DIR CMAKE_SOURCE_DIR CMAKE_CURRENT_SOURCE_DIR) + if(NOT DEFINED ${d}) + message(FATAL_ERROR "${d} is not defined") + endif() + if(EXPECTED_WORKING_DIR STREQUAL "${${d}}") + message(STATUS "${d} is the expected working directory (${EXPECTED_WORKING_DIR})") + else() + message(FATAL_ERROR "${d} = \"${${d}}\" is not the expected working directory (${EXPECTED_WORKING_DIR})") + endif() +endforeach() diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index cef636852..2d94e298f 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -115,6 +115,7 @@ run_cmake_command(E_sleep-bad-arg2 ${CMAKE_COMMAND} -E sleep 1 -1) run_cmake_command(E_sleep-one-tenth ${CMAKE_COMMAND} -E sleep 0.1) run_cmake_command(P_directory ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}) +run_cmake_command(P_working-dir ${CMAKE_COMMAND} -DEXPECTED_WORKING_DIR=${RunCMake_BINARY_DIR}/P_working-dir-build -P ${RunCMake_SOURCE_DIR}/P_working-dir.cmake) set(RunCMake_TEST_OPTIONS "-DFOO=-DBAR:BOOL=BAZ")