1

I am about to generate a CMake based project for eclipse CDT and import the same to eclipse.

Now, whenever I add new sources / header files, how do I tell CMakeLists.txt that a new file has been added?
A. Should I manually add an entry to CMakeLists.txt each time to keep this up-to-date?

B. Is there a plug-in which can do this automatically?

C. Am I supposed not to do this frequently, but do it occassionally when I have to share my project with other team members?

Thanks to anyone pointing me to the best practices...

2 Answers 2

1

A. Should I manually add an entry to CMakeLists.txt each time to keep this up-to-date?

One way is to use globbing to specify your source files:

file(GLOB_RECURSE MY_SRCS src/*.cpp)

which means you don't have to specify new source files every time; instead you are saying 'any file in this folder is part of the project'

B. Is there a plug-in which can do this automatically?

I don't know, but it seems like there wouldn't be; like @zaufi said, that would require something to maintain the CMakelists.txt file automatically, which seems like a messy problem. There are some Eclipse plugins, however, which should ease the maintenance of the file. CMakeEd provides syntax highlighting, and CMakeBuilder provides a gui for setting up various CMake options.

C. Am I supposed not to do this frequently, but do it occassionally when I have to share my project with other team members?

Again, with Globbing you can drop files in the folder and run CMake again. You don't need to specify the -G option again, as the new files should show up in eclipse automatically. Like @zaufi said, you generally shouldn't need to share the .project and .cproject files with team members. Instead, they can generate their own from CMake.

0

CMakeLists.txt is the primary source of configuration information. Modifying generated project files (for whatever IDE/editor) has no sense. You even shouldn't have them in your VCS -- consider them as build artefacts. I've never used Eclipse, but suppose it must regenerate projects after your modifications to CMakeLists.txt, then Eclipse should reload them and continue to build.

Also I don't like an idea that some plugin or IDE itself would modify my CMakeLists.txt automatically. Except of implementation complexity of that operation there is high probability that IDE would break something in it. As for me it is always better (and actually not so hard) to modify it manually.

Not the answer you're looking for? Browse other questions tagged or ask your own question.