CMakeFindEclipseCDT4.cmake 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. # This variable is used by the Eclipse generator and appended to the make invocation commands.
  17. SET(CMAKE_ECLIPSE_MAKE_ARGUMENTS "" CACHE STRING "Additional command line arguments when Eclipse invokes make. Enter e.g. -j<some_number> to get parallel builds")
  18. # This variable is used by the Eclipse generator in out-of-source builds only.
  19. SET(ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT FALSE CACHE BOOL "If enabled, CMake will generate a source project for Eclipse in CMAKE_SOURCE_DIR")
  20. MARK_AS_ADVANCED(ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT)
  21. # The Eclipse generator needs to know the standard include path
  22. # so that Eclipse ca find the headers at runtime and parsing etc. works better
  23. # This is done here by actually running gcc with the options so it prints its
  24. # system include directories, which are parsed then and stored in the cache.
  25. MACRO(_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS _lang _resultIncludeDirs _resultDefines)
  26. SET(${_resultIncludeDirs})
  27. SET(_gccOutput)
  28. FILE(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/dummy" "\n" )
  29. EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -v -E -x ${_lang} -dD dummy
  30. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles
  31. ERROR_VARIABLE _gccOutput
  32. OUTPUT_VARIABLE _gccStdout )
  33. FILE(REMOVE "${CMAKE_BINARY_DIR}/CMakeFiles/dummy")
  34. # First find the system include dirs:
  35. IF( "${_gccOutput}" MATCHES "> search starts here[^\n]+\n *(.+) *\n *End of (search) list" )
  36. # split the output into lines and then remove leading and trailing spaces from each of them:
  37. STRING(REGEX MATCHALL "[^\n]+\n" _includeLines "${CMAKE_MATCH_1}")
  38. FOREACH(nextLine ${_includeLines})
  39. STRING(STRIP "${nextLine}" _includePath)
  40. LIST(APPEND ${_resultIncludeDirs} "${_includePath}")
  41. ENDFOREACH(nextLine)
  42. ENDIF( "${_gccOutput}" MATCHES "> search starts here[^\n]+\n *(.+) *\n *End of (search) list" )
  43. # now find the builtin macros:
  44. STRING(REGEX MATCHALL "#define[^\n]+\n" _defineLines "${_gccStdout}")
  45. # A few example lines which the regexp below has to match properly:
  46. # #define MAX(a,b) ((a) > (b) ? (a) : (b))
  47. # #define __fastcall __attribute__((__fastcall__))
  48. # #define FOO (23)
  49. # #define __UINTMAX_TYPE__ long long unsigned int
  50. # #define __UINTMAX_TYPE__ long long unsigned int
  51. # #define __i386__ 1
  52. FOREACH(nextLine ${_defineLines})
  53. STRING(REGEX MATCH "^#define +([A-Za-z_][A-Za-z0-9_]*)(\\([^\\)]+\\))? +(.+) *$" _dummy "${nextLine}")
  54. SET(_name "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
  55. STRING(STRIP "${CMAKE_MATCH_3}" _value)
  56. #MESSAGE(STATUS "m1: -${CMAKE_MATCH_1}- m2: -${CMAKE_MATCH_2}- m3: -${CMAKE_MATCH_3}-")
  57. LIST(APPEND ${_resultDefines} "${_name}")
  58. IF(_value)
  59. LIST(APPEND ${_resultDefines} "${_value}")
  60. ELSE()
  61. LIST(APPEND ${_resultDefines} " ")
  62. ENDIF()
  63. ENDFOREACH(nextLine)
  64. ENDMACRO(_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS _lang)
  65. # Save the current LC_ALL, LC_MESSAGES, and LANG environment variables and set them
  66. # to "C" that way GCC's "search starts here" text is in English and we can grok it.
  67. SET(_orig_lc_all $ENV{LC_ALL})
  68. SET(_orig_lc_messages $ENV{LC_MESSAGES})
  69. SET(_orig_lang $ENV{LANG})
  70. IF(_orig_lc_all)
  71. SET(ENV{LC_ALL} C)
  72. ENDIF(_orig_lc_all)
  73. IF(_orig_lc_messages)
  74. SET(ENV{LC_MESSAGES} C)
  75. ENDIF(_orig_lc_messages)
  76. IF(_orig_lang)
  77. SET(ENV{LANG} C)
  78. ENDIF(_orig_lang)
  79. # Now check for C, works for gcc and Intel compiler at least
  80. IF (NOT CMAKE_ECLIPSE_C_SYSTEM_INCLUDE_DIRS)
  81. IF ("${CMAKE_C_COMPILER_ID}" MATCHES GNU OR "${CMAKE_C_COMPILER_ID}" MATCHES Intel)
  82. _DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c _dirs _defines)
  83. SET(CMAKE_ECLIPSE_C_SYSTEM_INCLUDE_DIRS "${_dirs}" CACHE INTERNAL "C compiler system include directories")
  84. SET(CMAKE_ECLIPSE_C_SYSTEM_DEFINED_MACROS "${_defines}" CACHE INTERNAL "C compiler system defined macros")
  85. ENDIF ("${CMAKE_C_COMPILER_ID}" MATCHES GNU OR "${CMAKE_C_COMPILER_ID}" MATCHES Intel)
  86. ENDIF (NOT CMAKE_ECLIPSE_C_SYSTEM_INCLUDE_DIRS)
  87. # And now the same for C++
  88. IF (NOT CMAKE_ECLIPSE_CXX_SYSTEM_INCLUDE_DIRS)
  89. IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES GNU OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Intel)
  90. _DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c++ _dirs _defines)
  91. SET(CMAKE_ECLIPSE_CXX_SYSTEM_INCLUDE_DIRS "${_dirs}" CACHE INTERNAL "CXX compiler system include directories")
  92. SET(CMAKE_ECLIPSE_CXX_SYSTEM_DEFINED_MACROS "${_defines}" CACHE INTERNAL "CXX compiler system defined macros")
  93. ENDIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES GNU OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Intel)
  94. ENDIF (NOT CMAKE_ECLIPSE_CXX_SYSTEM_INCLUDE_DIRS)
  95. # Restore original LC_ALL, LC_MESSAGES, and LANG
  96. IF(_orig_lc_all)
  97. SET(ENV{LC_ALL} ${_orig_lc_all})
  98. ENDIF(_orig_lc_all)
  99. IF(_orig_lc_messages)
  100. SET(ENV{LC_MESSAGES} ${_orig_lc_messages})
  101. ENDIF(_orig_lc_messages)
  102. IF(_orig_lang)
  103. SET(ENV{LANG} ${_orig_lang})
  104. ENDIF(_orig_lang)