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