Przeglądaj źródła

Tutorial: Move step 10 to step 4

Shifts steps 4-9 to 5-10.
Markus Ferrell 3 lat temu
rodzic
commit
ccba87b05b
42 zmienionych plików z 224 dodań i 313 usunięć
  1. 6 6
      Help/guide/tutorial/Adding Generator Expressions.rst
  2. 4 4
      Help/guide/tutorial/Adding Support for a Testing Dashboard.rst
  3. 5 5
      Help/guide/tutorial/Adding System Introspection.rst
  4. 6 6
      Help/guide/tutorial/Adding a Custom Command and Generated File.rst
  5. 2 1
      Help/guide/tutorial/Complete/CMakeLists.txt
  6. 1 1
      Help/guide/tutorial/Complete/License.txt
  7. 4 4
      Help/guide/tutorial/Installing and Testing.rst
  8. 2 2
      Help/guide/tutorial/Packaging an Installer.rst
  9. 7 7
      Help/guide/tutorial/Selecting Static or Shared Libraries.rst
  10. 21 12
      Help/guide/tutorial/Step10/CMakeLists.txt
  11. 1 1
      Help/guide/tutorial/Step10/License.txt
  12. 21 46
      Help/guide/tutorial/Step10/MathFunctions/CMakeLists.txt
  13. 1 14
      Help/guide/tutorial/Step10/MathFunctions/MathFunctions.h
  14. 0 4
      Help/guide/tutorial/Step10/MathFunctions/mysqrt.cxx
  15. 1 0
      Help/guide/tutorial/Step10/TutorialConfig.h.in
  16. 12 3
      Help/guide/tutorial/Step10/tutorial.cxx
  17. 4 2
      Help/guide/tutorial/Step11/CMakeLists.txt
  18. 1 1
      Help/guide/tutorial/Step11/License.txt
  19. 1 1
      Help/guide/tutorial/Step11/MathFunctions/CMakeLists.txt
  20. 1 0
      Help/guide/tutorial/Step11/tutorial.cxx
  21. 2 1
      Help/guide/tutorial/Step12/CMakeLists.txt
  22. 1 1
      Help/guide/tutorial/Step12/License.txt
  23. 13 39
      Help/guide/tutorial/Step5/CMakeLists.txt
  24. 0 7
      Help/guide/tutorial/Step5/CTestConfig.cmake
  25. 1 3
      Help/guide/tutorial/Step5/MathFunctions/CMakeLists.txt
  26. 14 5
      Help/guide/tutorial/Step6/CMakeLists.txt
  27. 4 1
      Help/guide/tutorial/Step6/MathFunctions/CMakeLists.txt
  28. 13 4
      Help/guide/tutorial/Step7/CMakeLists.txt
  29. 3 23
      Help/guide/tutorial/Step7/MathFunctions/CMakeLists.txt
  30. 0 25
      Help/guide/tutorial/Step7/MathFunctions/MakeTable.cxx
  31. 0 8
      Help/guide/tutorial/Step7/MathFunctions/mysqrt.cxx
  32. 14 4
      Help/guide/tutorial/Step8/CMakeLists.txt
  33. 0 2
      Help/guide/tutorial/Step8/License.txt
  34. 28 20
      Help/guide/tutorial/Step8/MathFunctions/CMakeLists.txt
  35. 8 9
      Help/guide/tutorial/Step8/MathFunctions/mysqrt.cxx
  36. 13 12
      Help/guide/tutorial/Step9/CMakeLists.txt
  37. 1 1
      Help/guide/tutorial/Step9/License.txt
  38. 6 1
      Help/guide/tutorial/Step9/MathFunctions/CMakeLists.txt
  39. 0 19
      Help/guide/tutorial/Step9/MathFunctions/MathFunctions.cxx
  40. 0 6
      Help/guide/tutorial/Step9/MathFunctions/mysqrt.h
  41. 1 1
      Help/guide/tutorial/index.rst
  42. 1 1
      Tests/CMakeLists.txt

+ 6 - 6
Help/guide/tutorial/Adding Generator Expressions.rst

@@ -1,4 +1,4 @@
-Step 10: Adding Generator Expressions
+Step 4: Adding Generator Expressions
 =====================================
 =====================================
 
 
 :manual:`Generator expressions <cmake-generator-expressions(7)>` are evaluated
 :manual:`Generator expressions <cmake-generator-expressions(7)>` are evaluated
@@ -37,16 +37,16 @@ instead of using :variable:`CMAKE_CXX_STANDARD`.
 
 
 So the following code:
 So the following code:
 
 
-.. literalinclude:: Step10/CMakeLists.txt
+.. literalinclude:: Step4/CMakeLists.txt
   :caption: CMakeLists.txt
   :caption: CMakeLists.txt
   :name: CMakeLists.txt-CXX_STANDARD-variable-remove
   :name: CMakeLists.txt-CXX_STANDARD-variable-remove
   :language: cmake
   :language: cmake
   :start-after: project(Tutorial VERSION 1.0)
   :start-after: project(Tutorial VERSION 1.0)
-  :end-before: # control where the static and shared libraries are built so that on windows
+  :end-before: # should we use our own math functions
 
 
 Would be replaced with:
 Would be replaced with:
 
 
-.. literalinclude:: Step11/CMakeLists.txt
+.. literalinclude:: Step5/CMakeLists.txt
   :caption: CMakeLists.txt
   :caption: CMakeLists.txt
   :name: CMakeLists.txt-cxx_std-feature
   :name: CMakeLists.txt-cxx_std-feature
   :language: cmake
   :language: cmake
@@ -69,12 +69,12 @@ warning flags vary based on the compiler we use the ``COMPILE_LANG_AND_ID``
 generator expression to control which flags to apply given a language and a set
 generator expression to control which flags to apply given a language and a set
 of compiler ids as seen below:
 of compiler ids as seen below:
 
 
-.. literalinclude:: Step11/CMakeLists.txt
+.. literalinclude:: Step5/CMakeLists.txt
   :caption: CMakeLists.txt
   :caption: CMakeLists.txt
   :name: CMakeLists.txt-target_compile_options-genex
   :name: CMakeLists.txt-target_compile_options-genex
   :language: cmake
   :language: cmake
   :start-after: # the BUILD_INTERFACE genex
   :start-after: # the BUILD_INTERFACE genex
-  :end-before: # control where the static and shared libraries are built so that on windows
+  :end-before: # should we use our own math functions
 
 
 Looking at this we see that the warning flags are encapsulated inside a
 Looking at this we see that the warning flags are encapsulated inside a
 ``BUILD_INTERFACE`` condition. This is done so that consumers of our installed
 ``BUILD_INTERFACE`` condition. This is done so that consumers of our installed

+ 4 - 4
Help/guide/tutorial/Adding Support for a Testing Dashboard.rst

@@ -1,4 +1,4 @@
-Step 5: Adding Support for a Testing Dashboard
+Step 6: Adding Support for a Testing Dashboard
 ==============================================
 ==============================================
 
 
 Adding support for submitting our test results to a dashboard is simple. We
 Adding support for submitting our test results to a dashboard is simple. We
@@ -9,7 +9,7 @@ we include the :module:`CTest` module in our top-level ``CMakeLists.txt``.
 
 
 Replace:
 Replace:
 
 
-.. literalinclude:: Step5/CMakeLists.txt
+.. literalinclude:: Step6/CMakeLists.txt
   :caption: CMakeLists.txt
   :caption: CMakeLists.txt
   :name: CMakeLists.txt-enable_testing-remove
   :name: CMakeLists.txt-enable_testing-remove
   :language: cmake
   :language: cmake
@@ -18,7 +18,7 @@ Replace:
 
 
 With:
 With:
 
 
-.. literalinclude:: Step6/CMakeLists.txt
+.. literalinclude:: Step7/CMakeLists.txt
   :caption: CMakeLists.txt
   :caption: CMakeLists.txt
   :name: CMakeLists.txt-include-CTest
   :name: CMakeLists.txt-include-CTest
   :language: cmake
   :language: cmake
@@ -46,7 +46,7 @@ downloaded from the ``Settings`` page of the project on the CDash
 instance that will host and display the test results.  Once downloaded from
 instance that will host and display the test results.  Once downloaded from
 CDash, the file should not be modified locally.
 CDash, the file should not be modified locally.
 
 
-.. literalinclude:: Step6/CTestConfig.cmake
+.. literalinclude:: Step7/CTestConfig.cmake
   :caption: CTestConfig.cmake
   :caption: CTestConfig.cmake
   :name: CTestConfig.cmake
   :name: CTestConfig.cmake
   :language: cmake
   :language: cmake

+ 5 - 5
Help/guide/tutorial/Adding System Introspection.rst

@@ -1,4 +1,4 @@
-Step 6: Adding System Introspection
+Step 7: Adding System Introspection
 ===================================
 ===================================
 
 
 Let us consider adding some code to our project that depends on features the
 Let us consider adding some code to our project that depends on features the
@@ -15,7 +15,7 @@ these functions using the :module:`CheckCXXSourceCompiles` module in
 Add the checks for ``log`` and ``exp`` to ``MathFunctions/CMakeLists.txt``,
 Add the checks for ``log`` and ``exp`` to ``MathFunctions/CMakeLists.txt``,
 after the call to :command:`target_include_directories`:
 after the call to :command:`target_include_directories`:
 
 
-.. literalinclude:: Step7/MathFunctions/CMakeLists.txt
+.. literalinclude:: Step8/MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :name: MathFunctions/CMakeLists.txt-check_cxx_source_compiles
   :name: MathFunctions/CMakeLists.txt-check_cxx_source_compiles
   :language: cmake
   :language: cmake
@@ -25,7 +25,7 @@ after the call to :command:`target_include_directories`:
 If available, use :command:`target_compile_definitions` to specify
 If available, use :command:`target_compile_definitions` to specify
 ``HAVE_LOG`` and ``HAVE_EXP`` as ``PRIVATE`` compile definitions.
 ``HAVE_LOG`` and ``HAVE_EXP`` as ``PRIVATE`` compile definitions.
 
 
-.. literalinclude:: Step7/MathFunctions/CMakeLists.txt
+.. literalinclude:: Step8/MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :name: MathFunctions/CMakeLists.txt-target_compile_definitions
   :name: MathFunctions/CMakeLists.txt-target_compile_definitions
   :language: cmake
   :language: cmake
@@ -37,7 +37,7 @@ compute the square root in the ``mysqrt`` function. Add the following code to
 the ``mysqrt`` function in ``MathFunctions/mysqrt.cxx`` (don't forget the
 the ``mysqrt`` function in ``MathFunctions/mysqrt.cxx`` (don't forget the
 ``#endif`` before returning the result!):
 ``#endif`` before returning the result!):
 
 
-.. literalinclude:: Step7/MathFunctions/mysqrt.cxx
+.. literalinclude:: Step8/MathFunctions/mysqrt.cxx
   :caption: MathFunctions/mysqrt.cxx
   :caption: MathFunctions/mysqrt.cxx
   :name: MathFunctions/mysqrt.cxx-ifdef
   :name: MathFunctions/mysqrt.cxx-ifdef
   :language: c++
   :language: c++
@@ -46,7 +46,7 @@ the ``mysqrt`` function in ``MathFunctions/mysqrt.cxx`` (don't forget the
 
 
 We will also need to modify ``mysqrt.cxx`` to include ``cmath``.
 We will also need to modify ``mysqrt.cxx`` to include ``cmath``.
 
 
-.. literalinclude:: Step7/MathFunctions/mysqrt.cxx
+.. literalinclude:: Step8/MathFunctions/mysqrt.cxx
   :caption: MathFunctions/mysqrt.cxx
   :caption: MathFunctions/mysqrt.cxx
   :name: MathFunctions/mysqrt.cxx-include-cmath
   :name: MathFunctions/mysqrt.cxx-include-cmath
   :language: c++
   :language: c++

+ 6 - 6
Help/guide/tutorial/Adding a Custom Command and Generated File.rst

@@ -1,4 +1,4 @@
-Step 7: Adding a Custom Command and Generated File
+Step 8: Adding a Custom Command and Generated File
 ==================================================
 ==================================================
 
 
 Suppose, for the purpose of this tutorial, we decide that we never want to use
 Suppose, for the purpose of this tutorial, we decide that we never want to use
@@ -26,7 +26,7 @@ accomplish this.
 First, at the top of ``MathFunctions/CMakeLists.txt``, the executable for
 First, at the top of ``MathFunctions/CMakeLists.txt``, the executable for
 ``MakeTable`` is added as any other executable would be added.
 ``MakeTable`` is added as any other executable would be added.
 
 
-.. literalinclude:: Step8/MathFunctions/CMakeLists.txt
+.. literalinclude:: Step9/MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :name: MathFunctions/CMakeLists.txt-add_executable-MakeTable
   :name: MathFunctions/CMakeLists.txt-add_executable-MakeTable
   :language: cmake
   :language: cmake
@@ -36,7 +36,7 @@ First, at the top of ``MathFunctions/CMakeLists.txt``, the executable for
 Then we add a custom command that specifies how to produce ``Table.h``
 Then we add a custom command that specifies how to produce ``Table.h``
 by running MakeTable.
 by running MakeTable.
 
 
-.. literalinclude:: Step8/MathFunctions/CMakeLists.txt
+.. literalinclude:: Step9/MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :name: MathFunctions/CMakeLists.txt-add_custom_command-Table.h
   :name: MathFunctions/CMakeLists.txt-add_custom_command-Table.h
   :language: cmake
   :language: cmake
@@ -47,7 +47,7 @@ Next we have to let CMake know that ``mysqrt.cxx`` depends on the generated
 file ``Table.h``. This is done by adding the generated ``Table.h`` to the list
 file ``Table.h``. This is done by adding the generated ``Table.h`` to the list
 of sources for the library MathFunctions.
 of sources for the library MathFunctions.
 
 
-.. literalinclude:: Step8/MathFunctions/CMakeLists.txt
+.. literalinclude:: Step9/MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :name: MathFunctions/CMakeLists.txt-add_library-Table.h
   :name: MathFunctions/CMakeLists.txt-add_library-Table.h
   :language: cmake
   :language: cmake
@@ -57,7 +57,7 @@ of sources for the library MathFunctions.
 We also have to add the current binary directory to the list of include
 We also have to add the current binary directory to the list of include
 directories so that ``Table.h`` can be found and included by ``mysqrt.cxx``.
 directories so that ``Table.h`` can be found and included by ``mysqrt.cxx``.
 
 
-.. literalinclude:: Step8/MathFunctions/CMakeLists.txt
+.. literalinclude:: Step9/MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :name: MathFunctions/CMakeLists.txt-target_include_directories-Table.h
   :name: MathFunctions/CMakeLists.txt-target_include_directories-Table.h
   :language: cmake
   :language: cmake
@@ -67,7 +67,7 @@ directories so that ``Table.h`` can be found and included by ``mysqrt.cxx``.
 Now let's use the generated table. First, modify ``mysqrt.cxx`` to include
 Now let's use the generated table. First, modify ``mysqrt.cxx`` to include
 ``Table.h``. Next, we can rewrite the ``mysqrt`` function to use the table:
 ``Table.h``. Next, we can rewrite the ``mysqrt`` function to use the table:
 
 
-.. literalinclude:: Step8/MathFunctions/mysqrt.cxx
+.. literalinclude:: Step9/MathFunctions/mysqrt.cxx
   :caption: MathFunctions/mysqrt.cxx
   :caption: MathFunctions/mysqrt.cxx
   :name: MathFunctions/mysqrt.cxx
   :name: MathFunctions/mysqrt.cxx
   :language: c++
   :language: c++

+ 2 - 1
Help/guide/tutorial/Complete/CMakeLists.txt

@@ -41,7 +41,7 @@ add_subdirectory(MathFunctions)
 add_executable(Tutorial tutorial.cxx)
 add_executable(Tutorial tutorial.cxx)
 set_target_properties(Tutorial PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
 set_target_properties(Tutorial PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
 
 
-target_link_libraries(Tutorial PUBLIC MathFunctions)
+target_link_libraries(Tutorial PUBLIC MathFunctions tutorial_compiler_flags)
 
 
 # add the binary tree to the search path for include files
 # add the binary tree to the search path for include files
 # so that we will find TutorialConfig.h
 # so that we will find TutorialConfig.h
@@ -84,6 +84,7 @@ do_test(Tutorial 25 "25 is 5")
 do_test(Tutorial -25 "-25 is (-nan|nan|0)")
 do_test(Tutorial -25 "-25 is (-nan|nan|0)")
 do_test(Tutorial 0.0001 "0.0001 is 0.01")
 do_test(Tutorial 0.0001 "0.0001 is 0.01")
 
 
+# setup installer
 include(InstallRequiredSystemLibraries)
 include(InstallRequiredSystemLibraries)
 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
 set(CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")
 set(CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")

+ 1 - 1
Help/guide/tutorial/Complete/License.txt

@@ -1,2 +1,2 @@
 This is the open source License.txt file introduced in
 This is the open source License.txt file introduced in
-CMake/Tutorial/Step7...
+CMake/Tutorial/Step9...

+ 4 - 4
Help/guide/tutorial/Installing and Testing.rst

@@ -1,4 +1,4 @@
-Step 4: Installing and Testing
+Step 5: Installing and Testing
 ==============================
 ==============================
 
 
 Now we can start adding install rules and testing support to our project.
 Now we can start adding install rules and testing support to our project.
@@ -12,7 +12,7 @@ executable and configured header.
 
 
 So to the end of ``MathFunctions/CMakeLists.txt`` we add:
 So to the end of ``MathFunctions/CMakeLists.txt`` we add:
 
 
-.. literalinclude:: Step5/MathFunctions/CMakeLists.txt
+.. literalinclude:: Step6/MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :name: MathFunctions/CMakeLists.txt-install-TARGETS
   :name: MathFunctions/CMakeLists.txt-install-TARGETS
   :language: cmake
   :language: cmake
@@ -20,7 +20,7 @@ So to the end of ``MathFunctions/CMakeLists.txt`` we add:
 
 
 And to the end of the top-level ``CMakeLists.txt`` we add:
 And to the end of the top-level ``CMakeLists.txt`` we add:
 
 
-.. literalinclude:: Step5/CMakeLists.txt
+.. literalinclude:: Step6/CMakeLists.txt
   :caption: CMakeLists.txt
   :caption: CMakeLists.txt
   :name: CMakeLists.txt-install-TARGETS
   :name: CMakeLists.txt-install-TARGETS
   :language: cmake
   :language: cmake
@@ -65,7 +65,7 @@ Next let's test our application. At the end of the top-level ``CMakeLists.txt``
 file we can enable testing and then add a number of basic tests to verify that
 file we can enable testing and then add a number of basic tests to verify that
 the application is working correctly.
 the application is working correctly.
 
 
-.. literalinclude:: Step5/CMakeLists.txt
+.. literalinclude:: Step6/CMakeLists.txt
   :caption: CMakeLists.txt
   :caption: CMakeLists.txt
   :name: CMakeLists.txt-enable_testing
   :name: CMakeLists.txt-enable_testing
   :language: cmake
   :language: cmake

+ 2 - 2
Help/guide/tutorial/Packaging an Installer.rst

@@ -1,4 +1,4 @@
-Step 8: Packaging an Installer
+Step 9: Packaging an Installer
 ==============================
 ==============================
 
 
 Next suppose that we want to distribute our project to other people so that
 Next suppose that we want to distribute our project to other people so that
@@ -11,7 +11,7 @@ installations and package management features. To accomplish this we will use
 CPack to create platform specific installers. Specifically we need to add a
 CPack to create platform specific installers. Specifically we need to add a
 few lines to the bottom of our top-level ``CMakeLists.txt`` file.
 few lines to the bottom of our top-level ``CMakeLists.txt`` file.
 
 
-.. literalinclude:: Step9/CMakeLists.txt
+.. literalinclude:: Step10/CMakeLists.txt
   :caption: CMakeLists.txt
   :caption: CMakeLists.txt
   :name: CMakeLists.txt-include-CPack
   :name: CMakeLists.txt-include-CPack
   :language: cmake
   :language: cmake

+ 7 - 7
Help/guide/tutorial/Selecting Static or Shared Libraries.rst

@@ -1,5 +1,5 @@
-Step 9: Selecting Static or Shared Libraries
-============================================
+Step 10: Selecting Static or Shared Libraries
+=============================================
 
 
 In this section we will show how the :variable:`BUILD_SHARED_LIBS` variable can
 In this section we will show how the :variable:`BUILD_SHARED_LIBS` variable can
 be used to control the default behavior of :command:`add_library`,
 be used to control the default behavior of :command:`add_library`,
@@ -19,7 +19,7 @@ library.
 The first step is to update the starting section of the top-level
 The first step is to update the starting section of the top-level
 ``CMakeLists.txt`` to look like:
 ``CMakeLists.txt`` to look like:
 
 
-.. literalinclude:: Step10/CMakeLists.txt
+.. literalinclude:: Step11/CMakeLists.txt
   :caption: CMakeLists.txt
   :caption: CMakeLists.txt
   :name: CMakeLists.txt-option-BUILD_SHARED_LIBS
   :name: CMakeLists.txt-option-BUILD_SHARED_LIBS
   :language: cmake
   :language: cmake
@@ -33,7 +33,7 @@ explicitly require that SqrtLibrary is built statically.
 
 
 The end result is that ``MathFunctions/CMakeLists.txt`` should look like:
 The end result is that ``MathFunctions/CMakeLists.txt`` should look like:
 
 
-.. literalinclude:: Step10/MathFunctions/CMakeLists.txt
+.. literalinclude:: Step11/MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :name: MathFunctions/CMakeLists.txt-add_library-STATIC
   :name: MathFunctions/CMakeLists.txt-add_library-STATIC
   :language: cmake
   :language: cmake
@@ -42,7 +42,7 @@ The end result is that ``MathFunctions/CMakeLists.txt`` should look like:
 Next, update ``MathFunctions/mysqrt.cxx`` to use the ``mathfunctions`` and
 Next, update ``MathFunctions/mysqrt.cxx`` to use the ``mathfunctions`` and
 ``detail`` namespaces:
 ``detail`` namespaces:
 
 
-.. literalinclude:: Step10/MathFunctions/mysqrt.cxx
+.. literalinclude:: Step11/MathFunctions/mysqrt.cxx
   :caption: MathFunctions/mysqrt.cxx
   :caption: MathFunctions/mysqrt.cxx
   :name: MathFunctions/mysqrt.cxx-namespace
   :name: MathFunctions/mysqrt.cxx-namespace
   :language: c++
   :language: c++
@@ -56,7 +56,7 @@ uses ``USE_MYMATH``:
 
 
 Finally, update ``MathFunctions/MathFunctions.h`` to use dll export defines:
 Finally, update ``MathFunctions/MathFunctions.h`` to use dll export defines:
 
 
-.. literalinclude:: Step10/MathFunctions/MathFunctions.h
+.. literalinclude:: Step11/MathFunctions/MathFunctions.h
   :caption: MathFunctions/MathFunctions.h
   :caption: MathFunctions/MathFunctions.h
   :name: MathFunctions/MathFunctions.h
   :name: MathFunctions/MathFunctions.h
   :language: c++
   :language: c++
@@ -67,7 +67,7 @@ library that has position independent code. The solution to this is to
 explicitly set the :prop_tgt:`POSITION_INDEPENDENT_CODE` target property of
 explicitly set the :prop_tgt:`POSITION_INDEPENDENT_CODE` target property of
 SqrtLibrary to be ``True`` no matter the build type.
 SqrtLibrary to be ``True`` no matter the build type.
 
 
-.. literalinclude:: Step10/MathFunctions/CMakeLists.txt
+.. literalinclude:: Step11/MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :caption: MathFunctions/CMakeLists.txt
   :name: MathFunctions/CMakeLists.txt-POSITION_INDEPENDENT_CODE
   :name: MathFunctions/CMakeLists.txt-POSITION_INDEPENDENT_CODE
   :language: cmake
   :language: cmake

+ 21 - 12
Help/guide/tutorial/Step10/CMakeLists.txt

@@ -1,29 +1,37 @@
-cmake_minimum_required(VERSION 3.10)
+cmake_minimum_required(VERSION 3.15)
 
 
 # set the project name and version
 # set the project name and version
 project(Tutorial VERSION 1.0)
 project(Tutorial VERSION 1.0)
 
 
 # specify the C++ standard
 # specify the C++ standard
-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)
 
 
-# control where the static and shared libraries are built so that on windows
-# we don't need to tinker with the path to run the executable
-set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
-set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
+# 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,LCC>")
+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>>"
+)
 
 
-option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
+# 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)
 configure_file(TutorialConfig.h.in TutorialConfig.h)
 
 
 # add the MathFunctions library
 # add the MathFunctions library
-add_subdirectory(MathFunctions)
+if(USE_MYMATH)
+  add_subdirectory(MathFunctions)
+  list(APPEND EXTRA_LIBS MathFunctions)
+endif()
 
 
 # add the executable
 # add the executable
 add_executable(Tutorial tutorial.cxx)
 add_executable(Tutorial tutorial.cxx)
-target_link_libraries(Tutorial PUBLIC MathFunctions)
+target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS} tutorial_compiler_flags)
 
 
 # add the binary tree to the search path for include files
 # add the binary tree to the search path for include files
 # so that we will find TutorialConfig.h
 # so that we will find TutorialConfig.h
@@ -66,6 +74,7 @@ do_test(Tutorial 25 "25 is 5")
 do_test(Tutorial -25 "-25 is (-nan|nan|0)")
 do_test(Tutorial -25 "-25 is (-nan|nan|0)")
 do_test(Tutorial 0.0001 "0.0001 is 0.01")
 do_test(Tutorial 0.0001 "0.0001 is 0.01")
 
 
+# setup installer
 include(InstallRequiredSystemLibraries)
 include(InstallRequiredSystemLibraries)
 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
 set(CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")
 set(CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")

+ 1 - 1
Help/guide/tutorial/Step10/License.txt

@@ -1,2 +1,2 @@
 This is the open source License.txt file introduced in
 This is the open source License.txt file introduced in
-CMake/Tutorial/Step7...
+CMake/Tutorial/Step9...

+ 21 - 46
Help/guide/tutorial/Step10/MathFunctions/CMakeLists.txt

@@ -1,55 +1,30 @@
-# add the library that runs
-add_library(MathFunctions MathFunctions.cxx)
+# first we add the executable that generates the table
+add_executable(MakeTable MakeTable.cxx)
+
+# add the command to generate the source code
+add_custom_command(
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+  COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+  DEPENDS MakeTable
+  )
+
+# add the main library
+add_library(MathFunctions
+            mysqrt.cxx
+            ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+            )
 
 
 # state that anybody linking to us needs to include the current source dir
 # state that anybody linking to us needs to include the current source dir
 # to find MathFunctions.h, while we don't.
 # to find MathFunctions.h, while we don't.
+# state that we depend on our binary dir to find Table.h
 target_include_directories(MathFunctions
 target_include_directories(MathFunctions
-                           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
-                           )
+          INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
+          PRIVATE   ${CMAKE_CURRENT_BINARY_DIR}
+          )
 
 
-# should we use our own math functions
-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)
-
-  # add the command to generate the source code
-  add_custom_command(
-    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
-    COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
-    DEPENDS MakeTable
-    )
-
-  # library that just does sqrt
-  add_library(SqrtLibrary STATIC
-              mysqrt.cxx
-              ${CMAKE_CURRENT_BINARY_DIR}/Table.h
-              )
-
-  # state that we depend on our binary dir to find Table.h
-  target_include_directories(SqrtLibrary PRIVATE
-                             ${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(MathFunctions PRIVATE SqrtLibrary)
-endif()
-
-# define the symbol stating we are using the declspec(dllexport) when
-# building on windows
-target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
+target_link_libraries(MathFunctions tutorial_compiler_flags)
 
 
 # install rules
 # install rules
-set(installable_libs MathFunctions)
-if(TARGET SqrtLibrary)
-  list(APPEND installable_libs SqrtLibrary)
-endif()
+set(installable_libs MathFunctions tutorial_compiler_flags)
 install(TARGETS ${installable_libs} DESTINATION lib)
 install(TARGETS ${installable_libs} DESTINATION lib)
 install(FILES MathFunctions.h DESTINATION include)
 install(FILES MathFunctions.h DESTINATION include)

+ 1 - 14
Help/guide/tutorial/Step10/MathFunctions/MathFunctions.h

@@ -1,14 +1 @@
-
-#if defined(_WIN32)
-#  if defined(EXPORTING_MYMATH)
-#    define DECLSPEC __declspec(dllexport)
-#  else
-#    define DECLSPEC __declspec(dllimport)
-#  endif
-#else // non windows
-#  define DECLSPEC
-#endif
-
-namespace mathfunctions {
-double DECLSPEC sqrt(double x);
-}
+double mysqrt(double x);

+ 0 - 4
Help/guide/tutorial/Step10/MathFunctions/mysqrt.cxx

@@ -5,8 +5,6 @@
 // include the generated table
 // include the generated table
 #include "Table.h"
 #include "Table.h"
 
 
-namespace mathfunctions {
-namespace detail {
 // a hack square root calculation using simple operations
 // a hack square root calculation using simple operations
 double mysqrt(double x)
 double mysqrt(double x)
 {
 {
@@ -33,5 +31,3 @@ double mysqrt(double x)
 
 
   return result;
   return result;
 }
 }
-}
-}

+ 1 - 0
Help/guide/tutorial/Step10/TutorialConfig.h.in

@@ -1,3 +1,4 @@
 // the configured options and settings for Tutorial
 // the configured options and settings for Tutorial
 #define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
 #define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
 #define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
 #define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
+#cmakedefine USE_MYMATH

+ 12 - 3
Help/guide/tutorial/Step10/tutorial.cxx

@@ -1,11 +1,15 @@
 // A simple program that computes the square root of a number
 // A simple program that computes the square root of a number
+#include <cmath>
 #include <iostream>
 #include <iostream>
-#include <sstream>
 #include <string>
 #include <string>
 
 
-#include "MathFunctions.h"
 #include "TutorialConfig.h"
 #include "TutorialConfig.h"
 
 
+// should we include the MathFunctions header?
+#ifdef USE_MYMATH
+#  include "MathFunctions.h"
+#endif
+
 int main(int argc, char* argv[])
 int main(int argc, char* argv[])
 {
 {
   if (argc < 2) {
   if (argc < 2) {
@@ -19,7 +23,12 @@ int main(int argc, char* argv[])
   // convert input to double
   // convert input to double
   const double inputValue = std::stod(argv[1]);
   const double inputValue = std::stod(argv[1]);
 
 
-  const double outputValue = mathfunctions::sqrt(inputValue);
+  // which square root function should we use?
+#ifdef USE_MYMATH
+  const double outputValue = mysqrt(inputValue);
+#else
+  const double outputValue = sqrt(inputValue);
+#endif
 
 
   std::cout << "The square root of " << inputValue << " is " << outputValue
   std::cout << "The square root of " << inputValue << " is " << outputValue
             << std::endl;
             << std::endl;

+ 4 - 2
Help/guide/tutorial/Step11/CMakeLists.txt

@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.15)
 # set the project name and version
 # set the project name and version
 project(Tutorial VERSION 1.0)
 project(Tutorial VERSION 1.0)
 
 
+# specify the C++ standard
 add_library(tutorial_compiler_flags INTERFACE)
 add_library(tutorial_compiler_flags INTERFACE)
 target_compile_features(tutorial_compiler_flags INTERFACE cxx_std_11)
 target_compile_features(tutorial_compiler_flags INTERFACE cxx_std_11)
 
 
@@ -31,7 +32,7 @@ add_subdirectory(MathFunctions)
 
 
 # add the executable
 # add the executable
 add_executable(Tutorial tutorial.cxx)
 add_executable(Tutorial tutorial.cxx)
-target_link_libraries(Tutorial PUBLIC MathFunctions)
+target_link_libraries(Tutorial PUBLIC MathFunctions tutorial_compiler_flags)
 
 
 # add the binary tree to the search path for include files
 # add the binary tree to the search path for include files
 # so that we will find TutorialConfig.h
 # so that we will find TutorialConfig.h
@@ -46,7 +47,7 @@ install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
   )
   )
 
 
 # enable testing
 # enable testing
-enable_testing()
+include(CTest)
 
 
 # does the application run
 # does the application run
 add_test(NAME Runs COMMAND Tutorial 25)
 add_test(NAME Runs COMMAND Tutorial 25)
@@ -74,6 +75,7 @@ do_test(Tutorial 25 "25 is 5")
 do_test(Tutorial -25 "-25 is (-nan|nan|0)")
 do_test(Tutorial -25 "-25 is (-nan|nan|0)")
 do_test(Tutorial 0.0001 "0.0001 is 0.01")
 do_test(Tutorial 0.0001 "0.0001 is 0.01")
 
 
+# setup installer
 include(InstallRequiredSystemLibraries)
 include(InstallRequiredSystemLibraries)
 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
 set(CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")
 set(CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")

+ 1 - 1
Help/guide/tutorial/Step11/License.txt

@@ -1,2 +1,2 @@
 This is the open source License.txt file introduced in
 This is the open source License.txt file introduced in
-CMake/Tutorial/Step7...
+CMake/Tutorial/Step9...

+ 1 - 1
Help/guide/tutorial/Step11/MathFunctions/CMakeLists.txt

@@ -47,7 +47,7 @@ endif()
 target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
 target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
 
 
 # define the symbol stating we are using the declspec(dllexport) when
 # define the symbol stating we are using the declspec(dllexport) when
-#building on windows
+# building on windows
 target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
 target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
 
 
 # install rules
 # install rules

+ 1 - 0
Help/guide/tutorial/Step11/tutorial.cxx

@@ -1,5 +1,6 @@
 // A simple program that computes the square root of a number
 // A simple program that computes the square root of a number
 #include <iostream>
 #include <iostream>
+#include <sstream>
 #include <string>
 #include <string>
 
 
 #include "MathFunctions.h"
 #include "MathFunctions.h"

+ 2 - 1
Help/guide/tutorial/Step12/CMakeLists.txt

@@ -37,7 +37,7 @@ add_subdirectory(MathFunctions)
 
 
 # add the executable
 # add the executable
 add_executable(Tutorial tutorial.cxx)
 add_executable(Tutorial tutorial.cxx)
-target_link_libraries(Tutorial PUBLIC MathFunctions)
+target_link_libraries(Tutorial PUBLIC MathFunctions tutorial_compiler_flags)
 
 
 # add the binary tree to the search path for include files
 # add the binary tree to the search path for include files
 # so that we will find TutorialConfig.h
 # so that we will find TutorialConfig.h
@@ -80,6 +80,7 @@ do_test(Tutorial 25 "25 is 5")
 do_test(Tutorial -25 "-25 is (-nan|nan|0)")
 do_test(Tutorial -25 "-25 is (-nan|nan|0)")
 do_test(Tutorial 0.0001 "0.0001 is 0.01")
 do_test(Tutorial 0.0001 "0.0001 is 0.01")
 
 
+# setup installer
 include(InstallRequiredSystemLibraries)
 include(InstallRequiredSystemLibraries)
 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
 set(CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")
 set(CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")

+ 1 - 1
Help/guide/tutorial/Step12/License.txt

@@ -1,2 +1,2 @@
 This is the open source License.txt file introduced in
 This is the open source License.txt file introduced in
-CMake/Tutorial/Step7...
+CMake/Tutorial/Step9...

+ 13 - 39
Help/guide/tutorial/Step5/CMakeLists.txt

@@ -1,11 +1,20 @@
-cmake_minimum_required(VERSION 3.10)
+cmake_minimum_required(VERSION 3.15)
 
 
 # set the project name and version
 # set the project name and version
 project(Tutorial VERSION 1.0)
 project(Tutorial VERSION 1.0)
 
 
 # specify the C++ standard
 # specify the C++ standard
-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,LCC>")
+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>>"
+)
 
 
 # should we use our own math functions
 # should we use our own math functions
 option(USE_MYMATH "Use tutorial provided math implementation" ON)
 option(USE_MYMATH "Use tutorial provided math implementation" ON)
@@ -22,45 +31,10 @@ endif()
 
 
 # add the executable
 # add the executable
 add_executable(Tutorial tutorial.cxx)
 add_executable(Tutorial tutorial.cxx)
-target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
+target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS} tutorial_compiler_flags)
 
 
 # add the binary tree to the search path for include files
 # add the binary tree to the search path for include files
 # so that we will find TutorialConfig.h
 # so that we will find TutorialConfig.h
 target_include_directories(Tutorial PUBLIC
 target_include_directories(Tutorial PUBLIC
                            "${PROJECT_BINARY_DIR}"
                            "${PROJECT_BINARY_DIR}"
                            )
                            )
-
-# add the install targets
-install(TARGETS Tutorial DESTINATION bin)
-install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
-  DESTINATION include
-  )
-
-# enable testing
-enable_testing()
-
-# does the application run
-add_test(NAME Runs COMMAND Tutorial 25)
-
-# does the usage message work?
-add_test(NAME Usage COMMAND Tutorial)
-set_tests_properties(Usage
-  PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number"
-  )
-
-# define a function to simplify adding tests
-function(do_test target arg result)
-  add_test(NAME Comp${arg} COMMAND ${target} ${arg})
-  set_tests_properties(Comp${arg}
-    PROPERTIES PASS_REGULAR_EXPRESSION ${result}
-    )
-endfunction()
-
-# do a bunch of result based tests
-do_test(Tutorial 4 "4 is 2")
-do_test(Tutorial 9 "9 is 3")
-do_test(Tutorial 5 "5 is 2.236")
-do_test(Tutorial 7 "7 is 2.645")
-do_test(Tutorial 25 "25 is 5")
-do_test(Tutorial -25 "-25 is (-nan|nan|0)")
-do_test(Tutorial 0.0001 "0.0001 is 0.01")

+ 0 - 7
Help/guide/tutorial/Step5/CTestConfig.cmake

@@ -1,7 +0,0 @@
-set(CTEST_PROJECT_NAME "CMakeTutorial")
-set(CTEST_NIGHTLY_START_TIME "00:00:00 EST")
-
-set(CTEST_DROP_METHOD "http")
-set(CTEST_DROP_SITE "my.cdash.org")
-set(CTEST_DROP_LOCATION "/submit.php?project=CMakeTutorial")
-set(CTEST_DROP_SITE_CDASH TRUE)

+ 1 - 3
Help/guide/tutorial/Step5/MathFunctions/CMakeLists.txt

@@ -6,6 +6,4 @@ target_include_directories(MathFunctions
           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
           )
           )
 
 
-# install rules
-install(TARGETS MathFunctions DESTINATION lib)
-install(FILES MathFunctions.h DESTINATION include)
+target_link_libraries(MathFunctions tutorial_compiler_flags)

+ 14 - 5
Help/guide/tutorial/Step6/CMakeLists.txt

@@ -1,11 +1,20 @@
-cmake_minimum_required(VERSION 3.10)
+cmake_minimum_required(VERSION 3.15)
 
 
 # set the project name and version
 # set the project name and version
 project(Tutorial VERSION 1.0)
 project(Tutorial VERSION 1.0)
 
 
 # specify the C++ standard
 # specify the C++ standard
-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,LCC>")
+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>>"
+)
 
 
 # should we use our own math functions
 # should we use our own math functions
 option(USE_MYMATH "Use tutorial provided math implementation" ON)
 option(USE_MYMATH "Use tutorial provided math implementation" ON)
@@ -22,7 +31,7 @@ endif()
 
 
 # add the executable
 # add the executable
 add_executable(Tutorial tutorial.cxx)
 add_executable(Tutorial tutorial.cxx)
-target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
+target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS} tutorial_compiler_flags)
 
 
 # add the binary tree to the search path for include files
 # add the binary tree to the search path for include files
 # so that we will find TutorialConfig.h
 # so that we will find TutorialConfig.h
@@ -37,7 +46,7 @@ install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
   )
   )
 
 
 # enable testing
 # enable testing
-include(CTest)
+enable_testing()
 
 
 # does the application run
 # does the application run
 add_test(NAME Runs COMMAND Tutorial 25)
 add_test(NAME Runs COMMAND Tutorial 25)

+ 4 - 1
Help/guide/tutorial/Step6/MathFunctions/CMakeLists.txt

@@ -6,6 +6,9 @@ target_include_directories(MathFunctions
           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
           )
           )
 
 
+target_link_libraries(MathFunctions tutorial_compiler_flags)
+
 # install rules
 # install rules
-install(TARGETS MathFunctions DESTINATION lib)
+set(installable_libs MathFunctions tutorial_compiler_flags)
+install(TARGETS ${installable_libs} DESTINATION lib)
 install(FILES MathFunctions.h DESTINATION include)
 install(FILES MathFunctions.h DESTINATION include)

+ 13 - 4
Help/guide/tutorial/Step7/CMakeLists.txt

@@ -1,11 +1,20 @@
-cmake_minimum_required(VERSION 3.10)
+cmake_minimum_required(VERSION 3.15)
 
 
 # set the project name and version
 # set the project name and version
 project(Tutorial VERSION 1.0)
 project(Tutorial VERSION 1.0)
 
 
 # specify the C++ standard
 # specify the C++ standard
-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,LCC>")
+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>>"
+)
 
 
 # should we use our own math functions
 # should we use our own math functions
 option(USE_MYMATH "Use tutorial provided math implementation" ON)
 option(USE_MYMATH "Use tutorial provided math implementation" ON)
@@ -22,7 +31,7 @@ endif()
 
 
 # add the executable
 # add the executable
 add_executable(Tutorial tutorial.cxx)
 add_executable(Tutorial tutorial.cxx)
-target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
+target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS} tutorial_compiler_flags)
 
 
 # add the binary tree to the search path for include files
 # add the binary tree to the search path for include files
 # so that we will find TutorialConfig.h
 # so that we will find TutorialConfig.h

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

@@ -6,29 +6,9 @@ target_include_directories(MathFunctions
           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
           )
           )
 
 
-# does this system provide the log and exp functions?
-include(CheckCXXSourceCompiles)
-check_cxx_source_compiles("
-  #include <cmath>
-  int main() {
-    std::log(1.0);
-    return 0;
-  }
-" HAVE_LOG)
-check_cxx_source_compiles("
-  #include <cmath>
-  int main() {
-    std::exp(1.0);
-    return 0;
-  }
-" HAVE_EXP)
-
-# add compile definitions
-if(HAVE_LOG AND HAVE_EXP)
-  target_compile_definitions(MathFunctions
-                             PRIVATE "HAVE_LOG" "HAVE_EXP")
-endif()
+target_link_libraries(MathFunctions tutorial_compiler_flags)
 
 
 # install rules
 # install rules
-install(TARGETS MathFunctions DESTINATION lib)
+set(installable_libs MathFunctions tutorial_compiler_flags)
+install(TARGETS ${installable_libs} DESTINATION lib)
 install(FILES MathFunctions.h DESTINATION include)
 install(FILES MathFunctions.h DESTINATION include)

+ 0 - 25
Help/guide/tutorial/Step7/MathFunctions/MakeTable.cxx

@@ -1,25 +0,0 @@
-// A simple program that builds a sqrt table
-#include <cmath>
-#include <fstream>
-#include <iostream>
-
-int main(int argc, char* argv[])
-{
-  // make sure we have enough arguments
-  if (argc < 2) {
-    return 1;
-  }
-
-  std::ofstream fout(argv[1], std::ios_base::out);
-  const bool fileOpen = fout.is_open();
-  if (fileOpen) {
-    fout << "double sqrtTable[] = {" << std::endl;
-    for (int i = 0; i < 10; ++i) {
-      fout << sqrt(static_cast<double>(i)) << "," << std::endl;
-    }
-    // close the table with a zero
-    fout << "0};" << std::endl;
-    fout.close();
-  }
-  return fileOpen ? 0 : 1; // return 0 if wrote the file
-}

+ 0 - 8
Help/guide/tutorial/Step7/MathFunctions/mysqrt.cxx

@@ -1,4 +1,3 @@
-#include <cmath>
 #include <iostream>
 #include <iostream>
 
 
 #include "MathFunctions.h"
 #include "MathFunctions.h"
@@ -10,12 +9,6 @@ double mysqrt(double x)
     return 0;
     return 0;
   }
   }
 
 
-  // if we have both log and exp then use them
-#if defined(HAVE_LOG) && defined(HAVE_EXP)
-  double result = std::exp(std::log(x) * 0.5);
-  std::cout << "Computing sqrt of " << x << " to be " << result
-            << " using log and exp" << std::endl;
-#else
   double result = x;
   double result = x;
 
 
   // do ten iterations
   // do ten iterations
@@ -27,6 +20,5 @@ double mysqrt(double x)
     result = result + 0.5 * delta / result;
     result = result + 0.5 * delta / result;
     std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
     std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
   }
   }
-#endif
   return result;
   return result;
 }
 }

+ 14 - 4
Help/guide/tutorial/Step8/CMakeLists.txt

@@ -1,11 +1,21 @@
-cmake_minimum_required(VERSION 3.10)
+cmake_minimum_required(VERSION 3.15)
 
 
 # set the project name and version
 # set the project name and version
 project(Tutorial VERSION 1.0)
 project(Tutorial VERSION 1.0)
 
 
 # specify the C++ standard
 # specify the C++ standard
-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,LCC>")
+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>>"
+)
+
 
 
 # should we use our own math functions
 # should we use our own math functions
 option(USE_MYMATH "Use tutorial provided math implementation" ON)
 option(USE_MYMATH "Use tutorial provided math implementation" ON)
@@ -22,7 +32,7 @@ endif()
 
 
 # add the executable
 # add the executable
 add_executable(Tutorial tutorial.cxx)
 add_executable(Tutorial tutorial.cxx)
-target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
+target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS} tutorial_compiler_flags)
 
 
 # add the binary tree to the search path for include files
 # add the binary tree to the search path for include files
 # so that we will find TutorialConfig.h
 # so that we will find TutorialConfig.h

+ 0 - 2
Help/guide/tutorial/Step8/License.txt

@@ -1,2 +0,0 @@
-This is the open source License.txt file introduced in
-CMake/Tutorial/Step7...

+ 28 - 20
Help/guide/tutorial/Step8/MathFunctions/CMakeLists.txt

@@ -1,29 +1,37 @@
-# first we add the executable that generates the table
-add_executable(MakeTable MakeTable.cxx)
-
-# add the command to generate the source code
-add_custom_command(
-  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
-  COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
-  DEPENDS MakeTable
-  )
-
-# add the main library
-add_library(MathFunctions
-            mysqrt.cxx
-            ${CMAKE_CURRENT_BINARY_DIR}/Table.h
-            )
+add_library(MathFunctions mysqrt.cxx)
 
 
 # state that anybody linking to us needs to include the current source dir
 # state that anybody linking to us needs to include the current source dir
 # to find MathFunctions.h, while we don't.
 # to find MathFunctions.h, while we don't.
-# state that we depend on Tutorial_BINARY_DIR but consumers don't, as the
-# TutorialConfig.h include is an implementation detail
-# state that we depend on our binary dir to find Table.h
 target_include_directories(MathFunctions
 target_include_directories(MathFunctions
           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
-          PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
           )
           )
 
 
+target_link_libraries(MathFunctions tutorial_compiler_flags)
+
+# does this system provide the log and exp functions?
+include(CheckCXXSourceCompiles)
+check_cxx_source_compiles("
+  #include <cmath>
+  int main() {
+    std::log(1.0);
+    return 0;
+  }
+" HAVE_LOG)
+check_cxx_source_compiles("
+  #include <cmath>
+  int main() {
+    std::exp(1.0);
+    return 0;
+  }
+" HAVE_EXP)
+
+# add compile definitions
+if(HAVE_LOG AND HAVE_EXP)
+  target_compile_definitions(MathFunctions
+                             PRIVATE "HAVE_LOG" "HAVE_EXP")
+endif()
+
 # install rules
 # install rules
-install(TARGETS MathFunctions DESTINATION lib)
+set(installable_libs MathFunctions tutorial_compiler_flags)
+install(TARGETS ${installable_libs} DESTINATION lib)
 install(FILES MathFunctions.h DESTINATION include)
 install(FILES MathFunctions.h DESTINATION include)

+ 8 - 9
Help/guide/tutorial/Step8/MathFunctions/mysqrt.cxx

@@ -1,10 +1,8 @@
+#include <cmath>
 #include <iostream>
 #include <iostream>
 
 
 #include "MathFunctions.h"
 #include "MathFunctions.h"
 
 
-// include the generated table
-#include "Table.h"
-
 // a hack square root calculation using simple operations
 // a hack square root calculation using simple operations
 double mysqrt(double x)
 double mysqrt(double x)
 {
 {
@@ -12,12 +10,13 @@ double mysqrt(double x)
     return 0;
     return 0;
   }
   }
 
 
-  // use the table to help find an initial value
+  // if we have both log and exp then use them
+#if defined(HAVE_LOG) && defined(HAVE_EXP)
+  double result = std::exp(std::log(x) * 0.5);
+  std::cout << "Computing sqrt of " << x << " to be " << result
+            << " using log and exp" << std::endl;
+#else
   double result = x;
   double result = x;
-  if (x >= 1 && x < 10) {
-    std::cout << "Use the table to help find an initial value " << std::endl;
-    result = sqrtTable[static_cast<int>(x)];
-  }
 
 
   // do ten iterations
   // do ten iterations
   for (int i = 0; i < 10; ++i) {
   for (int i = 0; i < 10; ++i) {
@@ -28,6 +27,6 @@ double mysqrt(double x)
     result = result + 0.5 * delta / result;
     result = result + 0.5 * delta / result;
     std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
     std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
   }
   }
-
+#endif
   return result;
   return result;
 }
 }

+ 13 - 12
Help/guide/tutorial/Step9/CMakeLists.txt

@@ -1,11 +1,20 @@
-cmake_minimum_required(VERSION 3.10)
+cmake_minimum_required(VERSION 3.15)
 
 
 # set the project name and version
 # set the project name and version
 project(Tutorial VERSION 1.0)
 project(Tutorial VERSION 1.0)
 
 
 # specify the C++ standard
 # specify the C++ standard
-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,LCC>")
+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>>"
+)
 
 
 # should we use our own math functions
 # should we use our own math functions
 option(USE_MYMATH "Use tutorial provided math implementation" ON)
 option(USE_MYMATH "Use tutorial provided math implementation" ON)
@@ -22,7 +31,7 @@ endif()
 
 
 # add the executable
 # add the executable
 add_executable(Tutorial tutorial.cxx)
 add_executable(Tutorial tutorial.cxx)
-target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
+target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS} tutorial_compiler_flags)
 
 
 # add the binary tree to the search path for include files
 # add the binary tree to the search path for include files
 # so that we will find TutorialConfig.h
 # so that we will find TutorialConfig.h
@@ -64,11 +73,3 @@ do_test(Tutorial 7 "7 is 2.645")
 do_test(Tutorial 25 "25 is 5")
 do_test(Tutorial 25 "25 is 5")
 do_test(Tutorial -25 "-25 is (-nan|nan|0)")
 do_test(Tutorial -25 "-25 is (-nan|nan|0)")
 do_test(Tutorial 0.0001 "0.0001 is 0.01")
 do_test(Tutorial 0.0001 "0.0001 is 0.01")
-
-# setup installer
-include(InstallRequiredSystemLibraries)
-set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
-set(CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")
-set(CPACK_PACKAGE_VERSION_MINOR "${Tutorial_VERSION_MINOR}")
-set(CPACK_SOURCE_GENERATOR "TGZ")
-include(CPack)

+ 1 - 1
Help/guide/tutorial/Step9/License.txt

@@ -1,2 +1,2 @@
 This is the open source License.txt file introduced in
 This is the open source License.txt file introduced in
-CMake/Tutorial/Step7...
+CMake/Tutorial/Step9...

+ 6 - 1
Help/guide/tutorial/Step9/MathFunctions/CMakeLists.txt

@@ -16,12 +16,17 @@ add_library(MathFunctions
 
 
 # state that anybody linking to us needs to include the current source dir
 # state that anybody linking to us needs to include the current source dir
 # to find MathFunctions.h, while we don't.
 # to find MathFunctions.h, while we don't.
+# state that we depend on Tutorial_BINARY_DIR but consumers don't, as the
+# TutorialConfig.h include is an implementation detail
 # state that we depend on our binary dir to find Table.h
 # state that we depend on our binary dir to find Table.h
 target_include_directories(MathFunctions
 target_include_directories(MathFunctions
           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
           PRIVATE   ${CMAKE_CURRENT_BINARY_DIR}
           PRIVATE   ${CMAKE_CURRENT_BINARY_DIR}
           )
           )
 
 
+target_link_libraries(MathFunctions tutorial_compiler_flags)
+
 # install rules
 # install rules
-install(TARGETS MathFunctions DESTINATION lib)
+set(installable_libs MathFunctions tutorial_compiler_flags)
+install(TARGETS ${installable_libs} DESTINATION lib)
 install(FILES MathFunctions.h DESTINATION include)
 install(FILES MathFunctions.h DESTINATION include)

+ 0 - 19
Help/guide/tutorial/Step9/MathFunctions/MathFunctions.cxx

@@ -1,19 +0,0 @@
-
-#include "MathFunctions.h"
-
-#include <cmath>
-
-#ifdef USE_MYMATH
-#  include "mysqrt.h"
-#endif
-
-namespace mathfunctions {
-double sqrt(double x)
-{
-#ifdef USE_MYMATH
-  return detail::mysqrt(x);
-#else
-  return std::sqrt(x);
-#endif
-}
-}

+ 0 - 6
Help/guide/tutorial/Step9/MathFunctions/mysqrt.h

@@ -1,6 +0,0 @@
-
-namespace mathfunctions {
-namespace detail {
-double mysqrt(double x);
-}
-}

+ 1 - 1
Help/guide/tutorial/index.rst

@@ -24,13 +24,13 @@ provides the complete solution for the previous step.
   A Basic Starting Point
   A Basic Starting Point
   Adding a Library
   Adding a Library
   Adding Usage Requirements for a Library
   Adding Usage Requirements for a Library
+  Adding Generator Expressions
   Installing and Testing
   Installing and Testing
   Adding Support for a Testing Dashboard
   Adding Support for a Testing Dashboard
   Adding System Introspection
   Adding System Introspection
   Adding a Custom Command and Generated File
   Adding a Custom Command and Generated File
   Packaging an Installer
   Packaging an Installer
   Selecting Static or Shared Libraries
   Selecting Static or Shared Libraries
-  Adding Generator Expressions
   Adding Export Configuration
   Adding Export Configuration
   Packaging Debug and Release
   Packaging Debug and Release
 
 

+ 1 - 1
Tests/CMakeLists.txt

@@ -1742,7 +1742,7 @@ if(BUILD_TESTING)
 
 
   if(NOT CMake_TEST_EXTERNAL_CMAKE)
   if(NOT CMake_TEST_EXTERNAL_CMAKE)
     foreach(STP RANGE 2 12)
     foreach(STP RANGE 2 12)
-      if (STP EQUAL 7)
+      if (STP EQUAL 8)
         set(pass_regex ".*using log and exp")
         set(pass_regex ".*using log and exp")
       else()
       else()
         set(pass_regex "The square root of 25 is 5")
         set(pass_regex "The square root of 25 is 5")