[PATCH 5/9] Update FindPhononInternal.cmake compiler specific settings with FindKDE4Internal.cmake changes from the kde framewoeks branch.
Jon Severinsson
jon at severinsson.net
Sat Oct 6 18:15:47 UTC 2012
---
cmake/FindPhononInternal.cmake | 110 ++++++++++++++++++++++++++--------------
1 fil ändrad, 71 tillägg(+), 39 borttagningar(-)
diff --git a/cmake/FindPhononInternal.cmake b/cmake/FindPhononInternal.cmake
index 91e318f..4321109 100644
--- a/cmake/FindPhononInternal.cmake
+++ b/cmake/FindPhononInternal.cmake
@@ -149,6 +149,26 @@ endif (CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME STREQUAL GNU)
# Keep this portion copy'n'pastable for updatability.
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+# this macro is for internal use only.
+macro(KDE_CHECK_FLAG_EXISTS FLAG VAR DOC)
+ if(NOT ${VAR} MATCHES "${FLAG}")
+ set(${VAR} "${${VAR}} ${FLAG}" CACHE STRING "Flags used by the linker during ${DOC} builds." FORCE)
+ endif(NOT ${VAR} MATCHES "${FLAG}")
+endmacro(KDE_CHECK_FLAG_EXISTS FLAG VAR)
+
+if (MSVC)
+ set (KDE4_ENABLE_EXCEPTIONS -EHsc)
+
+ # Qt disables the native wchar_t type, do it too to avoid linking issues
+ set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Zc:wchar_t-" )
+
+ # make sure that no header adds libcmt by default using #pragma comment(lib, "libcmt.lib") as done by mfc/afx.h
+ kde_check_flag_exists("/NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt" CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "Release with Debug Info")
+ kde_check_flag_exists("/NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt" CMAKE_EXE_LINKER_FLAGS_RELEASE "release")
+ kde_check_flag_exists("/NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt" CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "release minsize")
+ kde_check_flag_exists("/NODEFAULTLIB:libcmtd /DEFAULTLIB:msvcrtd" CMAKE_EXE_LINKER_FLAGS_DEBUG "debug")
+endif(MSVC)
+
# This macro is for internal use only
# Return the directories present in gcc's include path.
macro(_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS _lang _result)
@@ -192,10 +212,15 @@ if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS_DEBUGFULL "-g3 -fno-inline")
set(CMAKE_C_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs")
+ 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 -fno-exceptions -DQT_NO_EXCEPTIONS -fno-check-new -fno-common")
+
if (CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME STREQUAL GNU)
- 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 off 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 -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -DQT_NO_EXCEPTIONS -fno-check-new -fno-common")
+ # This should not be needed, as it is also part of _KDE4_PLATFORM_DEFINITIONS below.
+ # It is kept here nonetheless both for backwards compatibility in case one does not use add_definitions(${KDE4_DEFINITIONS})
+ # and also because it is/was needed by glibc for snprintf to be available when building C files.
+ # See commit 4a44862b2d178c1d2e1eb4da90010d19a1e4a42c.
add_definitions (-D_BSD_SOURCE)
endif (CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME STREQUAL GNU)
@@ -208,7 +233,6 @@ if (CMAKE_COMPILER_IS_GNUCXX)
if (MINGW)
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols -Wl,--disable-auto-import")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--export-all-symbols -Wl,--disable-auto-import")
-
endif (MINGW)
check_cxx_compiler_flag(-fPIE HAVE_FPIE_SUPPORT)
@@ -230,38 +254,14 @@ if (CMAKE_COMPILER_IS_GNUCXX)
check_cxx_compiler_flag(-fvisibility=hidden __KDE_HAVE_GCC_VISIBILITY)
set( __KDE_HAVE_GCC_VISIBILITY ${__KDE_HAVE_GCC_VISIBILITY} CACHE BOOL "GCC support for hidden visibility")
- # get the gcc version
- exec_program(${CMAKE_C_COMPILER} ARGS ${CMAKE_C_COMPILER_ARG1} --version OUTPUT_VARIABLE _gcc_version_info)
-
- string (REGEX MATCH "[345]\\.[0-9]\\.[0-9]" _gcc_version "${_gcc_version_info}")
- # gcc on mac just reports: "gcc (GCC) 3.3 20030304 ..." without the patch level, handle this here:
- if (NOT _gcc_version)
- string (REGEX MATCH ".*\\(GCC\\).* ([34]\\.[0-9]) .*" "\\1.0" _gcc_version "${gcc_on_macos}")
- if (gcc_on_macos)
- string (REGEX REPLACE ".*\\(GCC\\).* ([34]\\.[0-9]) .*" "\\1.0" _gcc_version "${_gcc_version_info}")
- endif (gcc_on_macos)
- endif (NOT _gcc_version)
-
- if (_gcc_version)
- macro_ensure_version("4.1.0" "${_gcc_version}" GCC_IS_NEWER_THAN_4_1)
- macro_ensure_version("4.2.0" "${_gcc_version}" GCC_IS_NEWER_THAN_4_2)
- macro_ensure_version("4.3.0" "${_gcc_version}" GCC_IS_NEWER_THAN_4_3)
- endif (_gcc_version)
-
# save a little by making local statics not threadsafe
- # ### do not enable it for older compilers, see
- # ### http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31806
- if (GCC_IS_NEWER_THAN_4_3)
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics")
- endif (GCC_IS_NEWER_THAN_4_3)
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics")
set(_GCC_COMPILED_WITH_BAD_ALLOCATOR FALSE)
- if (GCC_IS_NEWER_THAN_4_1)
- exec_program(${CMAKE_C_COMPILER} ARGS ${CMAKE_C_COMPILER_ARG1} -v OUTPUT_VARIABLE _gcc_alloc_info)
- string(REGEX MATCH "(--enable-libstdcxx-allocator=mt)" _GCC_COMPILED_WITH_BAD_ALLOCATOR "${_gcc_alloc_info}")
- endif (GCC_IS_NEWER_THAN_4_1)
+ exec_program(${CMAKE_C_COMPILER} ARGS ${CMAKE_C_COMPILER_ARG1} -v OUTPUT_VARIABLE _gcc_alloc_info)
+ string(REGEX MATCH "(--enable-libstdcxx-allocator=mt)" _GCC_COMPILED_WITH_BAD_ALLOCATOR "${_gcc_alloc_info}")
- if (__KDE_HAVE_GCC_VISIBILITY AND GCC_IS_NEWER_THAN_4_1 AND NOT _GCC_COMPILED_WITH_BAD_ALLOCATOR AND NOT WIN32)
+ if (__KDE_HAVE_GCC_VISIBILITY AND NOT _GCC_COMPILED_WITH_BAD_ALLOCATOR AND NOT WIN32)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
set (KDE4_C_FLAGS "-fvisibility=hidden")
# check that Qt defines Q_DECL_EXPORT as __attribute__ ((visibility("default")))
@@ -271,21 +271,53 @@ if (CMAKE_COMPILER_IS_GNUCXX)
file(WRITE "${_source_file}" "${_source}")
set(_include_dirs "-DINCLUDE_DIRECTORIES:STRING=${QT_INCLUDES}")
- try_compile(_compile_result ${CMAKE_BINARY_DIR} ${_source_file} CMAKE_FLAGS "${_include_dirs}" COMPILE_OUTPUT_VARIABLE _compile_output_var)
+ set (CMAKE_CXX_FLAGS_SAVED "${CMAKE_CXX_FLAGS}")
+
+ # If Qt is built with reduce-relocations (The default) we need to add -fPIE here.
+ set (CMAKE_CXX_FLAGS "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
+
+ try_compile(_compile_result ${CMAKE_BINARY_DIR} ${_source_file} CMAKE_FLAGS "${_include_dirs}" OUTPUT_VARIABLE _compile_output_var)
+
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_SAVED}")
if(NOT _compile_result)
- message(FATAL_ERROR "Qt compiled without support for -fvisibility=hidden. This will break plugins and linking of some applications. Please fix your Qt installation.")
+ message("${_compile_output_var}")
+ 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(NOT _compile_result)
- if (GCC_IS_NEWER_THAN_4_2)
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden")
- endif (GCC_IS_NEWER_THAN_4_2)
- else (__KDE_HAVE_GCC_VISIBILITY AND GCC_IS_NEWER_THAN_4_1 AND NOT _GCC_COMPILED_WITH_BAD_ALLOCATOR AND NOT WIN32)
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type -fvisibility-inlines-hidden")
+ else (__KDE_HAVE_GCC_VISIBILITY AND NOT _GCC_COMPILED_WITH_BAD_ALLOCATOR AND NOT WIN32)
set (__KDE_HAVE_GCC_VISIBILITY 0)
- endif (__KDE_HAVE_GCC_VISIBILITY AND GCC_IS_NEWER_THAN_4_1 AND NOT _GCC_COMPILED_WITH_BAD_ALLOCATOR AND NOT WIN32)
+ endif (__KDE_HAVE_GCC_VISIBILITY AND NOT _GCC_COMPILED_WITH_BAD_ALLOCATOR AND NOT WIN32)
endif (CMAKE_COMPILER_IS_GNUCXX)
+
+if (CMAKE_C_COMPILER MATCHES "icc")
+
+ set (KDE4_ENABLE_EXCEPTIONS -fexceptions)
+ # Select flags.
+ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
+ set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG -DQT_NO_DEBUG")
+ set(CMAKE_CXX_FLAGS_DEBUG "-O2 -g -fno-inline -noalign")
+ set(CMAKE_CXX_FLAGS_DEBUGFULL "-g -fno-inline -noalign")
+ set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
+ set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG -DQT_NO_DEBUG")
+ set(CMAKE_C_FLAGS_DEBUG "-O2 -g -fno-inline -noalign")
+ set(CMAKE_C_FLAGS_DEBUGFULL "-g -fno-inline -noalign")
+
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi -Wall -w1 -Wpointer-arith -fno-common")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi -Wall -w1 -Wpointer-arith -fno-exceptions -fno-common")
+
+ # visibility support
+ set(__KDE_HAVE_ICC_VISIBILITY)
+# check_cxx_compiler_flag(-fvisibility=hidden __KDE_HAVE_ICC_VISIBILITY)
+# if (__KDE_HAVE_ICC_VISIBILITY)
+# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+# endif (__KDE_HAVE_ICC_VISIBILITY)
+
+endif (CMAKE_C_COMPILER MATCHES "icc")
+
#-------------------------------------------------------------------------------
--
1.7.10.4
More information about the Kde-frameworks-devel
mailing list