mirror of
https://github.com/ttroy50/cmake-examples.git
synced 2025-12-18 20:24:35 +03:00
started updating examples for cmake v3 syntax
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
# Set a default C++ compile flag
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEX2" CACHE STRING "Set C++ Compiler Flags" FORCE)
|
||||
@@ -8,3 +8,7 @@ project (compile_flags)
|
||||
|
||||
# Add an executable
|
||||
add_executable(cmake_examples_compile_flags main.cpp)
|
||||
|
||||
target_compile_defintions(cmake_examples_compile_flags
|
||||
PRIVATE EX3
|
||||
)
|
||||
@@ -26,7 +26,7 @@ $ tree
|
||||
|
||||
## Set C++ Flag
|
||||
|
||||
Similar to the build type a C++ compiler flag can be set using the following methods.
|
||||
Similar to the build type a global C++ compiler flag can be set using the following methods.
|
||||
|
||||
- Using a gui tool such as ccmake / cmake-gui
|
||||
|
||||
@@ -60,6 +60,19 @@ are used to force this variable to be set in the CMakeCache.txt file.
|
||||
For more details, see https://cmake.org/cmake/help/v3.0/command/set.html[here]
|
||||
====
|
||||
|
||||
## Set Per-Target C++ Flags
|
||||
|
||||
Once set the +CMAKE_C_FLAGS+ and +CMAKE_CXX_FLAGS+ will set a compler flag / definiton globally for all targets in this directory or any included sub-directories. To set a compiler definitons for a specific target you can use the +target_compile_defintions()+ link:https://cmake.org/cmake/help/v3.0/command/target_compile_definitions.html[function]. This will cause the compiler to add the definition +-DEX3+ when compiling the target.
|
||||
|
||||
[source,cmake]
|
||||
----
|
||||
target_compile_defintions(cmake_examples_compile_flags
|
||||
PRIVATE EX3
|
||||
)
|
||||
----
|
||||
|
||||
Depending on the scope this defintion may also be included in any targets that link this target. For compiler options you can also use the +target_compile_options()+ link:https://cmake.org/cmake/help/v3.0/command/target_compile_options.html[function].
|
||||
|
||||
# Building the Example
|
||||
|
||||
[source,bash]
|
||||
|
||||
Reference in New Issue
Block a user