![]() PARENT_SCOPE) command inside child/CMakeLists.txt. The scope of the top-level CMakeList, which is affected by the set(.) commands in M圜Make and M圜Make2, and by the set(.So your example has just two scopes involved: The basic rule is simple: add_subdirectory establishes a new scope, include does not. In my eyes, if I use name 'A' both for binary target and library target, it should not result in confusion, because the real second target is 'libA'. It looks like that CMake does not allow to use the same target name for both. Is there a standard way to use say a library name for building in one child, and use the same name in another child for linking?Īlso a question: I have an application, consisting of a library and an executable. Why I started to experiment: under some conditions I do not see in the parent directory the variables (like include directories, library names, etc.) defined in the child directory. What is going on here? (it looks like I can overwrite a value of the variable, which is not in my scope) In the 5th line, however, I see that the PARENT scope value has changed, which I expected to be changed ONLY locally, in the child subdirectory. The 4th line shows that I set a LOCAL scope variable. (So, I can/shall the same variable with local scope?) The third line shows only variable with parent scope, OK. the defined variable has a scope ONLY in the parent. With the second line, it looks like it is a parent-only setting, i.e. This first line is OK, the 2nd and third variables are not yet defined. I do have files and directories like ├── test Let’s create a file in the project folder, sample.I am a bit confused about scoping rules of cmake. No new scope is created as if the content of the file is pasted at the include() line. We can include CMake scripts from another file by include. While CMAKE_CURRENT_SOURCE_DIR is dependent on the location of focused CMakeLists.txt, PROJECT_SOURCE_DIR is always set to the top-level folder containing CMakeLists.txt which has project() command in it.Ī subdirectory usually contains some source files that need to be compiled. The variables in subdirectory scope are private and not visible to the project scope. Afterward, CMake comes back to the project scope and sets CMAKE_CURRENT_SOURCE_DIR to myProject path. When it reaches the add_subdirectory line, it will jump into library1/CMakeLists.txt, set CMAKE_CURRENT_SOURCE_DIR to library1 path, and runs the command there. Running cmake, it will set CMAKE_CURRENT_SOURCE_DIR variable to the myProject path. Project ( myProject ) message ( "Hello from myProject" ) message ( $ ) add_subdirectory ( "library1" )
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |