Repository: spack/spack

Issue:
Installation issue: qt@5.12.4
### Steps to reproduce the issue

```console
$ spack -d install -j1 qt@5.12.4 ^font-util fonts=encodings
/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/include/c++/8.3.0/cmath:45:15: fatal error: math.h: No such file or directory
```
(the `fonts=` specification is due to #12547).

### Platform and user environment

Please report your OS here:
```commandline
$ uname -a 
Linux 453207a49b28 3.10.0-1062.4.3.el7.x86_64 #1 SMP Wed Nov 13 23:58:53 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -d
Description:    CentOS Linux release 7.7.1908 (Core) 
``` 
compilers.yaml and packages.yaml: https://gist.github.com/iarspider/7a9a7685e9c93fb214b608bb85bf9f19

The issue is triggered by taking packages (in my case - `libjpeg` and `openssl`) from system. This adds `-I /usr/include` to the list of flags passed to `gcc`. But Qt automatically adds `-isystem /usr/include`. As far as I can tell after long googling, this messes up order of include dirs and, as a result, `#include_next` preprocessor instruction.

### Additional information

[spack-build-out.txt](https://github.com/spack/spack/files/3960932/spack-build-out.txt)
[spack-cc-qt-jqmsy5g.in.log](https://github.com/spack/spack/files/3960933/spack-cc-qt-jqmsy5g.in.log)
[spack-cc-qt-jqmsy5g.out.log](https://github.com/spack/spack/files/3960934/spack-cc-qt-jqmsy5g.out.log)



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/qt/package.py b/var/spack/repos/builtin/packages/qt/package.py
--- a/var/spack/repos/builtin/packages/qt/package.py
+++ b/var/spack/repos/builtin/packages/qt/package.py
@@ -323,8 +323,8 @@ def common_config_args(self):
             '-release',
             '-confirm-license',
             '-openssl-linked',
-            '{0}'.format(openssl.libs.search_flags),
-            '{0}'.format(openssl.headers.include_flags),
+            openssl.libs.search_flags,
+            openssl.headers.include_flags,
             '-optimized-qmake',
             '-no-pch',
         ]
@@ -351,7 +351,7 @@ def common_config_args(self):
             sqlite = self.spec['sqlite']
             config_args.extend([
                 '-system-sqlite',
-                '-R', '{0}'.format(sqlite.prefix.lib),
+                '-R', sqlite.prefix.lib,
             ])
         else:
             comps = ['db2', 'ibase', 'oci', 'tds', 'mysql', 'odbc', 'psql',
@@ -369,19 +369,19 @@ def common_config_args(self):
             harfbuzz = self.spec['harfbuzz']
             config_args.extend([
                 '-system-harfbuzz',
-                '{0}'.format(harfbuzz.libs.search_flags),
-                '{0}'.format(harfbuzz.headers.include_flags),
+                harfbuzz.libs.search_flags,
+                harfbuzz.headers.include_flags,
                 '-system-pcre',
-                '{0}'.format(pcre.libs.search_flags),
-                '{0}'.format(pcre.headers.include_flags)
+                pcre.libs.search_flags,
+                pcre.headers.include_flags
             ])
 
         if self.spec.satisfies('@5.7:'):
             dc = self.spec['double-conversion']
             config_args.extend([
                 '-system-doubleconversion',
-                '{0}'.format(dc.libs.search_flags),
-                '{0}'.format(dc.headers.include_flags)
+                dc.libs.search_flags,
+                dc.headers.include_flags
             ])
 
         if '@:5.7.1' in self.spec:
@@ -389,19 +389,27 @@ def common_config_args(self):
         else:
             # FIXME: those could work for other versions
             png = self.spec['libpng']
+            config_args.append('-system-libpng')
+            if not png.external:
+                config_args.extend([
+                    png.libs.search_flags,
+                    png.headers.include_flags
+                ])
+
             jpeg = self.spec['jpeg']
+            config_args.append('-system-libjpeg')
+            if not jpeg.external:
+                config_args.extend([
+                    jpeg.libs.search_flags,
+                    jpeg.headers.include_flags,
+                ])
             zlib = self.spec['zlib']
-            config_args.extend([
-                '-system-libpng',
-                '{0}'.format(png.libs.search_flags),
-                '{0}'.format(png.headers.include_flags),
-                '-system-libjpeg',
-                '{0}'.format(jpeg.libs.search_flags),
-                '{0}'.format(jpeg.headers.include_flags),
-                '-system-zlib',
-                '{0}'.format(zlib.libs.search_flags),
-                '{0}'.format(zlib.headers.include_flags)
-            ])
+            config_args.append('-system-zlib')
+            if not zlib.external:
+                config_args.extend([
+                    zlib.libs.search_flags,
+                    zlib.headers.include_flags
+                ])
 
         if '@:5.7.0' in self.spec:
             config_args.extend([


Test patch: