summaryrefslogtreecommitdiff
path: root/Modules/CMakeParseImplicitIncludeInfo.cmake
diff options
context:
space:
mode:
authorChuck Cranor <chuck@ece.cmu.edu>2019-01-24 08:30:03 -0700
committerChuck Cranor <chuck@ece.cmu.edu>2019-01-25 07:48:00 -0700
commit568343767e5852f0e5751341a3aa44ab6feffb8a (patch)
tree155402b29ad86aaefdf3838fc42ba5594ad798b2 /Modules/CMakeParseImplicitIncludeInfo.cmake
parent40628b2519ae1553a33f701cf46ee8fbbd013b85 (diff)
downloadcmake-568343767e5852f0e5751341a3aa44ab6feffb8a.tar.gz
ParseImplicitIncludeInfo: handle/add SunPro, XL, and -nostdinc test cases
Add parser code for compiler IDs SunPro and XL. For SunPro, /usr/include appears to be hardwired in and it does not have a -nostdinc-type flag. For XL, the "xlc" and "xlC" commands determine if you are C or C++ based on input filename. So compiling x.c with "xlC" reverts to C and compiling x.cc with "xlc" upgrades to CXX. System include paths are specified by: -qc_stdinc=[path] and -qgcc_c_stdinc=[path] (for C) -qcpp_stdinc=[path] and -qgcc_cpp_stdinc=[path] (for CXX) If you specify "-qnostdinc" then the above flags are ignored. Specifying an empty path reverts the value to the default path (e.g. "-qgcc_c_stdinc=" reverts that to the default). Adjust the code to handle parsing the case where the user specifies additional compiler include flags via CMAKE_C_FLAGS/CMAKE_CXX_FLAGS. For example: "-DCMAKE_C_FLAGS=-nostdinc" ... note that gcc and clang output slightly differ when -nostdinc is specified (clang skips printing 'search starts here:' with the angle brackets, gcc always prints it). Enable sunos-{C,CXX}-SunPro test cases and add XL test cases. Also add a few -nostdinc style tests.
Diffstat (limited to 'Modules/CMakeParseImplicitIncludeInfo.cmake')
-rw-r--r--Modules/CMakeParseImplicitIncludeInfo.cmake101
1 files changed, 90 insertions, 11 deletions
diff --git a/Modules/CMakeParseImplicitIncludeInfo.cmake b/Modules/CMakeParseImplicitIncludeInfo.cmake
index 9901fea48a..6603e1cb72 100644
--- a/Modules/CMakeParseImplicitIncludeInfo.cmake
+++ b/Modules/CMakeParseImplicitIncludeInfo.cmake
@@ -11,8 +11,9 @@ function(cmake_parse_implicit_include_line line lang id_var log_var state_var)
unset(rv)
set(log "")
- # ccfe: cray compiler front end (PrgEnv-cray)
+ # Cray compiler (from cray wrapper, via PrgEnv-cray)
if("${CMAKE_${lang}_COMPILER_ID}" STREQUAL "Cray" AND
+ "${line}" MATCHES "^/" AND "${line}" MATCHES "/ccfe " AND
"${line}" MATCHES "-isystem")
string(REGEX MATCHALL " (-I ?|-isystem )([^ ]*)" incs "${line}")
foreach(inc IN LISTS incs)
@@ -26,10 +27,78 @@ function(cmake_parse_implicit_include_line line lang id_var log_var state_var)
endif()
endif()
+ # SunPro compiler
+ if("${CMAKE_${lang}_COMPILER_ID}" STREQUAL "SunPro" AND
+ "${line}" MATCHES "-D__SUNPRO_C")
+ string(REGEX MATCHALL " (-I ?)([^ ]*)" incs "${line}")
+ foreach(inc IN LISTS incs)
+ string(REGEX REPLACE " (-I ?)([^ ]*)" "\\2" idir "${inc}")
+ if(NOT "${idir}" STREQUAL "-xbuiltin")
+ list(APPEND rv "${idir}")
+ endif()
+ endforeach()
+ if(rv)
+ # /usr/include appears to be hardwired in
+ list(APPEND rv "/usr/include")
+ string(APPEND log " got implicit includes via sunpro parser!\n")
+ else()
+ string(APPEND log " warning: sunpro parse failed!\n")
+ endif()
+ endif()
+
+ # XL C/CXX compiler
+ if("${CMAKE_${lang}_COMPILER_ID}" STREQUAL "XL" AND
+ "${line}" MATCHES "^/" AND "${line}" MATCHES "/xlcentry |/xlCentry " AND
+ "${line}" MATCHES " -qosvar=")
+ # -qnostdinc cancels other stdinc flags, even if present
+ string(FIND "${line}" " -qnostdinc" nostd)
+ if(NOT ${nostd} EQUAL -1)
+ set(rv "") # defined but empty
+ string(APPEND log " got implicit includes via XL parser (nostdinc)\n")
+ else()
+ if("${lang}" STREQUAL "CXX")
+ string(REGEX MATCHALL " -qcpp_stdinc=([^ ]*)" std "${line}")
+ string(REGEX MATCHALL " -qgcc_cpp_stdinc=([^ ]*)" gcc_std "${line}")
+ else()
+ string(REGEX MATCHALL " -qc_stdinc=([^ ]*)" std "${line}")
+ string(REGEX MATCHALL " -qgcc_c_stdinc=([^ ]*)" gcc_std "${line}")
+ endif()
+ set(xlstd ${std} ${gcc_std})
+ foreach(inc IN LISTS xlstd)
+ string(REGEX REPLACE " -q(cpp|gcc_cpp|c|gcc_c)_stdinc=([^ ]*)" "\\2"
+ ipath "${inc}")
+ string(REPLACE ":" ";" ipath "${ipath}")
+ list(APPEND rv ${ipath})
+ endforeach()
+ endif()
+ # user can add -I flags via CMAKE_{C,CXX}_FLAGS, look for that too
+ string(REGEX MATCHALL " (-I ?)([^ ]*)" incs "${line}")
+ unset(urv)
+ foreach(inc IN LISTS incs)
+ string(REGEX REPLACE " (-I ?)([^ ]*)" "\\2" idir "${inc}")
+ list(APPEND urv "${idir}")
+ endforeach()
+ if(urv)
+ if ("${rv}" STREQUAL "")
+ set(rv ${urv})
+ else()
+ list(APPEND rv ${urv})
+ endif()
+ endif()
+
+ if(DEFINED rv)
+ string(APPEND log " got implicit includes via XL parser!\n")
+ else()
+ string(APPEND log " warning: XL parse failed!\n")
+ endif()
+ endif()
+
if(log)
set(${log_var} "${log}" PARENT_SCOPE)
+ else()
+ unset(${log_var} PARENT_SCOPE)
endif()
- if(rv)
+ if(DEFINED rv)
set(${id_var} "${rv}" PARENT_SCOPE)
set(${state_var} "done" PARENT_SCOPE)
endif()
@@ -48,10 +117,11 @@ function(cmake_parse_implicit_include_info text lang dir_var log_var state_var)
string(REGEX REPLACE "\r?\n" ";" output_lines "${text}")
foreach(line IN LISTS output_lines)
if(state STREQUAL start)
- string(FIND "${line}" "#include <...> search starts here:" rv)
+ string(FIND "${line}" "#include \"...\" search starts here:" rv)
if(rv GREATER -1)
set(state loading)
- string(APPEND log " found start of implicit include info\n")
+ set(preload 1) # looking for include <...> now
+ string(APPEND log " found start of include info\n")
else()
cmake_parse_implicit_include_line("${line}" "${lang}" implicit_dirs_tmp
linelog state)
@@ -68,15 +138,24 @@ function(cmake_parse_implicit_include_info text lang dir_var log_var state_var)
set(state done)
string(APPEND log " end of search list found\n")
break()
- else()
- string(STRIP "${line}" path) # remove leading/trailing spaces
- if ("${path}" MATCHES " \\(framework directory\\)$")
- continue() # frameworks are handled elsewhere, ignore them here
+ endif()
+ if(preload)
+ string(FIND "${line}" "#include <...> search starts here:" rv)
+ if(rv GREATER -1)
+ set(preload 0)
+ string(APPEND log " found start of implicit include info\n")
endif()
- string(REPLACE "\\" "/" path "${path}")
- list(APPEND implicit_dirs_tmp "${path}")
- string(APPEND log " add: [${path}]\n")
+ continue()
+ endif()
+ if("${line}" MATCHES "^ ")
+ string(SUBSTRING "${line}" 1 -1 line) # remove leading space
+ endif()
+ if ("${line}" MATCHES " \\(framework directory\\)$")
+ continue() # frameworks are handled elsewhere, ignore them here
endif()
+ string(REPLACE "\\" "/" path "${line}")
+ list(APPEND implicit_dirs_tmp "${path}")
+ string(APPEND log " add: [${path}]\n")
endif()
endforeach()