From ecb29b6ca2b31ba6a7296ab325597a325806ab56 Mon Sep 17 00:00:00 2001 From: Raphael Kubo da Costa Date: Wed, 21 Aug 2013 13:19:23 +0300 Subject: CompilerSettings: Add a separate block for clang definitions. Sharing compiler settings between GCC and clang does not always work: there are flags (such as "-fno-check-new" or "-fno-reorder-blocks") that are specific to GCC, and nothing stops these incompatibilities from becoming bigger in the future. Conversely, a separate clang block allows us to pass some additional flags to clang that would have required yet another if() in the GCC block. For now, this amounts to "-fdelayed-template-parsing". (For KDE4, we also need -Wno-return-type-c-linkage because kdepim's ktexteditorkabcbridge.cpp exports a function that returns a QString with C linkage, but I hope this can be solved in a different way for kdepim5). Last but not least, checks for bad GCC allocators or support for some flags which are always present in clang can be avoided altogether when we know the compiler we are using. REVIEW: 112136 --- kde-modules/KDECompilerSettings.cmake | 54 +++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'kde-modules') diff --git a/kde-modules/KDECompilerSettings.cmake b/kde-modules/KDECompilerSettings.cmake index 4a9f760b..b745ec3c 100644 --- a/kde-modules/KDECompilerSettings.cmake +++ b/kde-modules/KDECompilerSettings.cmake @@ -235,7 +235,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # TODO: why do the other KDE4_ENABLE_EXCEPTIONS not have -UQT_NO_EXCEPTIONS ? set (KDE4_ENABLE_EXCEPTIONS "-fexceptions -UQT_NO_EXCEPTIONS") # Select flags. @@ -291,7 +291,57 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQ endif() endif() -endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") +endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") +# TODO: why do the other KDE4_ENABLE_EXCEPTIONS not have -UQT_NO_EXCEPTIONS ? + set (KDE4_ENABLE_EXCEPTIONS "-fexceptions -UQT_NO_EXCEPTIONS") + # Select flags. + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG -DQT_NO_DEBUG") + set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG -DQT_NO_DEBUG") + set(CMAKE_CXX_FLAGS_DEBUG "-g -O2 -fno-inline") + set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -fno-inline") + set(CMAKE_CXX_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs") + set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG -DQT_NO_DEBUG") + set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG -DQT_NO_DEBUG") + set(CMAKE_C_FLAGS_DEBUG "-g -O2 -fno-inline") + set(CMAKE_C_FLAGS_DEBUGFULL "-g3 -fno-inline") + set(CMAKE_C_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs") + set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage") + + # TODO: do those flags also apply to the Intel compiler? + set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") + set (CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") + set (CMAKE_MODULE_LINKER_FLAGS_PROFILE "${CMAKE_MODULE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-long-long -std=iso9899:1990 -Wundef -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common") + # As of Qt 4.6.x we need to override the new exception macros if we want compile with -fno-exceptions + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -Woverloaded-virtual -fno-exceptions -DQT_NO_EXCEPTIONS -fno-common -Werror=return-type") + + # There is a lot of code out there that includes headers that throw + # exceptions, but we disable exceptions by default. + # GCC, MSVC and ICC do not complain about these cases when the exceptions + # are thrown inside some template code that is not expanded/used, which is + # what happens most of the time. + # We have to follow suit and be less strict in order not to break the build + # in many places. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdelayed-template-parsing") + + if (CMAKE_SYSTEM_NAME STREQUAL GNU) + set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread") + set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pthread") + endif () + + if (NOT WIN32) + if (TARGET Qt5::Core) + if(NOT QT_VISIBILITY_AVAILABLE) + message(FATAL_ERROR "Qt compiled without support for -fvisibility=hidden. This will break plugins and linking of some applications. Please fix your Qt installation (try passing --reduce-exports to configure).") + endif() + endif() + endif() +endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") -- cgit v1.2.1