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