diff --git a/CMakeLists.txt b/CMakeLists.txt index ea7aea118..a6cbfb1b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,38 @@ if(EIGEN_BUILD_LIB) option(EIGEN_TEST_LIB "Build the unit tests using the library (disable -pedantic)" OFF) endif(EIGEN_BUILD_LIB) + +############################################################################# +# find how to link to the standard libraries # +############################################################################# + +find_package(StandardMathLibrary) + +set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "") + +if(NOT STANDARD_MATH_LIBRARY_FOUND) + + message(FATAL_ERROR + "Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.") + +else() + + if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) + set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${STANDARD_MATH_LIBRARY}") + else() + set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}") + endif() + +endif() + +if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) + message(STATUS "Standard libraries to link to explicitly: ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}") +else() + message(STATUS "Standard libraries to link to explicitly: none") +endif() + + + set(CMAKE_INCLUDE_CURRENT_DIR ON) if(CMAKE_COMPILER_IS_GNUCXX) diff --git a/doc/examples/CMakeLists.txt b/doc/examples/CMakeLists.txt index 29cf078c1..9db5b1f58 100644 --- a/doc/examples/CMakeLists.txt +++ b/doc/examples/CMakeLists.txt @@ -5,6 +5,9 @@ ADD_CUSTOM_TARGET(all_examples) FOREACH(example_src ${examples_SRCS}) GET_FILENAME_COMPONENT(example ${example_src} NAME_WE) ADD_EXECUTABLE(${example} ${example_src}) +if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) + target_link_libraries(${example} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}) +endif() GET_TARGET_PROPERTY(example_executable ${example} LOCATION) ADD_CUSTOM_COMMAND( diff --git a/doc/snippets/CMakeLists.txt b/doc/snippets/CMakeLists.txt index 72bd7770a..7458830b0 100644 --- a/doc/snippets/CMakeLists.txt +++ b/doc/snippets/CMakeLists.txt @@ -11,6 +11,9 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/compile_snippet.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src}) ADD_EXECUTABLE(${compile_snippet_target} ${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src}) +if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) + target_link_libraries(${compile_snippet_target} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}) +endif() GET_TARGET_PROPERTY(compile_snippet_executable ${compile_snippet_target} LOCATION) ADD_CUSTOM_COMMAND( diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9cdebb02c..179fbada2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -161,6 +161,10 @@ macro(ei_add_test testname) target_link_libraries(${targetname} Eigen2) endif(TEST_LIB) + if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) + target_link_libraries(${targetname} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}) + endif() + target_link_libraries(${targetname} ${EXTERNAL_LIBS}) if(${ARGC} GREATER 2) string(STRIP "${ARGV2}" ARGV2_stripped)