mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
Tutorial: Improve Step 5
* Updated output message * Use 'target_compile_definitions' for HAVE_LOG and HAVE_EXP Previously, the change from using TutorialConfig.h to target_compile_definitions happened without explanation as part of Step 8.
This commit is contained in:
@@ -10,12 +10,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
# should we use our own math functions
|
||||
option(USE_MYMATH "Use tutorial provided math implementation" ON)
|
||||
|
||||
# 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)
|
||||
|
||||
# configure a header file to pass some of the CMake settings
|
||||
# to the source code
|
||||
configure_file(TutorialConfig.h.in TutorialConfig.h)
|
||||
|
||||
@@ -2,13 +2,21 @@ add_library(MathFunctions mysqrt.cxx)
|
||||
|
||||
# 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
|
||||
target_include_directories(MathFunctions
|
||||
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PRIVATE ${Tutorial_BINARY_DIR}
|
||||
)
|
||||
|
||||
# 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)
|
||||
|
||||
if(HAVE_LOG AND HAVE_EXP)
|
||||
target_compile_definitions(MathFunctions
|
||||
PRIVATE "HAVE_LOG" "HAVE_EXP")
|
||||
endif()
|
||||
|
||||
# install rules
|
||||
install(TARGETS MathFunctions DESTINATION lib)
|
||||
install(FILES MathFunctions.h DESTINATION include)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "MathFunctions.h"
|
||||
#include "TutorialConfig.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <cmath>
|
||||
@@ -14,8 +13,8 @@ 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);
|
||||
std::cout << "Computing sqrt of " << x << " to be " << result << " using log"
|
||||
<< std::endl;
|
||||
std::cout << "Computing sqrt of " << x << " to be " << result
|
||||
<< " using log and exp" << std::endl;
|
||||
#else
|
||||
double result = x;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user