Commit f808e0c6 authored by David Gobbi's avatar David Gobbi
Browse files

14164: Fix incorrectly set VTK_HAS_STD_ISFINITE variable.

This change is necessary for compilation with gcc in C++11 mode.

The check_symbol_exists() macro that we had been using to find
std::isfinite, std::isnan, and std::isinf always failed, so it
wasn't doing anything useful.  Both this macro and the newer
check_cxx_symbol_exists() are unsuitable for std::isfinite etc.
because these function might exist either as function templates,
or as simple function overloads, depending on the compiler.

As a side note, the existing checks for the c99 functions, e.g.
  cmake_symbol_exists(isnan "math.h" VTK_HAS_ISNAN)
should instead use this:
  cmake_cxx_symbol_exists(isnan "cmath" VTK_HAS_ISNAN)
because vtkMath.h includes cmath, not math.h, and on some systems
math.h provides these function while cmath does not (or, cmath
might only provide them within the std namespace).  In fact, most
instances of cmake_symbol_exists() in VTK should be replaced by
cmake_cxx_symbol_exists() when VTK adopts a more recent CMake.

Change-Id: I1ef7cd4daa52067badb0928d01c3f8b22953c601
parent 46a51e1c
# - Check if a C++ function exists
# CHECK_CXX_EXPRESSION_COMPILES(<expression> <files> <variable>)
#
# Check that the <expression> compiles in a program that includes
# <files> and store the result in a <variable>. Specify the list
# of files in one argument as a semicolon-separated list.
#
# The following variables may be set before calling this macro to
# modify the way the check is run:
#
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_INCLUDES = list of include directories
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
#=============================================================================
# Copyright 2003-2011 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
INCLUDE(CheckCXXSourceCompiles)
MACRO(CHECK_CXX_EXPRESSION_COMPILES EXPRESSION FILES VARIABLE)
SET(SOURCE "/* CHECK_CXX_EXPRESSION_COMPILES */\n")
FOREACH(FILE ${FILES})
SET(SOURCE "${SOURCE}#include <${FILE}>\n")
ENDFOREACH(FILE ${FILES})
SET(SOURCE "${SOURCE}\nint main()\n{\n")
SET(SOURCE "${SOURCE} static_cast<void>(${EXPRESSION});\n\n")
SET(SOURCE "${SOURCE} return 0;\n}\n")
CHECK_CXX_SOURCE_COMPILES("${SOURCE}" "${VARIABLE}")
ENDMACRO(CHECK_CXX_EXPRESSION_COMPILES)
......@@ -311,13 +311,14 @@ foreach(t Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64 Float32 Float64)
endforeach()
# look for various headers and functions
include(CheckCXXExpressionCompiles)
include(CheckSymbolExists)
include(CheckIncludeFile)
# Check C++ <cmath> first, where the C++11 standard says these must be.
check_symbol_exists(std::isnan "cmath" VTK_HAS_STD_ISNAN)
check_symbol_exists(std::isinf "cmath" VTK_HAS_STD_ISINF)
check_symbol_exists(std::isfinite "cmath" VTK_HAS_STD_ISFINITE)
check_cxx_expression_compiles("std::isnan(0.0)" "cmath" VTK_HAS_STD_ISNAN)
check_cxx_expression_compiles("std::isinf(0.0)" "cmath" VTK_HAS_STD_ISINF)
check_cxx_expression_compiles("std::isfinite(0.0)" "cmath" VTK_HAS_STD_ISFINITE)
# Check C99 <math.h> next, where the C99 standard says these must be.
# (they will be found even if they are defined as macros)
......
......@@ -1245,8 +1245,11 @@ inline double vtkMath::ClampAndNormalizeValue(double value,
#define VTK_MATH_ISINF_IS_INLINE
inline int vtkMath::IsInf(double x)
{
using namespace std; // Could be isinf() or std::isinf()
#if defined(VTK_HAS_STD_ISINF)
return std::isinf(x);
#else
return (isinf(x) != 0); // Force conversion to bool
#endif
}
#endif
......@@ -1255,8 +1258,11 @@ inline int vtkMath::IsInf(double x)
#define VTK_MATH_ISNAN_IS_INLINE
inline int vtkMath::IsNan(double x)
{
using namespace std; // Could be isnan() or std::isnan()
#if defined(VTK_HAS_STD_ISNAN)
return std::isnan(x);
#else
return (isnan(x) != 0); // Force conversion to bool
#endif
}
#endif
......@@ -1265,8 +1271,9 @@ inline int vtkMath::IsNan(double x)
#define VTK_MATH_ISFINITE_IS_INLINE
inline bool vtkMath::IsFinite(double x)
{
#if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE)
using namespace std; // Could be isfinite() or std::isfinite()
#if defined(VTK_HAS_STD_ISFINITE)
return std::isfinite(x);
#elif defined(VTK_HAS_ISFINITE)
return (isfinite(x) != 0); // Force conversion to bool
#else
return (finite(x) != 0); // Force conversion to bool
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment