Sign in to follow this  
rogerdv

basic cmake setup

Recommended Posts

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 this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this