diff options
Diffstat (limited to 'test cases/common/13 pch')
35 files changed, 262 insertions, 0 deletions
diff --git a/test cases/common/13 pch/c/meson.build b/test cases/common/13 pch/c/meson.build new file mode 100644 index 0000000..6fba15b --- /dev/null +++ b/test cases/common/13 pch/c/meson.build @@ -0,0 +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') diff --git a/test cases/common/13 pch/c/pch/prog.h b/test cases/common/13 pch/c/pch/prog.h new file mode 100644 index 0000000..c89890a --- /dev/null +++ b/test cases/common/13 pch/c/pch/prog.h @@ -0,0 +1,6 @@ +#ifndef PROG_H +// Header guards for PCH confuse msvc in some situations. +// Using them here makes sure we handle this correctly. +#define PROG_H +#include<stdio.h> +#endif diff --git a/test cases/common/13 pch/c/prog.c b/test cases/common/13 pch/c/prog.c new file mode 100644 index 0000000..4ef2fd8 --- /dev/null +++ b/test cases/common/13 pch/c/prog.c @@ -0,0 +1,9 @@ +// No includes here, they need to come from the PCH + +void func(void) { + fprintf(stdout, "This is a function that fails if stdio is not #included.\n"); +} + +int main(void) { + return 0; +} diff --git a/test cases/common/13 pch/cpp/meson.build b/test cases/common/13 pch/cpp/meson.build new file mode 100644 index 0000000..b01cd58 --- /dev/null +++ b/test cases/common/13 pch/cpp/meson.build @@ -0,0 +1 @@ +exe = executable('prog', 'prog.cc', cpp_pch : 'pch/prog.hh') diff --git a/test cases/common/13 pch/cpp/pch/prog.hh b/test cases/common/13 pch/cpp/pch/prog.hh new file mode 100644 index 0000000..751cc4a --- /dev/null +++ b/test cases/common/13 pch/cpp/pch/prog.hh @@ -0,0 +1 @@ +#include<iostream> diff --git a/test cases/common/13 pch/cpp/prog.cc b/test cases/common/13 pch/cpp/prog.cc new file mode 100644 index 0000000..0ba8519 --- /dev/null +++ b/test cases/common/13 pch/cpp/prog.cc @@ -0,0 +1,11 @@ +// Note: if using PGI compilers, you will need to add #include "prog.hh" +// even though you're using precompiled headers. +void func(void) { + std::cout << "This is a function that fails to compile if iostream is not included." + << std::endl; +} + +int main(void) { + func(); + return 0; +} diff --git a/test cases/common/13 pch/generated/gen_custom.py b/test cases/common/13 pch/generated/gen_custom.py new file mode 100644 index 0000000..650e03c --- /dev/null +++ b/test cases/common/13 pch/generated/gen_custom.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +import sys + +with open(sys.argv[1], 'w') as f: + f.write("#define FOO 0") diff --git a/test cases/common/13 pch/generated/gen_generator.py b/test cases/common/13 pch/generated/gen_generator.py new file mode 100644 index 0000000..a245e7a --- /dev/null +++ b/test cases/common/13 pch/generated/gen_generator.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +import sys + +with open(sys.argv[1]) as f: + content = f.read() +with open(sys.argv[2], 'w') as f: + f.write(content) diff --git a/test cases/common/13 pch/generated/generated_generator.in b/test cases/common/13 pch/generated/generated_generator.in new file mode 100644 index 0000000..1a00ebd --- /dev/null +++ b/test cases/common/13 pch/generated/generated_generator.in @@ -0,0 +1 @@ +#define BAR 0 diff --git a/test cases/common/13 pch/generated/meson.build b/test cases/common/13 pch/generated/meson.build new file mode 100644 index 0000000..ba06bce --- /dev/null +++ b/test cases/common/13 pch/generated/meson.build @@ -0,0 +1,22 @@ +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@']) + +generated_generator = generator(find_program('gen_generator.py'), + output: '@BASENAME@.h', + arguments: ['@INPUT@', '@OUTPUT@']) + +exe = executable('prog', 'prog.c', generated_customTarget, generated_generator.process('generated_generator.in'), + c_pch: 'pch/prog.h') diff --git a/test cases/common/13 pch/generated/pch/prog.h b/test cases/common/13 pch/generated/pch/prog.h new file mode 100644 index 0000000..15fec38 --- /dev/null +++ b/test cases/common/13 pch/generated/pch/prog.h @@ -0,0 +1,2 @@ +#include "generated_customTarget.h" +#include "generated_generator.h" diff --git a/test cases/common/13 pch/generated/prog.c b/test cases/common/13 pch/generated/prog.c new file mode 100644 index 0000000..a75c2d2 --- /dev/null +++ b/test cases/common/13 pch/generated/prog.c @@ -0,0 +1,5 @@ +// No includes here, they need to come from the PCH + +int main(void) { + return FOO + BAR; +} diff --git a/test cases/common/13 pch/linkwhole/lib1.c b/test cases/common/13 pch/linkwhole/lib1.c new file mode 100644 index 0000000..b56c17b --- /dev/null +++ b/test cases/common/13 pch/linkwhole/lib1.c @@ -0,0 +1,4 @@ +void func1() { + printf("Calling func2."); + func2(); +} diff --git a/test cases/common/13 pch/linkwhole/lib2.c b/test cases/common/13 pch/linkwhole/lib2.c new file mode 100644 index 0000000..0a13f60 --- /dev/null +++ b/test cases/common/13 pch/linkwhole/lib2.c @@ -0,0 +1,6 @@ +#include<stdio.h> + +void func2() { + const char *cl = GetCommandLineA(); + printf("Command line was: %s\n", cl); +} diff --git a/test cases/common/13 pch/linkwhole/main.c b/test cases/common/13 pch/linkwhole/main.c new file mode 100644 index 0000000..6615a8b --- /dev/null +++ b/test cases/common/13 pch/linkwhole/main.c @@ -0,0 +1,9 @@ +#include<stdio.h> + +void func1(); + +int main(int argc, char **argv) { + printf("Calling func1\n"); + func1(); + return 0; +} diff --git a/test cases/common/13 pch/linkwhole/meson.build b/test cases/common/13 pch/linkwhole/meson.build new file mode 100644 index 0000000..dec76ba --- /dev/null +++ b/test cases/common/13 pch/linkwhole/meson.build @@ -0,0 +1,8 @@ +# https://github.com/mesonbuild/meson/issues/10745 + +l2 = static_library('two', 'lib2.c', c_pch: 'pch2/pch_two.h') +l1 = static_library('one', 'lib1.c', c_pch: 'pch1/pch_one.h', + link_whole: l2) + +executable('linkprog', 'main.c', + link_with: l1) diff --git a/test cases/common/13 pch/linkwhole/pch1/pch_one.h b/test cases/common/13 pch/linkwhole/pch1/pch_one.h new file mode 100644 index 0000000..757c206 --- /dev/null +++ b/test cases/common/13 pch/linkwhole/pch1/pch_one.h @@ -0,0 +1,4 @@ +#ifndef PCH_ONE +#define PCH_ONE +#include<stdio.h> +#endif diff --git a/test cases/common/13 pch/linkwhole/pch2/pch_two.h b/test cases/common/13 pch/linkwhole/pch2/pch_two.h new file mode 100644 index 0000000..1be0a20 --- /dev/null +++ b/test cases/common/13 pch/linkwhole/pch2/pch_two.h @@ -0,0 +1,4 @@ +#ifndef PCH_TWO +#define PCH_TWO +#include<windows.h> +#endif diff --git a/test cases/common/13 pch/meson.build b/test cases/common/13 pch/meson.build new file mode 100644 index 0000000..4bb3e1f --- /dev/null +++ b/test cases/common/13 pch/meson.build @@ -0,0 +1,26 @@ +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') +subdir('generated') +subdir('userDefined') +subdir('withIncludeDirectories') +subdir('withIncludeFile') + +if meson.backend() == 'xcode' + warning('Xcode backend only supports one precompiled header per target. Skipping "mixed" which has various precompiled headers.') +else + subdir('mixed') +endif + +if cc_id == 'msvc' + subdir('linkwhole') +endif diff --git a/test cases/common/13 pch/mixed/func.c b/test cases/common/13 pch/mixed/func.c new file mode 100644 index 0000000..620eca1 --- /dev/null +++ b/test cases/common/13 pch/mixed/func.c @@ -0,0 +1,7 @@ +void tmp_func(void) { + fprintf(stdout, "This is a function that fails if stdio is not #included.\n"); +} + +int cfunc(void) { + return 0; +} diff --git a/test cases/common/13 pch/mixed/main.cc b/test cases/common/13 pch/mixed/main.cc new file mode 100644 index 0000000..4321203 --- /dev/null +++ b/test cases/common/13 pch/mixed/main.cc @@ -0,0 +1,10 @@ +extern "C" int cfunc(); + +void func(void) { + std::cout << "This is a function that fails to compile if iostream is not included." + << std::endl; +} + +int main(void) { + return cfunc(); +} diff --git a/test cases/common/13 pch/mixed/meson.build b/test cases/common/13 pch/mixed/meson.build new file mode 100644 index 0000000..266e7a5 --- /dev/null +++ b/test cases/common/13 pch/mixed/meson.build @@ -0,0 +1,14 @@ +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'), + c_pch : ['pch/func.h'], + cpp_pch : ['pch/main.h'], +) diff --git a/test cases/common/13 pch/mixed/pch/func.h b/test cases/common/13 pch/mixed/pch/func.h new file mode 100644 index 0000000..354499a --- /dev/null +++ b/test cases/common/13 pch/mixed/pch/func.h @@ -0,0 +1 @@ +#include<stdio.h> diff --git a/test cases/common/13 pch/mixed/pch/main.h b/test cases/common/13 pch/mixed/pch/main.h new file mode 100644 index 0000000..751cc4a --- /dev/null +++ b/test cases/common/13 pch/mixed/pch/main.h @@ -0,0 +1 @@ +#include<iostream> diff --git a/test cases/common/13 pch/userDefined/meson.build b/test cases/common/13 pch/userDefined/meson.build new file mode 100644 index 0000000..9b60572 --- /dev/null +++ b/test cases/common/13 pch/userDefined/meson.build @@ -0,0 +1,10 @@ +cc = meson.get_compiler('c') +cc_id = cc.get_id() + +# User supplied PCH implementation should override the auto +# generated one. PCH implementations are only supported for +# msvc and generally should not be used at all. Support for +# them is only kept for backwards compatibility. +if cc_id == 'msvc' + exe = executable('prog', 'prog.c', c_pch : ['pch/pch.h', 'pch/pch.c']) +endif diff --git a/test cases/common/13 pch/userDefined/pch/pch.c b/test cases/common/13 pch/userDefined/pch/pch.c new file mode 100644 index 0000000..6a97140 --- /dev/null +++ b/test cases/common/13 pch/userDefined/pch/pch.c @@ -0,0 +1,5 @@ +#include "pch.h" + +int foo(void) { + return 0; +} diff --git a/test cases/common/13 pch/userDefined/pch/pch.h b/test cases/common/13 pch/userDefined/pch/pch.h new file mode 100644 index 0000000..5d5f8f0 --- /dev/null +++ b/test cases/common/13 pch/userDefined/pch/pch.h @@ -0,0 +1 @@ +int foo(); diff --git a/test cases/common/13 pch/userDefined/prog.c b/test cases/common/13 pch/userDefined/prog.c new file mode 100644 index 0000000..475131b --- /dev/null +++ b/test cases/common/13 pch/userDefined/prog.c @@ -0,0 +1,8 @@ +// No includes here, they need to come from the PCH + +int main(void) { + // Method is implemented in pch.c. + // This makes sure that we can properly handle user defined + // pch implementation files and not only auto-generated ones. + return foo(); +} diff --git a/test cases/common/13 pch/withIncludeDirectories/include/lib/lib.h b/test cases/common/13 pch/withIncludeDirectories/include/lib/lib.h new file mode 100644 index 0000000..53c5fdf --- /dev/null +++ b/test cases/common/13 pch/withIncludeDirectories/include/lib/lib.h @@ -0,0 +1 @@ +#include <stdio.h> diff --git a/test cases/common/13 pch/withIncludeDirectories/meson.build b/test cases/common/13 pch/withIncludeDirectories/meson.build new file mode 100644 index 0000000..95f7888 --- /dev/null +++ b/test cases/common/13 pch/withIncludeDirectories/meson.build @@ -0,0 +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') diff --git a/test cases/common/13 pch/withIncludeDirectories/pch/prog.h b/test cases/common/13 pch/withIncludeDirectories/pch/prog.h new file mode 100644 index 0000000..383b2c5 --- /dev/null +++ b/test cases/common/13 pch/withIncludeDirectories/pch/prog.h @@ -0,0 +1 @@ +#include<lib/lib.h> diff --git a/test cases/common/13 pch/withIncludeDirectories/prog.c b/test cases/common/13 pch/withIncludeDirectories/prog.c new file mode 100644 index 0000000..4ef2fd8 --- /dev/null +++ b/test cases/common/13 pch/withIncludeDirectories/prog.c @@ -0,0 +1,9 @@ +// No includes here, they need to come from the PCH + +void func(void) { + fprintf(stdout, "This is a function that fails if stdio is not #included.\n"); +} + +int main(void) { + return 0; +} diff --git a/test cases/common/13 pch/withIncludeFile/meson.build b/test cases/common/13 pch/withIncludeFile/meson.build new file mode 100644 index 0000000..4fd2322 --- /dev/null +++ b/test cases/common/13 pch/withIncludeFile/meson.build @@ -0,0 +1,18 @@ +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 + +if cc.get_argument_syntax() == 'gcc' + c_args = ['-include', 'locale.h'] +elif cc.get_argument_syntax() == 'msvc' + c_args = ['/FI' + 'locale.h'] +else + subdir_done() +endif + +exe = executable('prog', 'prog.c', +c_args: c_args, +c_pch : 'pch/prog.h') diff --git a/test cases/common/13 pch/withIncludeFile/pch/prog.h b/test cases/common/13 pch/withIncludeFile/pch/prog.h new file mode 100644 index 0000000..c89890a --- /dev/null +++ b/test cases/common/13 pch/withIncludeFile/pch/prog.h @@ -0,0 +1,6 @@ +#ifndef PROG_H +// Header guards for PCH confuse msvc in some situations. +// Using them here makes sure we handle this correctly. +#define PROG_H +#include<stdio.h> +#endif diff --git a/test cases/common/13 pch/withIncludeFile/prog.c b/test cases/common/13 pch/withIncludeFile/prog.c new file mode 100644 index 0000000..9d495f6 --- /dev/null +++ b/test cases/common/13 pch/withIncludeFile/prog.c @@ -0,0 +1,10 @@ +// No includes here, they need to come from the PCH or explicit inclusion + +void func(void) { + fprintf(stdout, "This is a function that fails if stdio is not #included.\n"); + setlocale(LC_ALL, ""); /* This will fail if locale.h is not included */ +} + +int main(void) { + return 0; +} |