|
1 | 1 | include(CheckCXXCompilerFlag) # for check_cxx_compiler_flag() |
2 | 2 |
|
3 | | -# Set cmake policy to recognize the AppleClang compiler |
| 3 | +# Set cmake policy to recognize the Apple Clang compiler |
4 | 4 | # independently from the Clang compiler. |
5 | 5 | if(POLICY CMP0025) |
6 | 6 | cmake_policy(SET CMP0025 NEW) |
@@ -87,10 +87,10 @@ if(MSVC) |
87 | 87 | list_append_cache(GTSAM_COMPILE_DEFINITIONS_PRIVATE |
88 | 88 | WINDOWS_LEAN_AND_MEAN |
89 | 89 | NOMINMAX |
90 | | - ) |
| 90 | + ) |
91 | 91 | # Avoid literally hundreds to thousands of warnings: |
92 | 92 | list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC |
93 | | - /wd4267 # warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data |
| 93 | + /wd4267 # warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data |
94 | 94 | ) |
95 | 95 |
|
96 | 96 | add_compile_options(/wd4005) |
@@ -183,19 +183,43 @@ set(CMAKE_EXE_LINKER_FLAGS_PROFILING ${GTSAM_CMAKE_EXE_LINKER_FLAGS_PROFILING}) |
183 | 183 |
|
184 | 184 | # Clang uses a template depth that is less than standard and is too small |
185 | 185 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") |
186 | | - # Apple Clang before 5.0 does not support -ftemplate-depth. |
187 | | - if(NOT (APPLE AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "5.0")) |
188 | | - list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC "-ftemplate-depth=1024") |
189 | | - endif() |
| 186 | + # Apple Clang before 5.0 does not support -ftemplate-depth. |
| 187 | + if(NOT (APPLE AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "5.0")) |
| 188 | + list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC "-ftemplate-depth=1024") |
| 189 | + endif() |
190 | 190 | endif() |
191 | 191 |
|
192 | 192 | if (NOT MSVC) |
193 | 193 | option(GTSAM_BUILD_WITH_MARCH_NATIVE "Enable/Disable building with all instructions supported by native architecture (binary may not be portable!)" OFF) |
194 | | - if(GTSAM_BUILD_WITH_MARCH_NATIVE AND (APPLE AND NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")) |
195 | | - # Add as public flag so all dependant projects also use it, as required |
196 | | - # by Eigen to avid crashes due to SIMD vectorization: |
197 | | - list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC "-march=native") |
198 | | - endif() |
| 194 | + if(GTSAM_BUILD_WITH_MARCH_NATIVE) |
| 195 | + # Check if Apple OS and compiler is [Apple]Clang |
| 196 | + if(APPLE AND (${CMAKE_CXX_COMPILER_ID} MATCHES "^(Apple)?Clang$")) |
| 197 | + # Check Clang version since march=native is only supported for version 15.0+. |
| 198 | + if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "15.0") |
| 199 | + if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") |
| 200 | + # Add as public flag so all dependent projects also use it, as required |
| 201 | + # by Eigen to avoid crashes due to SIMD vectorization: |
| 202 | + list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC "-march=native") |
| 203 | + else() |
| 204 | + message(WARNING "Option GTSAM_BUILD_WITH_MARCH_NATIVE ignored, because native architecture is not supported for Apple silicon and AppleClang version < 15.0.") |
| 205 | + endif() # CMAKE_SYSTEM_PROCESSOR |
| 206 | + else() |
| 207 | + # Add as public flag so all dependent projects also use it, as required |
| 208 | + # by Eigen to avoid crashes due to SIMD vectorization: |
| 209 | + list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC "-march=native") |
| 210 | + endif() # CMAKE_CXX_COMPILER_VERSION |
| 211 | + else() |
| 212 | + include(CheckCXXCompilerFlag) |
| 213 | + CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) |
| 214 | + if(COMPILER_SUPPORTS_MARCH_NATIVE) |
| 215 | + # Add as public flag so all dependent projects also use it, as required |
| 216 | + # by Eigen to avoid crashes due to SIMD vectorization: |
| 217 | + list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC "-march=native") |
| 218 | + else() |
| 219 | + message(WARNING "Option GTSAM_BUILD_WITH_MARCH_NATIVE ignored, because native architecture is not supported.") |
| 220 | + endif() # COMPILER_SUPPORTS_MARCH_NATIVE |
| 221 | + endif() # APPLE |
| 222 | + endif() # GTSAM_BUILD_WITH_MARCH_NATIVE |
199 | 223 | endif() |
200 | 224 |
|
201 | 225 | # Set up build type library postfixes |
|
0 commit comments