If CMakeList.txt contains a line add_subdirectory("./B"), then.PROJECT_SOURCE_DIR will be "path to project/A", because include command does not create a new scope and the nearest CMakeList.txt file that has its own scope and contains project command is in folder A.ĬMAKE_CURRENT_SOURCE_DIR will be "path to project/A", because include command does not create a new scope and the nearest CMakeList.txt file that has its own scope is in folder A.ĬMAKE_CURRENT_LIST_DIR will be "path to project/A/B", because currently processed file is in subfolder B. If CMakeList.txt in folder A contains a line include("B/CMakeList.txt"), thenĬMAKE_SOURCE_DIR will be source directory which is "path to project/A".While include(file) command is not creating a new scope, add_subdirectory is creating a new scope which affects the PROJECT_SOURCE_DIR and CMAKE_CURRENT_SOURCE_DIR values.Īnd let us assume we are printing all cmake variables by putting message command to CMakeList.txt file in subfolder B. What I mean by its own scope is related to scoping rules. (File do not need to contain project() command)ĬMAKE_CURRENT_LIST_DIR: The folder that contains currently processed CMakeList.txt or. PROJECT_SOURCE_DIR: The nearest folder that contains CMakeList.txt file, with its own scope, that contains project() command.ĬMAKE_CURRENT_SOURCE_DIR: The nearest folder that contains CMakeList.txt file with its own scope. The value never changes in different scopes. Under what circumstances would these variables hold different values?ĬMAKE_SOURCE_DIR: Topmost folder(source directory) that contains a CMakeList.txt file. Therefore the value of the variable inside a macro or function is the directory of the file invoking the bottom-most entry on the call stack, not the directory of the file containing the macro or function definition. When CMake finishes processing commands from the file it restores the previous value. When CMake starts processing commands in a source file it sets this variable to the directory where this file is located. This the full path to the source directory that is currently being processed by cmake.ĬMAKE_CURRENT_LIST_DIR: Full directory of the listfile currently being processed.Īs CMake processes the listfiles in your project this variable will always be set to the directory where the listfile which is currently being processed (CMAKE_CURRENT_LIST_FILE) is located. From the Docs:ĬMAKE_CURRENT_SOURCE_DIR: The path to the source directory currently being processed. (since 2.8.3) this is the directory of the listfile currently being processed. This is the directory where the currently processed CMakeLists.txt is located in
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |