cmake variable scope, add_subdirectory

后端 未结 1 1631
猫巷女王i
猫巷女王i 2020-12-04 10:54

I have a CMakeLists.txt in my project root and one in my /src folder. The one in the /src folder only contains a variable with the .cpp files (set (SOURCEFILES main.cp

相关标签:
1条回答
  • 2020-12-04 11:07

    As mentioned in the documentation of the set command, each directory added with add_subdirectory or each function declared with function creates a new scope.

    The new child scope inherits all variable definitions from its parent scope. Variable assignments in the new child scope with the set command will only be visible in the child scope unless the PARENT_SCOPE option is used.

    To make the SOURCEFILES assignment visible in the root folder of your project, try:

    set (SOURCEFILES main.cpp foo.cpp PARENT_SCOPE) 
    
    0 讨论(0)
提交回复
热议问题