1 # This file is included in CMakeSystemSpecificInformation.cmake if
2 # the Eclipse CDT4 extra generator has been selected.
4 FIND_PROGRAM(CMAKE_ECLIPSE_EXECUTABLE NAMES eclipse DOC "The Eclipse executable")
7 # The Eclipse generator needs to know the standard include path
8 # so that Eclipse ca find the headers at runtime and parsing etc. works better
9 # This is done here by actually running gcc with the options so it prints its
10 # system include directories, which are parsed then and stored in the cache.
11 MACRO(_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS _lang _result _resultDefines)
14 FILE(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/dummy" "\n" )
15 EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -v -E -x ${_lang} -dD dummy
16 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles
17 ERROR_VARIABLE _gccOutput
18 OUTPUT_VARIABLE _gccStdout )
19 FILE(REMOVE "${CMAKE_BINARY_DIR}/CMakeFiles/dummy")
21 IF( "${_gccOutput}" MATCHES "> search starts here[^\n]+\n *(.+) *\n *End of (search) list" )
22 SET(${_result} ${CMAKE_MATCH_1})
23 STRING(REPLACE "\n" " " ${_result} "${${_result}}")
24 SEPARATE_ARGUMENTS(${_result})
25 ENDIF( "${_gccOutput}" MATCHES "> search starts here[^\n]+\n *(.+) *\n *End of (search) list" )
27 IF( "${_gccStdout}" MATCHES "built-in>\"\n(.+)# 1 +\"dummy\"" )
28 SET(_builtinDefines ${CMAKE_MATCH_1})
29 # Remove the '# 1 "<command-line>"' lines
30 STRING(REGEX REPLACE "# 1[^\n]+\n" "" _filteredOutput "${_builtinDefines}")
31 # Remove the "#define " parts from the output:
32 STRING(REGEX REPLACE "#define " "" _defineRemoved "${_filteredOutput}")
33 # Replace the line breaks with spaces, so we can use separate arguments afterwards
34 STRING(REGEX REPLACE "\n" " " _defineRemoved "${_defineRemoved}")
35 # Remove space at the end, this would produce empty list items
36 STRING(REGEX REPLACE " +$" "" ${_resultDefines} "${_defineRemoved}")
37 SEPARATE_ARGUMENTS(${_resultDefines})
38 ENDIF( "${_gccStdout}" MATCHES "built-in>\"\n(.+)# 1 +\"dummy\"" )
39 ENDMACRO(_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS _lang)
41 # Save the current LC_ALL, LC_MESSAGES, and LANG environment variables and set them
42 # to "C" that way GCC's "search starts here" text is in English and we can grok it.
43 SET(_orig_lc_all $ENV{LC_ALL})
44 SET(_orig_lc_messages $ENV{LC_MESSAGES})
45 SET(_orig_lang $ENV{LANG})
50 SET(ENV{LC_MESSAGES} C)
51 ENDIF(_orig_lc_messages)
56 # Now check for C, works for gcc and Intel compiler at least
57 IF (NOT CMAKE_ECLIPSE_C_SYSTEM_INCLUDE_DIRS)
58 IF ("${CMAKE_C_COMPILER_ID}" MATCHES GNU OR "${CMAKE_C_COMPILER_ID}" MATCHES Intel)
59 _DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c _dirs _defines)
60 SET(CMAKE_ECLIPSE_C_SYSTEM_INCLUDE_DIRS "${_dirs}" CACHE INTERNAL "C compiler system include directories")
61 SET(CMAKE_ECLIPSE_C_SYSTEM_DEFINED_MACROS "${_defines}" CACHE INTERNAL "C compiler system defined macros")
62 ENDIF ("${CMAKE_C_COMPILER_ID}" MATCHES GNU OR "${CMAKE_C_COMPILER_ID}" MATCHES Intel)
63 ENDIF (NOT CMAKE_ECLIPSE_C_SYSTEM_INCLUDE_DIRS)
65 # And now the same for C++
66 IF (NOT CMAKE_ECLIPSE_CXX_SYSTEM_INCLUDE_DIRS)
67 IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES GNU OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Intel)
68 _DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c++ _dirs _defines)
69 SET(CMAKE_ECLIPSE_CXX_SYSTEM_INCLUDE_DIRS "${_dirs}" CACHE INTERNAL "CXX compiler system include directories")
70 SET(CMAKE_ECLIPSE_CXX_SYSTEM_DEFINED_MACROS "${_defines}" CACHE INTERNAL "CXX compiler system defined macros")
71 ENDIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES GNU OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Intel)
72 ENDIF (NOT CMAKE_ECLIPSE_CXX_SYSTEM_INCLUDE_DIRS)
74 # Restore original LC_ALL, LC_MESSAGES, and LANG
76 SET(ENV{LC_ALL} ${_orig_lc_all})
79 SET(ENV{LC_MESSAGES} ${_orig_lc_messages})
80 ENDIF(_orig_lc_messages)
82 SET(ENV{LANG} ${_orig_lang})