使用cmake子目录中的源组

使用cmake子目录中的源组,cmake,Cmake,在cmake中,您可以使用source\u group命令对IDE中的源文件进行分组(在我的例子中,它在Visual Studio项目中创建过滤器) 我有一个这样的目录结构 Main (dir) +-- CMakeLists.txt +-- main.cpp +-- shaders(dir) +-- CMakeLists.txt +-- shader1.glsl +-- shader2.glsl Main/CMakeLists.txt

在cmake中,您可以使用
source\u group
命令对IDE中的源文件进行分组(在我的例子中,它在Visual Studio项目中创建过滤器)

我有一个这样的目录结构

Main (dir)
  +-- CMakeLists.txt
  +-- main.cpp
  +-- shaders(dir)
        +-- CMakeLists.txt
        +-- shader1.glsl
        +-- shader2.glsl
Main/CMakeLists.txt:

cmake_minimum_required (VERSION 3.13)
add_executable(myExec main.cpp)
add_subdirectory(shaders)
target_sources(myExec PRIVATE shader1.glsl shader2.glsl)
着色器/CMakeLists.txt:

cmake_minimum_required (VERSION 3.13)
add_executable(myExec main.cpp)
add_subdirectory(shaders)
target_sources(myExec PRIVATE shader1.glsl shader2.glsl)
如果我将
source\u组(“Config Files”REGULAR\u EXPRESSION“*\.glsl”)
添加到Main/CMakeLists.txt,它将创建一个包含shader1.glsl和shader2.glsl的过滤器。但是,如果我在shaders/CMakeList.txt中使用它,它不会添加过滤器,shader1.glsl和shader2.glsl会直接显示在myExec项目中

在我看来,它似乎只适用于在同一CMakeList.txt文件中创建的目标。这种行为在我看来并不明显

这有文件记录吗?有没有办法从子目录中使用
source\u group
(对我来说,在shaders/CMakeLists.txt中保留所有与着色器相关的内容是最合乎逻辑的)