]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Check for attribute aligned compiler support
authorlawadr <3211473+lawadr@users.noreply.github.com>
Thu, 30 Mar 2023 19:37:14 +0000 (20:37 +0100)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 13 Apr 2023 12:34:29 +0000 (14:34 +0200)
Check for compiler support in CMake and the configure script. This
allows ALIGNED_ to be defined for more compilers so that more than
just Clang, GCC and MSVC can build the project.

CMakeLists.txt
configure
zbuild.h

index e5184cca30f033bdd1b957014c5d14de0a6be898..ffde3d29492954973b577771873c4f4e4c9f65b6 100644 (file)
@@ -391,6 +391,20 @@ if(HAVE_ATTRIBUTE_VISIBILITY_INTERNAL)
     add_definitions(-DHAVE_VISIBILITY_INTERNAL)
 endif()
 
+#
+# Check for __attribute__((aligned(x))) support in the compiler
+#
+check_c_source_compiles(
+    "int main(void) {
+        __attribute__((aligned(8))) int test = 0;
+        (void)test;
+        return 0;
+    }"
+    HAVE_ATTRIBUTE_ALIGNED FAIL_REGEX "aligned")
+if(HAVE_ATTRIBUTE_ALIGNED)
+    add_definitions(-DHAVE_ATTRIBUTE_ALIGNED)
+endif()
+
 #
 # check for _Thread_local() support in the compiler
 #
index 2c320227fe2ba75bca997f18c3ae13719a735334..896b0b8a4f12b10f36f2d2a517df9df8f632901d 100755 (executable)
--- a/configure
+++ b/configure
@@ -985,6 +985,22 @@ EOF
   fi
 fi
 
+# Check for attribute(aligned) support in compiler
+cat > $test.c << EOF
+int main(void) {
+  __attribute__((aligned(8))) int test = 0;
+  (void)test;
+  return 0;
+}
+EOF
+if try ${CC} ${CFLAGS} $test.c $LDSHAREDLIBC; then
+    echo "Checking for attribute(aligned) ... Yes." | tee -a configure.log
+    CFLAGS="$CFLAGS -DHAVE_ATTRIBUTE_ALIGNED"
+    SFLAGS="$SFLAGS -DHAVE_ATTRIBUTE_ALIGNED"
+else
+    echo "Checking for attribute(aligned) ... No." | tee -a configure.log
+fi
+
 # Check for _Thread_local support in compiler
 cat > $test.c << EOF
 _Thread_local int test;
index de1999cff4fc487a2eb5898a984f347134799998..922b2cae2cf808b6715a6e65c7d2d6b1921ddc4e 100644 (file)
--- a/zbuild.h
+++ b/zbuild.h
 #  define UNLIKELY(x)           x
 #endif /* (un)likely */
 
-#if defined(__clang__) || defined(__GNUC__)
+#if defined(HAVE_ATTRIBUTE_ALIGNED)
 #  define ALIGNED_(x) __attribute__ ((aligned(x)))
 #elif defined(_MSC_VER)
 #  define ALIGNED_(x) __declspec(align(x))