KDE/kdelibs/cmake/modules

Raphael Kubo da Costa kubito at gmail.com
Mon Jun 7 22:37:38 CEST 2010


SVN commit 1135642 by rkcosta:

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 at kde.org


 M  +28 -0     FindKDE4Internal.cmake  


--- trunk/KDE/kdelibs/cmake/modules/FindKDE4Internal.cmake #1135641:1135642
@@ -1136,8 +1136,36 @@
    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")


More information about the Kde-buildsystem mailing list