basic cmake setup

Started by
4 comments, last by l0calh05t 9 years, 1 month ago

Im trying to create the cmake files for a project, but cant find how to achieve it. The project has this structure:

project-dir

src

sources1

sources2

I have tried several combinations, but cant make it work. So, I have to specify all source files manually in the CMakeLists.txt located at src. How can I implement this?

Advertisement

I have some CMAKE hints in my notebook at http://www.gamedevpensieve.com/programming/language/c/cmake . See if it can help you make sense of it. I prefer to use lists made with file GLOB.


file(GLOB SRC_FILES *.cc *.h) 
add_executable(zerofps ${SRC_FILES})    

@spinningcubes | Blog: Spinningcubes.com | Gamedev notes: GameDev Pensieve | Spinningcubes on Youtube

The problem with using glob is that CMake doesn't recognise when you add/remove files from the project. ;)

This is a great tutorial -> https://www.johnlamp.net/cmake-tutorial.html

Too many projects; too much time

The problem with using glob is that CMake doesn't recognise when you add/remove files from the project. ;)


But you have to remember added each file to the CMakeLists.txt. I don't know how often I forgot to do this before I gave up and switched my project to globs. biggrin.png
At least with Visual Studio globbing works as long as you add every file via the Solution Explorer. You just need to run CMake manually after pulling an update from version control.
Personally I see adding the files to the relevant CMakeLists by hand is a complete non-issue. At work some parts of the project work with GLOBs (because the whole thing was moved to CMake after years of growing outside it). It's an acceptable workaround for quickly moving a large existing codebase into CMake but when I'm working in an area I try to spare the time to drop the GLOBs and move to explicit listings. It's much less painless in the long run, especially if you also need to add/remove compilation units depending on the current platform or other factors.

Personally I see adding the files to the relevant CMakeLists by hand is a complete non-issue. At work some parts of the project work with GLOBs (because the whole thing was moved to CMake after years of growing outside it). It's an acceptable workaround for quickly moving a large existing codebase into CMake but when I'm working in an area I try to spare the time to drop the GLOBs and move to explicit listings. It's much less painless in the long run, especially if you also need to add/remove compilation units depending on the current platform or other factors.

It also makes it obvious far earlier in the build process when someone forgets to upload a file to the SCM. Which happens a lot.

This topic is closed to new replies.

Advertisement