aboutsummaryrefslogtreecommitdiffstats
path: root/meson/test cases/common/13 pch
diff options
context:
space:
mode:
authorAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
committerAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
commitaf1a266670d040d2f4083ff309d732d648afba2a (patch)
tree2fc46203448ddcc6f81546d379abfaeb323575e9 /meson/test cases/common/13 pch
parente02cda008591317b1625707ff8e115a4841aa889 (diff)
Add submodule dependency filesHEADmaster
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'meson/test cases/common/13 pch')
-rw-r--r--meson/test cases/common/13 pch/c/meson.build14
-rw-r--r--meson/test cases/common/13 pch/c/pch/prog.h6
-rw-r--r--meson/test cases/common/13 pch/c/prog.c10
-rw-r--r--meson/test cases/common/13 pch/cpp/meson.build1
-rw-r--r--meson/test cases/common/13 pch/cpp/pch/prog.hh1
-rw-r--r--meson/test cases/common/13 pch/cpp/prog.cc11
-rw-r--r--meson/test cases/common/13 pch/generated/gen_custom.py5
-rw-r--r--meson/test cases/common/13 pch/generated/gen_generator.py7
-rw-r--r--meson/test cases/common/13 pch/generated/generated_generator.in1
-rw-r--r--meson/test cases/common/13 pch/generated/meson.build22
-rw-r--r--meson/test cases/common/13 pch/generated/pch/prog.h2
-rw-r--r--meson/test cases/common/13 pch/generated/prog.c6
-rw-r--r--meson/test cases/common/13 pch/meson.build22
-rw-r--r--meson/test cases/common/13 pch/mixed/func.c7
-rw-r--r--meson/test cases/common/13 pch/mixed/main.cc10
-rw-r--r--meson/test cases/common/13 pch/mixed/meson.build14
-rw-r--r--meson/test cases/common/13 pch/mixed/pch/func.h1
-rw-r--r--meson/test cases/common/13 pch/mixed/pch/main.h1
-rw-r--r--meson/test cases/common/13 pch/userDefined/meson.build10
-rw-r--r--meson/test cases/common/13 pch/userDefined/pch/pch.c5
-rw-r--r--meson/test cases/common/13 pch/userDefined/pch/pch.h1
-rw-r--r--meson/test cases/common/13 pch/userDefined/prog.c8
-rw-r--r--meson/test cases/common/13 pch/withIncludeDirectories/include/lib/lib.h1
-rw-r--r--meson/test cases/common/13 pch/withIncludeDirectories/meson.build15
-rw-r--r--meson/test cases/common/13 pch/withIncludeDirectories/pch/prog.h1
-rw-r--r--meson/test cases/common/13 pch/withIncludeDirectories/prog.c10
-rw-r--r--meson/test cases/common/13 pch/withIncludeFile/meson.build18
-rw-r--r--meson/test cases/common/13 pch/withIncludeFile/pch/prog.h6
-rw-r--r--meson/test cases/common/13 pch/withIncludeFile/prog.c11
29 files changed, 227 insertions, 0 deletions
diff --git a/meson/test cases/common/13 pch/c/meson.build b/meson/test cases/common/13 pch/c/meson.build
new file mode 100644
index 000000000..6fba15bf4
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/c/pch/prog.h b/meson/test cases/common/13 pch/c/pch/prog.h
new file mode 100644
index 000000000..c89890a77
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/c/prog.c b/meson/test cases/common/13 pch/c/prog.c
new file mode 100644
index 000000000..124bba063
--- /dev/null
+++ b/meson/test cases/common/13 pch/c/prog.c
@@ -0,0 +1,10 @@
+// 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/meson/test cases/common/13 pch/cpp/meson.build b/meson/test cases/common/13 pch/cpp/meson.build
new file mode 100644
index 000000000..b01cd58f3
--- /dev/null
+++ b/meson/test cases/common/13 pch/cpp/meson.build
@@ -0,0 +1 @@
+exe = executable('prog', 'prog.cc', cpp_pch : 'pch/prog.hh')
diff --git a/meson/test cases/common/13 pch/cpp/pch/prog.hh b/meson/test cases/common/13 pch/cpp/pch/prog.hh
new file mode 100644
index 000000000..751cc4a71
--- /dev/null
+++ b/meson/test cases/common/13 pch/cpp/pch/prog.hh
@@ -0,0 +1 @@
+#include<iostream>
diff --git a/meson/test cases/common/13 pch/cpp/prog.cc b/meson/test cases/common/13 pch/cpp/prog.cc
new file mode 100644
index 000000000..0ba8519dc
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/generated/gen_custom.py b/meson/test cases/common/13 pch/generated/gen_custom.py
new file mode 100644
index 000000000..650e03c2b
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/generated/gen_generator.py b/meson/test cases/common/13 pch/generated/gen_generator.py
new file mode 100644
index 000000000..a245e7aef
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/generated/generated_generator.in b/meson/test cases/common/13 pch/generated/generated_generator.in
new file mode 100644
index 000000000..1a00ebd21
--- /dev/null
+++ b/meson/test cases/common/13 pch/generated/generated_generator.in
@@ -0,0 +1 @@
+#define BAR 0
diff --git a/meson/test cases/common/13 pch/generated/meson.build b/meson/test cases/common/13 pch/generated/meson.build
new file mode 100644
index 000000000..ba06bcea8
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/generated/pch/prog.h b/meson/test cases/common/13 pch/generated/pch/prog.h
new file mode 100644
index 000000000..15fec38ce
--- /dev/null
+++ b/meson/test cases/common/13 pch/generated/pch/prog.h
@@ -0,0 +1,2 @@
+#include "generated_customTarget.h"
+#include "generated_generator.h"
diff --git a/meson/test cases/common/13 pch/generated/prog.c b/meson/test cases/common/13 pch/generated/prog.c
new file mode 100644
index 000000000..6765ac102
--- /dev/null
+++ b/meson/test cases/common/13 pch/generated/prog.c
@@ -0,0 +1,6 @@
+// No includes here, they need to come from the PCH
+
+int main(void) {
+ return FOO + BAR;
+}
+
diff --git a/meson/test cases/common/13 pch/meson.build b/meson/test cases/common/13 pch/meson.build
new file mode 100644
index 000000000..5ca9ab1d8
--- /dev/null
+++ b/meson/test cases/common/13 pch/meson.build
@@ -0,0 +1,22 @@
+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
diff --git a/meson/test cases/common/13 pch/mixed/func.c b/meson/test cases/common/13 pch/mixed/func.c
new file mode 100644
index 000000000..620eca133
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/mixed/main.cc b/meson/test cases/common/13 pch/mixed/main.cc
new file mode 100644
index 000000000..432120329
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/mixed/meson.build b/meson/test cases/common/13 pch/mixed/meson.build
new file mode 100644
index 000000000..266e7a575
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/mixed/pch/func.h b/meson/test cases/common/13 pch/mixed/pch/func.h
new file mode 100644
index 000000000..354499acd
--- /dev/null
+++ b/meson/test cases/common/13 pch/mixed/pch/func.h
@@ -0,0 +1 @@
+#include<stdio.h>
diff --git a/meson/test cases/common/13 pch/mixed/pch/main.h b/meson/test cases/common/13 pch/mixed/pch/main.h
new file mode 100644
index 000000000..751cc4a71
--- /dev/null
+++ b/meson/test cases/common/13 pch/mixed/pch/main.h
@@ -0,0 +1 @@
+#include<iostream>
diff --git a/meson/test cases/common/13 pch/userDefined/meson.build b/meson/test cases/common/13 pch/userDefined/meson.build
new file mode 100644
index 000000000..9b60572e6
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/userDefined/pch/pch.c b/meson/test cases/common/13 pch/userDefined/pch/pch.c
new file mode 100644
index 000000000..6a971404d
--- /dev/null
+++ b/meson/test cases/common/13 pch/userDefined/pch/pch.c
@@ -0,0 +1,5 @@
+#include "pch.h"
+
+int foo(void) {
+ return 0;
+}
diff --git a/meson/test cases/common/13 pch/userDefined/pch/pch.h b/meson/test cases/common/13 pch/userDefined/pch/pch.h
new file mode 100644
index 000000000..5d5f8f0c9
--- /dev/null
+++ b/meson/test cases/common/13 pch/userDefined/pch/pch.h
@@ -0,0 +1 @@
+int foo();
diff --git a/meson/test cases/common/13 pch/userDefined/prog.c b/meson/test cases/common/13 pch/userDefined/prog.c
new file mode 100644
index 000000000..475131b35
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/withIncludeDirectories/include/lib/lib.h b/meson/test cases/common/13 pch/withIncludeDirectories/include/lib/lib.h
new file mode 100644
index 000000000..53c5fdf17
--- /dev/null
+++ b/meson/test cases/common/13 pch/withIncludeDirectories/include/lib/lib.h
@@ -0,0 +1 @@
+#include <stdio.h>
diff --git a/meson/test cases/common/13 pch/withIncludeDirectories/meson.build b/meson/test cases/common/13 pch/withIncludeDirectories/meson.build
new file mode 100644
index 000000000..95f7888d9
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/withIncludeDirectories/pch/prog.h b/meson/test cases/common/13 pch/withIncludeDirectories/pch/prog.h
new file mode 100644
index 000000000..383b2c513
--- /dev/null
+++ b/meson/test cases/common/13 pch/withIncludeDirectories/pch/prog.h
@@ -0,0 +1 @@
+#include<lib/lib.h>
diff --git a/meson/test cases/common/13 pch/withIncludeDirectories/prog.c b/meson/test cases/common/13 pch/withIncludeDirectories/prog.c
new file mode 100644
index 000000000..124bba063
--- /dev/null
+++ b/meson/test cases/common/13 pch/withIncludeDirectories/prog.c
@@ -0,0 +1,10 @@
+// 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/meson/test cases/common/13 pch/withIncludeFile/meson.build b/meson/test cases/common/13 pch/withIncludeFile/meson.build
new file mode 100644
index 000000000..4fd232251
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/withIncludeFile/pch/prog.h b/meson/test cases/common/13 pch/withIncludeFile/pch/prog.h
new file mode 100644
index 000000000..c89890a77
--- /dev/null
+++ b/meson/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/meson/test cases/common/13 pch/withIncludeFile/prog.c b/meson/test cases/common/13 pch/withIncludeFile/prog.c
new file mode 100644
index 000000000..7a9a93c6a
--- /dev/null
+++ b/meson/test cases/common/13 pch/withIncludeFile/prog.c
@@ -0,0 +1,11 @@
+// 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;
+}
+