CMakeLists.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. project(Eigen3)
  2. cmake_minimum_required(VERSION 2.8.5)
  3. # guard against in-source builds
  4. if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
  5. 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. ")
  6. endif()
  7. # Alias Eigen_*_DIR to Eigen3_*_DIR:
  8. set(Eigen_SOURCE_DIR ${Eigen3_SOURCE_DIR})
  9. set(Eigen_BINARY_DIR ${Eigen3_BINARY_DIR})
  10. # guard against bad build-type strings
  11. if (NOT CMAKE_BUILD_TYPE)
  12. set(CMAKE_BUILD_TYPE "Release")
  13. endif()
  14. string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
  15. if( NOT cmake_build_type_tolower STREQUAL "debug"
  16. AND NOT cmake_build_type_tolower STREQUAL "release"
  17. AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo")
  18. message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Release, RelWithDebInfo (case-insensitive).")
  19. endif()
  20. #############################################################################
  21. # retrieve version infomation #
  22. #############################################################################
  23. # automatically parse the version number
  24. file(READ "${PROJECT_SOURCE_DIR}/Eigen/src/Core/util/Macros.h" _eigen_version_header)
  25. string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}")
  26. set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}")
  27. string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen_major_version_match "${_eigen_version_header}")
  28. set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}")
  29. string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen_minor_version_match "${_eigen_version_header}")
  30. set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}")
  31. set(EIGEN_VERSION_NUMBER ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})
  32. # if we are not in a mercurial clone
  33. if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.hg)
  34. # if the mercurial program is absent or this will leave the EIGEN_HG_CHANGESET string empty,
  35. # but won't stop CMake.
  36. execute_process(COMMAND hg tip -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_HGTIP_OUTPUT)
  37. execute_process(COMMAND hg branch -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_BRANCH_OUTPUT)
  38. endif()
  39. # if this is the default (aka development) branch, extract the mercurial changeset number from the hg tip output...
  40. if(EIGEN_BRANCH_OUTPUT MATCHES "default")
  41. string(REGEX MATCH "^changeset: *[0-9]*:([0-9;a-f]+).*" EIGEN_HG_CHANGESET_MATCH "${EIGEN_HGTIP_OUTPUT}")
  42. set(EIGEN_HG_CHANGESET "${CMAKE_MATCH_1}")
  43. endif(EIGEN_BRANCH_OUTPUT MATCHES "default")
  44. #...and show it next to the version number
  45. if(EIGEN_HG_CHANGESET)
  46. set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER} (mercurial changeset ${EIGEN_HG_CHANGESET})")
  47. else(EIGEN_HG_CHANGESET)
  48. set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}")
  49. endif(EIGEN_HG_CHANGESET)
  50. include(CheckCXXCompilerFlag)
  51. include(GNUInstallDirs)
  52. set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
  53. option(EIGEN_TEST_CXX11 "Enable testing with C++11 and C++11 features (e.g. Tensor module)." OFF)
  54. macro(ei_add_cxx_compiler_flag FLAG)
  55. string(REGEX REPLACE "-" "" SFLAG1 ${FLAG})
  56. string(REGEX REPLACE "\\+" "p" SFLAG ${SFLAG1})
  57. check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORT_${SFLAG})
  58. if(COMPILER_SUPPORT_${SFLAG})
  59. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
  60. endif()
  61. endmacro(ei_add_cxx_compiler_flag)
  62. check_cxx_compiler_flag("-std=c++11" EIGEN_COMPILER_SUPPORT_CPP11)
  63. if(EIGEN_TEST_CXX11)
  64. set(CMAKE_CXX_STANDARD 11)
  65. set(CMAKE_CXX_EXTENSIONS OFF)
  66. if(EIGEN_COMPILER_SUPPORT_CPP11)
  67. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  68. endif()
  69. else()
  70. #set(CMAKE_CXX_STANDARD 03)
  71. #set(CMAKE_CXX_EXTENSIONS OFF)
  72. ei_add_cxx_compiler_flag("-std=c++03")
  73. endif()
  74. #############################################################################
  75. # find how to link to the standard libraries #
  76. #############################################################################
  77. find_package(StandardMathLibrary)
  78. set(EIGEN_TEST_CUSTOM_LINKER_FLAGS "" CACHE STRING "Additional linker flags when linking unit tests.")
  79. set(EIGEN_TEST_CUSTOM_CXX_FLAGS "" CACHE STRING "Additional compiler flags when compiling unit tests.")
  80. set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "")
  81. if(NOT STANDARD_MATH_LIBRARY_FOUND)
  82. message(FATAL_ERROR
  83. "Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.")
  84. else()
  85. if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
  86. set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${STANDARD_MATH_LIBRARY}")
  87. else()
  88. set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}")
  89. endif()
  90. endif()
  91. if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
  92. message(STATUS "Standard libraries to link to explicitly: ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}")
  93. else()
  94. message(STATUS "Standard libraries to link to explicitly: none")
  95. endif()
  96. option(EIGEN_BUILD_BTL "Build benchmark suite" OFF)
  97. # Disable pkgconfig only for native Windows builds
  98. if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
  99. option(EIGEN_BUILD_PKGCONFIG "Build pkg-config .pc file for Eigen" ON)
  100. endif()
  101. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  102. option(EIGEN_SPLIT_LARGE_TESTS "Split large tests into smaller executables" ON)
  103. option(EIGEN_DEFAULT_TO_ROW_MAJOR "Use row-major as default matrix storage order" OFF)
  104. if(EIGEN_DEFAULT_TO_ROW_MAJOR)
  105. add_definitions("-DEIGEN_DEFAULT_TO_ROW_MAJOR")
  106. endif()
  107. set(EIGEN_TEST_MAX_SIZE "320" CACHE STRING "Maximal matrix/vector size, default is 320")
  108. if(NOT MSVC)
  109. # We assume that other compilers are partly compatible with GNUCC
  110. # clang outputs some warnings for unknown flags that are not caught by check_cxx_compiler_flag
  111. # adding -Werror turns such warnings into errors
  112. check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR)
  113. if(COMPILER_SUPPORT_WERROR)
  114. set(CMAKE_REQUIRED_FLAGS "-Werror")
  115. endif()
  116. ei_add_cxx_compiler_flag("-pedantic")
  117. ei_add_cxx_compiler_flag("-Wall")
  118. ei_add_cxx_compiler_flag("-Wextra")
  119. #ei_add_cxx_compiler_flag("-Weverything") # clang
  120. ei_add_cxx_compiler_flag("-Wundef")
  121. ei_add_cxx_compiler_flag("-Wcast-align")
  122. ei_add_cxx_compiler_flag("-Wchar-subscripts")
  123. ei_add_cxx_compiler_flag("-Wnon-virtual-dtor")
  124. ei_add_cxx_compiler_flag("-Wunused-local-typedefs")
  125. ei_add_cxx_compiler_flag("-Wpointer-arith")
  126. ei_add_cxx_compiler_flag("-Wwrite-strings")
  127. ei_add_cxx_compiler_flag("-Wformat-security")
  128. ei_add_cxx_compiler_flag("-Wshorten-64-to-32")
  129. ei_add_cxx_compiler_flag("-Wlogical-op")
  130. ei_add_cxx_compiler_flag("-Wenum-conversion")
  131. ei_add_cxx_compiler_flag("-Wc++11-extensions")
  132. ei_add_cxx_compiler_flag("-Wdouble-promotion")
  133. # ei_add_cxx_compiler_flag("-Wconversion")
  134. # -Wshadow is insanely too strict with gcc, hopefully it will become usable with gcc 6
  135. # if(NOT CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.0.0"))
  136. if(NOT CMAKE_COMPILER_IS_GNUCXX)
  137. ei_add_cxx_compiler_flag("-Wshadow")
  138. endif()
  139. ei_add_cxx_compiler_flag("-Wno-psabi")
  140. ei_add_cxx_compiler_flag("-Wno-variadic-macros")
  141. ei_add_cxx_compiler_flag("-Wno-long-long")
  142. ei_add_cxx_compiler_flag("-fno-check-new")
  143. ei_add_cxx_compiler_flag("-fno-common")
  144. ei_add_cxx_compiler_flag("-fstrict-aliasing")
  145. ei_add_cxx_compiler_flag("-wd981") # disable ICC's "operands are evaluated in unspecified order" remark
  146. 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
  147. # The -ansi flag must be added last, otherwise it is also used as a linker flag by check_cxx_compiler_flag making it fails
  148. # Moreover we should not set both -strict-ansi and -ansi
  149. check_cxx_compiler_flag("-strict-ansi" COMPILER_SUPPORT_STRICTANSI)
  150. ei_add_cxx_compiler_flag("-Qunused-arguments") # disable clang warning: argument unused during compilation: '-ansi'
  151. if(COMPILER_SUPPORT_STRICTANSI)
  152. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -strict-ansi")
  153. else()
  154. ei_add_cxx_compiler_flag("-ansi")
  155. endif()
  156. if(ANDROID_NDK)
  157. ei_add_cxx_compiler_flag("-pie")
  158. ei_add_cxx_compiler_flag("-fPIE")
  159. endif()
  160. set(CMAKE_REQUIRED_FLAGS "")
  161. option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
  162. if(EIGEN_TEST_SSE2)
  163. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
  164. message(STATUS "Enabling SSE2 in tests/examples")
  165. endif()
  166. option(EIGEN_TEST_SSE3 "Enable/Disable SSE3 in tests/examples" OFF)
  167. if(EIGEN_TEST_SSE3)
  168. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
  169. message(STATUS "Enabling SSE3 in tests/examples")
  170. endif()
  171. option(EIGEN_TEST_SSSE3 "Enable/Disable SSSE3 in tests/examples" OFF)
  172. if(EIGEN_TEST_SSSE3)
  173. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3")
  174. message(STATUS "Enabling SSSE3 in tests/examples")
  175. endif()
  176. option(EIGEN_TEST_SSE4_1 "Enable/Disable SSE4.1 in tests/examples" OFF)
  177. if(EIGEN_TEST_SSE4_1)
  178. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
  179. message(STATUS "Enabling SSE4.1 in tests/examples")
  180. endif()
  181. option(EIGEN_TEST_SSE4_2 "Enable/Disable SSE4.2 in tests/examples" OFF)
  182. if(EIGEN_TEST_SSE4_2)
  183. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
  184. message(STATUS "Enabling SSE4.2 in tests/examples")
  185. endif()
  186. option(EIGEN_TEST_AVX "Enable/Disable AVX in tests/examples" OFF)
  187. if(EIGEN_TEST_AVX)
  188. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
  189. message(STATUS "Enabling AVX in tests/examples")
  190. endif()
  191. option(EIGEN_TEST_FMA "Enable/Disable FMA in tests/examples" OFF)
  192. if(EIGEN_TEST_FMA AND NOT EIGEN_TEST_NEON)
  193. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfma")
  194. message(STATUS "Enabling FMA in tests/examples")
  195. endif()
  196. option(EIGEN_TEST_AVX512 "Enable/Disable AVX512 in tests/examples" OFF)
  197. if(EIGEN_TEST_AVX512)
  198. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f -fabi-version=6 -DEIGEN_ENABLE_AVX512")
  199. message(STATUS "Enabling AVX512 in tests/examples")
  200. endif()
  201. option(EIGEN_TEST_F16C "Enable/Disable F16C in tests/examples" OFF)
  202. if(EIGEN_TEST_F16C)
  203. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mf16c")
  204. message(STATUS "Enabling F16C in tests/examples")
  205. endif()
  206. option(EIGEN_TEST_ALTIVEC "Enable/Disable AltiVec in tests/examples" OFF)
  207. if(EIGEN_TEST_ALTIVEC)
  208. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec -mabi=altivec")
  209. message(STATUS "Enabling AltiVec in tests/examples")
  210. endif()
  211. option(EIGEN_TEST_VSX "Enable/Disable VSX in tests/examples" OFF)
  212. if(EIGEN_TEST_VSX)
  213. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -mvsx")
  214. message(STATUS "Enabling VSX in tests/examples")
  215. endif()
  216. option(EIGEN_TEST_NEON "Enable/Disable Neon in tests/examples" OFF)
  217. if(EIGEN_TEST_NEON)
  218. if(EIGEN_TEST_FMA)
  219. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon-vfpv4")
  220. else()
  221. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
  222. endif()
  223. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=hard")
  224. message(STATUS "Enabling NEON in tests/examples")
  225. endif()
  226. option(EIGEN_TEST_NEON64 "Enable/Disable Neon in tests/examples" OFF)
  227. if(EIGEN_TEST_NEON64)
  228. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  229. message(STATUS "Enabling NEON in tests/examples")
  230. endif()
  231. option(EIGEN_TEST_ZVECTOR "Enable/Disable S390X(zEC13) ZVECTOR in tests/examples" OFF)
  232. if(EIGEN_TEST_ZVECTOR)
  233. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=z13 -mzvector")
  234. message(STATUS "Enabling S390X(zEC13) ZVECTOR in tests/examples")
  235. endif()
  236. check_cxx_compiler_flag("-fopenmp" COMPILER_SUPPORT_OPENMP)
  237. if(COMPILER_SUPPORT_OPENMP)
  238. option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
  239. if(EIGEN_TEST_OPENMP)
  240. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
  241. message(STATUS "Enabling OpenMP in tests/examples")
  242. endif()
  243. endif()
  244. else(NOT MSVC)
  245. # C4127 - conditional expression is constant
  246. # C4714 - marked as __forceinline not inlined (I failed to deactivate it selectively)
  247. # We can disable this warning in the unit tests since it is clear that it occurs
  248. # because we are oftentimes returning objects that have a destructor or may
  249. # throw exceptions - in particular in the unit tests we are throwing extra many
  250. # exceptions to cover indexing errors.
  251. # C4505 - unreferenced local function has been removed (impossible to deactive selectively)
  252. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /wd4127 /wd4505 /wd4714")
  253. # replace all /Wx by /W4
  254. string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  255. check_cxx_compiler_flag("/openmp" COMPILER_SUPPORT_OPENMP)
  256. if(COMPILER_SUPPORT_OPENMP)
  257. option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF)
  258. if(EIGEN_TEST_OPENMP)
  259. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
  260. message(STATUS "Enabling OpenMP in tests/examples")
  261. endif()
  262. endif()
  263. option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF)
  264. if(EIGEN_TEST_SSE2)
  265. if(NOT CMAKE_CL_64)
  266. # arch is not supported on 64 bit systems, SSE is enabled automatically.
  267. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
  268. endif(NOT CMAKE_CL_64)
  269. message(STATUS "Enabling SSE2 in tests/examples")
  270. endif(EIGEN_TEST_SSE2)
  271. endif(NOT MSVC)
  272. option(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION "Disable explicit vectorization in tests/examples" OFF)
  273. option(EIGEN_TEST_X87 "Force using X87 instructions. Implies no vectorization." OFF)
  274. option(EIGEN_TEST_32BIT "Force generating 32bit code." OFF)
  275. if(EIGEN_TEST_X87)
  276. set(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION ON)
  277. if(CMAKE_COMPILER_IS_GNUCXX)
  278. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=387")
  279. message(STATUS "Forcing use of x87 instructions in tests/examples")
  280. else()
  281. message(STATUS "EIGEN_TEST_X87 ignored on your compiler")
  282. endif()
  283. endif()
  284. if(EIGEN_TEST_32BIT)
  285. if(CMAKE_COMPILER_IS_GNUCXX)
  286. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
  287. message(STATUS "Forcing generation of 32-bit code in tests/examples")
  288. else()
  289. message(STATUS "EIGEN_TEST_32BIT ignored on your compiler")
  290. endif()
  291. endif()
  292. if(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
  293. add_definitions(-DEIGEN_DONT_VECTORIZE=1)
  294. message(STATUS "Disabling vectorization in tests/examples")
  295. endif()
  296. option(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT "Disable explicit alignment (hence vectorization) in tests/examples" OFF)
  297. if(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT)
  298. add_definitions(-DEIGEN_DONT_ALIGN=1)
  299. message(STATUS "Disabling alignment in tests/examples")
  300. endif()
  301. option(EIGEN_TEST_NO_EXCEPTIONS "Disables C++ exceptions" OFF)
  302. if(EIGEN_TEST_NO_EXCEPTIONS)
  303. ei_add_cxx_compiler_flag("-fno-exceptions")
  304. message(STATUS "Disabling exceptions in tests/examples")
  305. endif()
  306. set(EIGEN_CUDA_COMPUTE_ARCH 30 CACHE STRING "The CUDA compute architecture level to target when compiling CUDA code")
  307. include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
  308. # Backward compatibility support for EIGEN_INCLUDE_INSTALL_DIR
  309. if(EIGEN_INCLUDE_INSTALL_DIR)
  310. message(WARNING "EIGEN_INCLUDE_INSTALL_DIR is deprecated. Use INCLUDE_INSTALL_DIR instead.")
  311. endif()
  312. if(EIGEN_INCLUDE_INSTALL_DIR AND NOT INCLUDE_INSTALL_DIR)
  313. set(INCLUDE_INSTALL_DIR ${EIGEN_INCLUDE_INSTALL_DIR}
  314. CACHE STRING "The directory relative to CMAKE_PREFIX_PATH where Eigen header files are installed")
  315. else()
  316. set(INCLUDE_INSTALL_DIR
  317. "${CMAKE_INSTALL_INCLUDEDIR}/eigen3"
  318. CACHE STRING "The directory relative to CMAKE_PREFIX_PATH where Eigen header files are installed"
  319. )
  320. endif()
  321. set(CMAKEPACKAGE_INSTALL_DIR
  322. "${CMAKE_INSTALL_DATADIR}/eigen3/cmake"
  323. CACHE STRING "The directory relative to CMAKE_PREFIX_PATH where Eigen3Config.cmake is installed"
  324. )
  325. set(PKGCONFIG_INSTALL_DIR
  326. "${CMAKE_INSTALL_DATADIR}/pkgconfig"
  327. CACHE STRING "The directory relative to CMAKE_PREFIX_PATH where eigen3.pc is installed"
  328. )
  329. foreach(var INCLUDE_INSTALL_DIR CMAKEPACKAGE_INSTALL_DIR PKGCONFIG_INSTALL_DIR)
  330. if(IS_ABSOLUTE "${${var}}")
  331. message(FATAL_ERROR "${var} must be relative to CMAKE_PREFIX_PATH. Got: ${${var}}")
  332. endif()
  333. endforeach()
  334. # similar to set_target_properties but append the property instead of overwriting it
  335. macro(ei_add_target_property target prop value)
  336. get_target_property(previous ${target} ${prop})
  337. # if the property wasn't previously set, ${previous} is now "previous-NOTFOUND" which cmake allows catching with plain if()
  338. if(NOT previous)
  339. set(previous "")
  340. endif(NOT previous)
  341. set_target_properties(${target} PROPERTIES ${prop} "${previous} ${value}")
  342. endmacro(ei_add_target_property)
  343. install(FILES
  344. signature_of_eigen3_matrix_library
  345. DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel
  346. )
  347. if(EIGEN_BUILD_PKGCONFIG)
  348. configure_file(eigen3.pc.in eigen3.pc @ONLY)
  349. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/eigen3.pc
  350. DESTINATION ${PKGCONFIG_INSTALL_DIR}
  351. )
  352. endif()
  353. add_subdirectory(Eigen)
  354. add_subdirectory(doc EXCLUDE_FROM_ALL)
  355. option(BUILD_TESTING "Enable creation of Eigen tests." ON)
  356. if(BUILD_TESTING)
  357. include(EigenConfigureTesting)
  358. if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
  359. add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest
  360. else()
  361. add_subdirectory(test EXCLUDE_FROM_ALL)
  362. endif()
  363. endif()
  364. if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
  365. add_subdirectory(blas)
  366. add_subdirectory(lapack)
  367. else()
  368. add_subdirectory(blas EXCLUDE_FROM_ALL)
  369. add_subdirectory(lapack EXCLUDE_FROM_ALL)
  370. endif()
  371. # add SYCL
  372. option(EIGEN_TEST_SYCL "Add Sycl support." OFF)
  373. if(EIGEN_TEST_SYCL)
  374. set (CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules" "cmake/Modules/" "${CMAKE_MODULE_PATH}")
  375. include(FindComputeCpp)
  376. endif()
  377. add_subdirectory(unsupported)
  378. add_subdirectory(demos EXCLUDE_FROM_ALL)
  379. # must be after test and unsupported, for configuring buildtests.in
  380. add_subdirectory(scripts EXCLUDE_FROM_ALL)
  381. # TODO: consider also replacing EIGEN_BUILD_BTL by a custom target "make btl"?
  382. if(EIGEN_BUILD_BTL)
  383. add_subdirectory(bench/btl EXCLUDE_FROM_ALL)
  384. endif(EIGEN_BUILD_BTL)
  385. if(NOT WIN32)
  386. add_subdirectory(bench/spbench EXCLUDE_FROM_ALL)
  387. endif(NOT WIN32)
  388. configure_file(scripts/cdashtesting.cmake.in cdashtesting.cmake @ONLY)
  389. if(BUILD_TESTING)
  390. ei_testing_print_summary()
  391. endif()
  392. message(STATUS "")
  393. message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}")
  394. message(STATUS "")
  395. option(EIGEN_FAILTEST "Enable failtests." OFF)
  396. if(EIGEN_FAILTEST)
  397. add_subdirectory(failtest)
  398. endif()
  399. string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
  400. if(cmake_generator_tolower MATCHES "makefile")
  401. message(STATUS "Some things you can do now:")
  402. message(STATUS "--------------+--------------------------------------------------------------")
  403. message(STATUS "Command | Description")
  404. message(STATUS "--------------+--------------------------------------------------------------")
  405. message(STATUS "make install | Install Eigen. Headers will be installed to:")
  406. message(STATUS " | <CMAKE_INSTALL_PREFIX>/<INCLUDE_INSTALL_DIR>")
  407. message(STATUS " | Using the following values:")
  408. message(STATUS " | CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
  409. message(STATUS " | INCLUDE_INSTALL_DIR: ${INCLUDE_INSTALL_DIR}")
  410. message(STATUS " | Change the install location of Eigen headers using:")
  411. message(STATUS " | cmake . -DCMAKE_INSTALL_PREFIX=yourprefix")
  412. message(STATUS " | Or:")
  413. message(STATUS " | cmake . -DINCLUDE_INSTALL_DIR=yourdir")
  414. message(STATUS "make doc | Generate the API documentation, requires Doxygen & LaTeX")
  415. message(STATUS "make check | Build and run the unit-tests. Read this page:")
  416. message(STATUS " | http://eigen.tuxfamily.org/index.php?title=Tests")
  417. message(STATUS "make blas | Build BLAS library (not the same thing as Eigen)")
  418. message(STATUS "make uninstall| Removes files installed by make install")
  419. message(STATUS "--------------+--------------------------------------------------------------")
  420. else()
  421. message(STATUS "To build/run the unit tests, read this page:")
  422. message(STATUS " http://eigen.tuxfamily.org/index.php?title=Tests")
  423. endif()
  424. message(STATUS "")
  425. set ( EIGEN_VERSION_STRING ${EIGEN_VERSION_NUMBER} )
  426. set ( EIGEN_VERSION_MAJOR ${EIGEN_WORLD_VERSION} )
  427. set ( EIGEN_VERSION_MINOR ${EIGEN_MAJOR_VERSION} )
  428. set ( EIGEN_VERSION_PATCH ${EIGEN_MINOR_VERSION} )
  429. set ( EIGEN_DEFINITIONS "")
  430. set ( EIGEN_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}" )
  431. set ( EIGEN_ROOT_DIR ${CMAKE_INSTALL_PREFIX} )
  432. # Interface libraries require at least CMake 3.0
  433. if (NOT CMAKE_VERSION VERSION_LESS 3.0)
  434. include (CMakePackageConfigHelpers)
  435. # Imported target support
  436. add_library (eigen INTERFACE)
  437. target_compile_definitions (eigen INTERFACE ${EIGEN_DEFINITIONS})
  438. target_include_directories (eigen INTERFACE
  439. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  440. $<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
  441. )
  442. # Export as title case Eigen
  443. set_target_properties (eigen PROPERTIES EXPORT_NAME Eigen)
  444. install (TARGETS eigen EXPORT Eigen3Targets)
  445. configure_package_config_file (
  446. ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3Config.cmake.in
  447. ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
  448. PATH_VARS EIGEN_INCLUDE_DIR EIGEN_ROOT_DIR
  449. INSTALL_DESTINATION ${CMAKEPACKAGE_INSTALL_DIR}
  450. NO_CHECK_REQUIRED_COMPONENTS_MACRO # Eigen does not provide components
  451. )
  452. # Remove CMAKE_SIZEOF_VOID_P from Eigen3ConfigVersion.cmake since Eigen does
  453. # not depend on architecture specific settings or libraries. More
  454. # specifically, an Eigen3Config.cmake generated from a 64 bit target can be
  455. # used for 32 bit targets as well (and vice versa).
  456. set (_Eigen3_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
  457. unset (CMAKE_SIZEOF_VOID_P)
  458. write_basic_package_version_file (Eigen3ConfigVersion.cmake
  459. VERSION ${EIGEN_VERSION_NUMBER}
  460. COMPATIBILITY SameMajorVersion)
  461. set (CMAKE_SIZEOF_VOID_P ${_Eigen3_CMAKE_SIZEOF_VOID_P})
  462. # The Eigen target will be located in the Eigen3 namespace. Other CMake
  463. # targets can refer to it using Eigen3::Eigen.
  464. export (TARGETS eigen NAMESPACE Eigen3:: FILE Eigen3Targets.cmake)
  465. # Export Eigen3 package to CMake registry such that it can be easily found by
  466. # CMake even if it has not been installed to a standard directory.
  467. export (PACKAGE Eigen3)
  468. install (EXPORT Eigen3Targets NAMESPACE Eigen3:: DESTINATION ${CMAKEPACKAGE_INSTALL_DIR})
  469. else (NOT CMAKE_VERSION VERSION_LESS 3.0)
  470. # Fallback to legacy Eigen3Config.cmake without the imported target
  471. # If CMakePackageConfigHelpers module is available (CMake >= 2.8.8)
  472. # create a relocatable Config file, otherwise leave the hardcoded paths
  473. include(CMakePackageConfigHelpers OPTIONAL RESULT_VARIABLE CPCH_PATH)
  474. if(CPCH_PATH)
  475. configure_package_config_file (
  476. ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3ConfigLegacy.cmake.in
  477. ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
  478. PATH_VARS EIGEN_INCLUDE_DIR EIGEN_ROOT_DIR
  479. INSTALL_DESTINATION ${CMAKEPACKAGE_INSTALL_DIR}
  480. NO_CHECK_REQUIRED_COMPONENTS_MACRO # Eigen does not provide components
  481. )
  482. else()
  483. # The PACKAGE_* variables are defined by the configure_package_config_file
  484. # but without it we define them manually to the hardcoded paths
  485. set(PACKAGE_INIT "")
  486. set(PACKAGE_EIGEN_INCLUDE_DIR ${EIGEN_INCLUDE_DIR})
  487. set(PACKAGE_EIGEN_ROOT_DIR ${EIGEN_ROOT_DIR})
  488. configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3ConfigLegacy.cmake.in
  489. ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
  490. @ONLY ESCAPE_QUOTES )
  491. endif()
  492. write_basic_package_version_file( Eigen3ConfigVersion.cmake
  493. VERSION ${EIGEN_VERSION_NUMBER}
  494. COMPATIBILITY SameMajorVersion )
  495. endif (NOT CMAKE_VERSION VERSION_LESS 3.0)
  496. install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/UseEigen3.cmake
  497. ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake
  498. ${CMAKE_CURRENT_BINARY_DIR}/Eigen3ConfigVersion.cmake
  499. DESTINATION ${CMAKEPACKAGE_INSTALL_DIR} )
  500. # Add uninstall target
  501. add_custom_target ( uninstall
  502. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/EigenUninstall.cmake)