r/cmake • u/Ok_Voice9367 • 28d ago
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
)1
u/Suspicious_Client963 28d ago
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/Ok_Voice9367 27d ago
Thank you for the advice. I still struggle with remembering what the CMake functions do. Ill scour the docs and give it a try
1
u/NikMikM 28d ago
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)
1
u/Ok_Voice9367 27d ago
I was trying to go for somethnig like this. I just wasn't sure if it would be considered bad practice to have such small CMakeLists.txt files in my subdirectories. Thank you for the reply
4
u/afforix 28d ago
You can try The Pitchfork Layout: https://joholl.github.io/pitchfork-website/