package/exiv2: fix compiler flags detection
authorThomas Petazzoni <thomas.petazzoni@bootlin.com>
Sun, 19 Jul 2020 14:34:04 +0000 (16:34 +0200)
committerYann E. MORIN <yann.morin.1998@free.fr>
Sun, 19 Jul 2020 16:17:36 +0000 (18:17 +0200)
Add a patch, which has been submitted upstream, to properly detect the
availability of compiler flags before using them.

This will fix the build of exiv2 on CPU architectures for which gcc
doesn't implement -fcf-protection.

Fixes:

  http://autobuild.buildroot.net/results/ef6a6fa2309e66a7a36fface626ae0da1a7ec633/
  (and many similar build failures on other architectures)

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
[yann.morin.1998@free.fr:
  - fix indentation s/TAB/spaces/
  - fix CRLF dropped by patchwork
]
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
package/exiv2/0001-cmake-compilerFlags.cmake-properly-detect-availabili.patch [new file with mode: 0644]

diff --git a/package/exiv2/0001-cmake-compilerFlags.cmake-properly-detect-availabili.patch b/package/exiv2/0001-cmake-compilerFlags.cmake-properly-detect-availabili.patch
new file mode 100644 (file)
index 0000000..7b9fa48
--- /dev/null
@@ -0,0 +1,58 @@
+From 2f6d2e5795382f0d6e22f5aea52e8104110d24ad Mon Sep 17 00:00:00 2001
+From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
+Date: Sun, 19 Jul 2020 16:29:15 +0200
+Subject: [PATCH] cmake/compilerFlags.cmake: properly detect availability of
+ flags
+
+Instead of relying on fragile and complex logic to decide if a
+compiler flag is available or not, use the check_c_compiler_flag()
+macro provided by the CMake standard library.
+
+This for example avoids using -fcf-protection on architectures that
+don't support this option.
+
+[Upstream: https://github.com/Exiv2/exiv2/pull/1252. The submitted
+patch is slightly different than this one, due to other changes
+between 0.27.3 and master.]
+Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
+---
+ cmake/compilerFlags.cmake | 18 +++++++++++-------
+ 1 file changed, 11 insertions(+), 7 deletions(-)
+
+diff --git a/cmake/compilerFlags.cmake b/cmake/compilerFlags.cmake
+index 0418aa61..be430977 100644
+--- a/cmake/compilerFlags.cmake
++++ b/cmake/compilerFlags.cmake
+@@ -1,4 +1,5 @@
+ # These flags applies to exiv2lib, the applications, and to the xmp code\r
++include(CheckCCompilerFlag)\r
\r
+ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN\r
+     if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)\r
+@@ -25,13 +26,16 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN
\r
+         # This fails under Fedora, MinGW GCC 8.3.0 and CYGWIN/MSYS 9.3.0\r
+         if (NOT (MINGW OR CMAKE_HOST_SOLARIS OR CYGWIN OR MSYS) )\r
+-            if (COMPILER_IS_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)\r
+-                add_compile_options(-fstack-clash-protection -fcf-protection)\r
+-            endif()\r
+-\r
+-            if( (COMPILER_IS_GCC   AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5.0) # Not in GCC 4.8\r
+-            OR  (COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.7) # Not in Clang 3.4.2\r
+-            )\r
++            check_c_compiler_flag(-fstack-clash-protection HAS_FSTACK_CLASH_PROTECTION)\r
++            check_c_compiler_flag(-fcf-protection HAS_FCF_PROTECTION)\r
++            check_c_compiler_flag(-fstack-protector-strong HAS_FSTACK_PROTECTOR_STRONG)\r
++            if(HAS_FSTACK_CLASH_PROTECTION)\r
++                add_compile_options(-fstack-clash-protection)\r
++            endif()\r
++            if(GCC_HAS_FCF_PROTECTION)\r
++                add_compile_options(-fcf-protection)\r
++            endif()\r
++            if(GCC_HAS_FSTACK_PROTECTOR_STRONG)\r
+                 add_compile_options(-fstack-protector-strong)\r
+             endif()\r
+         endif()\r
+--- 
+2.26.2
+