Navigating through the directories in CMake has a common pitfall that not everyone is aware of. When writing CMake scripts, try to distinguish between the following built-in variables:
- PROJECT_SOURCE_DIR: The directory where the project command was last called from a CMake script.
- PROJECT_BINARY_DIR: Like the preceding one, but for the build directory tree.
- CMAKE_SOURCE_DIR: Top-level source directory (this may be in another project that just adds ours as a dependency/subdirectory).
- CMAKE_BINARY_DIR: Like CMAKE_SOURCE_DIR, but for the build directory tree.
- CMAKE_CURRENT_SOURCE_DIR: The source directory corresponding to the currently processed CMakeLists.txt file.
- CMAKE_CURRENT_BINARY_DIR: The binary (build) directory matching CMAKE_CURRENT_SOURCE_DIR.
- CMAKE_CURRENT_LIST_DIR: The directory of CMAKE_CURRENT_LIST_FILE. It can be different from the current source directory if the current CMake script was included from another one...