Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 811
jaeho jo Avatar asked Dec 06 '25 13:12

jaeho jo


2 Answers

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.

like image 72
Mario Cianciolo Avatar answered Dec 08 '25 08:12

Mario Cianciolo


Yes write your CMakeLists.txt manually. This can barely be automated, beside adding new header files. There is a way to include all *.h files, but it is not enouraged.

And add every new header file manually. C files are not needed. Adding header files should not happen ofen.

like image 40
usr1234567 Avatar answered Dec 08 '25 06:12

usr1234567



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!