mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-01 12:18:36 -06:00
Merge topic 'function-var-current'
24fdd51f45Refactor: Replace CMAKE_CURRENT_LIST_DIR with CMAKE_CURRENT_FUNCTION_LIST_DIR90e3e2a777cmFunctionCommand: Introduce `CMAKE_CURRENT_FUNCTION*` variablesdd54290dabRefactor: 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:
6
Help/variable/CMAKE_CURRENT_FUNCTION.rst
Normal file
6
Help/variable/CMAKE_CURRENT_FUNCTION.rst
Normal 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.
|
||||
33
Help/variable/CMAKE_CURRENT_FUNCTION_LIST_DIR.rst
Normal file
33
Help/variable/CMAKE_CURRENT_FUNCTION_LIST_DIR.rst
Normal 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()
|
||||
5
Help/variable/CMAKE_CURRENT_FUNCTION_LIST_FILE.rst
Normal file
5
Help/variable/CMAKE_CURRENT_FUNCTION_LIST_FILE.rst
Normal 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.
|
||||
5
Help/variable/CMAKE_CURRENT_FUNCTION_LIST_LINE.rst
Normal file
5
Help/variable/CMAKE_CURRENT_FUNCTION_LIST_LINE.rst
Normal 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.
|
||||
Reference in New Issue
Block a user