Here is the patch which documents and tests those 4 variables in script mode, based on master: -----------
>From f1a6f5e258321317a8086d0538e0a3240d980731 Mon Sep 17 00:00:00 2001 From: Tamas Kenez <tamas.ke...@gmail.com> 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 | 8 ++++++++ Help/variable/CMAKE_SOURCE_DIR.rst | 8 ++++++++ Tests/RunCMake/CommandLine/P_working-dir.cmake | 14 ++++++++++++++ Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 5 +++++ 6 files changed, 45 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 f8dd8ab..3b323b7 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 cc3b639..40496b5 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 db063a4..728291e 100644 --- a/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst +++ b/Help/variable/CMAKE_CURRENT_SOURCE_DIR.rst @@ -5,3 +5,11 @@ 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 this variable to the current +working directory. + +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 3df0226..3644bbb 100644 --- a/Help/variable/CMAKE_SOURCE_DIR.rst +++ b/Help/variable/CMAKE_SOURCE_DIR.rst @@ -6,3 +6,11 @@ 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 this variable to the current +working directory. + +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 0000000..4ea0293 --- /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 cef6368..3cc9225 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -22,6 +22,11 @@ run_cmake_command(G_bad-arg ${CMAKE_COMMAND} -G NoSuchGenerator) run_cmake_command(P_no-arg ${CMAKE_COMMAND} -P) run_cmake_command(P_no-file ${CMAKE_COMMAND} -P nosuchscriptfile.cmake) +set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/P_working-dir-build) +file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") +run_cmake_command(P_working-dir ${CMAKE_COMMAND} -DEXPECTED_WORKING_DIR=${RunCMake_TEST_BINARY_DIR} -P ${RunCMake_SOURCE_DIR}/P_working-dir.cmake) +unset(RunCMake_TEST_BINARY_DIR) + run_cmake_command(build-no-dir ${CMAKE_COMMAND} --build) run_cmake_command(build-no-cache -- 2.2.1 On Fri, Oct 2, 2015 at 2:45 PM, Brad King <brad.k...@kitware.com> wrote: > On 10/02/2015 08:00 AM, J Decker wrote: > > On Fri, Oct 2, 2015 at 4:40 AM, Tamás Kenéz wrote: > >> In script mode it seems that all the CMAKE_[CURRENT_](BINARY|SOURCE)_DIR > >> variables are set to the current working directory. > > > > if CMAKE_[CURRENT]_SOURCE_DIR is current directory; you're doing > > something wrong :) That implies that you're doing an in-source build > > Tamas is not doing a build at all but instead running > > cmake -P myscript.cmake > > and checking the values of these variables. Yes, the four variables > are meant to be the current working directory in script mode. This > should be added to the documentation, but such a patch should also > come with an update to the test suite, perhaps in RunCMake/CommandLine, > that covers the behavior explicitly. > > -Brad > > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > http://public.kitware.com/mailman/listinfo/cmake-developers >
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers