aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Kubo da Costa <kubito@gmail.com>2010-06-07 20:37:38 +0000
committerRaphael Kubo da Costa <kubito@gmail.com>2010-06-07 20:37:38 +0000
commit48eab9f321582523eef6445e6c5baab8c3adb729 (patch)
tree4f1a91f1c63f102c0451f4f95e7d89b21d00c750
parent0f23ee767198999f8feac7d4053a78dbaec24409 (diff)
downloadextra-cmake-modules-48eab9f321582523eef6445e6c5baab8c3adb729.tar.gz
extra-cmake-modules-48eab9f321582523eef6445e6c5baab8c3adb729.tar.bz2
Check gcc's include path and add any previously missing entries to
CMAKE_{C,CXX}_IMPLICIT_INCLUDE_DIRECTORIES. As discussed on the kde-buildsystem mailing list, this is particularly useful on systems such as FreeBSD, which have most of the libraries and headers installed in /usr/local: CMake would not add -I/usr/include when compiling code, but would do that with other directories such as /usr/local. This, in turn, would sometimes make the system-wide includes be added to the include path before the local ones, which can lead to compilation failures. With this patch, if CPATH is properly set, directories such as /usr/local/* will not be added by CMake when gcc is invoked. For now, this works only with gcc, but can be extended to other compilers if necessary. CCMAIL: kde-buildsystem@kde.org svn path=/trunk/KDE/kdelibs/; revision=1135642
-rw-r--r--modules/FindKDE4Internal.cmake32
1 files changed, 30 insertions, 2 deletions
diff --git a/modules/FindKDE4Internal.cmake b/modules/FindKDE4Internal.cmake
index 8c67c8b2..28f82b19 100644
--- a/modules/FindKDE4Internal.cmake
+++ b/modules/FindKDE4Internal.cmake
@@ -234,12 +234,12 @@
# KDE4_ADD_APP_ICON (SRCS_VAR pattern)
# adds an application icon to target source list.
# Mac OSX notes : the application icon is added to a Mac OS X bundle so that Finder and friends show the right thing.
-# Win32 notes: the application icon(s) are compiled into the application
+# Win32 notes: the application icon(s) are compiled into the application
# There is some workaround in kde4_add_kdeinit_executable to make it possible for those applications as well.
# Parameters:
# SRCS_VAR - specifies the list of source files; this has to end in _SRCS or _KDEINIT_SRCS
# (see the replace stuff below)
-# pattern - regular expression for searching application icons
+# pattern - regular expression for searching application icons
# Example: KDE4_ADD_APP_ICON( myapp_SRCS "pics/cr*-myapp.png")
# Example: KDE4_ADD_APP_ICON( myapp_KDEINIT_SRCS "icons/oxygen/*/apps/myapp.png")
#
@@ -1136,8 +1136,36 @@ if (MSVC)
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)
+ set(${_result})
+ set(_gccOutput)
+ file(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/dummy" "\n" )
+ execute_process(COMMAND ${CMAKE_C_COMPILER} -v -E -x ${_lang} -dD dummy
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles
+ ERROR_VARIABLE _gccOutput
+ OUTPUT_VARIABLE _gccStdout )
+ file(REMOVE "${CMAKE_BINARY_DIR}/CMakeFiles/dummy")
+
+ if( "${_gccOutput}" MATCHES "> search starts here[^\n]+\n *(.+) *\n *End of (search) list" )
+ SET(${_result} ${CMAKE_MATCH_1})
+ STRING(REPLACE "\n" " " ${_result} "${${_result}}")
+ SEPARATE_ARGUMENTS(${_result})
+ ENDIF( "${_gccOutput}" MATCHES "> search starts here[^\n]+\n *(.+) *\n *End of (search) list" )
+ENDMACRO(_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS _lang)
+
+if (CMAKE_COMPILER_IS_GNUCC)
+ _DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c _dirs)
+ set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES
+ ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES} ${_dirs})
+endif (CMAKE_COMPILER_IS_GNUCC)
if (CMAKE_COMPILER_IS_GNUCXX)
+ _DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c++ _dirs)
+ set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
+ ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES} ${_dirs})
+
set (KDE4_ENABLE_EXCEPTIONS "-fexceptions -UQT_NO_EXCEPTIONS")
# Select flags.
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG -DQT_NO_DEBUG")