summaryrefslogtreecommitdiff
path: root/Tests/Tutorial/Complete/MathFunctions
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2021-10-08 09:14:18 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2021-10-08 09:14:18 +0900
commitd40909a98298a97d879ceeb3b29dcdc858e85628 (patch)
tree0a9255654a9376c5e9f29aa53d15f0ae173751a0 /Tests/Tutorial/Complete/MathFunctions
parentc5223aaf98b2d10aee32aa614519ee7a23698998 (diff)
downloadcmake-d40909a98298a97d879ceeb3b29dcdc858e85628.tar.gz
cmake-d40909a98298a97d879ceeb3b29dcdc858e85628.tar.bz2
cmake-d40909a98298a97d879ceeb3b29dcdc858e85628.zip
Imported Upstream version 3.16.0upstream/3.16.0
Diffstat (limited to 'Tests/Tutorial/Complete/MathFunctions')
-rw-r--r--Tests/Tutorial/Complete/MathFunctions/CMakeLists.txt68
-rw-r--r--Tests/Tutorial/Complete/MathFunctions/MakeTable.cxx25
-rw-r--r--Tests/Tutorial/Complete/MathFunctions/MathFunctions.cxx18
-rw-r--r--Tests/Tutorial/Complete/MathFunctions/MathFunctions.h14
-rw-r--r--Tests/Tutorial/Complete/MathFunctions/mysqrt.cxx45
-rw-r--r--Tests/Tutorial/Complete/MathFunctions/mysqrt.h6
6 files changed, 0 insertions, 176 deletions
diff --git a/Tests/Tutorial/Complete/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Complete/MathFunctions/CMakeLists.txt
deleted file mode 100644
index 161ad6449..000000000
--- a/Tests/Tutorial/Complete/MathFunctions/CMakeLists.txt
+++ /dev/null
@@ -1,68 +0,0 @@
-
-# add the library that runs
-add_library(MathFunctions MathFunctions.cxx)
-
-# state that anybody linking to us needs to include the current source dir
-# to find MathFunctions.h, while we don't.
-target_include_directories(MathFunctions
- INTERFACE
- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
- $<INSTALL_INTERFACE:include>
- )
-
-# should we use our own math functions
-option(USE_MYMATH "Use tutorial provided math implementation" ON)
-if(USE_MYMATH)
-
- # 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)
-
- # 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}
- )
-
- set_target_properties(SqrtLibrary PROPERTIES
- POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
- )
-
- target_compile_definitions(SqrtLibrary PRIVATE
- "$<$<BOOL:${HAVE_LOG}>:HAVE_LOG>"
- "$<$<BOOL:${HAVE_EXP}>:HAVE_EXP>"
- )
- 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")
-
-# setup the version numbering
-set_property(TARGET MathFunctions PROPERTY VERSION "1.0.0")
-set_property(TARGET MathFunctions PROPERTY SOVERSION "1")
-
-install(TARGETS MathFunctions
- DESTINATION lib
- EXPORT MathFunctionsTargets)
-install(FILES MathFunctions.h DESTINATION include)
diff --git a/Tests/Tutorial/Complete/MathFunctions/MakeTable.cxx b/Tests/Tutorial/Complete/MathFunctions/MakeTable.cxx
deleted file mode 100644
index ee585568c..000000000
--- a/Tests/Tutorial/Complete/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/Complete/MathFunctions/MathFunctions.cxx b/Tests/Tutorial/Complete/MathFunctions/MathFunctions.cxx
deleted file mode 100644
index 5351184be..000000000
--- a/Tests/Tutorial/Complete/MathFunctions/MathFunctions.cxx
+++ /dev/null
@@ -1,18 +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
-}
-}
diff --git a/Tests/Tutorial/Complete/MathFunctions/MathFunctions.h b/Tests/Tutorial/Complete/MathFunctions/MathFunctions.h
deleted file mode 100644
index 3fb547b4a..000000000
--- a/Tests/Tutorial/Complete/MathFunctions/MathFunctions.h
+++ /dev/null
@@ -1,14 +0,0 @@
-
-#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);
-}
diff --git a/Tests/Tutorial/Complete/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Complete/MathFunctions/mysqrt.cxx
deleted file mode 100644
index 96d94212d..000000000
--- a/Tests/Tutorial/Complete/MathFunctions/mysqrt.cxx
+++ /dev/null
@@ -1,45 +0,0 @@
-#include "MathFunctions.h"
-#include <iostream>
-
-// include the generated table
-#include "Table.h"
-
-#include <cmath>
-
-namespace mathfunctions {
-namespace detail {
-// 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/Complete/MathFunctions/mysqrt.h b/Tests/Tutorial/Complete/MathFunctions/mysqrt.h
deleted file mode 100644
index e1c42ef0c..000000000
--- a/Tests/Tutorial/Complete/MathFunctions/mysqrt.h
+++ /dev/null
@@ -1,6 +0,0 @@
-
-namespace mathfunctions {
-namespace detail {
-double mysqrt(double x);
-}
-}