From 1a3e22c1e1aa99489452e7b7a1d8282f40b9fe65 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Fri, 22 Feb 2019 17:54:10 +0100 Subject: [PATCH] Adding simple example --- SUMMARY.md | 1 + chapters/basics/example.md | 8 ++++++++ examples/simple-project/CMakeLists.txt | 5 +++++ 3 files changed, 14 insertions(+) create mode 100644 chapters/basics/example.md diff --git a/SUMMARY.md b/SUMMARY.md index 8f23086..26470b3 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -11,6 +11,7 @@ * [Communicating with your code](chapters/basics/comms.md) * [How to Structure Your Project](chapters/basics/structure.md) * [Running Other Programs](chapters/basics/programs.md) + * [A Simple Example](chapters/basics/example.md) * [Adding Features](chapters/features.md) * [C++11 and Beyond](chapters/features/cpp11.md) * [Small but common needs](chapters/features/small.md) diff --git a/chapters/basics/example.md b/chapters/basics/example.md new file mode 100644 index 0000000..fa87b9c --- /dev/null +++ b/chapters/basics/example.md @@ -0,0 +1,8 @@ +# A simple example + +This is a simple yet complete example of a proper CMakeLists. For this program, we have one library (MyLibExample) with a header file and a source file, +and one application, MyExample, with one source file. + +2[import:'main', lang:'cmake'](../../examples/simple-project/CMakeLists.txt) + +The complete example is available in examples folder in the Modern CMake git repository. diff --git a/examples/simple-project/CMakeLists.txt b/examples/simple-project/CMakeLists.txt index 1879d17..a6881b6 100644 --- a/examples/simple-project/CMakeLists.txt +++ b/examples/simple-project/CMakeLists.txt @@ -1,3 +1,5 @@ +## [main] + # Almost all CMake files should start with this # You should always specify a range with the newest # and oldest tested versions of CMake. This will ensure @@ -30,7 +32,10 @@ add_executable(MyExample simple_example.cpp) # even flags, so linking a target that does not exist will not give a configure-time error. target_link_libraries(MyExample PRIVATE MyLibExample) +## [main] + # This part is so the Modern CMake book can verify this example builds. For your code, # you'll probably want tests too enable_testing() add_test(NAME MyExample COMMAND MyExample) +