2016-09-27 22:01:08 +03:00
|
|
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
2011-08-02 03:46:39 +04:00
|
|
|
|
|
|
|
|
|
|
|
# This file is included by CMakeFindEclipseCDT4.cmake and CMakeFindCodeBlocks.cmake
|
|
|
|
|
|
|
|
# The Eclipse and the CodeBlocks generators need to know the standard include path
|
|
|
|
# so that they can find the headers at runtime and parsing etc. works better
|
|
|
|
# This is done here by actually running gcc with the options so it prints its
|
|
|
|
# system include directories, which are parsed then and stored in the cache.
|
2012-08-13 21:47:32 +04:00
|
|
|
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}")
|
2014-07-02 19:15:28 +04:00
|
|
|
|
|
|
|
if (CMAKE_CXX_FLAGS MATCHES "(-stdlib=[^ ]+)")
|
|
|
|
set(_stdlib "${CMAKE_MATCH_1}")
|
|
|
|
endif ()
|
2014-07-03 00:06:42 +04:00
|
|
|
if (CMAKE_CXX_FLAGS MATCHES "(-std=[^ ]+)")
|
|
|
|
set(_stdver "${CMAKE_MATCH_1}")
|
|
|
|
endif ()
|
2012-08-13 21:47:32 +04:00
|
|
|
else ()
|
|
|
|
set(_compilerExecutable "${CMAKE_C_COMPILER}")
|
|
|
|
set(_arg1 "${CMAKE_C_COMPILER_ARG1}")
|
|
|
|
endif ()
|
2014-07-03 00:06:42 +04:00
|
|
|
execute_process(COMMAND ${_compilerExecutable} ${_arg1} ${_stdver} ${_stdlib} -v -E -x ${_lang} -dD dummy
|
2011-08-02 03:46:39 +04:00
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles
|
|
|
|
ERROR_VARIABLE _gccOutput
|
|
|
|
OUTPUT_VARIABLE _gccStdout )
|
2012-08-13 21:47:32 +04:00
|
|
|
file(REMOVE "${CMAKE_BINARY_DIR}/CMakeFiles/dummy")
|
2011-08-02 03:46:39 +04:00
|
|
|
|
|
|
|
# First find the system include dirs:
|
2012-08-13 21:47:32 +04:00
|
|
|
if( "${_gccOutput}" MATCHES "> search starts here[^\n]+\n *(.+ *\n) *End of (search) list" )
|
2011-08-02 03:46:39 +04:00
|
|
|
|
|
|
|
# split the output into lines and then remove leading and trailing spaces from each of them:
|
2012-08-13 21:47:32 +04:00
|
|
|
string(REGEX MATCHALL "[^\n]+\n" _includeLines "${CMAKE_MATCH_1}")
|
|
|
|
foreach(nextLine ${_includeLines})
|
2012-08-10 23:28:40 +04:00
|
|
|
# on OSX, gcc says things like this: "/System/Library/Frameworks (framework directory)", strip the last part
|
|
|
|
string(REGEX REPLACE "\\(framework directory\\)" "" nextLineNoFramework "${nextLine}")
|
|
|
|
# strip spaces at the beginning and the end
|
|
|
|
string(STRIP "${nextLineNoFramework}" _includePath)
|
2012-08-13 21:47:32 +04:00
|
|
|
list(APPEND ${_resultIncludeDirs} "${_includePath}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endforeach()
|
2011-08-02 03:46:39 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
endif()
|
2011-08-02 03:46:39 +04:00
|
|
|
|
|
|
|
|
|
|
|
# now find the builtin macros:
|
2012-08-13 21:47:32 +04:00
|
|
|
string(REGEX MATCHALL "#define[^\n]+\n" _defineLines "${_gccStdout}")
|
2011-08-02 03:46:39 +04:00
|
|
|
# A few example lines which the regexp below has to match properly:
|
|
|
|
# #define MAX(a,b) ((a) > (b) ? (a) : (b))
|
|
|
|
# #define __fastcall __attribute__((__fastcall__))
|
|
|
|
# #define FOO (23)
|
|
|
|
# #define __UINTMAX_TYPE__ long long unsigned int
|
|
|
|
# #define __UINTMAX_TYPE__ long long unsigned int
|
|
|
|
# #define __i386__ 1
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
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)
|
|
|
|
#message(STATUS "m1: -${CMAKE_MATCH_1}- m2: -${CMAKE_MATCH_2}- m3: -${CMAKE_MATCH_3}-")
|
2011-08-02 03:46:39 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
list(APPEND ${_resultDefines} "${_name}")
|
|
|
|
if(_value)
|
|
|
|
list(APPEND ${_resultDefines} "${_value}")
|
|
|
|
else()
|
|
|
|
list(APPEND ${_resultDefines} " ")
|
|
|
|
endif()
|
2012-08-13 21:50:14 +04:00
|
|
|
endforeach()
|
2011-08-02 03:46:39 +04:00
|
|
|
|
2012-08-13 21:50:14 +04:00
|
|
|
endmacro()
|
2011-08-02 03:46:39 +04:00
|
|
|
|
|
|
|
# Save the current LC_ALL, LC_MESSAGES, and LANG environment variables and set them
|
|
|
|
# to "C" that way GCC's "search starts here" text is in English and we can grok it.
|
2012-08-13 21:47:32 +04:00
|
|
|
set(_orig_lc_all $ENV{LC_ALL})
|
|
|
|
set(_orig_lc_messages $ENV{LC_MESSAGES})
|
|
|
|
set(_orig_lang $ENV{LANG})
|
2012-06-26 01:09:27 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
set(ENV{LC_ALL} C)
|
|
|
|
set(ENV{LC_MESSAGES} C)
|
|
|
|
set(ENV{LANG} C)
|
2011-08-02 03:46:39 +04:00
|
|
|
|
|
|
|
# Now check for C, works for gcc and Intel compiler at least
|
2012-08-13 21:47:32 +04:00
|
|
|
if (NOT CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS)
|
2014-10-14 18:25:32 +04:00
|
|
|
if (CMAKE_C_COMPILER_ID MATCHES GNU OR CMAKE_C_COMPILER_ID MATCHES Intel OR CMAKE_C_COMPILER_ID MATCHES Clang)
|
2011-08-02 03:46:39 +04:00
|
|
|
_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c _dirs _defines)
|
2012-08-13 21:47:32 +04:00
|
|
|
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")
|
2015-08-14 12:38:23 +03:00
|
|
|
elseif ("${CMAKE_C_COMPILER_ID}" MATCHES MSVC)
|
|
|
|
set(CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS "$ENV{INCLUDE}" CACHE INTERNAL "C compiler system include directories")
|
2012-08-13 21:47:32 +04:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2011-08-02 03:46:39 +04:00
|
|
|
|
|
|
|
# And now the same for C++
|
2012-08-13 21:47:32 +04:00
|
|
|
if (NOT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS)
|
2013-02-10 21:58:27 +04:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES GNU OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Intel OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Clang)
|
2011-08-02 03:46:39 +04:00
|
|
|
_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS(c++ _dirs _defines)
|
2012-08-13 21:47:32 +04:00
|
|
|
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")
|
2015-08-14 12:38:23 +03:00
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES MSVC)
|
|
|
|
set(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS "$ENV{INCLUDE}" CACHE INTERNAL "CXX compiler system include directories")
|
2012-08-13 21:47:32 +04:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2011-08-02 03:46:39 +04:00
|
|
|
|
|
|
|
# Restore original LC_ALL, LC_MESSAGES, and LANG
|
2012-08-13 21:47:32 +04:00
|
|
|
set(ENV{LC_ALL} ${_orig_lc_all})
|
|
|
|
set(ENV{LC_MESSAGES} ${_orig_lc_messages})
|
|
|
|
set(ENV{LANG} ${_orig_lang})
|