开发者

cmake, several questions

开发者 https://www.devze.com 2023-03-23 16:19 出处:网络
I\'m new to cmake. Are there any good tutorials that go deeper into the matter? Are there any articles about \"good pra开发者_StackOverflow中文版ctices\" with cmake?

I'm new to cmake. Are there any good tutorials that go deeper into the matter? Are there any articles about "good pra开发者_StackOverflow中文版ctices" with cmake? Are here any good overviews about all cmake commands and what they do? The original cmake docs are rather confusing and messed up in my opinion...

Now for something more specific: As far as I found out, you have to tell cmake every source file (.cpp) that should be compiled. Isn't it possible to simply tell "just compile everything you find in folder /src" (like you can simply define an include folder without havinf to define every single .h file)?

What's the best way to tell cmake to also compile files that are not in the /src dir? I have another folder for external source code, that also has subdirectories and everything. Do I have to write (again..) every single .cpp file into the cmake script to let it know that the external code should be compiled, too?

Basically I'm looking for the quickest and best way to add new source/header files to a project without having to constantly adjust the cmake files.


You can just glob *.cpp *.h etc, but if your list of files changes CMake won't notice unless you touch your CMakeLists.txt file.

The best practice is to constantly adjust your CMake files, though. You'll get consistent behavior if you list the files, which is what is really important.

It really isn't that much work in practice, really.

Using a CMakeLists.txt file for each directory, and using add_subdirectory is usually the easiest way to manage it. That way you don't deal with paths beyond the current and child scope.

Here is a CMake Tutorial

0

精彩评论

暂无评论...
验证码 换一张
取 消