CMake/MinimalExamples: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
(Add explicit preformat markup)
Line 4: Line 4:
For instance, here is the simplest possible CMakeLists.txt for a "Hello, World" project:
For instance, here is the simplest possible CMakeLists.txt for a "Hello, World" project:


<pre>
     add_executable(hello hello.c)
     add_executable(hello hello.c)
</pre>


And here's the simplest possible one for a shared library:
And here's the simplest possible one for a shared library:


<pre>
     add_library(hellolib SHARED hellolib.c)
     add_library(hellolib SHARED hellolib.c)
</pre>


That's right - CMakeLists.txt can be a single line.  And if that's all you need, that's all you should use!
That's right - CMakeLists.txt can be a single line.  And if that's all you need, that's all you should use!


{{CMake/Template/Footer}}
{{CMake/Template/Footer}}

Revision as of 18:32, 24 April 2018

CMake has lots of good documentation, but when learning a new feature (or just starting out), there is no substitute for trying it out in isolation. That way, if anything goes wrong, you have fewer lines of CMakeList.txt to look through for problems.

For instance, here is the simplest possible CMakeLists.txt for a "Hello, World" project:

    add_executable(hello hello.c)

And here's the simplest possible one for a shared library:

    add_library(hellolib SHARED hellolib.c)

That's right - CMakeLists.txt can be a single line. And if that's all you need, that's all you should use!



CMake: [Welcome | Site Map]