12 Commits

Author SHA1 Message Date
Brad King
4b46523d90 CMakeParseImplicitIncludeInfo: Remove all CR chars from compiler output
With Clang/LLVM on MinGW, lines ending in `\r\r\n` have been observed.
Filter out all `\r` characters from these line endings.

Fixes: #20021
2019-11-25 14:32:02 -05:00
Brad King
0a7b61269c Merge branch 'backport-implicit-includes-cray-hlist' 2019-07-09 13:13:26 -04:00
Chuck Atkins
98e371f13e Cray: Fix include parsing when the -hlist= flag is present
Update parsing logic from commit 5990ecb741 (Compute implicit include
directories from compiler output, 2018-12-07, v3.14.0-rc1~108^2)
to handle the quoting behavior caused by the `-hlist=` flag.
2019-07-09 13:12:52 -04:00
Brad King
442f4c4902 Merge branch 'backport-implicit-includes-relative' 2019-04-08 10:16:47 -04:00
Brad King
ef41d49812 Fix implicit include directory extraction for adaptive relative paths
In some cases GCC reports *relative* implicit include directories.  They
are computed adaptively with respect to the current working directory
such that the effective implicit include directory is an unchanging
absolute path.  Teach our implicit include directory extraction to
recognize such paths and normalize them.

Fixes: #19133
2019-04-08 10:12:22 -04:00
Brad King
c690e11a56 Merge topic 'implicit-includes'
dad86f1873 ParseImplicitIncludeInfo: Canonicalize implicit include dirs

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Michel Zou <xantares09@hotmail.com>
Merge-request: !3157
2019-03-29 09:11:41 -04:00
Brad King
dad86f1873 ParseImplicitIncludeInfo: Canonicalize implicit include dirs
The implicit include directory extraction added by commit 5990ecb741
(Compute implicit include directories from compiler output, 2018-12-07,
v3.14.0-rc1~108^2) leaves paths like `/usr/lib/../include` unchanged.
Fix the logic to canonicalize such paths (e.g. to `/usr/include`)
as we do for implicit link directories already.  This is important
to ensure the set of implicit directories is represented in the same
form as the include directories that will be compared to them.

Issue: #19095
2019-03-29 08:48:56 -04:00
Brad King
f709089d84 XLClang: Extract compiler implicit include directories 2019-02-25 08:24:28 -05:00
Chuck Cranor
ef8f237686 ParseImplicitIncludeInfo: add SunPro Fortran and PGI compiler, Cray fix
Add implicit include parser for PGI compiler ID.  PGI verbose output
for CXX differs from C and Fortran, so CXX is broken out into its own
case.  The C and Fortran compilers take "-YI,path" and "-Mnostdinc" to
change or disable the builtin include path.  The last arg on the command
line appears to override previous args (e.g. "-YI,path1 -YI,path2" will
set the path to "path2" ... the previous "-YI,path1" gets undone).
The CXX compiler verbose output reports with "-I" rather than "-stdinc"
for the built in path.  In addition with CXX "-Mnostdinc" does not
completely zero the include path (e.g. "#include <stdio.h>" still works
with "-Mnostdinc"... "-I/usr/include" still shows up in the verbose output).

Minor adjustments to get the SunPro parser to handle Fortran as well.

Fixes for Cray compiler support (Modules/Compiler/Cray-{C,CXX}.cmake):
The *_COMPILE_OPTION flags contain options like "-h c99,gnu" ...
these options need to be in double quotes (they are currently not).
Otherwise, cmake treats them as lists and tries to run the compiler
with "-h;c99,gnu" and fails when it is "Detecting C compile features"...
Also, the Cray-CXX.cmake contains "__compiler_cray(C)" instead of
"__compiler_cray(CXX)" -- this error prevents the correct VERBOSE
flags for CXX from being defined which prevents the implicit include
parser from running.

Add additional test cases for PGI and SunPro Fortran to the
Tests/RunCMake/ParseImplicitIncludeInfo area.
2019-01-29 07:48:03 -07:00
Chuck Cranor
2e91627dea ParseImplicitIncludeInfo: add Fortran implicit include handling
Currently cmake is only setting CMAKE_Fortran_IMPLICIT_INCLUDE_DIRECTORIES
the first time it runs (the implicit includes parser is only run when
the cache variables are initially populated).  It is left unset
during additional runs.  This behavior is both confusing and
inconsistent.

Modify CMakeFortranCompiler.cmake.in to preserve the value of
CMAKE_Fortran_IMPLICIT_INCLUDE_DIRECTORIES so that cmake's Fortran
behavior matches C and CXX (i.e. CMAKE_Fortran_IMPLICIT_INCLUDE_DIRECTORIES
retains its value across runs).  The implicit includes variable may
not be as useful for Fortran as it is for C and CXX, but we do want
cmake to be consistent in how it is handled.

Adjust CMakeParseImplicitIncludeInfo to parse verbose Fortran output
for Cray and XL compiler IDs (GNU and clang were already ok since
they use the same verbose output format as they do with C/CXX).

Allow Tests/RunCMake/ParseImplicitIncludeInfo/data/CMakeLists.txt
to generate test inputs for Fortran too, and add some sample Fortran
input files for the Tests/RunCMake/ParseImplicitIncludeInfo test.
2019-01-25 10:57:42 -07:00
Chuck Cranor
568343767e 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.
2019-01-25 07:48:00 -07:00
Chuck Cranor
5990ecb741 Compute implicit include directories from compiler output
- CMakeParseImplicitIncludeInfo.cmake: new parser that extracts the
   compiler's include path from verbose output.  If the parser cannot
   parse the output, we fall back to the old behavior.  On osx we skip
   over framework directories (handled elsewhere).

 - CMakeDetermineCompilerABI.cmake:
     - use verbose flag in try_compile for ${src}
     - use new cmake_parse_implicit_include_info() to attempt extract
       implicit include directory path and if successful set
        CMAKE_${LANG}_IMPLICIT_INCLUDE_DIRECTORIES

 - CMakeCCompiler.cmake.in and CMakeCXXCompiler.cmake.in - preserve
   CMAKE_${LANG}_IMPLICIT_INCLUDE_DIRECTORIES value between runs in
   the same way CMAKE_${LANG}_IMPLICIT_LINK_DIRECTORIES is preserved

 - Tests/RunCMake/ParseImplicitIncludeInfo: tests for parse
   based on the older Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in.
   The test runs a set of verbose compiler outputs collected from
   various machines through the parser and checks the results.  New
   compiler files can be added by dropping input/output files in the
   ParseImplicitIncludeInfo/data subdirectory and then adding the new set
   of files to the ${targets} list in ParseImplicitIncludeInfo.cmake.
   There is a helper CMakeLists.txt in ParseImplicitIncludeInfo/data
   that can help with the generation of test input files.
   NOTE: the standard cmake pre-commit hook rejects verbose compiler
   output with trailing spaces... you have to manually edit them out.
   This shouldn't impact the test.

Note that both the parser and the test code can use CMAKE_${LANG}_COMPILER_*
variables such as ${CMAKE_CXX_COMPILER_ID} to decide how to parse
verbose compiler output.  For the test code, this requires us to
save the variables values in the test input files.

Fixes: #16291
2019-01-21 11:14:08 -05:00