Merge topic 'function-var-current'

24fdd51f45 Refactor: Replace CMAKE_CURRENT_LIST_DIR with CMAKE_CURRENT_FUNCTION_LIST_DIR
90e3e2a777 cmFunctionCommand: Introduce `CMAKE_CURRENT_FUNCTION*` variables
dd54290dab Refactor: Modernize `function` command

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Ben Boeckel <ben.boeckel@kitware.com>
Merge-request: !4000
This commit is contained in:
Kyle Edwards
2019-12-12 19:00:30 +00:00
committed by Kitware Robot
19 changed files with 253 additions and 41 deletions

View File

@@ -0,0 +1,6 @@
CMAKE_CURRENT_FUNCTION
----------------------
When executing code inside a :command:`function`, this variable
contains the name of the current function. It can be used for
diagnostic or debug messages.

View File

@@ -0,0 +1,33 @@
CMAKE_CURRENT_FUNCTION_LIST_DIR
-------------------------------
When executing code inside a :command:`function`, this variable
contains the full directory of the listfile defining the current function.
It is quite common practice in CMake that modules use some additional files
(e.g., templates to render). And the code typically did the following:
.. code-block:: cmake
:caption: Bad
set(_THIS_MODULE_BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
function(foo)
configure_file(
"${_THIS_MODULE_BASE_DIR}/some.template.in"
some.output
)
endfunction()
Using this variable inside a function eliminates the neccessity of the
additional one with "global" scope:
.. code-block:: cmake
:caption: Good
function(foo)
configure_file(
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/some.template.in"
some.output
)
endfunction()

View File

@@ -0,0 +1,5 @@
CMAKE_CURRENT_FUNCTION_LIST_FILE
--------------------------------
When executing code inside a :command:`function`, this variable
contains the full path to the listfile declaring a current function.

View File

@@ -0,0 +1,5 @@
CMAKE_CURRENT_FUNCTION_LIST_LINE
--------------------------------
When executing code inside a :command:`function`, this variable
contains the line number in the listfile where a current function has defined.