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)
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With