CMakeFindEclipseCDT4.cmake 4.6 KB

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