]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
various CMake fixes:
authorR.J.V. Bertin <rjvbertin@gmail.com>
Tue, 23 May 2017 17:32:53 +0000 (19:32 +0200)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Thu, 17 Aug 2017 09:44:39 +0000 (11:44 +0200)
- on Mac, builds can target 1 or more architectures that are not the host
  architecture. Pick the first from the list and ignore the others.
  A more complete implementation would warn if i386 and x86_64 builds are
  mixed via the compiler options.
- use CMake's compiler IDs to detect GCC and Clang (should be applied to
  icc too but I can't test)
- disable PCLMUL optimisation in 32bit Mac builds. It crashes and provides
  very little gain (to builds that are probably increasingly rare)

Committed from host : Portia.local

CMakeLists.txt

index de26867678fd92bcf99321ed52f40aaa84d854d2..b89be4280f541441070f7ff080a2d80f21b72872 100644 (file)
@@ -40,7 +40,12 @@ check_include_file(stddef.h    HAVE_STDDEF_H)
 #
 # Options parsing
 #
-set(ARCH ${CMAKE_SYSTEM_PROCESSOR})
+if(CMAKE_OSX_ARCHITECTURES)
+    # if multiple architectures are requested (universal build), pick only the first
+    list(GET CMAKE_OSX_ARCHITECTURES 0 ARCH)
+else()
+    set(ARCH ${CMAKE_SYSTEM_PROCESSOR})
+endif()
 message(STATUS "Architecture: ${ARCH}")
 
 option (ZLIB_COMPAT "Compile with zlib compatible API" OFF)
@@ -98,6 +103,7 @@ elseif(MSVC)
         message(STATUS "Ignoring WITH_NATIVE_INSTRUCTIONS; not supported on this configuration")
     endif()
 else()
+    # catch all GNU C compilers as well as Clang and AppleClang
     if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
         set(__GNUC__ ON)
     endif()
@@ -312,19 +318,24 @@ else()
     else()
         set(CMAKE_REQUIRED_FLAGS "${PCLMULFLAG}")
     endif()
-    check_c_source_compile_or_run(
-        "#include <immintrin.h>
-        #include <wmmintrin.h>
-        int main(void)
-        {
-            __m128i a = _mm_setzero_si128();
-            __m128i b = _mm_setzero_si128();
-            __m128i c = _mm_clmulepi64_si128(a, b, 0x10);
-            (void)c;
-            return 0;
-        }"
-        HAVE_PCLMULQDQ_INTRIN
-    )
+    if(NOT (APPLE AND ${ARCH} MATCHES "i386"))
+        # the pclmul code currently crashes on Mac in 32bit mode. Avoid for now.
+        check_c_source_compile_or_run(
+            "#include <immintrin.h>
+            #include <wmmintrin.h>
+            int main(void)
+            {
+                __m128i a = _mm_setzero_si128();
+                __m128i b = _mm_setzero_si128();
+                __m128i c = _mm_clmulepi64_si128(a, b, 0x10);
+                (void)c;
+                return 0;
+            }"
+            HAVE_PCLMULQDQ_INTRIN
+        )
+    else()
+        set(HAVE_PCLMULQDQ_INTRIN NO)
+    endif()
 endif()
 
 #