# basic cmake setup

## Recommended Posts

rogerdv    418

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?

##### Share on other sites
DUDVim    1598

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})    

##### Share on other sites
jacmoe    2179

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

##### Share on other sites
Jan2go    2057

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.
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.

##### Share on other sites
BitMaster    8651
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.

##### Share on other sites
l0calh05t    1797

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.

## Create an account

Register a new account