summaryrefslogtreecommitdiffstats
path: root/Help/guide/tutorial
diff options
context:
space:
mode:
authorBetsy McPhail <betsy.mcphail@kitware.com>2019-07-18 19:40:25 (GMT)
committerBrad King <brad.king@kitware.com>2019-08-19 15:49:05 (GMT)
commit6f6a32a0f601688da24e1737509a0b6e1ed4f63f (patch)
treea8a6f89b0a8126172337f543ebaca43d8a0469c2 /Help/guide/tutorial
parent6a35d630dce6e9da6115cc4acb3393ce62a017ad (diff)
downloadCMake-6f6a32a0f601688da24e1737509a0b6e1ed4f63f.zip
CMake-6f6a32a0f601688da24e1737509a0b6e1ed4f63f.tar.gz
CMake-6f6a32a0f601688da24e1737509a0b6e1ed4f63f.tar.bz2
Tutorial: Improve Step 9
* Move USE_MYMATH from configured header to target_compile_definitions
Diffstat (limited to 'Help/guide/tutorial')
-rw-r--r--Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt6
-rw-r--r--Help/guide/tutorial/MultiPackage/MathFunctions/CMakeLists.txt5
-rw-r--r--Help/guide/tutorial/MultiPackage/tutorial.cxx1
-rw-r--r--Help/guide/tutorial/Step10/MathFunctions/CMakeLists.txt4
-rw-r--r--Help/guide/tutorial/Step11/MathFunctions/CMakeLists.txt5
-rw-r--r--Help/guide/tutorial/Step11/tutorial.cxx1
-rw-r--r--Help/guide/tutorial/Step9/CMakeLists.txt3
-rw-r--r--Help/guide/tutorial/Step9/MathFunctions/CMakeLists.txt4
-rw-r--r--Help/guide/tutorial/Step9/TutorialConfig.h.in3
-rw-r--r--Help/guide/tutorial/Step9/tutorial.cxx1
-rw-r--r--Help/guide/tutorial/index.rst9
11 files changed, 22 insertions, 20 deletions
diff --git a/Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt b/Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt
index 3dbf287..dfa84c9 100644
--- a/Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt
+++ b/Help/guide/tutorial/Complete/MathFunctions/CMakeLists.txt
@@ -13,6 +13,8 @@ target_include_directories(MathFunctions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
if(USE_MYMATH)
+ target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
+
# first we add the executable that generates the table
add_executable(MakeTable MakeTable.cxx)
target_link_libraries(MakeTable tutorial_compiler_flags)
@@ -35,14 +37,12 @@ if(USE_MYMATH)
${CMAKE_CURRENT_BINARY_DIR}
)
+ # state that SqrtLibrary need PIC when the default is shared libraries
set_target_properties(SqrtLibrary PROPERTIES
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
)
target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
-
-
- target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
endif()
diff --git a/Help/guide/tutorial/MultiPackage/MathFunctions/CMakeLists.txt b/Help/guide/tutorial/MultiPackage/MathFunctions/CMakeLists.txt
index 483e20c..a2df2a7 100644
--- a/Help/guide/tutorial/MultiPackage/MathFunctions/CMakeLists.txt
+++ b/Help/guide/tutorial/MultiPackage/MathFunctions/CMakeLists.txt
@@ -13,6 +13,8 @@ target_include_directories(MathFunctions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
if(USE_MYMATH)
+ target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
+
# first we add the executable that generates the table
add_executable(MakeTable MakeTable.cxx)
@@ -34,6 +36,7 @@ if(USE_MYMATH)
${CMAKE_CURRENT_BINARY_DIR}
)
+ # state that SqrtLibrary need PIC when the default is shared libraries
set_target_properties(SqrtLibrary PROPERTIES
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
)
@@ -41,8 +44,6 @@ if(USE_MYMATH)
target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
endif()
-target_compile_definitions(MathFunctions PRIVATE "$<$<BOOL:${USE_MYMATH}>:USE_MYMATH>")
-
# define the symbol stating we are using the declspec(dllexport) when
# building on windows
target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
diff --git a/Help/guide/tutorial/MultiPackage/tutorial.cxx b/Help/guide/tutorial/MultiPackage/tutorial.cxx
index ddc6364..f97805b 100644
--- a/Help/guide/tutorial/MultiPackage/tutorial.cxx
+++ b/Help/guide/tutorial/MultiPackage/tutorial.cxx
@@ -1,6 +1,5 @@
// A simple program that computes the square root of a number
#include <iostream>
-#include <sstream>
#include <string>
#include "MathFunctions.h"
diff --git a/Help/guide/tutorial/Step10/MathFunctions/CMakeLists.txt b/Help/guide/tutorial/Step10/MathFunctions/CMakeLists.txt
index 57555d3..e0c0621 100644
--- a/Help/guide/tutorial/Step10/MathFunctions/CMakeLists.txt
+++ b/Help/guide/tutorial/Step10/MathFunctions/CMakeLists.txt
@@ -11,6 +11,8 @@ target_include_directories(MathFunctions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
if(USE_MYMATH)
+ target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
+
# first we add the executable that generates the table
add_executable(MakeTable MakeTable.cxx)
@@ -37,8 +39,6 @@ if(USE_MYMATH)
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
)
- target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
-
target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
endif()
diff --git a/Help/guide/tutorial/Step11/MathFunctions/CMakeLists.txt b/Help/guide/tutorial/Step11/MathFunctions/CMakeLists.txt
index df9f4df..e6cb8ba 100644
--- a/Help/guide/tutorial/Step11/MathFunctions/CMakeLists.txt
+++ b/Help/guide/tutorial/Step11/MathFunctions/CMakeLists.txt
@@ -11,6 +11,8 @@ target_include_directories(MathFunctions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
if(USE_MYMATH)
+ target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
+
# first we add the executable that generates the table
add_executable(MakeTable MakeTable.cxx)
target_link_libraries(MakeTable tutorial_compiler_flags)
@@ -33,13 +35,12 @@ if(USE_MYMATH)
${CMAKE_CURRENT_BINARY_DIR}
)
+ # state that SqrtLibrary need PIC when the default is shared libraries
set_target_properties(SqrtLibrary PROPERTIES
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
)
target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
-
- target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
endif()
diff --git a/Help/guide/tutorial/Step11/tutorial.cxx b/Help/guide/tutorial/Step11/tutorial.cxx
index a3a2bdc..a4f44d5 100644
--- a/Help/guide/tutorial/Step11/tutorial.cxx
+++ b/Help/guide/tutorial/Step11/tutorial.cxx
@@ -1,5 +1,4 @@
// A simple program that computes the square root of a number
-#include <cmath>
#include <iostream>
#include <string>
diff --git a/Help/guide/tutorial/Step9/CMakeLists.txt b/Help/guide/tutorial/Step9/CMakeLists.txt
index f437053..d5f1cc8 100644
--- a/Help/guide/tutorial/Step9/CMakeLists.txt
+++ b/Help/guide/tutorial/Step9/CMakeLists.txt
@@ -10,7 +10,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
-# configure a header file to pass the version number only
+# configure a header file to pass some of the CMake settings
+# to the source code
configure_file(TutorialConfig.h.in TutorialConfig.h)
# add the MathFunctions library
diff --git a/Help/guide/tutorial/Step9/MathFunctions/CMakeLists.txt b/Help/guide/tutorial/Step9/MathFunctions/CMakeLists.txt
index b40b464..50f0701 100644
--- a/Help/guide/tutorial/Step9/MathFunctions/CMakeLists.txt
+++ b/Help/guide/tutorial/Step9/MathFunctions/CMakeLists.txt
@@ -22,10 +22,6 @@ target_include_directories(MathFunctions
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
)
-# use compile definitions to state if we have enabled USE_MYMATH
-# and that anything that links to use will get this define
-target_compile_definitions(MathFunctions INTERFACE "USE_MYMATH")
-
# install rules
install(TARGETS MathFunctions DESTINATION lib)
install(FILES MathFunctions.h DESTINATION include)
diff --git a/Help/guide/tutorial/Step9/TutorialConfig.h.in b/Help/guide/tutorial/Step9/TutorialConfig.h.in
index 8cd2fc9..e23f521 100644
--- a/Help/guide/tutorial/Step9/TutorialConfig.h.in
+++ b/Help/guide/tutorial/Step9/TutorialConfig.h.in
@@ -1,3 +1,4 @@
-// the configured version number
+// the configured options and settings for Tutorial
#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
+#cmakedefine USE_MYMATH
diff --git a/Help/guide/tutorial/Step9/tutorial.cxx b/Help/guide/tutorial/Step9/tutorial.cxx
index 779fbca..b3c6a4f 100644
--- a/Help/guide/tutorial/Step9/tutorial.cxx
+++ b/Help/guide/tutorial/Step9/tutorial.cxx
@@ -1,7 +1,6 @@
// A simple program that computes the square root of a number
#include <cmath>
#include <iostream>
-#include <sstream>
#include <string>
#include "TutorialConfig.h"
diff --git a/Help/guide/tutorial/index.rst b/Help/guide/tutorial/index.rst
index f6fd580..d858c25 100644
--- a/Help/guide/tutorial/index.rst
+++ b/Help/guide/tutorial/index.rst
@@ -645,7 +645,6 @@ The first step is to update the starting section of the top-level
.. literalinclude:: Step10/CMakeLists.txt
:language: cmake
- :start-after: set(CMAKE_CXX_STANDARD 14)
:end-before: # add the binary tree
Now that we have made MathFunctions always be used, we will need to update
@@ -658,7 +657,7 @@ The end result is that ``MathFunctions/CMakeLists.txt`` should look like:
.. literalinclude:: Step10/MathFunctions/CMakeLists.txt
:language: cmake
- :lines: 1-40,46-
+ :lines: 1-36,42-
Next, update ``MathFunctions/mysqrt.cxx`` to use the ``mathfunctions`` and
``detail`` namespaces:
@@ -671,6 +670,7 @@ uses ``USE_MYMATH``:
#. Always include ``MathFunctions.h``
#. Always use ``mathfunctions::sqrt``
+#. Don't include cmath
Finally, update ``MathFunctions/MathFunctions.h`` to use dll export defines:
@@ -683,9 +683,14 @@ library that has position enabled code. The solution to this is to explicitly
set the ``POSITION_INDEPENDENT_CODE`` target property of SqrtLibrary to be
True no matter the build type.
+.. literalinclude:: Step10/MathFunctions/CMakeLists.txt
+ :language: cmake
+ :lines: 37-42
+
**Exercise**: We modified ``MathFunctions.h`` to use dll export defines.
Using CMake documentation can you find a helper module to simplify this?
+
Adding Generator Expressions (Step 10)
======================================