summaryrefslogtreecommitdiff
path: root/share/cmake-3.17/Help/variable/CMAKE_CURRENT_FUNCTION_LIST_DIR.rst
blob: 0119381ae956f4a72c7c0bc5752cbc587b1e74dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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()