My understanding is, that for larger projects the best practice is to use a CMakeLists.txt per folder.
I have the following structure (though this will increase in the future with more nested folders):
QPV
|
|---- CMakeLists.txt
|---- 3rdparty
| |
| |---- glfw
|---- src/
| |
| |---- CMakeLists.txt
| |---- main.cpp
| |---- VulkanRenderer.h
| |---- VulkanRenderer.cpp
| |---- utils/
| | |
| | |---- CMakeLists.txt
| | |---- VulkanUtils.h
| | |---- VulkanUtils.cpp
I want to mirror my subfolders in Visual Studio as they are on disk.
My understanding is, source_group
can achieve this, but I haven't been able to get it to work.
My three current CMakeLists files contain: QPV/CMakeLists.txt:
project(QPV VERSION 0.1)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_subdirectory(src)
# GLFW stuff
# Vulkan stuff
QPV/src/CMakeLists.txt:
add_executable(QPV
main.cpp
VulkanRenderer.h
VulkanRenderer.cpp
)
include_directories(src PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(utils)
and finally QPV/src/utils/CMakeLists.txt
target_sources(${PROJECT_NAME} PUBLIC
VulkanUtils.h
VulkanUtils.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
set(ROOT_DIR "${CMAKE_SOURCE_DIR}/src")
source_group(TREE "${CMAKE_SOURCE_DIR}"
PREFIX "utils"
FILES
Vulkanutils.h
VulkanUtils.cpp
)
I'm pretty sure my error is in the source_group
command is what I did wrong, but I can't figure out how to fix it. Can I even do this from a nested folder? From what I could see online it looked like this command would go into the root folder's CMakeLists.txt but that would make the best practice of one CMakeLists.txt per folder obsolete.
Note that I don't want utils to be a different library, it still belongs to the QPV project. I just want my source files to not lie next to each other if sorting them into folders makes more sense.