Search code examples
ceclipsebuildcmake

How do I create a CMakeLists.txt?


I am starting to learn about CMake and have two questions:

1. Do I need to update the CMakeLists.txt file every time When I add a new file?

Assuming that the size of the project grows, the number of subdirectories and source files in the project will also increased greatly.

In such a case, I guess it is inconvenient to update the CMakelists.txt file whenever a new file or directory is added to the project.

Or is it part of the code management? How is it usually done?

2. In order to build a C Eclipse project(makefile) using CMake, should I write the CMakeList.txt manually?

There are many ways to import CMake projects into Eclipse, but I can't see how to build a C Eclipse project with CMake.


Solution

  • Do I need to update the CMakeLists.txt file every time When I add a new file?

    CMake, like GNU make, allows to use wildcards to specify source files.

    However, it's good practice to explicitly list files to build, in order to avoid silly mistakes (due, for example, to missing or unexpected files in source directory).

    When file list becomes large, build definition files (like CMakeLists.txt) may be split into multiple files.

    In order to build a / C Eclipse project(makefile) / using CMake, Should I write CMakelist.txt manually?

    I don't know aboud Eclipse, but many IDEs partially/completely automate CMakelists.txt creation. Maybe Eclipse has such a tool too.