mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-01-30 17:40:05 +08:00
add platform check for how to link to the standard math library.
This allows to support QNX.
This commit is contained in:
parent
40b2aaa8b1
commit
84d1b2ae3a
@ -2,10 +2,17 @@ project(Eigen)
|
||||
|
||||
cmake_minimum_required(VERSION 2.6.2)
|
||||
|
||||
|
||||
# guard against in-source builds
|
||||
|
||||
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
||||
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. (you may need to remove CMakeCache.txt ")
|
||||
endif()
|
||||
|
||||
#############################################################################
|
||||
# retrieve version infomation #
|
||||
#############################################################################
|
||||
|
||||
# automatically parse the version number
|
||||
file(READ "${CMAKE_SOURCE_DIR}/Eigen/src/Core/util/Macros.h" _eigen_version_header)
|
||||
string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}")
|
||||
@ -33,10 +40,40 @@ else(EIGEN_HG_CHANGESET)
|
||||
set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}")
|
||||
endif(EIGEN_HG_CHANGESET)
|
||||
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||
|
||||
#############################################################################
|
||||
# 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()
|
||||
|
||||
option(EIGEN_BUILD_BTL "Build benchmark suite" OFF)
|
||||
if(NOT WIN32)
|
||||
option(EIGEN_BUILD_PKGCONFIG "Build pkg-config .pc file for Eigen" ON)
|
||||
|
@ -6,6 +6,12 @@ set(EigenBlas_SRCS single.cpp double.cpp complex_single.cpp complex_double.cpp x
|
||||
|
||||
add_library(eigen_blas_static ${EigenBlas_SRCS})
|
||||
add_library(eigen_blas SHARED ${EigenBlas_SRCS})
|
||||
|
||||
if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
|
||||
target_link_libraries(eigen_blas_static ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO})
|
||||
target_link_libraries(eigen_blas ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO})
|
||||
endif()
|
||||
|
||||
add_dependencies(blas eigen_blas eigen_blas_static)
|
||||
|
||||
install(TARGETS eigen_blas
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
64
cmake/FindStandardMathLibrary.cmake
Normal file
64
cmake/FindStandardMathLibrary.cmake
Normal file
@ -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()
|
@ -1,17 +1,20 @@
|
||||
FILE(GLOB examples_SRCS "*.cpp")
|
||||
file(GLOB examples_SRCS "*.cpp")
|
||||
|
||||
ADD_CUSTOM_TARGET(all_examples)
|
||||
add_custom_target(all_examples)
|
||||
|
||||
FOREACH(example_src ${examples_SRCS})
|
||||
GET_FILENAME_COMPONENT(example ${example_src} NAME_WE)
|
||||
ADD_EXECUTABLE(${example} ${example_src})
|
||||
GET_TARGET_PROPERTY(example_executable
|
||||
${example} LOCATION)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET ${example}
|
||||
POST_BUILD
|
||||
COMMAND ${example_executable}
|
||||
ARGS >${CMAKE_CURRENT_BINARY_DIR}/${example}.out
|
||||
)
|
||||
ADD_DEPENDENCIES(all_examples ${example})
|
||||
ENDFOREACH(example_src)
|
||||
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(
|
||||
TARGET ${example}
|
||||
POST_BUILD
|
||||
COMMAND ${example_executable}
|
||||
ARGS >${CMAKE_CURRENT_BINARY_DIR}/${example}.out
|
||||
)
|
||||
add_dependencies(all_examples ${example})
|
||||
endforeach(example_src)
|
||||
|
@ -1,25 +1,28 @@
|
||||
FILE(GLOB snippets_SRCS "*.cpp")
|
||||
file(GLOB snippets_SRCS "*.cpp")
|
||||
|
||||
ADD_CUSTOM_TARGET(all_snippets)
|
||||
add_custom_target(all_snippets)
|
||||
|
||||
FOREACH(snippet_src ${snippets_SRCS})
|
||||
GET_FILENAME_COMPONENT(snippet ${snippet_src} NAME_WE)
|
||||
SET(compile_snippet_target compile_${snippet})
|
||||
SET(compile_snippet_src ${compile_snippet_target}.cpp)
|
||||
FILE(READ ${snippet_src} snippet_source_code)
|
||||
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/compile_snippet.cpp.in
|
||||
foreach(snippet_src ${snippets_SRCS})
|
||||
get_filename_component(snippet ${snippet_src} NAME_WE)
|
||||
set(compile_snippet_target compile_${snippet})
|
||||
set(compile_snippet_src ${compile_snippet_target}.cpp)
|
||||
file(READ ${snippet_src} snippet_source_code)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/compile_snippet.cpp.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src})
|
||||
ADD_EXECUTABLE(${compile_snippet_target}
|
||||
add_executable(${compile_snippet_target}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src})
|
||||
GET_TARGET_PROPERTY(compile_snippet_executable
|
||||
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(
|
||||
add_custom_command(
|
||||
TARGET ${compile_snippet_target}
|
||||
POST_BUILD
|
||||
COMMAND ${compile_snippet_executable}
|
||||
ARGS >${CMAKE_CURRENT_BINARY_DIR}/${snippet}.out
|
||||
)
|
||||
ADD_DEPENDENCIES(all_snippets ${compile_snippet_target})
|
||||
add_dependencies(all_snippets ${compile_snippet_target})
|
||||
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src}
|
||||
PROPERTIES OBJECT_DEPENDS ${snippet_src})
|
||||
ENDFOREACH(snippet_src)
|
||||
endforeach(snippet_src)
|
||||
|
@ -3,15 +3,18 @@ FILE(GLOB examples_SRCS "*.cpp")
|
||||
ADD_CUSTOM_TARGET(unsupported_examples)
|
||||
|
||||
FOREACH(example_src ${examples_SRCS})
|
||||
GET_FILENAME_COMPONENT(example ${example_src} NAME_WE)
|
||||
ADD_EXECUTABLE(example_${example} ${example_src})
|
||||
GET_TARGET_PROPERTY(example_executable
|
||||
example_${example} LOCATION)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET example_${example}
|
||||
POST_BUILD
|
||||
COMMAND ${example_executable}
|
||||
ARGS >${CMAKE_CURRENT_BINARY_DIR}/${example}.out
|
||||
)
|
||||
ADD_DEPENDENCIES(unsupported_examples example_${example})
|
||||
GET_FILENAME_COMPONENT(example ${example_src} NAME_WE)
|
||||
ADD_EXECUTABLE(example_${example} ${example_src})
|
||||
if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
|
||||
target_link_libraries(example_${example} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO})
|
||||
endif()
|
||||
GET_TARGET_PROPERTY(example_executable
|
||||
example_${example} LOCATION)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET example_${example}
|
||||
POST_BUILD
|
||||
COMMAND ${example_executable}
|
||||
ARGS >${CMAKE_CURRENT_BINARY_DIR}/${example}.out
|
||||
)
|
||||
ADD_DEPENDENCIES(unsupported_examples example_${example})
|
||||
ENDFOREACH(example_src)
|
||||
|
@ -11,6 +11,9 @@ FOREACH(snippet_src ${snippets_SRCS})
|
||||
${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(
|
||||
|
Loading…
Reference in New Issue
Block a user