Skip to content
Snippets Groups Projects
Commit f18ce6b2 authored by Simon Praetorius's avatar Simon Praetorius
Browse files

Rewrite FindQuadMath to provide imported targets

parent 30cbe040
Branches
Tags
1 merge request!819Rewrite FindQuadMath to provide imported targets
# .. cmake_module::
#
# Find the GCC Quad-Precision library
#
# Sets the following variables:
#
# :code:`QUADMATH_FOUND`
# True if the Quad-Precision library was found.
#
#
# search for the header quadmath.h
include(CheckIncludeFile)
check_include_file(quadmath.h QUADMATH_HEADER)
include(CheckCSourceCompiles)
include(CMakePushCheckState)
#[=======================================================================[.rst:
FindQuadMath
------------
Find the GCC Quad-Precision library
This module checks if the used compiler has built-in support for QuadMath
by compiling a small source file.
Imported Targets
^^^^^^^^^^^^^^^^
This module provides the following imported targets, if found:
``QuadMath::QuadMath``
Library to link against if QuadMath should be used.
Result Variables
^^^^^^^^^^^^^^^^
This will define the following variables:
``QuadMath_FOUND``
True if the Quad-Precision library was found.
cmake_push_check_state() # Save variables
#]=======================================================================]
# Add a feature summary for this package
include(FeatureSummary)
set_package_properties(QuadMath PROPERTIES
DESCRIPTION "GCC Quad-Precision Math Library"
URL "https://gcc.gnu.org/onlinedocs/libquadmath"
)
# Check if QuadMath support is built into the compiler
include(CheckCXXSourceCompiles)
include(CMakePushCheckState)
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES quadmath)
check_c_source_compiles("
check_cxx_source_compiles("
#include <quadmath.h>
int main ()
......@@ -27,33 +45,31 @@ int main ()
__float128 r = 1.0q;
r = strtoflt128(\"1.2345678\", NULL);
return 0;
}" QUADMATH_COMPILES)
cmake_pop_check_state()
}" 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"
find_package_handle_standard_args(QuadMath
DEFAULT_MSG
QUADMATH_HEADER
QUADMATH_COMPILES
QuadMath_VAR QuadMath_HEADER QuadMath_COMPILES
)
# text for feature summary
set_package_properties("QuadMath" PROPERTIES
DESCRIPTION "GCC Quad-Precision library")
# set HAVE_QUADMATH for config.h
set(HAVE_QUADMATH ${QUADMATH_FOUND})
# -fext-numeric-literals is a GCC extension not available in other compilers like clang
if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
set(_QUADMATH_EXT_NUMERIC_LITERALS "-fext-numeric-literals")
endif()
# 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)
# register all QuadMath related flags
if(HAVE_QUADMATH)
dune_register_package_flags(COMPILE_DEFINITIONS "ENABLE_QUADMATH=1" "_GLIBCXX_USE_FLOAT128=1"
COMPILE_OPTIONS ${_QUADMATH_EXT_NUMERIC_LITERALS}
LIBRARIES "quadmath")
target_compile_definitions(QuadMath::QuadMath INTERFACE
_GLIBCXX_USE_FLOAT128
)
target_compile_options(QuadMath::QuadMath INTERFACE
$<$<CXX_COMPILER_ID:GNU>:-fext-numeric-literals>
)
endif()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment