diff options
author | Brad King <brad.king@kitware.com> | 2022-06-02 13:20:52 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-06-02 13:21:06 (GMT) |
commit | dbb6e04b5fe45c413fb3a06b52ffceb5e86bf60c (patch) | |
tree | 24135a7724cfe50b036521f67ebb1d878d827ee7 /Help | |
parent | 4c9aa6c4256bc78ffd4c5fb3e7fe8adc6533dc46 (diff) | |
parent | 5c84eca2108c8b47a74391c732710c67e23adfa3 (diff) | |
download | CMake-dbb6e04b5fe45c413fb3a06b52ffceb5e86bf60c.zip CMake-dbb6e04b5fe45c413fb3a06b52ffceb5e86bf60c.tar.gz CMake-dbb6e04b5fe45c413fb3a06b52ffceb5e86bf60c.tar.bz2 |
Merge topic 'tutorial-cmath'
5c84eca210 Tutorial: Simplify logic checking for cmath functions
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !7314
Diffstat (limited to 'Help')
-rw-r--r-- | Help/guide/tutorial/Adding System Introspection.rst | 8 | ||||
-rw-r--r-- | Help/guide/tutorial/Step6/MathFunctions/CMakeLists.txt | 28 | ||||
-rw-r--r-- | Help/guide/tutorial/Step6/MathFunctions/mysqrt.cxx | 2 |
3 files changed, 19 insertions, 19 deletions
diff --git a/Help/guide/tutorial/Adding System Introspection.rst b/Help/guide/tutorial/Adding System Introspection.rst index e149110..8db0cb8 100644 --- a/Help/guide/tutorial/Adding System Introspection.rst +++ b/Help/guide/tutorial/Adding System Introspection.rst @@ -9,17 +9,15 @@ tutorial assume that they are not common. If the platform has ``log`` and ``exp`` then we will use them to compute the square root in the ``mysqrt`` function. We first test for the availability of -these functions using the :module:`CheckSymbolExists` module in -``MathFunctions/CMakeLists.txt``. On some platforms, we will need to link to -the ``m`` library. If ``log`` and ``exp`` are not initially found, require the -``m`` library and try again. +these functions using the :module:`CheckCXXSourceCompiles` module in +``MathFunctions/CMakeLists.txt``. Add the checks for ``log`` and ``exp`` to ``MathFunctions/CMakeLists.txt``, after the call to :command:`target_include_directories`: .. literalinclude:: Step6/MathFunctions/CMakeLists.txt :caption: MathFunctions/CMakeLists.txt - :name: MathFunctions/CMakeLists.txt-check_symbol_exists + :name: MathFunctions/CMakeLists.txt-check_cxx_source_compiles :language: cmake :start-after: # to find MathFunctions.h, while we don't. :end-before: # add compile definitions diff --git a/Help/guide/tutorial/Step6/MathFunctions/CMakeLists.txt b/Help/guide/tutorial/Step6/MathFunctions/CMakeLists.txt index f64c6ac..42e098a 100644 --- a/Help/guide/tutorial/Step6/MathFunctions/CMakeLists.txt +++ b/Help/guide/tutorial/Step6/MathFunctions/CMakeLists.txt @@ -7,19 +7,21 @@ target_include_directories(MathFunctions ) # does this system provide the log and exp functions? -include(CheckSymbolExists) -check_symbol_exists(log "math.h" HAVE_LOG) -check_symbol_exists(exp "math.h" HAVE_EXP) -if(NOT (HAVE_LOG AND HAVE_EXP)) - unset(HAVE_LOG CACHE) - unset(HAVE_EXP CACHE) - set(CMAKE_REQUIRED_LIBRARIES "m") - check_symbol_exists(log "math.h" HAVE_LOG) - check_symbol_exists(exp "math.h" HAVE_EXP) - if(HAVE_LOG AND HAVE_EXP) - target_link_libraries(MathFunctions PRIVATE m) - endif() -endif() +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) diff --git a/Help/guide/tutorial/Step6/MathFunctions/mysqrt.cxx b/Help/guide/tutorial/Step6/MathFunctions/mysqrt.cxx index 0637063..7eecd26 100644 --- a/Help/guide/tutorial/Step6/MathFunctions/mysqrt.cxx +++ b/Help/guide/tutorial/Step6/MathFunctions/mysqrt.cxx @@ -12,7 +12,7 @@ double mysqrt(double x) // if we have both log and exp then use them #if defined(HAVE_LOG) && defined(HAVE_EXP) - double result = exp(log(x) * 0.5); + 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 |