CMakeLists.txt 24 KB

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