Skip to content

Commit

Permalink
PGI: cpp_pch precompiled headers functionality
Browse files Browse the repository at this point in the history
* PGI C++ PCH enable

PGI compilers support precompiled headers for C++ only.
The common/13 pch test passes if run manually with no spaces in the build path.
However, since Meson run_project_tests.py makes temporary build directories
with spaces in each tests, PGI --pch_dir can't handle this and fails.
So we skip the test for PGI despite it working for usual case with no-spaces
in build dir.
Note: it's fine to have spaces in full path for sourcedir, just no spaces in
relative path to builddir.

* doc
  • Loading branch information
scivision authored and jpakkane committed Jul 30, 2019
1 parent 9865870 commit 1e53f67
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 3 deletions.
1 change: 0 additions & 1 deletion mesonbuild/compilers/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice,
CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
PGICompiler.__init__(self, compiler_type)


class ElbrusCPPCompiler(GnuCPPCompiler, ElbrusCompiler):
def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs):
GnuCPPCompiler.__init__(self, exelist, version, compiler_type, for_machine, is_cross, exe_wrapper, defines, **kwargs)
Expand Down
18 changes: 17 additions & 1 deletion mesonbuild/compilers/mixins/pgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import typing
import os
from pathlib import Path

from ..compilers import clike_debug_args, clike_optimization_args

Expand All @@ -42,8 +43,9 @@
} # type: typing.Dict[str, typing.List[str]]


class PGICompiler:
class PGICompiler():
def __init__(self, compiler_type: 'CompilerType'):
self.base_options = ['b_pch']
self.id = 'pgi'
self.compiler_type = compiler_type

Expand Down Expand Up @@ -93,3 +95,17 @@ def get_dependency_gen_args(self, outtarget: str, outfile: str) -> typing.List[s

def get_always_args(self) -> typing.List[str]:
return []

def get_pch_suffix(self) -> str:
# PGI defaults to .pch suffix for PCH on Linux and Windows with --pch option
return 'pch'

def get_pch_use_args(self, pch_dir: str, header: str) -> typing.List[str]:
# PGI supports PCH for C++ only.
hdr = Path(pch_dir).resolve().parent / header
if self.language == 'cpp':
return ['--pch',
'--pch_dir', str(hdr.parent),
'-I{}'.format(hdr.parent)]
else:
return []
6 changes: 6 additions & 0 deletions test cases/common/13 pch/c/meson.build
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
cc = meson.get_compiler('c')
cc_id = cc.get_id()

if cc_id == 'lcc'
error('MESON_SKIP_TEST: Elbrus compiler does not support PCH.')
endif

# PGI compiler only supports PCH for C++
if cc_id == 'pgi'
subdir_done()
endif

exe = executable('prog', 'prog.c',
c_pch : 'pch/prog.h')
3 changes: 3 additions & 0 deletions test cases/common/13 pch/cpp/prog.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Note: if using PGI compilers, you will need to add #include "prog.hh"
// even though you're using precompiled headers.
void func() {
std::cout << "This is a function that fails to compile if iostream is not included."
<< std::endl;
}

int main(int argc, char **argv) {
func();
return 0;
}
6 changes: 6 additions & 0 deletions test cases/common/13 pch/generated/meson.build
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
cc = meson.get_compiler('c')
cc_id = cc.get_id()

if cc_id == 'lcc'
error('MESON_SKIP_TEST: Elbrus compiler does not support PCH.')
endif

# PGI compiler only supports PCH for C++
if cc_id == 'pgi'
subdir_done()
endif

generated_customTarget = custom_target('makeheader',
output: 'generated_customTarget.h',
command : [find_program('gen_custom.py'), '@OUTPUT0@'])
Expand Down
10 changes: 9 additions & 1 deletion test cases/common/13 pch/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
project('pch test', 'c', 'cpp')
project('pch test', 'c', 'cpp',
meson_version: '>= 0.46.0')

cc = meson.get_compiler('c')
cc_id = cc.get_id()

if cc_id == 'pgi'
error('MESON_SKIP_TEST: PGI compiler does support PCH, however, PGI cannot tolerate spaces in the --pch_dir path and Meson run_project_tests.py uses spaces in temporary build path names. If this test is run individually with no spaces in build path, it will pass.')
endif

subdir('c')
subdir('cpp')
Expand Down
8 changes: 8 additions & 0 deletions test cases/common/13 pch/mixed/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
cc = meson.get_compiler('c')
cc_id = cc.get_id()

# PGI compiler only supports PCH for C++
if cc_id == 'pgi'
subdir_done()
endif

exe = executable(
'prog',
files('main.cc', 'func.c'),
Expand Down
6 changes: 6 additions & 0 deletions test cases/common/13 pch/withIncludeDirectories/meson.build
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
cc = meson.get_compiler('c')
cc_id = cc.get_id()

if cc_id == 'lcc'
error('MESON_SKIP_TEST: Elbrus compiler does not support PCH.')
endif

# PGI compiler only supports PCH for C++
if cc_id == 'pgi'
subdir_done()
endif

exe = executable('prog', 'prog.c',
include_directories: 'include',
c_pch : 'pch/prog.h')

0 comments on commit 1e53f67

Please sign in to comment.