Skip to content
Snippets Groups Projects
Commit 1f1a158c authored by Sebastian Eibl's avatar Sebastian Eibl
Browse files

think in targets

parent 078b06d4
No related branches found
No related tags found
No related merge requests found
# Define Targets
# Think in targets!
This recipe illustrates how to build a basic application.
It consists of a backend library and an application frontend.
## Define the target type
[add_library]([https://cmake.org/cmake/help/latest/command/add_library.html])
[add_executable]([https://cmake.org/cmake/help/latest/command/add_executable.html])
# Set Target Properties
[target_compile_definitions]([https://cmake.org/cmake/help/latest/command/target_compile_definitions.html])
[target_compile_options]([https://cmake.org/cmake/help/latest/command/target_compile_options.html])
[target_include_directories]([https://cmake.org/cmake/help/latest/command/target_include_directories.html])
[target_link_libraries]([https://cmake.org/cmake/help/latest/command/target_link_libraries.html])
[target_link_options]([https://cmake.org/cmake/help/latest/command/target_link_options.html])
[target_sources]([https://cmake.org/cmake/help/latest/command/target_sources.html])
\ No newline at end of file
## Set target properties
| Aim | Command |
|----------------------------------------|-------------------------------------------------------------------------------------------------------------|
| add definitions | [target_compile_definitions]([https://cmake.org/cmake/help/latest/command/target_compile_definitions.html]) |
| add compile flags | [target_compile_options]([https://cmake.org/cmake/help/latest/command/target_compile_options.html]) |
| add include directories | [target_include_directories]([https://cmake.org/cmake/help/latest/command/target_include_directories.html]) |
| add a dependency, link against library | [target_link_libraries]([https://cmake.org/cmake/help/latest/command/target_link_libraries.html]) |
| add linker options | [target_link_options]([https://cmake.org/cmake/help/latest/command/target_link_options.html]) |
| add sources | [target_sources]([https://cmake.org/cmake/help/latest/command/target_sources.html]) |
## Usage requirements
https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#transitive-usage-requirements
| keyword | result |
|---------------|------------------------------------------------------------|
| **PRIVATE** | only relevant for the target |
| **INTERFACE** | only relevant for targets depending on this target |
| **PUBLIC** | relevant for both, the target itself and dependent targets |
## How to link against a "supported" third-party library?
Find the library with [find_package]([https://cmake.org/cmake/help/latest/command/find_package.html]) and link against
the imported target with [target_link_libraries]([https://cmake.org/cmake/help/latest/command/target_link_libraries.html]).
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment