started updating examples for cmake v3 syntax

This commit is contained in:
ttroy50
2016-04-15 23:49:39 +01:00
parent e56847a5ef
commit 3335200e43
12 changed files with 96 additions and 48 deletions

View File

@@ -6,7 +6,9 @@ toc::[]
# Introduction
Shows a hello world example which first creates and links a shared library
Shows a hello world example which first creates and links a shared library.
This also shows how to create an link:https://cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#alias-targets[alias target]
The files in this tutorial are below:
@@ -48,6 +50,17 @@ add_library(hello_library SHARED ${library_SOURCES})
This will be used to create a shared library with the name libhello_library.so with
the sources from the +library_SOURCES+ variable.
## Alias Target
As the name suggests an alias target is an alternative name for a target that can be used instead of the real target name in read-only contexts.
[source,cmake]
----
add_library(hello::library ALIAS hello_library)
----
As show below, this allows you to reference the target using the alias name when linking it against other targets.
## Linking a Shared Library
Linking a shared library is the same as linking a static library. When creating your
@@ -58,12 +71,11 @@ executable use the the +target_link_library()+ function to point to your library
add_executable(hello_binary ${binary_SOURCES})
target_link_libraries( hello_binary
hello_library
hello::library
)
----
This tells CMake to link the hello_library against the hello_binary executable
during link time.
This tells CMake to link the hello_library against the hello_binary executable using the alias target name.
An example of this being called by the linker is