diff options
Diffstat (limited to 'Help/guide/tutorial/Step7')
-rw-r--r-- | Help/guide/tutorial/Step7/CMakeLists.txt | 28 | ||||
-rw-r--r-- | Help/guide/tutorial/Step7/MathFunctions/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Help/guide/tutorial/Step7/MathFunctions/mysqrt.cxx | 4 | ||||
-rw-r--r-- | Help/guide/tutorial/Step7/TutorialConfig.h.in | 4 | ||||
-rw-r--r-- | Help/guide/tutorial/Step7/tutorial.cxx | 7 |
5 files changed, 15 insertions, 31 deletions
diff --git a/Help/guide/tutorial/Step7/CMakeLists.txt b/Help/guide/tutorial/Step7/CMakeLists.txt index a1efa77..c3b375a 100644 --- a/Help/guide/tutorial/Step7/CMakeLists.txt +++ b/Help/guide/tutorial/Step7/CMakeLists.txt @@ -1,34 +1,24 @@ -cmake_minimum_required(VERSION 3.3) -project(Tutorial) +cmake_minimum_required(VERSION 3.10) +# set the project name and version +project(Tutorial VERSION 1.0) + +# specify the C++ standard set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) -# set the version number -set(Tutorial_VERSION_MAJOR 1) -set(Tutorial_VERSION_MINOR 0) - -# 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( - "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in" - "${PROJECT_BINARY_DIR}/TutorialConfig.h" - ) +configure_file(TutorialConfig.h.in TutorialConfig.h) -# add the MathFunctions library? +# add the MathFunctions library if(USE_MYMATH) add_subdirectory(MathFunctions) list(APPEND EXTRA_LIBS MathFunctions) -endif(USE_MYMATH) +endif() # add the executable add_executable(Tutorial tutorial.cxx) @@ -38,7 +28,7 @@ target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS}) # so that we will find TutorialConfig.h target_include_directories(Tutorial PUBLIC "${PROJECT_BINARY_DIR}" - ) + ) # add the install targets install(TARGETS Tutorial DESTINATION bin) diff --git a/Help/guide/tutorial/Step7/MathFunctions/CMakeLists.txt b/Help/guide/tutorial/Step7/MathFunctions/CMakeLists.txt index 3c3a816..9ede4b3 100644 --- a/Help/guide/tutorial/Step7/MathFunctions/CMakeLists.txt +++ b/Help/guide/tutorial/Step7/MathFunctions/CMakeLists.txt @@ -21,8 +21,7 @@ add_library(MathFunctions # state that we depend on our binary dir to find Table.h target_include_directories(MathFunctions INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${Tutorial_BINARY_DIR} - ${CMAKE_CURRENT_BINARY_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ) # install rules diff --git a/Help/guide/tutorial/Step7/MathFunctions/mysqrt.cxx b/Help/guide/tutorial/Step7/MathFunctions/mysqrt.cxx index 5272f56..2ae60c6 100644 --- a/Help/guide/tutorial/Step7/MathFunctions/mysqrt.cxx +++ b/Help/guide/tutorial/Step7/MathFunctions/mysqrt.cxx @@ -1,12 +1,9 @@ #include "MathFunctions.h" -#include "TutorialConfig.h" #include <iostream> // include the generated table #include "Table.h" -#include <cmath> - // a hack square root calculation using simple operations double mysqrt(double x) { @@ -17,6 +14,7 @@ double mysqrt(double x) // use the table to help find an initial value 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)]; } diff --git a/Help/guide/tutorial/Step7/TutorialConfig.h.in b/Help/guide/tutorial/Step7/TutorialConfig.h.in index e97ce24..e23f521 100644 --- a/Help/guide/tutorial/Step7/TutorialConfig.h.in +++ b/Help/guide/tutorial/Step7/TutorialConfig.h.in @@ -2,7 +2,3 @@ #define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@ #define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@ #cmakedefine USE_MYMATH - -// does the platform provide exp and log functions? -#cmakedefine HAVE_LOG -#cmakedefine HAVE_EXP diff --git a/Help/guide/tutorial/Step7/tutorial.cxx b/Help/guide/tutorial/Step7/tutorial.cxx index 8156a9c..b3c6a4f 100644 --- a/Help/guide/tutorial/Step7/tutorial.cxx +++ b/Help/guide/tutorial/Step7/tutorial.cxx @@ -20,13 +20,14 @@ int main(int argc, char* argv[]) return 1; } - double inputValue = std::stod(argv[1]); + // convert input to double + const double inputValue = std::stod(argv[1]); // which square root function should we use? #ifdef USE_MYMATH - double outputValue = mysqrt(inputValue); + const double outputValue = mysqrt(inputValue); #else - double outputValue = sqrt(inputValue); + const double outputValue = sqrt(inputValue); #endif std::cout << "The square root of " << inputValue << " is " << outputValue |