1
0
mirror of synced 2024-12-22 12:40:00 +01:00

Adding simple example

This commit is contained in:
Henry Fredrick Schreiner 2019-02-22 17:54:10 +01:00
parent f27230808e
commit 1a3e22c1e1
3 changed files with 14 additions and 0 deletions

View File

@ -11,6 +11,7 @@
* [Communicating with your code](chapters/basics/comms.md) * [Communicating with your code](chapters/basics/comms.md)
* [How to Structure Your Project](chapters/basics/structure.md) * [How to Structure Your Project](chapters/basics/structure.md)
* [Running Other Programs](chapters/basics/programs.md) * [Running Other Programs](chapters/basics/programs.md)
* [A Simple Example](chapters/basics/example.md)
* [Adding Features](chapters/features.md) * [Adding Features](chapters/features.md)
* [C++11 and Beyond](chapters/features/cpp11.md) * [C++11 and Beyond](chapters/features/cpp11.md)
* [Small but common needs](chapters/features/small.md) * [Small but common needs](chapters/features/small.md)

View File

@ -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.

View File

@ -1,3 +1,5 @@
## [main]
# Almost all CMake files should start with this # Almost all CMake files should start with this
# You should always specify a range with the newest # You should always specify a range with the newest
# and oldest tested versions of CMake. This will ensure # 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. # even flags, so linking a target that does not exist will not give a configure-time error.
target_link_libraries(MyExample PRIVATE MyLibExample) target_link_libraries(MyExample PRIVATE MyLibExample)
## [main]
# This part is so the Modern CMake book can verify this example builds. For your code, # This part is so the Modern CMake book can verify this example builds. For your code,
# you'll probably want tests too # you'll probably want tests too
enable_testing() enable_testing()
add_test(NAME MyExample COMMAND MyExample) add_test(NAME MyExample COMMAND MyExample)