Difference between CMAKE_CURRENT_SOURCE_DIR and CMAKE_CURRENT_LIST_DIR

The variables CMAKE_CURRENT_SOURCE_DIR and CMAKE_CURRENT_LIST_DIR may refer to different directories for a CMake list file that is included by another file with the include command. E.g., if a CMakeLists.txt is present in a directory project and contains the following directive

include(src/CMakeLists.txt)

then while src/CMakeLists.txt is being processed CMAKE_CURRENT_LIST_DIR will refer to project/src whereas CMAKE_CURRENT_SOURCE_DIR still points to the outer directory project.

CMAKE_CURRENT_LIST_DIR comes in handy, when you need to locate resource files like template files or batch scripts that are located next to the CMakeLists.txt file currently being processed.


Note: When using the add_subdirectory() command rather than include(), the behavior is different, and when src/CMakeLists.txt is being processed, both variables will point to project/src.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)