| 1 |
# * downloaded Nov 2016 from https://android.googlesource.com/platform/external/eigen/+/master/cmake/FindStandardMathLibrary.cmake |
| 2 |
# * changed CXX to C |
| 3 |
# * note that full path to libm *not* detected |
| 4 |
|
| 5 |
# - Try to find how to link to the standard math library, if anything at all is needed to do. |
| 6 |
# On most platforms this is automatic, but for example it's not automatic on QNX. |
| 7 |
# |
| 8 |
# Once done this will define |
| 9 |
# |
| 10 |
# STANDARD_MATH_LIBRARY_FOUND - we found how to successfully link to the standard math library |
| 11 |
# STANDARD_MATH_LIBRARY - the name of the standard library that one has to link to. |
| 12 |
# -- this will be left empty if it's automatic (most platforms). |
| 13 |
# -- this will be set to "m" on platforms where one must explicitly |
| 14 |
# pass the "-lm" linker flag. |
| 15 |
# |
| 16 |
# Copyright (c) 2010 Benoit Jacob <[email protected]> |
| 17 |
# Redistribution and use is allowed according to the terms of the 2-clause BSD license. |
| 18 |
include(CheckCSourceCompiles) |
| 19 |
# a little test program for c++ math functions. |
| 20 |
# notice the std:: is required on some platforms such as QNX |
| 21 |
set(find_standard_math_library_test_program |
| 22 |
"#include<math.h> |
| 23 |
int main() { sin(0.0); log(0.0f); }") |
| 24 |
# C++ test program |
| 25 |
# "#include<cmath> |
| 26 |
# int main() { std::sin(0.0); std::log(0.0f); }") |
| 27 |
# first try compiling/linking the test program without any linker flags |
| 28 |
set(CMAKE_REQUIRED_FLAGS "") |
| 29 |
set(CMAKE_REQUIRED_LIBRARIES "") |
| 30 |
CHECK_C_SOURCE_COMPILES( |
| 31 |
"${find_standard_math_library_test_program}" |
| 32 |
standard_math_library_linked_to_automatically |
| 33 |
) |
| 34 |
if(standard_math_library_linked_to_automatically) |
| 35 |
# the test program linked successfully without any linker flag. |
| 36 |
set(STANDARD_MATH_LIBRARY "") |
| 37 |
set(STANDARD_MATH_LIBRARY_FOUND TRUE) |
| 38 |
else() |
| 39 |
# the test program did not link successfully without any linker flag. |
| 40 |
# This is a very uncommon case that so far we only saw on QNX. The next try is the |
| 41 |
# standard name 'm' for the standard math library. |
| 42 |
set(CMAKE_REQUIRED_LIBRARIES "m") |
| 43 |
CHECK_C_SOURCE_COMPILES( |
| 44 |
"${find_standard_math_library_test_program}" |
| 45 |
standard_math_library_linked_to_as_m) |
| 46 |
if(standard_math_library_linked_to_as_m) |
| 47 |
# the test program linked successfully when linking to the 'm' library |
| 48 |
set(STANDARD_MATH_LIBRARY "m") |
| 49 |
set(STANDARD_MATH_LIBRARY_FOUND TRUE) |
| 50 |
else() |
| 51 |
# the test program still doesn't link successfully |
| 52 |
set(STANDARD_MATH_LIBRARY_FOUND FALSE) |
| 53 |
endif() |
| 54 |
endif() |