1project(Eigen3)
2
3cmake_minimum_required(VERSION 2.8.5)
4
5# guard against in-source builds
6
7if(${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. ")
9endif()
10
11# Alias Eigen_*_DIR to Eigen3_*_DIR:
12
13set(Eigen_SOURCE_DIR ${Eigen3_SOURCE_DIR})
14set(Eigen_BINARY_DIR ${Eigen3_BINARY_DIR})
15
16# guard against bad build-type strings
17
18if (NOT CMAKE_BUILD_TYPE)
19  set(CMAKE_BUILD_TYPE "Release")
20endif()
21
22string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
23if(    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).")
27endif()
28
29
30#############################################################################
31# retrieve version infomation                                               #
32#############################################################################
33
34# automatically parse the version number
35file(READ "${PROJECT_SOURCE_DIR}/Eigen/src/Core/util/Macros.h" _eigen_version_header)
36string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}")
37set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}")
38string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen_major_version_match "${_eigen_version_header}")
39set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}")
40string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen_minor_version_match "${_eigen_version_header}")
41set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}")
42set(EIGEN_VERSION_NUMBER ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})
43
44# if the mercurial program is absent, this will leave the EIGEN_HG_CHANGESET string empty,
45# but won't stop CMake.
46execute_process(COMMAND hg tip -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_HGTIP_OUTPUT)
47execute_process(COMMAND hg branch -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_BRANCH_OUTPUT)
48
49# if this is the default (aka development) branch, extract the mercurial changeset number from the hg tip output...
50if(EIGEN_BRANCH_OUTPUT MATCHES "default")
51string(REGEX MATCH "^changeset: *[0-9]*:([0-9;a-f]+).*" EIGEN_HG_CHANGESET_MATCH "${EIGEN_HGTIP_OUTPUT}")
52set(EIGEN_HG_CHANGESET "${CMAKE_MATCH_1}")
53endif(EIGEN_BRANCH_OUTPUT MATCHES "default")
54#...and show it next to the version number
55if(EIGEN_HG_CHANGESET)
56  set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER} (mercurial changeset ${EIGEN_HG_CHANGESET})")
57else(EIGEN_HG_CHANGESET)
58  set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}")
59endif(EIGEN_HG_CHANGESET)
60
61
62include(CheckCXXCompilerFlag)
63include(GNUInstallDirs)
64
65set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
66
67#############################################################################
68# find how to link to the standard libraries                                #
69#############################################################################
70
71find_package(StandardMathLibrary)
72
73
74set(EIGEN_TEST_CUSTOM_LINKER_FLAGS  "" CACHE STRING "Additional linker flags when linking unit tests.")
75set(EIGEN_TEST_CUSTOM_CXX_FLAGS     "" CACHE STRING "Additional compiler flags when compiling unit tests.")
76
77set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "")
78
79if(NOT STANDARD_MATH_LIBRARY_FOUND)
80
81  message(FATAL_ERROR
82    "Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.")
83
84else()
85
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}")
88  else()
89    set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}")
90  endif()
91
92endif()
93
94if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
95  message(STATUS "Standard libraries to link to explicitly: ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}")
96else()
97  message(STATUS "Standard libraries to link to explicitly: none")
98endif()
99
100option(EIGEN_BUILD_BTL "Build benchmark suite" OFF)
101
102# Disable pkgconfig only for native Windows builds
103if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
104  option(EIGEN_BUILD_PKGCONFIG "Build pkg-config .pc file for Eigen" ON)
105endif()
106
107set(CMAKE_INCLUDE_CURRENT_DIR ON)
108
109option(EIGEN_SPLIT_LARGE_TESTS "Split large tests into smaller executables" ON)
110
111option(EIGEN_DEFAULT_TO_ROW_MAJOR "Use row-major as default matrix storage order" OFF)
112if(EIGEN_DEFAULT_TO_ROW_MAJOR)
113  add_definitions("-DEIGEN_DEFAULT_TO_ROW_MAJOR")
114endif()
115
116set(EIGEN_TEST_MAX_SIZE "320" CACHE STRING "Maximal matrix/vector size, default is 320")
117
118macro(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}")
124  endif()
125endmacro(ei_add_cxx_compiler_flag)
126
127if(NOT MSVC)
128  # We assume that other compilers are partly compatible with GNUCC
129
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")
135  endif()
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
140
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")
155
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")
160  endif()
161
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")
165
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
171
172
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'
177
178  if(COMPILER_SUPPORT_STRICTANSI)
179    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -strict-ansi")
180  else()
181    ei_add_cxx_compiler_flag("-ansi")
182  endif()
183
184  if(ANDROID_NDK)
185    ei_add_cxx_compiler_flag("-pie")
186    ei_add_cxx_compiler_flag("-fPIE")
187  endif()
188
189  set(CMAKE_REQUIRED_FLAGS "")
190
191  option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
192  if(EIGEN_TEST_SSE2)
193    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
194    message(STATUS "Enabling SSE2 in tests/examples")
195  endif()
196
197  option(EIGEN_TEST_SSE3 "Enable/Disable SSE3 in tests/examples" OFF)
198  if(EIGEN_TEST_SSE3)
199    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
200    message(STATUS "Enabling SSE3 in tests/examples")
201  endif()
202
203  option(EIGEN_TEST_SSSE3 "Enable/Disable SSSE3 in tests/examples" OFF)
204  if(EIGEN_TEST_SSSE3)
205    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3")
206    message(STATUS "Enabling SSSE3 in tests/examples")
207  endif()
208
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")
213  endif()
214
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")
219  endif()
220
221  option(EIGEN_TEST_AVX "Enable/Disable AVX in tests/examples" OFF)
222  if(EIGEN_TEST_AVX)
223    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
224    message(STATUS "Enabling AVX in tests/examples")
225  endif()
226
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")
231  endif()
232
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")
237  endif()
238
239  option(EIGEN_TEST_F16C "Enable/Disable F16C in tests/examples" OFF)
240  if(EIGEN_TEST_F16C)
241    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mf16c")
242    message(STATUS "Enabling F16C in tests/examples")
243  endif()
244
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")
249  endif()
250
251  option(EIGEN_TEST_VSX "Enable/Disable VSX in tests/examples" OFF)
252  if(EIGEN_TEST_VSX)
253    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -mvsx")
254    message(STATUS "Enabling VSX in tests/examples")
255  endif()
256
257  option(EIGEN_TEST_NEON "Enable/Disable Neon in tests/examples" OFF)
258  if(EIGEN_TEST_NEON)
259    if(EIGEN_TEST_FMA)
260      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon-vfpv4")
261    else()
262      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
263    endif()
264    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=hard")
265    message(STATUS "Enabling NEON in tests/examples")
266  endif()
267
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")
272  endif()
273
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")
278  endif()
279
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")
286    endif()
287  endif()
288
289else(NOT MSVC)
290
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")
299
300  # replace all /Wx by /W4
301  string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
302
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")
309    endif()
310  endif()
311
312  option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
313  if(EIGEN_TEST_SSE2)
314    if(NOT CMAKE_CL_64)
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)
320endif(NOT MSVC)
321
322option(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION "Disable explicit vectorization in tests/examples" OFF)
323option(EIGEN_TEST_X87 "Force using X87 instructions. Implies no vectorization." OFF)
324option(EIGEN_TEST_32BIT "Force generating 32bit code." OFF)
325
326if(EIGEN_TEST_X87)
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")
331  else()
332    message(STATUS "EIGEN_TEST_X87 ignored on your compiler")
333  endif()
334endif()
335
336if(EIGEN_TEST_32BIT)
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")
340  else()
341    message(STATUS "EIGEN_TEST_32BIT ignored on your compiler")
342  endif()
343endif()
344
345if(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
346  add_definitions(-DEIGEN_DONT_VECTORIZE=1)
347  message(STATUS "Disabling vectorization in tests/examples")
348endif()
349
350option(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT "Disable explicit alignment (hence vectorization) in tests/examples" OFF)
351if(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT)
352  add_definitions(-DEIGEN_DONT_ALIGN=1)
353  message(STATUS "Disabling alignment in tests/examples")
354endif()
355
356option(EIGEN_TEST_NO_EXCEPTIONS "Disables C++ exceptions" OFF)
357if(EIGEN_TEST_NO_EXCEPTIONS)
358  ei_add_cxx_compiler_flag("-fno-exceptions")
359  message(STATUS "Disabling exceptions in tests/examples")
360endif()
361
362option(EIGEN_TEST_CXX11 "Enable testing with C++11 and C++11 features (e.g. Tensor module)." OFF)
363
364set(EIGEN_CUDA_COMPUTE_ARCH 30 CACHE STRING "The CUDA compute architecture level to target when compiling CUDA code")
365
366include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
367
368# Backward compatibility support for EIGEN_INCLUDE_INSTALL_DIR
369if(EIGEN_INCLUDE_INSTALL_DIR)
370  message(WARNING "EIGEN_INCLUDE_INSTALL_DIR is deprecated. Use INCLUDE_INSTALL_DIR instead.")
371endif()
372
373if(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")
376else()
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"
380      )
381endif()
382set(CMAKEPACKAGE_INSTALL_DIR
383    "${CMAKE_INSTALL_DATADIR}/eigen3/cmake"
384    CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where Eigen3Config.cmake is installed"
385    )
386set(PKGCONFIG_INSTALL_DIR
387    "${CMAKE_INSTALL_DATADIR}/pkgconfig"
388    CACHE PATH "The directory relative to CMAKE_PREFIX_PATH where eigen3.pc is installed"
389    )
390
391
392# similar to set_target_properties but append the property instead of overwriting it
393macro(ei_add_target_property target prop value)
394
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()
397  if(NOT previous)
398    set(previous "")
399  endif(NOT previous)
400  set_target_properties(${target} PROPERTIES ${prop} "${previous} ${value}")
401endmacro(ei_add_target_property)
402
403install(FILES
404  signature_of_eigen3_matrix_library
405  DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel
406  )
407
408if(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}
412        )
413endif()
414
415add_subdirectory(Eigen)
416
417add_subdirectory(doc EXCLUDE_FROM_ALL)
418
419include(EigenConfigureTesting)
420
421# fixme, not sure this line is still needed:
422enable_testing() # must be called from the root CMakeLists, see man page
423
424
425if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
426  add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest
427else()
428  add_subdirectory(test EXCLUDE_FROM_ALL)
429endif()
430
431if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
432  add_subdirectory(blas)
433  add_subdirectory(lapack)
434else()
435  add_subdirectory(blas EXCLUDE_FROM_ALL)
436  add_subdirectory(lapack EXCLUDE_FROM_ALL)
437endif()
438
439# add SYCL
440option(EIGEN_TEST_SYCL "Add Sycl support." OFF)
441if(EIGEN_TEST_SYCL)
442  set (CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules" "cmake/Modules/" "${CMAKE_MODULE_PATH}")
443  include(FindComputeCpp)
444endif()
445
446add_subdirectory(unsupported)
447
448add_subdirectory(demos EXCLUDE_FROM_ALL)
449
450# must be after test and unsupported, for configuring buildtests.in
451add_subdirectory(scripts EXCLUDE_FROM_ALL)
452
453# TODO: consider also replacing EIGEN_BUILD_BTL by a custom target "make btl"?
454if(EIGEN_BUILD_BTL)
455  add_subdirectory(bench/btl EXCLUDE_FROM_ALL)
456endif(EIGEN_BUILD_BTL)
457
458if(NOT WIN32)
459  add_subdirectory(bench/spbench EXCLUDE_FROM_ALL)
460endif(NOT WIN32)
461
462configure_file(scripts/cdashtesting.cmake.in cdashtesting.cmake @ONLY)
463
464ei_testing_print_summary()
465
466message(STATUS "")
467message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}")
468message(STATUS "")
469
470option(EIGEN_FAILTEST "Enable failtests." OFF)
471if(EIGEN_FAILTEST)
472  add_subdirectory(failtest)
473endif()
474
475string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
476if(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 "--------------+--------------------------------------------------------------")
496else()
497  message(STATUS "To build/run the unit tests, read this page:")
498  message(STATUS "  http://eigen.tuxfamily.org/index.php?title=Tests")
499endif()
500
501message(STATUS "")
502
503
504set ( EIGEN_VERSION_STRING ${EIGEN_VERSION_NUMBER} )
505set ( EIGEN_VERSION_MAJOR  ${EIGEN_WORLD_VERSION} )
506set ( EIGEN_VERSION_MINOR  ${EIGEN_MAJOR_VERSION} )
507set ( EIGEN_VERSION_PATCH  ${EIGEN_MINOR_VERSION} )
508set ( EIGEN_DEFINITIONS "")
509set ( EIGEN_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}" )
510set ( EIGEN_ROOT_DIR ${CMAKE_INSTALL_PREFIX} )
511
512# Interface libraries require at least CMake 3.0
513if (NOT CMAKE_VERSION VERSION_LESS 3.0)
514  include (CMakePackageConfigHelpers)
515
516  # Imported target support
517  add_library (eigen INTERFACE)
518
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}>
523  )
524
525  # Export as title case Eigen
526  set_target_properties (eigen PROPERTIES EXPORT_NAME Eigen)
527
528  install (TARGETS eigen EXPORT Eigen3Targets)
529
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
536  )
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})
547
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)
554
555  install (EXPORT Eigen3Targets NAMESPACE Eigen3:: DESTINATION ${CMAKEPACKAGE_INSTALL_DIR})
556
557else (NOT CMAKE_VERSION VERSION_LESS 3.0)
558  # Fallback to legacy Eigen3Config.cmake without the imported target
559
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)
563
564  if(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
571    )
572  else()
573    # The PACKAGE_* variables are defined by the configure_package_config_file
574    # but without it we define them manually to the hardcoded paths
575    set(PACKAGE_INIT "")
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 )
581  endif()
582
583  write_basic_package_version_file( Eigen3ConfigVersion.cmake
584                                    VERSION ${EIGEN_VERSION_NUMBER}
585                                    COMPATIBILITY SameMajorVersion )
586
587endif (NOT CMAKE_VERSION VERSION_LESS 3.0)
588
589install ( 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} )
593
594# Add uninstall target
595add_custom_target ( uninstall
596    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/EigenUninstall.cmake)
597