CMAKE_CURRENT_SOURCE_DIR
时间: 2023-08-31 11:12:47 浏览: 52
CMAKE_CURRENT_SOURCE_DIR is a CMake variable that represents the path to the directory that contains the CMakeLists.txt file that is currently being processed. This variable is useful for specifying paths to source files, such as header files or source code files, relative to the current CMakeLists.txt file.
For example, if a project has the following directory structure:
```
project/
CMakeLists.txt
src/
main.cpp
helper.h
```
The CMakeLists.txt file might contain the following lines:
```
add_executable(my_executable src/main.cpp src/helper.h)
target_include_directories(my_executable PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
```
In this example, the add_executable command specifies the source files for the executable, and the target_include_directories command adds the src directory to the include path for the my_executable target. The ${CMAKE_CURRENT_SOURCE_DIR}/src argument specifies the path to the src directory relative to the directory containing the CMakeLists.txt file.