diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2019-07-18 17:48:58 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-07-25 11:30:13 (GMT) |
commit | fa203ee32375d1e1f92a5be0155b02ca46ab8ead (patch) | |
tree | 7eb76397e02397bb80e50f9337578918950c633f /Help/guide/tutorial/Complete | |
parent | a1c6d7e9af5a241b1afa29b3f7459ee9ee4ec77a (diff) | |
download | CMake-fa203ee32375d1e1f92a5be0155b02ca46ab8ead.zip CMake-fa203ee32375d1e1f92a5be0155b02ca46ab8ead.tar.gz CMake-fa203ee32375d1e1f92a5be0155b02ca46ab8ead.tar.bz2 |
Tutorial: Improve Step 10 generator expression example.
Use compiler flags and standard levels as the compelling argument
for using generator expressions and interface libraries
Diffstat (limited to 'Help/guide/tutorial/Complete')
-rw-r--r-- | Help/guide/tutorial/Complete/CMakeLists.txt | 15 | ||||
-rw-r--r-- | Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt | 17 |
2 files changed, 23 insertions, 9 deletions
diff --git a/Help/guide/tutorial/Complete/CMakeLists.txt b/Help/guide/tutorial/Complete/CMakeLists.txt index bea611c..4541392 100644 --- a/Help/guide/tutorial/Complete/CMakeLists.txt +++ b/Help/guide/tutorial/Complete/CMakeLists.txt @@ -1,8 +1,17 @@ -cmake_minimum_required(VERSION 3.3) +cmake_minimum_required(VERSION 3.15) project(Tutorial) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED True) +add_library(tutorial_compiler_flags INTERFACE) +target_compile_features(tutorial_compiler_flags INTERFACE cxx_std_11) + +# add compiler warning flags just when building this project via +# the BUILD_INTERFACE genex +set(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU>") +set(msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>") +target_compile_options(tutorial_compiler_flags INTERFACE + "$<${gcc_like_cxx}:$<BUILD_INTERFACE:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused>>" + "$<${msvc_cxx}:$<BUILD_INTERFACE:-W3>>" +) # set the version number set(Tutorial_VERSION_MAJOR 1) diff --git a/Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt b/Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt index 63c0f5f..c12955d 100644 --- a/Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt +++ b/Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt @@ -21,6 +21,7 @@ if(USE_MYMATH) # first we add the executable that generates the table add_executable(MakeTable MakeTable.cxx) + target_link_libraries(MakeTable tutorial_compiler_flags) # add the command to generate the source code add_custom_command( @@ -44,14 +45,18 @@ if(USE_MYMATH) POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS} ) - target_compile_definitions(SqrtLibrary PRIVATE - "$<$<BOOL:${HAVE_LOG}>:HAVE_LOG>" - "$<$<BOOL:${HAVE_EXP}>:HAVE_EXP>" - ) + target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags) + + + target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH") + if(HAVE_LOG AND HAVE_EXP) + target_compile_definitions(SqrtLibrary + PRIVATE "HAVE_LOG" "HAVE_EXP") + endif() target_link_libraries(MathFunctions PRIVATE SqrtLibrary) endif() -target_compile_definitions(MathFunctions PRIVATE "$<$<BOOL:${USE_MYMATH}>:USE_MYMATH>") +target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags) # define the symbol stating we are using the declspec(dllexport) when # building on windows @@ -62,7 +67,7 @@ set_property(TARGET MathFunctions PROPERTY VERSION "1.0.0") set_property(TARGET MathFunctions PROPERTY SOVERSION "1") # install rules -install(TARGETS MathFunctions +install(TARGETS MathFunctions tutorial_compiler_flags DESTINATION lib EXPORT MathFunctionsTargets) install(FILES MathFunctions.h DESTINATION include) |