[CMake] Making existing, compiled projects CMake aware

Johannes Zarl-Zierl johannes.zarl-zierl at jku.at
Wed Nov 15 07:50:45 EST 2017


Hello Saad,

On Dienstag, 14. November 2017 18:38:17 CET Saad Khattak wrote:
> There are some projects that are already compiled and I would like to fork
> those projects and write a CMakeLists.txt file for them such that they can
> be added by other CMake projects easily.

In my experience, looking at other projects and how they switched to CMake is 
usually not very helpful. After all, you can only see the resulting 
CMakeLists.txt but no steps how it was created.

What you can do instead, is to just write the CMakeLists.txt from scratch and 
keep it simple (i.e. don't introduce complexity that you don't understand).

Before starting, it might be a good idea to update your knowledge about modern 
C++. A good starting point is the "Modern CMake" talk by Daniel Pfeiffer, 
especially the part about how to add and link to libraries:
https://youtu.be/bsXLMQ6WgIk?t=818

> For instance, for the library: https://github.com/ygpark/Everything-SDK,
> how would I write a CMakeLists.txt file such that:
> 
> => the project has a CMake library named "Everything" (which is normally
> the result of add_library)

As you already said: use add_library.

> => it's headers, lib and dll files specified in the target "Everything"
> properly

This is also explained in the linked video. The official documentation is here:

https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.
7.html#transitive-usage-requirements

> => install() command to install the above for the target "Everything"
> => CMake generates the relevant "-config.cmake" file

This is documented here:

https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html

> so that the library
> can be easily found using the find_library() command

I guess you meant to write find_package(), not find_library()


HTH,
  Johannes



More information about the CMake mailing list