aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmake
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2010-04-19 11:19:22 -0400
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2010-04-19 11:19:22 -0400
commit84d1b2ae3a7187f418b1cbbec03eabda372ea699 (patch)
tree2a62b619ec3e5299edfcf3b7e4a184670ff3e29a /cmake
parent40b2aaa8b149403a8f345f1f7721ddd6088db669 (diff)
add platform check for how to link to the standard math library.
This allows to support QNX.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/EigenTesting.cmake3
-rw-r--r--cmake/FindEigen3.cmake3
-rw-r--r--cmake/FindStandardMathLibrary.cmake64
3 files changed, 69 insertions, 1 deletions
diff --git a/cmake/EigenTesting.cmake b/cmake/EigenTesting.cmake
index 3bb9aed2b..4b2ee9f6f 100644
--- a/cmake/EigenTesting.cmake
+++ b/cmake/EigenTesting.cmake
@@ -40,6 +40,9 @@ macro(ei_add_test_internal testname testname_with_suffix)
ei_add_target_property(${targetname} COMPILE_FLAGS "${ARGV2}")
endif(${ARGC} GREATER 2)
+ if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
+ target_link_libraries(${targetname} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO})
+ endif()
if(EXTERNAL_LIBS)
target_link_libraries(${targetname} ${EXTERNAL_LIBS})
endif()
diff --git a/cmake/FindEigen3.cmake b/cmake/FindEigen3.cmake
index b87ebff4b..9c546a05d 100644
--- a/cmake/FindEigen3.cmake
+++ b/cmake/FindEigen3.cmake
@@ -12,7 +12,8 @@
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
-# Redistribution and use is allowed according to the terms of the BSD license.
+# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
if(NOT Eigen3_FIND_VERSION)
if(NOT Eigen3_FIND_VERSION_MAJOR)
diff --git a/cmake/FindStandardMathLibrary.cmake b/cmake/FindStandardMathLibrary.cmake
new file mode 100644
index 000000000..711b0e4b4
--- /dev/null
+++ b/cmake/FindStandardMathLibrary.cmake
@@ -0,0 +1,64 @@
+# - Try to find how to link to the standard math library, if anything at all is needed to do.
+# On most platforms this is automatic, but for example it's not automatic on QNX.
+#
+# Once done this will define
+#
+# STANDARD_MATH_LIBRARY_FOUND - we found how to successfully link to the standard math library
+# STANDARD_MATH_LIBRARY - the name of the standard library that one has to link to.
+# -- this will be left empty if it's automatic (most platforms).
+# -- this will be set to "m" on platforms where one must explicitly
+# pass the "-lm" linker flag.
+#
+# Copyright (c) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
+
+
+include(CheckCXXSourceCompiles)
+
+# a little test program for c++ math functions.
+# notice the std:: is required on some platforms such as QNX
+
+set(find_standard_math_library_test_program
+"#include<cmath>
+int main() { std::sin(0.0); std::log(0.0f); }")
+
+# first try compiling/linking the test program without any linker flags
+
+set(CMAKE_REQUIRED_FLAGS "")
+set(CMAKE_REQUIRED_LIBRARIES "")
+CHECK_CXX_SOURCE_COMPILES(
+ "${find_standard_math_library_test_program}"
+ standard_math_library_linked_to_automatically
+)
+
+if(standard_math_library_linked_to_automatically)
+
+ # the test program linked successfully without any linker flag.
+ set(STANDARD_MATH_LIBRARY "")
+ set(STANDARD_MATH_LIBRARY_FOUND TRUE)
+
+else()
+
+ # the test program did not link successfully without any linker flag.
+ # This is a very uncommon case that so far we only saw on QNX. The next try is the
+ # standard name 'm' for the standard math library.
+
+ set(CMAKE_REQUIRED_LIBRARIES "m")
+ CHECK_CXX_SOURCE_COMPILES(
+ "${find_standard_math_library_test_program}"
+ standard_math_library_linked_to_as_m)
+
+ if(standard_math_library_linked_to_as_m)
+
+ # the test program linked successfully when linking to the 'm' library
+ set(STANDARD_MATH_LIBRARY "m")
+ set(STANDARD_MATH_LIBRARY_FOUND TRUE)
+
+ else()
+
+ # the test program still doesn't link successfully
+ set(STANDARD_MATH_LIBRARY_FOUND FALSE)
+
+ endif()
+
+endif()