Bläddra i källkod

Tutorial: Improve Step 3

* Move `option(USE_MYMATH...` to the same location in all CMakeLists files
Betsy McPhail 6 år sedan
förälder
incheckning
bc64401c3d

+ 3 - 3
Help/guide/tutorial/Step6/CMakeLists.txt

@@ -7,15 +7,15 @@ project(Tutorial VERSION 1.0)
 set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED True)
 
+# should we use our own math functions
+option(USE_MYMATH "Use tutorial provided math implementation" ON)
+
 # does this system provide the log and exp functions?
 include(CheckSymbolExists)
 set(CMAKE_REQUIRED_LIBRARIES "m")
 check_symbol_exists(log "math.h" HAVE_LOG)
 check_symbol_exists(exp "math.h" HAVE_EXP)
 
-# should we use our own math functions
-option(USE_MYMATH "Use tutorial provided math implementation" ON)
-
 # configure a header file to pass some of the CMake settings
 # to the source code
 configure_file(TutorialConfig.h.in TutorialConfig.h)

+ 3 - 3
Help/guide/tutorial/Step7/CMakeLists.txt

@@ -7,15 +7,15 @@ project(Tutorial VERSION 1.0)
 set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED True)
 
+# should we use our own math functions
+option(USE_MYMATH "Use tutorial provided math implementation" ON)
+
 # does this system provide the log and exp functions?
 include(CheckSymbolExists)
 set(CMAKE_REQUIRED_LIBRARIES "m")
 check_symbol_exists(log "math.h" HAVE_LOG)
 check_symbol_exists(exp "math.h" HAVE_EXP)
 
-# should we use our own math functions
-option(USE_MYMATH "Use tutorial provided math implementation" ON)
-
 # configure a header file to pass some of the CMake settings
 # to the source code
 configure_file(TutorialConfig.h.in TutorialConfig.h)

+ 3 - 3
Help/guide/tutorial/Step8/CMakeLists.txt

@@ -7,15 +7,15 @@ project(Tutorial VERSION 1.0)
 set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED True)
 
+# should we use our own math functions
+option(USE_MYMATH "Use tutorial provided math implementation" ON)
+
 # does this system provide the log and exp functions?
 include(CheckSymbolExists)
 set(CMAKE_REQUIRED_LIBRARIES "m")
 check_symbol_exists(log "math.h" HAVE_LOG)
 check_symbol_exists(exp "math.h" HAVE_EXP)
 
-# should we use our own math functions
-option(USE_MYMATH "Use tutorial provided math implementation" ON)
-
 # configure a header file to pass some of the CMake settings
 # to the source code
 configure_file(TutorialConfig.h.in TutorialConfig.h)

+ 3 - 3
Help/guide/tutorial/Step9/CMakeLists.txt

@@ -7,15 +7,15 @@ project(Tutorial VERSION 1.0)
 set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED True)
 
+# should we use our own math functions
+option(USE_MYMATH "Use tutorial provided math implementation" ON)
+
 # does this system provide the log and exp functions?
 include(CheckSymbolExists)
 set(CMAKE_REQUIRED_LIBRARIES "m")
 check_symbol_exists(log "math.h" HAVE_LOG)
 check_symbol_exists(exp "math.h" HAVE_EXP)
 
-# 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_file(TutorialConfig.h.in TutorialConfig.h)
 

+ 19 - 6
Help/guide/tutorial/index.rst

@@ -253,12 +253,14 @@ requirements are:
   - ``target_include_directories``
   - ``target_link_libraries``
 
-First up is MathFunctions. We first state that anybody linking to MathFunctions
-needs to include the current source directory, while MathFunctions itself
-doesn't. So this can become an ``INTERFACE`` usage requirement.
+Let's refactor our code from `Adding a Library (Step 2)`_ to use the modern
+CMake approach of usage requirements. We first state that anybody linking to
+MathFunctions needs to include the current source directory, while
+MathFunctions itself doesn't. So  this can become an ``INTERFACE`` usage
+requirement.
 
 Remember ``INTERFACE`` means things that consumers require but the producer
-doesn't. Update ``MathFunctions/CMakeLists.txt`` with:
+doesn't. Add the following lines to the end of ``MathFunctions/CMakeLists.txt``:
 
 .. literalinclude:: Step4/MathFunctions/CMakeLists.txt
   :language: cmake
@@ -266,7 +268,18 @@ doesn't. Update ``MathFunctions/CMakeLists.txt`` with:
 
 Now that we've specified usage requirements for MathFunctions we can safely
 remove our uses of the ``EXTRA_INCLUDES`` variable from the top-level
-CMakeLists.
+CMakeLists, here:
+
+.. literalinclude:: Step4/CMakeLists.txt
+  :language: cmake
+  :start-after: # add the MathFunctions library
+  :end-before: # add the executable
+
+And here:
+
+.. literalinclude:: Step4/CMakeLists.txt
+  :language: cmake
+  :start-after: # so that we will find TutorialConfig.h
 
 Once this is done, run **cmake** or **cmake-gui** to configure the project
 and then build it with your chosen build tool or by using ``cmake --build .``
@@ -355,7 +368,7 @@ CMakeLists file as follows:
 .. literalinclude:: Step6/CMakeLists.txt
   :language: cmake
   :start-after: # does this system provide the log and exp functions?
-  :end-before: # should we use our own math functions
+  :end-before: # configure a header file to pass some of the CMake settings
 
 Now let's add these defines to ``TutorialConfig.h.in`` so that we can use them
 from ``mysqrt.cxx``: