From faaee1cbbd7ad5ac5c99a6f1fbb0562f2c3f548c Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Mon, 30 Nov 2015 10:17:01 +0100 Subject: [PATCH] only use -flto when supported, quenched policy warnings --- CMakeLists.txt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fa32e81a..c77ab8f7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,14 +27,23 @@ set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6) find_package(PythonLibs ${PYBIND11_PYTHON_VERSION} REQUIRED) find_package(PythonInterp ${PYBIND11_PYTHON_VERSION} REQUIRED) -if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") +include(CheckCXXCompilerFlag) + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") # Enable C++11 mode on C++ / Clang set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # Enable link time optimization and set the default symbol # visibility to hidden (very important to obtain small binaries) if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -flto") + # Default symbol visibility + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") + + # Check for Link Time Optimization support + CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG) + if (HAS_LTO_FLAG) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") + endif() endif() endif()