1CMAKE_CURRENT_FUNCTION_LIST_DIR 2------------------------------- 3 4.. versionadded:: 3.17 5 6When executing code inside a :command:`function`, this variable 7contains the full directory of the listfile that defined the current function. 8 9It is quite common practice in CMake for modules to use some additional files, 10such as templates to be copied in after substituting CMake variables. 11In such cases, a function needs to know where to locate those files in a way 12that doesn't depend on where the function is called. Without 13``CMAKE_CURRENT_FUNCTION_LIST_DIR``, the code to do that would typically use 14the following pattern: 15 16.. code-block:: cmake 17 18 set(_THIS_MODULE_BASE_DIR "${CMAKE_CURRENT_LIST_DIR}") 19 20 function(foo) 21 configure_file( 22 "${_THIS_MODULE_BASE_DIR}/some.template.in" 23 some.output 24 ) 25 endfunction() 26 27Using ``CMAKE_CURRENT_FUNCTION_LIST_DIR`` inside the function instead 28eliminates the need for the extra variable which would otherwise be visible 29outside the function's scope. 30The above example can be written in the more concise and more robust form: 31 32.. code-block:: cmake 33 34 function(foo) 35 configure_file( 36 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/some.template.in" 37 some.output 38 ) 39 endfunction() 40 41See also :variable:`CMAKE_CURRENT_FUNCTION`, 42:variable:`CMAKE_CURRENT_FUNCTION_LIST_FILE` and 43:variable:`CMAKE_CURRENT_FUNCTION_LIST_LINE`. 44