Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

source_group CMake command isn't working

Tags:

cmake

I don't understand the source_group command in my CMakeLists.txt. When I do this it works:

file(GLOB INPUT_HEAD    KeyBoard.h Mouse.h)
source_group("Header Files\\Input" FILES ${INPUT_HEAD})

But this isn't working:

file(GLOB SHADERS ../Shaders/*.txt)
source_group("Source Files\\Shaders" FILES ${SHADERS})

Any suggestions on how to solve this? (I have read the documentation for this command, I don't understand whythis doesn't work)

like image 870
Edvin Avatar asked Jul 27 '15 11:07

Edvin


2 Answers

You need to use the files in an actual target. For example they must be used in an add_library or add_executable statement, then they will be in a folder within that project. Also, I use ''/'' rather than \\ as a separator. You may also want to use set_property(GLOBAL PROPERTY USE_FOLDERS ON) to have the predefined cmake projects go into their own solution folder.

like image 76
Phil Avatar answered Oct 18 '22 00:10

Phil


There is a new command since CMake 3.8 to automatically filter your files according to the folder structure relative to a certain path.

Here is a small example where the SRC_BUILD_FILES is a set containing all the files you want to filter. The filtering occurs relative to a certain base path, which is set using CMAKE_CURRENT_SOURCE_DIR in this example, but it can be any folder. The PREFIX name (here: Implementation) can be set to your liking and will contain the filtered set.

    source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}"
         PREFIX "Implementation"
         FILES ${SRC_BUILD_FILES})

So there is no need for globbing or manually re-iterating folder names in your cmake script.

like image 8
StarShine Avatar answered Oct 18 '22 00:10

StarShine