From 58aa36db2aff24df3a300ccba2a27ab8168275d8 Mon Sep 17 00:00:00 2001 From: Daniel Scharrer Date: Tue, 24 Apr 2012 16:44:32 +0200 Subject: [PATCH] CMakeLists.txt: Don't use -fwhole-program with GCC < 4.5 and Boost < 1.41. (fixes bug #243) --- CMakeLists.txt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66825e89e7..608192fae1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -436,7 +436,25 @@ else(MSVC) endif() if(UNITY_BUILD) - add_cxxflag("-fwhole-program") + + set(USE_FWHOLE_PROGRAM 1) + + if(CMAKE_COMPILER_IS_GNUCXX AND ${Boost_VERSION} LESS 104100) + exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE compiler_string) + string(REGEX REPLACE ".* ([0-9])\\.([0-9])\\.[0-9].*" "\\1.\\2" + compiler_version "${compiler_string}") + if("${compiler_version}" VERSION_LESS 4.5 AND NOT "${compiler_version}" STREQUAL "") + # Cross-shared-object typeid is broken with some gcc versions + # Boost 1.41+ has a workaround for boost::any_cast: + # https://svn.boost.org/trac/boost/ticket/754 + message(STATUS "not using -fwhole-program for GCC ${compiler_version} + Boost ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}") + set(USE_FWHOLE_PROGRAM 0) + endif() + endif() + + if(${USE_FWHOLE_PROGRAM}) + add_cxxflag("-fwhole-program") + endif() endif() # Because we are lazy