File: FindQuadMath.cmake

package info (click to toggle)
opm-common 2024.10%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 98,420 kB
  • sloc: cpp: 263,013; python: 3,155; sh: 198; xml: 174; pascal: 136; makefile: 12
file content (69 lines) | stat: -rw-r--r-- 2,063 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Module that checks whether the compiler supports the
# quadruple precision floating point math
#
# Adds target QuadMath::QuadMath if found
#
# perform tests
include(CheckCXXSourceCompiles)
include(CMakePushCheckState)
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES quadmath)
if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
  set(CMAKE_REQUIRED_FLAGS "-fext-numeric-literals")
endif()
check_cxx_source_compiles("
#include <quadmath.h>

int main ()
{
  __float128 r = 1.0q;
  r = strtoflt128(\"1.2345678\", NULL);
  return 0;
}" QuadMath_COMPILES)
cmake_pop_check_state()  # Reset CMAKE_REQUIRED_XXX variables

if(QuadMath_COMPILES)
  # Use additional variable for better report message
  set(QuadMath_VAR "(Supported by compiler)")
endif()

# Report that package was found
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(QuadMath
  DEFAULT_MSG
  QuadMath_VAR QuadMath_COMPILES
)

# add imported target for quadmath
if(QuadMath_FOUND AND NOT TARGET QuadMath::QuadMath)
  # Compiler supports QuadMath: Add appropriate linker flag
  add_library(QuadMath::QuadMath INTERFACE IMPORTED)
  target_link_libraries(QuadMath::QuadMath INTERFACE quadmath)

  target_compile_definitions(QuadMath::QuadMath INTERFACE
    _GLIBCXX_USE_FLOAT128
  )
  target_compile_options(QuadMath::QuadMath INTERFACE
    $<$<CXX_COMPILER_ID:GNU>:-fext-numeric-literals>
  )

  # Check for numeric_limits specialization
  cmake_push_check_state()
  set(CMAKE_REQUIRED_LIBRARIES quadmath)
  set(CMAKE_REQUIRED_FLAGS)
  if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
    set(CMAKE_REQUIRED_FLAGS "-fext-numeric-literals")
  endif()
  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_GLIBCXX_USE_FLOAT128")
  check_cxx_source_compiles("
  #include <limits>
  int main()
  {
     static_assert(std::numeric_limits<__float128>::is_specialized);
     return 0;
  }" QuadMath_HAS_LIMITS)
  cmake_pop_check_state()  # Reset CMAKE_REQUIRED_XXX variables
  if(QuadMath_HAS_LIMITS)
    target_compile_definitions(QuadMath::QuadMath INTERFACE LIMITS_HAS_QUAD=1)
  endif()
endif()