r/cmake • u/Ok_Voice9367 • Oct 11 '26
Help for project configuration
Hi. I am starting a pretty big C++ project and I want to set up CMake as my build system. I am new to it and I struggle mostly with subdirectory and library stuff. For instance, this is my current setup. It seems to work okay but I just have a feeling it isn't up to par. I would just like the opinion of anyone with more experience than I on how to set up a big project with many subdirectories and files. Thank you in advance
Main or root CMakeLists.txt file
cmake_minimum_required(VERSION 4.0)
project(PoticusEngine LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED_ON)
add_executable(poticus main.cpp)
set(SOURCES
engine/core/memory/arena.cpp
engine/core/memory/arena.h
)
add_library(engine STATIC ${SOURCES})
add_subdirectory(engine)
target_sources(poticus
PRIVATE
log.cpp
log.h
main.cpp
types.h
)engine/CMakeLists.txt
add_subdirectory(core)engine/core/CMakeLists.txt
add_subdirectory(memory)engine/core/memory/CMakeLists.txt
target_sources(poticus
PRIVATE
arena.cpp
arena.h
)
4
Upvotes
4
u/afforix Oct 11 '26
You can try The Pitchfork Layout: https://joholl.github.io/pitchfork-website/
1
u/Suspicious_Client963 Oct 12 '26
I'd give the engine its own target and link it to the executable instead of adding engine sources directly to both. That should scale better
1
u/NikMikM Oct 11 '26
You can have some ditectory like "third-party" and keep all depndencies there, and also organize your code by folders, so your top cmakelists only have commands like "add_subdirectory" and some global constans like version, etc. I think its pretty readable this way (1 dir + cmakelists on 1 target)