123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- macro(_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS _lang _resultIncludeDirs _resultDefines)
- set(${_resultIncludeDirs})
- set(_gccOutput)
- file(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/dummy" "\n" )
- if (${_lang} STREQUAL "c++")
- set(_compilerExecutable "${CMAKE_CXX_COMPILER}")
- set(_arg1 "${CMAKE_CXX_COMPILER_ARG1}")
- if (CMAKE_CXX_FLAGS MATCHES "(-stdlib=[^ ]+)")
- set(_stdlib "${CMAKE_MATCH_1}")
- endif ()
- if (CMAKE_CXX_FLAGS MATCHES "(-std=[^ ]+)")
- set(_stdver "${CMAKE_MATCH_1}")
- endif ()
- else ()
- set(_compilerExecutable "${CMAKE_C_COMPILER}")
- set(_arg1 "${CMAKE_C_COMPILER_ARG1}")
- endif ()
- separate_arguments(_arg1 NATIVE_COMMAND "${_arg1}")
- execute_process(COMMAND ${_compilerExecutable} ${_arg1} ${_stdver} ${_stdlib} -v -E -x ${_lang} -dD dummy
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles
- ERROR_VARIABLE _gccOutput
- OUTPUT_VARIABLE _gccStdout )
- file(REMOVE "${CMAKE_BINARY_DIR}/CMakeFiles/dummy")
-
- if( "${_gccOutput}" MATCHES "> search starts here[^\n]+\n *(.+ *\n) *End of (search) list" )
-
- string(REGEX MATCHALL "[^\n]+\n" _includeLines "${CMAKE_MATCH_1}")
- foreach(nextLine ${_includeLines})
-
- string(REGEX REPLACE "\\(framework directory\\)" "" nextLineNoFramework "${nextLine}")
-
- string(STRIP "${nextLineNoFramework}" _includePath)
- list(APPEND ${_resultIncludeDirs} "${_includePath}")
- endforeach()
- endif()
-
- string(REGEX MATCHALL "#define[^\n]+\n" _defineLines "${_gccStdout}")
- foreach(nextLine ${_defineLines})
- string(REGEX MATCH "^#define +([A-Za-z_][A-Za-z0-9_]*)(\\([^\\)]+\\))? +(.+) *$" _dummy "${nextLine}")
- set(_name "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
- string(STRIP "${CMAKE_MATCH_3}" _value)
-
- list(APPEND ${_resultDefines} "${_name}")
- if ("${_value}" STREQUAL "")
- list(APPEND ${_resultDefines} " ")
- else()
- list(APPEND ${_resultDefines} "${_value}")
- endif()
- endforeach()
- endmacro()
- set(_orig_lc_all $ENV{LC_ALL})
- set(_orig_lc_messages $ENV{LC_MESSAGES})
- set(_orig_lang $ENV{LANG})
- set(ENV{LC_ALL} C)
- set(ENV{LC_MESSAGES} C)
- set(ENV{LANG} C)
- if (NOT CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS)
- if (CMAKE_C_COMPILER_ID MATCHES GNU OR CMAKE_C_COMPILER_ID MATCHES Intel OR CMAKE_C_COMPILER_ID MATCHES Clang)
- _DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c _dirs _defines)
- set(CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS "${_dirs}" CACHE INTERNAL "C compiler system include directories")
- set(CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS "${_defines}" CACHE INTERNAL "C compiler system defined macros")
- elseif ("${CMAKE_C_COMPILER_ID}" MATCHES MSVC)
- set(CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS "$ENV{INCLUDE}" CACHE INTERNAL "C compiler system include directories")
- endif ()
- endif ()
- if (NOT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS)
- if ("${CMAKE_CXX_COMPILER_ID}" MATCHES GNU OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Intel OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Clang)
- _DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c++ _dirs _defines)
- set(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS "${_dirs}" CACHE INTERNAL "CXX compiler system include directories")
- set(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS "${_defines}" CACHE INTERNAL "CXX compiler system defined macros")
- elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES MSVC)
- set(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS "$ENV{INCLUDE}" CACHE INTERNAL "CXX compiler system include directories")
- endif ()
- endif ()
- set(ENV{LC_ALL} ${_orig_lc_all})
- set(ENV{LC_MESSAGES} ${_orig_lc_messages})
- set(ENV{LANG} ${_orig_lang})
|