diff options
author | Kitware Robot <kwrobot@kitware.com> | 2019-05-30 16:41:21 (GMT) |
---|---|---|
committer | Betsy McPhail <betsy.mcphail@kitware.com> | 2019-06-18 14:36:16 (GMT) |
commit | 862cfc0e6c3f275db73281f3b9b989704251ab6a (patch) | |
tree | 91c65801e02f337fa95e9776a6bf59057d55ec17 /Tests/Tutorial/Step8 | |
parent | d2fde9480955cf2246519357e01ab5142a067efc (diff) | |
download | CMake-862cfc0e6c3f275db73281f3b9b989704251ab6a.zip CMake-862cfc0e6c3f275db73281f3b9b989704251ab6a.tar.gz CMake-862cfc0e6c3f275db73281f3b9b989704251ab6a.tar.bz2 |
Help/guide/tutorial: Adopt tutorial code
Diffstat (limited to 'Tests/Tutorial/Step8')
-rw-r--r-- | Tests/Tutorial/Step8/CMakeLists.txt | 81 | ||||
-rw-r--r-- | Tests/Tutorial/Step8/License.txt | 2 | ||||
-rw-r--r-- | Tests/Tutorial/Step8/MathFunctions/CMakeLists.txt | 29 | ||||
-rw-r--r-- | Tests/Tutorial/Step8/MathFunctions/MakeTable.cxx | 25 | ||||
-rw-r--r-- | Tests/Tutorial/Step8/MathFunctions/MathFunctions.h | 1 | ||||
-rw-r--r-- | Tests/Tutorial/Step8/MathFunctions/mysqrt.cxx | 42 | ||||
-rw-r--r-- | Tests/Tutorial/Step8/TutorialConfig.h.in | 8 | ||||
-rw-r--r-- | Tests/Tutorial/Step8/directions.txt | 38 | ||||
-rw-r--r-- | Tests/Tutorial/Step8/tutorial.cxx | 32 |
9 files changed, 0 insertions, 258 deletions
diff --git a/Tests/Tutorial/Step8/CMakeLists.txt b/Tests/Tutorial/Step8/CMakeLists.txt deleted file mode 100644 index 03dc7c0..0000000 --- a/Tests/Tutorial/Step8/CMakeLists.txt +++ /dev/null @@ -1,81 +0,0 @@ -cmake_minimum_required(VERSION 3.3) -project(Tutorial) - -set(CMAKE_CXX_STANDARD 14) - -# 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" - ) - -# add the MathFunctions library? -if(USE_MYMATH) - add_subdirectory(MathFunctions) - list(APPEND EXTRA_LIBS MathFunctions) -endif(USE_MYMATH) - -# add the executable -add_executable(Tutorial tutorial.cxx) -target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS}) - -# add the binary tree to the search path for include files -# so that we will find TutorialConfig.h -target_include_directories(Tutorial PUBLIC - "${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_test) - -# 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") - -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}") -include(CPack) diff --git a/Tests/Tutorial/Step8/License.txt b/Tests/Tutorial/Step8/License.txt deleted file mode 100644 index c62d00b..0000000 --- a/Tests/Tutorial/Step8/License.txt +++ /dev/null @@ -1,2 +0,0 @@ -This is the open source License.txt file introduced in -CMake/Tutorial/Step7... diff --git a/Tests/Tutorial/Step8/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Step8/MathFunctions/CMakeLists.txt deleted file mode 100644 index dc3eb98..0000000 --- a/Tests/Tutorial/Step8/MathFunctions/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# 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 -# 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 - INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${Tutorial_BINARY_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - ) - -install(TARGETS MathFunctions DESTINATION lib) -install(FILES MathFunctions.h DESTINATION include) diff --git a/Tests/Tutorial/Step8/MathFunctions/MakeTable.cxx b/Tests/Tutorial/Step8/MathFunctions/MakeTable.cxx deleted file mode 100644 index ee58556..0000000 --- a/Tests/Tutorial/Step8/MathFunctions/MakeTable.cxx +++ /dev/null @@ -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 -} diff --git a/Tests/Tutorial/Step8/MathFunctions/MathFunctions.h b/Tests/Tutorial/Step8/MathFunctions/MathFunctions.h deleted file mode 100644 index cd36bcc..0000000 --- a/Tests/Tutorial/Step8/MathFunctions/MathFunctions.h +++ /dev/null @@ -1 +0,0 @@ -double mysqrt(double x); diff --git a/Tests/Tutorial/Step8/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step8/MathFunctions/mysqrt.cxx deleted file mode 100644 index 5b862fb..0000000 --- a/Tests/Tutorial/Step8/MathFunctions/mysqrt.cxx +++ /dev/null @@ -1,42 +0,0 @@ -#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) -{ - if (x <= 0) { - return 0; - } - - // if we have both log and exp then use them -#if defined(HAVE_LOG) && defined(HAVE_EXP) - double result = exp(log(x) * 0.5); - std::cout << "Computing sqrt of " << x << " to be " << result << " using log" - << std::endl; -#else - // use the table to help find an initial value - double result = x; - if (x >= 1 && x < 10) { - result = sqrtTable[static_cast<int>(x)]; - } - - // if we have both log and exp then use them - - // do ten iterations - for (int i = 0; i < 10; ++i) { - if (result <= 0) { - result = 0.1; - } - double delta = x - (result * result); - result = result + 0.5 * delta / result; - std::cout << "Computing sqrt of " << x << " to be " << result << std::endl; - } -#endif - return result; -} diff --git a/Tests/Tutorial/Step8/TutorialConfig.h.in b/Tests/Tutorial/Step8/TutorialConfig.h.in deleted file mode 100644 index e97ce24..0000000 --- a/Tests/Tutorial/Step8/TutorialConfig.h.in +++ /dev/null @@ -1,8 +0,0 @@ -// the configured options and settings for Tutorial -#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/Tests/Tutorial/Step8/directions.txt b/Tests/Tutorial/Step8/directions.txt deleted file mode 100644 index 588d9c6..0000000 --- a/Tests/Tutorial/Step8/directions.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Adding Support for a Dashboard # - -Adding support for submitting our test results to a dashboard is very easy. We -already defined a number of tests for our project in the earlier steps of this -tutorial. We just have to run those tests and submit them to a dashboard. To -include support for dashboards we include the CTest module in our top-level -CMakeLists.txt. - -Replace: - # enable testing - enable_testing() - -With: - # enable dashboard scripting - include(CTest) - -The CTest module will automatically call enable_testing(), so -we can remove it from our CMake files. - -We will also need to create a CTestConfig.cmake file where we can specify the -name of the project and where to submit the dashboard. - - set(CTEST_PROJECT_NAME "CMakeTutorial") - set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC") - - 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) - -CTest will read in this file when it runs. To create a simple dashboard you can -run cmake or cmake-gui to configure the project, but do not build it yet. -Instead, change directory to the binary tree, and then run: - 'ctest [-VV] –D Experimental'. On Windows, build the EXPERIMENTAL target. - -Ctest will build and test the project and submit results to the Kitware public -dashboard. The results of your dashboard will be uploaded to Kitware's public -dashboard here: https://my.cdash.org/index.php?project=CMakeTutorial. diff --git a/Tests/Tutorial/Step8/tutorial.cxx b/Tests/Tutorial/Step8/tutorial.cxx deleted file mode 100644 index c2b89df..0000000 --- a/Tests/Tutorial/Step8/tutorial.cxx +++ /dev/null @@ -1,32 +0,0 @@ -// A simple program that computes the square root of a number -#include <cmath> -#include <iostream> -#include <string> - -#include "TutorialConfig.h" - -#ifdef USE_MYMATH -# include "MathFunctions.h" -#endif - -int main(int argc, char* argv[]) -{ - if (argc < 2) { - std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "." - << Tutorial_VERSION_MINOR << std::endl; - std::cout << "Usage: " << argv[0] << " number" << std::endl; - return 1; - } - - double inputValue = std::stod(argv[1]); - -#ifdef USE_MYMATH - double outputValue = mysqrt(inputValue); -#else - double outputValue = sqrt(inputValue); -#endif - - std::cout << "The square root of " << inputValue << " is " << outputValue - << std::endl; - return 0; -} |