CMakeFindEclipseCDT4.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 distribute 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 _resultIncludeDirs _resultDefines)
  21. SET(${_resultIncludeDirs})
  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. # First find the system include dirs:
  30. IF( "${_gccOutput}" MATCHES "> search starts here[^\n]+\n *(.+) *\n *End of (search) list" )
  31. # split the output into lines and then remove leading and trailing spaces from each of them:
  32. STRING(REGEX MATCHALL "[^\n]+\n" _includeLines "${CMAKE_MATCH_1}")
  33. FOREACH(nextLine ${_includeLines})
  34. STRING(STRIP "${nextLine}" _includePath)
  35. LIST(APPEND ${_resultIncludeDirs} "${_includePath}")
  36. ENDFOREACH(nextLine)
  37. ENDIF( "${_gccOutput}" MATCHES "> search starts here[^\n]+\n *(.+) *\n *End of (search) list" )
  38. # now find the builtin macros:
  39. STRING(REGEX MATCHALL "#define[^\n]+\n" _defineLines "${_gccStdout}")
  40. # A few example lines which the regexp below has to match properly:
  41. # #define MAX(a,b) ((a) > (b) ? (a) : (b))
  42. # #define __fastcall __attribute__((__fastcall__))
  43. # #define FOO (23)
  44. # #define __UINTMAX_TYPE__ long long unsigned int
  45. # #define __UINTMAX_TYPE__ long long unsigned int
  46. # #define __i386__ 1
  47. FOREACH(nextLine ${_defineLines})
  48. STRING(REGEX MATCH "^#define +([A-Za-z_][A-Za-z0-9_]*)(\\([^\\)]+\\))? +(.+) *$" _dummy "${nextLine}")
  49. SET(_name "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
  50. STRING(STRIP "${CMAKE_MATCH_3}" _value)
  51. #MESSAGE(STATUS "m1: -${CMAKE_MATCH_1}- m2: -${CMAKE_MATCH_2}- m3: -${CMAKE_MATCH_3}-")
  52. LIST(APPEND ${_resultDefines} "${_name}")
  53. IF(_value)
  54. LIST(APPEND ${_resultDefines} "${_value}")
  55. ELSE()
  56. LIST(APPEND ${_resultDefines} " ")
  57. ENDIF()
  58. ENDFOREACH(nextLine)
  59. ENDMACRO(_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS _lang)
  60. # Save the current LC_ALL, LC_MESSAGES, and LANG environment variables and set them
  61. # to "C" that way GCC's "search starts here" text is in English and we can grok it.
  62. SET(_orig_lc_all $ENV{LC_ALL})
  63. SET(_orig_lc_messages $ENV{LC_MESSAGES})
  64. SET(_orig_lang $ENV{LANG})
  65. IF(_orig_lc_all)
  66. SET(ENV{LC_ALL} C)
  67. ENDIF(_orig_lc_all)
  68. IF(_orig_lc_messages)
  69. SET(ENV{LC_MESSAGES} C)
  70. ENDIF(_orig_lc_messages)
  71. IF(_orig_lang)
  72. SET(ENV{LANG} C)
  73. ENDIF(_orig_lang)
  74. # Now check for C, works for gcc and Intel compiler at least
  75. IF (NOT CMAKE_ECLIPSE_C_SYSTEM_INCLUDE_DIRS)
  76. IF ("${CMAKE_C_COMPILER_ID}" MATCHES GNU OR "${CMAKE_C_COMPILER_ID}" MATCHES Intel)
  77. _DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c _dirs _defines)
  78. SET(CMAKE_ECLIPSE_C_SYSTEM_INCLUDE_DIRS "${_dirs}" CACHE INTERNAL "C compiler system include directories")
  79. SET(CMAKE_ECLIPSE_C_SYSTEM_DEFINED_MACROS "${_defines}" CACHE INTERNAL "C compiler system defined macros")
  80. ENDIF ("${CMAKE_C_COMPILER_ID}" MATCHES GNU OR "${CMAKE_C_COMPILER_ID}" MATCHES Intel)
  81. ENDIF (NOT CMAKE_ECLIPSE_C_SYSTEM_INCLUDE_DIRS)
  82. # And now the same for C++
  83. IF (NOT CMAKE_ECLIPSE_CXX_SYSTEM_INCLUDE_DIRS)
  84. IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES GNU OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Intel)
  85. _DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c++ _dirs _defines)
  86. SET(CMAKE_ECLIPSE_CXX_SYSTEM_INCLUDE_DIRS "${_dirs}" CACHE INTERNAL "CXX compiler system include directories")
  87. SET(CMAKE_ECLIPSE_CXX_SYSTEM_DEFINED_MACROS "${_defines}" CACHE INTERNAL "CXX compiler system defined macros")
  88. ENDIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES GNU OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Intel)
  89. ENDIF (NOT CMAKE_ECLIPSE_CXX_SYSTEM_INCLUDE_DIRS)
  90. # Restore original LC_ALL, LC_MESSAGES, and LANG
  91. IF(_orig_lc_all)
  92. SET(ENV{LC_ALL} ${_orig_lc_all})
  93. ENDIF(_orig_lc_all)
  94. IF(_orig_lc_messages)
  95. SET(ENV{LC_MESSAGES} ${_orig_lc_messages})
  96. ENDIF(_orig_lc_messages)
  97. IF(_orig_lang)
  98. SET(ENV{LANG} ${_orig_lang})
  99. ENDIF(_orig_lang)