From d37a1961da4d63fea7fe4353b3de5ac62aca2d7b Mon Sep 17 00:00:00 2001
From: Michael Kuron <mkuron@icp.uni-stuttgart.de>
Date: Tue, 12 Jan 2021 18:27:50 +0100
Subject: [PATCH] Check whether LTO works before enabling it

---
 CMakeLists.txt | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bc0d8638d..4b05ed5d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1112,7 +1112,14 @@ endif()
 ##
 ############################################################################################################################
 if ( WALBERLA_BUILD_WITH_LTO  )
-    set( CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE )
+    cmake_policy( SET CMP0069 NEW )
+    include( CheckIPOSupported )
+    check_ipo_supported( RESULT LTO_SUPPORTED LANGUAGES CXX )
+    if( LTO_SUPPORTED )
+       set( CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE )
+    else()
+       message( WARNING "Link-time optimization is not supported with this compiler" )
+    endif()
 endif ( )
 
 ############################################################################################################################
-- 
GitLab