CMakeFindEclipseCDT4.cmake 4.0 KB

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