From: R.J.V. Bertin Date: Tue, 23 May 2017 17:32:53 +0000 (+0200) Subject: various CMake fixes: X-Git-Tag: 1.9.9-b1~660^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d265bf7f4be7c6efe52dd719b3633260221f56b4;p=thirdparty%2Fzlib-ng.git various CMake fixes: - 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index de2686767..b89be4280 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 - #include - 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 + #include + 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() #