3 cmake_minimum_required(VERSION 2.8.5)
5 # guard against in-source builds
7 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
8 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. ")
11 # Alias Eigen_*_DIR to Eigen3_*_DIR:
13 set(Eigen_SOURCE_DIR ${Eigen3_SOURCE_DIR})
14 set(Eigen_BINARY_DIR ${Eigen3_BINARY_DIR})
16 # guard against bad build-type strings
18 if (NOT CMAKE_BUILD_TYPE)
19 set(CMAKE_BUILD_TYPE "Release")
22 string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
23 if( NOT cmake_build_type_tolower STREQUAL "debug"
24 AND NOT cmake_build_type_tolower STREQUAL "release"
25 AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo")
26 message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Release, RelWithDebInfo (case-insensitive).")
30 #############################################################################
31 # retrieve version infomation #
32 #############################################################################
34 # automatically parse the version number
35 file(READ "${PROJECT_SOURCE_DIR}/Eigen/src/Core/util/Macros.h" _eigen_version_header)
36 string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}")
37 set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}")
38 string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen_major_version_match "${_eigen_version_header}")
39 set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}")
40 string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen_minor_version_match "${_eigen_version_header}")
41 set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}")
42 set(EIGEN_VERSION_NUMBER ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})
44 # if the mercurial program is absent, this will leave the EIGEN_HG_CHANGESET string empty,
45 # but won't stop CMake.
46 execute_process(COMMAND hg tip -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_HGTIP_OUTPUT)
47 execute_process(COMMAND hg branch -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_BRANCH_OUTPUT)
49 # if this is the default (aka development) branch, extract the mercurial changeset number from the hg tip output...
50 if(EIGEN_BRANCH_OUTPUT MATCHES "default")
51 string(REGEX MATCH "^changeset: *[0-9]*:([0-9;a-f]+).*" EIGEN_HG_CHANGESET_MATCH "${EIGEN_HGTIP_OUTPUT}")
52 set(EIGEN_HG_CHANGESET "${CMAKE_MATCH_1}")
53 endif(EIGEN_BRANCH_OUTPUT MATCHES "default")
54 #...and show it next to the version number
55 if(EIGEN_HG_CHANGESET)
56 set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER} (mercurial changeset ${EIGEN_HG_CHANGESET})")
57 else(EIGEN_HG_CHANGESET)
58 set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}")
59 endif(EIGEN_HG_CHANGESET)
62 include(CheckCXXCompilerFlag)
63 include(GNUInstallDirs)
65 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
67 #############################################################################
68 # find how to link to the standard libraries #
69 #############################################################################
71 find_package(StandardMathLibrary)
74 set(EIGEN_TEST_CUSTOM_LINKER_FLAGS "" CACHE STRING "Additional linker flags when linking unit tests.")
75 set(EIGEN_TEST_CUSTOM_CXX_FLAGS "" CACHE STRING "Additional compiler flags when compiling unit tests.")
77 set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "")
79 if(NOT STANDARD_MATH_LIBRARY_FOUND)
82 "Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.")
86 if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
87 set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${STANDARD_MATH_LIBRARY}")
89 set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}")
94 if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
95 message(STATUS "Standard libraries to link to explicitly: ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}")
97 message(STATUS "Standard libraries to link to explicitly: none")
100 option(EIGEN_BUILD_BTL "Build benchmark suite" OFF)
102 # Disable pkgconfig only for native Windows builds
103 if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
104 option(EIGEN_BUILD_PKGCONFIG "Build pkg-config .pc file for Eigen" ON)
107 set(CMAKE_INCLUDE_CURRENT_DIR ON)
109 option(EIGEN_SPLIT_LARGE_TESTS "Split large tests into smaller executables" ON)
111 option(EIGEN_DEFAULT_TO_ROW_MAJOR "Use row-major as default matrix storage order" OFF)
112 if(EIGEN_DEFAULT_TO_ROW_MAJOR)
113 add_definitions("-DEIGEN_DEFAULT_TO_ROW_MAJOR")
116 set(EIGEN_TEST_MAX_SIZE "320" CACHE STRING "Maximal matrix/vector size, default is 320")
118 macro(ei_add_cxx_compiler_flag FLAG)
119 string(REGEX REPLACE "-" "" SFLAG1 ${FLAG})
120 string(REGEX REPLACE "\\+" "p" SFLAG ${SFLAG1})
121 check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORT_${SFLAG})
122 if(COMPILER_SUPPORT_${SFLAG})
123 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
125 endmacro(ei_add_cxx_compiler_flag)
128 # We assume that other compilers are partly compatible with GNUCC
130 # clang outputs some warnings for unknown flags that are not caught by check_cxx_compiler_flag
131 # adding -Werror turns such warnings into errors
132 check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR)
133 if(COMPILER_SUPPORT_WERROR)
134 set(CMAKE_REQUIRED_FLAGS "-Werror")
136 ei_add_cxx_compiler_flag("-pedantic")
137 ei_add_cxx_compiler_flag("-Wall")
138 ei_add_cxx_compiler_flag("-Wextra")
139 #ei_add_cxx_compiler_flag("-Weverything") # clang
141 ei_add_cxx_compiler_flag("-Wundef")
142 ei_add_cxx_compiler_flag("-Wcast-align")
143 ei_add_cxx_compiler_flag("-Wchar-subscripts")
144 ei_add_cxx_compiler_flag("-Wnon-virtual-dtor")
145 ei_add_cxx_compiler_flag("-Wunused-local-typedefs")
146 ei_add_cxx_compiler_flag("-Wpointer-arith")
147 ei_add_cxx_compiler_flag("-Wwrite-strings")
148 ei_add_cxx_compiler_flag("-Wformat-security")
149 ei_add_cxx_compiler_flag("-Wshorten-64-to-32")
150 ei_add_cxx_compiler_flag("-Wlogical-op")
151 ei_add_cxx_compiler_flag("-Wenum-conversion")
152 ei_add_cxx_compiler_flag("-Wc++11-extensions")
153 ei_add_cxx_compiler_flag("-Wdouble-promotion")
154 # ei_add_cxx_compiler_flag("-Wconversion")
156 # -Wshadow is insanely too strict with gcc, hopefully it will become usable with gcc 6
157 # if(NOT CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.0.0"))
158 if(NOT CMAKE_COMPILER_IS_GNUCXX)
159 ei_add_cxx_compiler_flag("-Wshadow")
162 ei_add_cxx_compiler_flag("-Wno-psabi")
163 ei_add_cxx_compiler_flag("-Wno-variadic-macros")
164 ei_add_cxx_compiler_flag("-Wno-long-long")
166 ei_add_cxx_compiler_flag("-fno-check-new")
167 ei_add_cxx_compiler_flag("-fno-common")
168 ei_add_cxx_compiler_flag("-fstrict-aliasing")
169 ei_add_cxx_compiler_flag("-wd981") # disable ICC's "operands are evaluated in unspecified order" remark
170 ei_add_cxx_compiler_flag("-wd2304") # disable ICC's "warning #2304: non-explicit constructor with single argument may cause implicit type conversion" produced by -Wnon-virtual-dtor
173 # The -ansi flag must be added last, otherwise it is also used as a linker flag by check_cxx_compiler_flag making it fails
174 # Moreover we should not set both -strict-ansi and -ansi
175 check_cxx_compiler_flag("-strict-ansi" COMPILER_SUPPORT_STRICTANSI)
176 ei_add_cxx_compiler_flag("-Qunused-arguments") # disable clang warning: argument unused during compilation: '-ansi'
178 if(COMPILER_SUPPORT_STRICTANSI)
179 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -strict-ansi")
181 ei_add_cxx_compiler_flag("-ansi")
185 ei_add_cxx_compiler_flag("-pie")
186 ei_add_cxx_compiler_flag("-fPIE")
189 set(CMAKE_REQUIRED_FLAGS "")
191 option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
193 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
194 message(STATUS "Enabling SSE2 in tests/examples")
197 option(EIGEN_TEST_SSE3 "Enable/Disable SSE3 in tests/examples" OFF)
199 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
200 message(STATUS "Enabling SSE3 in tests/examples")
203 option(EIGEN_TEST_SSSE3 "Enable/Disable SSSE3 in tests/examples" OFF)
205 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3")
206 message(STATUS "Enabling SSSE3 in tests/examples")
209 option(EIGEN_TEST_SSE4_1 "Enable/Disable SSE4.1 in tests/examples" OFF)
210 if(EIGEN_TEST_SSE4_1)
211 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
212 message(STATUS "Enabling SSE4.1 in tests/examples")
215 option(EIGEN_TEST_SSE4_2 "Enable/Disable SSE4.2 in tests/examples" OFF)
216 if(EIGEN_TEST_SSE4_2)
217 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
218 message(STATUS "Enabling SSE4.2 in tests/examples")
221 option(EIGEN_TEST_AVX "Enable/Disable AVX in tests/examples" OFF)
223 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
224 message(STATUS "Enabling AVX in tests/examples")
227 option(EIGEN_TEST_FMA "Enable/Disable FMA in tests/examples" OFF)
228 if(EIGEN_TEST_FMA AND NOT EIGEN_TEST_NEON)
229 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfma")
230 message(STATUS "Enabling FMA in tests/examples")
233 option(EIGEN_TEST_AVX512 "Enable/Disable AVX512 in tests/examples" OFF)
234 if(EIGEN_TEST_AVX512)
235 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f -fabi-version=6 -DEIGEN_ENABLE_AVX512")
236 message(STATUS "Enabling AVX512 in tests/examples")
239 option(EIGEN_TEST_F16C "Enable/Disable F16C in tests/examples" OFF)
241 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mf16c")
242 message(STATUS "Enabling F16C in tests/examples")
245 option(EIGEN_TEST_ALTIVEC "Enable/Disable AltiVec in tests/examples" OFF)
246 if(EIGEN_TEST_ALTIVEC)
247 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec -mabi=altivec")
248 message(STATUS "Enabling AltiVec in tests/examples")
251 option(EIGEN_TEST_VSX "Enable/Disable VSX in tests/examples" OFF)
253 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -mvsx")
254 message(STATUS "Enabling VSX in tests/examples")
257 option(EIGEN_TEST_NEON "Enable/Disable Neon in tests/examples" OFF)
260 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon-vfpv4")
262 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
264 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=hard")
265 message(STATUS "Enabling NEON in tests/examples")
268 option(EIGEN_TEST_NEON64 "Enable/Disable Neon in tests/examples" OFF)
269 if(EIGEN_TEST_NEON64)
270 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
271 message(STATUS "Enabling NEON in tests/examples")
274 option(EIGEN_TEST_ZVECTOR "Enable/Disable S390X(zEC13) ZVECTOR in tests/examples" OFF)
275 if(EIGEN_TEST_ZVECTOR)
276 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=z13 -mzvector")
277 message(STATUS "Enabling S390X(zEC13) ZVECTOR in tests/examples")
280 check_cxx_compiler_flag("-fopenmp" COMPILER_SUPPORT_OPENMP)
281 if(COMPILER_SUPPORT_OPENMP)
282 option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
283 if(EIGEN_TEST_OPENMP)
284 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
285 message(STATUS "Enabling OpenMP in tests/examples")
291 # C4127 - conditional expression is constant
292 # C4714 - marked as __forceinline not inlined (I failed to deactivate it selectively)
293 # We can disable this warning in the unit tests since it is clear that it occurs
294 # because we are oftentimes returning objects that have a destructor or may
295 # throw exceptions - in particular in the unit tests we are throwing extra many
296 # exceptions to cover indexing errors.
297 # C4505 - unreferenced local function has been removed (impossible to deactive selectively)
298 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /wd4127 /wd4505 /wd4714")
300 # replace all /Wx by /W4
301 string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
303 check_cxx_compiler_flag("/openmp" COMPILER_SUPPORT_OPENMP)
304 if(COMPILER_SUPPORT_OPENMP)
305 option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
306 if(EIGEN_TEST_OPENMP)
307 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
308 message(STATUS "Enabling OpenMP in tests/examples")
312 option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
315 # arch is not supported on 64 bit systems, SSE is enabled automatically.
316 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
317 endif(NOT CMAKE_CL_64)
318 message(STATUS "Enabling SSE2 in tests/examples")
319 endif(EIGEN_TEST_SSE2)
322 option(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION "Disable explicit vectorization in tests/examples" OFF)
323 option(EIGEN_TEST_X87 "Force using X87 instructions. Implies no vectorization." OFF)
324 option(EIGEN_TEST_32BIT "Force generating 32bit code." OFF)
327 set(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION ON)
328 if(CMAKE_COMPILER_IS_GNUCXX)
329 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=387")
330 message(STATUS "Forcing use of x87 instructions in tests/examples")
332 message(STATUS "EIGEN_TEST_X87 ignored on your compiler")
337 if(CMAKE_COMPILER_IS_GNUCXX)
338 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
339 message(STATUS "Forcing generation of 32-bit code in tests/examples")
341 message(STATUS "EIGEN_TEST_32BIT ignored on your compiler")
345 if(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
346 add_definitions(-DEIGEN_DONT_VECTORIZE=1)
347 message(STATUS "Disabling vectorization in tests/examples")
350 option(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT "Disable explicit alignment (hence vectorization) in tests/examples" OFF)
351 if(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT)
352 add_definitions(-DEIGEN_DONT_ALIGN=1)
353 message(STATUS "Disabling alignment in tests/examples")
356 option(EIGEN_TEST_NO_EXCEPTIONS "Disables C++ exceptions" OFF)
357 if(EIGEN_TEST_NO_EXCEPTIONS)
358 ei_add_cxx_compiler_flag("-fno-exceptions")
359 message(STATUS "Disabling exceptions in tests/examples")
362 option(EIGEN_TEST_CXX11 "Enable testing with C++11 and C++11 features (e.g. Tensor module)." OFF)
364 set(EIGEN_CUDA_COMPUTE_ARCH 30 CACHE STRING "The CUDA compute architecture level to target when compiling CUDA code")
366 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
368 # Backward compatibility support for EIGEN_INCLUDE_INSTALL_DIR
369 if(EIGEN_INCLUDE_INSTALL_DIR)
370 message(WARNING "EIGEN_INCLUDE_INSTALL_DIR is deprecated. Use INCLUDE_INSTALL_DIR instead.")
373 if(EIGEN_INCLUDE_INSTALL_DIR AND NOT INCLUDE_INSTALL_DIR)
374 set(INCLUDE_INSTALL_DIR ${EIGEN_INCLUDE_INSTALL_DIR}
375 CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where Eigen header files are installed")
377 set(INCLUDE_INSTALL_DIR
378 "${CMAKE_INSTALL_INCLUDEDIR}/eigen3"
379 CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where Eigen header files are installed"
382 set(CMAKEPACKAGE_INSTALL_DIR
383 "${CMAKE_INSTALL_DATADIR}/eigen3/cmake"
384 CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where Eigen3Config.cmake is installed"
386 set(PKGCONFIG_INSTALL_DIR
387 "${CMAKE_INSTALL_DATADIR}/pkgconfig"
388 CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where eigen3.pc is installed"
392 # similar to set_target_properties but append the property instead of overwriting it
393 macro(ei_add_target_property target prop value)
395 get_target_property(previous ${target} ${prop})
396 # if the property wasn't previously set, ${previous} is now "previous-NOTFOUND" which cmake allows catching with plain if()
400 set_target_properties(${target} PROPERTIES ${prop} "${previous} ${value}")
401 endmacro(ei_add_target_property)
404 signature_of_eigen3_matrix_library
405 DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel
408 if(EIGEN_BUILD_PKGCONFIG)
409 configure_file(eigen3.pc.in eigen3.pc @ONLY)
410 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/eigen3.pc
411 DESTINATION ${PKGCONFIG_INSTALL_DIR}
415 add_subdirectory(Eigen)
417 add_subdirectory(doc EXCLUDE_FROM_ALL)
419 include(EigenConfigureTesting)
421 # fixme, not sure this line is still needed:
422 enable_testing() # must be called from the root CMakeLists, see man page
425 if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
426 add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest
428 add_subdirectory(test EXCLUDE_FROM_ALL)
431 if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
432 add_subdirectory(blas)
433 add_subdirectory(lapack)
435 add_subdirectory(blas EXCLUDE_FROM_ALL)
436 add_subdirectory(lapack EXCLUDE_FROM_ALL)
440 option(EIGEN_TEST_SYCL "Add Sycl support." OFF)
442 set (CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules" "cmake/Modules/" "${CMAKE_MODULE_PATH}")
443 include(FindComputeCpp)
446 add_subdirectory(unsupported)
448 add_subdirectory(demos EXCLUDE_FROM_ALL)
450 # must be after test and unsupported, for configuring buildtests.in
451 add_subdirectory(scripts EXCLUDE_FROM_ALL)
453 # TODO: consider also replacing EIGEN_BUILD_BTL by a custom target "make btl"?
455 add_subdirectory(bench/btl EXCLUDE_FROM_ALL)
456 endif(EIGEN_BUILD_BTL)
459 add_subdirectory(bench/spbench EXCLUDE_FROM_ALL)
462 configure_file(scripts/cdashtesting.cmake.in cdashtesting.cmake @ONLY)
464 ei_testing_print_summary()
467 message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}")
470 option(EIGEN_FAILTEST "Enable failtests." OFF)
472 add_subdirectory(failtest)
475 string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
476 if(cmake_generator_tolower MATCHES "makefile")
477 message(STATUS "Some things you can do now:")
478 message(STATUS "--------------+--------------------------------------------------------------")
479 message(STATUS "Command | Description")
480 message(STATUS "--------------+--------------------------------------------------------------")
481 message(STATUS "make install | Install Eigen. Headers will be installed to:")
482 message(STATUS " | <CMAKE_INSTALL_PREFIX>/<INCLUDE_INSTALL_DIR>")
483 message(STATUS " | Using the following values:")
484 message(STATUS " | CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
485 message(STATUS " | INCLUDE_INSTALL_DIR: ${INCLUDE_INSTALL_DIR}")
486 message(STATUS " | Change the install location of Eigen headers using:")
487 message(STATUS " | cmake . -DCMAKE_INSTALL_PREFIX=yourprefix")
488 message(STATUS " | Or:")
489 message(STATUS " | cmake . -DINCLUDE_INSTALL_DIR=yourdir")
490 message(STATUS "make doc | Generate the API documentation, requires Doxygen & LaTeX")
491 message(STATUS "make check | Build and run the unit-tests. Read this page:")
492 message(STATUS " | http://eigen.tuxfamily.org/index.php?title=Tests")
493 message(STATUS "make blas | Build BLAS library (not the same thing as Eigen)")
494 message(STATUS "make uninstall| Removes files installed by make install")
495 message(STATUS "--------------+--------------------------------------------------------------")
497 message(STATUS "To build/run the unit tests, read this page:")
498 message(STATUS " http://eigen.tuxfamily.org/index.php?title=Tests")
504 set ( EIGEN_VERSION_STRING ${EIGEN_VERSION_NUMBER} )
505 set ( EIGEN_VERSION_MAJOR ${EIGEN_WORLD_VERSION} )
506 set ( EIGEN_VERSION_MINOR ${EIGEN_MAJOR_VERSION} )
507 set ( EIGEN_VERSION_PATCH ${EIGEN_MINOR_VERSION} )
508 set ( EIGEN_DEFINITIONS "")
509 set ( EIGEN_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}" )
510 set ( EIGEN_ROOT_DIR ${CMAKE_INSTALL_PREFIX} )
512 # Interface libraries require at least CMake 3.0
513 if (NOT CMAKE_VERSION VERSION_LESS 3.0)
514 include (CMakePackageConfigHelpers)
516 # Imported target support
517 add_library (eigen INTERFACE)
519 target_compile_definitions (eigen INTERFACE ${EIGEN_DEFINITIONS})
520 target_include_directories (eigen INTERFACE
521 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
522 $<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
525 # Export as title case Eigen
526 set_target_properties (eigen PROPERTIES EXPORT_NAME Eigen)
528 install (TARGETS eigen EXPORT Eigen3Targets)
530 configure_package_config_file (
531 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3Config.cmake.in
532 ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
533 PATH_VARS EIGEN_INCLUDE_DIR EIGEN_ROOT_DIR
534 INSTALL_DESTINATION ${CMAKEPACKAGE_INSTALL_DIR}
535 NO_CHECK_REQUIRED_COMPONENTS_MACRO # Eigen does not provide components
537 # Remove CMAKE_SIZEOF_VOID_P from Eigen3ConfigVersion.cmake since Eigen does
538 # not depend on architecture specific settings or libraries. More
539 # specifically, an Eigen3Config.cmake generated from a 64 bit target can be
540 # used for 32 bit targets as well (and vice versa).
541 set (_Eigen3_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
542 unset (CMAKE_SIZEOF_VOID_P)
543 write_basic_package_version_file (Eigen3ConfigVersion.cmake
544 VERSION ${EIGEN_VERSION_NUMBER}
545 COMPATIBILITY SameMajorVersion)
546 set (CMAKE_SIZEOF_VOID_P ${_Eigen3_CMAKE_SIZEOF_VOID_P})
548 # The Eigen target will be located in the Eigen3 namespace. Other CMake
549 # targets can refer to it using Eigen3::Eigen.
550 export (TARGETS eigen NAMESPACE Eigen3:: FILE Eigen3Targets.cmake)
551 # Export Eigen3 package to CMake registry such that it can be easily found by
552 # CMake even if it has not been installed to a standard directory.
553 export (PACKAGE Eigen3)
555 install (EXPORT Eigen3Targets NAMESPACE Eigen3:: DESTINATION ${CMAKEPACKAGE_INSTALL_DIR})
557 else (NOT CMAKE_VERSION VERSION_LESS 3.0)
558 # Fallback to legacy Eigen3Config.cmake without the imported target
560 # If CMakePackageConfigHelpers module is available (CMake >= 2.8.8)
561 # create a relocatable Config file, otherwise leave the hardcoded paths
562 include(CMakePackageConfigHelpers OPTIONAL RESULT_VARIABLE CPCH_PATH)
565 configure_package_config_file (
566 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3ConfigLegacy.cmake.in
567 ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
568 PATH_VARS EIGEN_INCLUDE_DIR EIGEN_ROOT_DIR
569 INSTALL_DESTINATION ${CMAKEPACKAGE_INSTALL_DIR}
570 NO_CHECK_REQUIRED_COMPONENTS_MACRO # Eigen does not provide components
573 # The PACKAGE_* variables are defined by the configure_package_config_file
574 # but without it we define them manually to the hardcoded paths
576 set(PACKAGE_EIGEN_INCLUDE_DIR ${EIGEN_INCLUDE_DIR})
577 set(PACKAGE_EIGEN_ROOT_DIR ${EIGEN_ROOT_DIR})
578 configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3ConfigLegacy.cmake.in
579 ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
580 @ONLY ESCAPE_QUOTES )
583 write_basic_package_version_file( Eigen3ConfigVersion.cmake
584 VERSION ${EIGEN_VERSION_NUMBER}
585 COMPATIBILITY SameMajorVersion )
587 endif (NOT CMAKE_VERSION VERSION_LESS 3.0)
589 install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/UseEigen3.cmake
590 ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
591 ${CMAKE_CURRENT_BINARY_DIR}/Eigen3ConfigVersion.cmake
592 DESTINATION ${CMAKEPACKAGE_INSTALL_DIR} )
594 # Add uninstall target
595 add_custom_target ( uninstall
596 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/EigenUninstall.cmake)