aboutsummaryrefslogtreecommitdiffstats
path: root/meson/test cases/common/130 include order
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/130 include order
parente02cda008591317b1625707ff8e115a4841aa889 (diff)
Add submodule dependency filesHEADmaster
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'meson/test cases/common/130 include order')
-rw-r--r--meson/test cases/common/130 include order/ctsub/copyfile.py6
-rw-r--r--meson/test cases/common/130 include order/ctsub/emptyfile.c0
-rw-r--r--meson/test cases/common/130 include order/ctsub/main.h1
-rw-r--r--meson/test cases/common/130 include order/ctsub/meson.build9
-rw-r--r--meson/test cases/common/130 include order/inc1/hdr.h1
-rw-r--r--meson/test cases/common/130 include order/inc2/hdr.h1
-rw-r--r--meson/test cases/common/130 include order/meson.build36
-rw-r--r--meson/test cases/common/130 include order/ordertest.c10
-rw-r--r--meson/test cases/common/130 include order/sub1/main.h1
-rw-r--r--meson/test cases/common/130 include order/sub1/meson.build4
-rw-r--r--meson/test cases/common/130 include order/sub1/some.c6
-rw-r--r--meson/test cases/common/130 include order/sub1/some.h10
-rw-r--r--meson/test cases/common/130 include order/sub2/main.h1
-rw-r--r--meson/test cases/common/130 include order/sub2/meson.build2
-rw-r--r--meson/test cases/common/130 include order/sub3/main.h1
-rw-r--r--meson/test cases/common/130 include order/sub3/meson.build1
-rw-r--r--meson/test cases/common/130 include order/sub4/main.c8
-rw-r--r--meson/test cases/common/130 include order/sub4/main.h3
-rw-r--r--meson/test cases/common/130 include order/sub4/meson.build6
19 files changed, 107 insertions, 0 deletions
diff --git a/meson/test cases/common/130 include order/ctsub/copyfile.py b/meson/test cases/common/130 include order/ctsub/copyfile.py
new file mode 100644
index 000000000..ff42ac359
--- /dev/null
+++ b/meson/test cases/common/130 include order/ctsub/copyfile.py
@@ -0,0 +1,6 @@
+#!/usr/bin/env python3
+
+import sys
+import shutil
+
+shutil.copyfile(sys.argv[1], sys.argv[2])
diff --git a/meson/test cases/common/130 include order/ctsub/emptyfile.c b/meson/test cases/common/130 include order/ctsub/emptyfile.c
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/meson/test cases/common/130 include order/ctsub/emptyfile.c
diff --git a/meson/test cases/common/130 include order/ctsub/main.h b/meson/test cases/common/130 include order/ctsub/main.h
new file mode 100644
index 000000000..9d9acf36f
--- /dev/null
+++ b/meson/test cases/common/130 include order/ctsub/main.h
@@ -0,0 +1 @@
+#error "ctsub/main.h included"
diff --git a/meson/test cases/common/130 include order/ctsub/meson.build b/meson/test cases/common/130 include order/ctsub/meson.build
new file mode 100644
index 000000000..a242e0764
--- /dev/null
+++ b/meson/test cases/common/130 include order/ctsub/meson.build
@@ -0,0 +1,9 @@
+# https://github.com/mesonbuild/meson/pull/2291
+copy = find_program('copyfile.py')
+configure_file(input : 'main.h',
+ output : 'main.h',
+ command : [copy, '@INPUT@', '@OUTPUT@'])
+ctfile = custom_target('emptyfile',
+ input : 'emptyfile.c',
+ output : 'emptyfile.c',
+ command : [copy, '@INPUT@', '@OUTPUT@'])
diff --git a/meson/test cases/common/130 include order/inc1/hdr.h b/meson/test cases/common/130 include order/inc1/hdr.h
new file mode 100644
index 000000000..9d755a830
--- /dev/null
+++ b/meson/test cases/common/130 include order/inc1/hdr.h
@@ -0,0 +1 @@
+#define SOME_DEFINE 42
diff --git a/meson/test cases/common/130 include order/inc2/hdr.h b/meson/test cases/common/130 include order/inc2/hdr.h
new file mode 100644
index 000000000..2ebcacaf4
--- /dev/null
+++ b/meson/test cases/common/130 include order/inc2/hdr.h
@@ -0,0 +1 @@
+#undef SOME_DEFINE
diff --git a/meson/test cases/common/130 include order/meson.build b/meson/test cases/common/130 include order/meson.build
new file mode 100644
index 000000000..9f275b866
--- /dev/null
+++ b/meson/test cases/common/130 include order/meson.build
@@ -0,0 +1,36 @@
+project('include order', 'c')
+
+# Test that the order of priority of include paths (from first to last) is:
+#
+# 1. Target's current build directory
+# 2. Target's current source directory
+# 3. Include paths added with the `c_args:` kwarg
+# 4. Include paths added with the `include_directories`: kwarg
+# Within this, the build dir takes precedence over the source dir
+# 5. Include paths added via `include_directories:` of internal deps
+# Within this, the build dir takes precedence over the source dir
+
+# Custom target dir with a built header
+subdir('ctsub')
+# Defines an internal dep
+subdir('sub1')
+# Defines a per-target include path
+subdir('sub2')
+# Directory for `c_args:` include path
+subdir('sub3')
+# The directory where the target resides
+subdir('sub4')
+
+# Test that the order in which internal dependencies are specified is
+# preserved. This is needed especially when subprojects get involved and
+# multiple build-root config.h files exist, and we must be sure that the
+# correct one is found: https://github.com/mesonbuild/meson/issues/1495
+f = executable('somefxe', 'sub4/main.c',
+ dependencies : [correctinc, dep, wronginc])
+
+test('eh', e)
+test('oh', f)
+
+# Test that the order in include_directories() is maintained
+incs = include_directories('inc1', 'inc2')
+executable('ordertest', 'ordertest.c', include_directories: incs)
diff --git a/meson/test cases/common/130 include order/ordertest.c b/meson/test cases/common/130 include order/ordertest.c
new file mode 100644
index 000000000..775e34fa1
--- /dev/null
+++ b/meson/test cases/common/130 include order/ordertest.c
@@ -0,0 +1,10 @@
+#include "hdr.h"
+
+#if !defined(SOME_DEFINE) || SOME_DEFINE != 42
+#error "Should have picked up hdr.h from inc1/hdr.h"
+#endif
+
+int main(void)
+{
+ return 0;
+}
diff --git a/meson/test cases/common/130 include order/sub1/main.h b/meson/test cases/common/130 include order/sub1/main.h
new file mode 100644
index 000000000..acf4a358c
--- /dev/null
+++ b/meson/test cases/common/130 include order/sub1/main.h
@@ -0,0 +1 @@
+#error "sub1/main.h included"
diff --git a/meson/test cases/common/130 include order/sub1/meson.build b/meson/test cases/common/130 include order/sub1/meson.build
new file mode 100644
index 000000000..9672945b6
--- /dev/null
+++ b/meson/test cases/common/130 include order/sub1/meson.build
@@ -0,0 +1,4 @@
+i = include_directories('.')
+l = shared_library('somelib', 'some.c')
+dep = declare_dependency(link_with : l,
+ include_directories : i)
diff --git a/meson/test cases/common/130 include order/sub1/some.c b/meson/test cases/common/130 include order/sub1/some.c
new file mode 100644
index 000000000..1ab0db4dd
--- /dev/null
+++ b/meson/test cases/common/130 include order/sub1/some.c
@@ -0,0 +1,6 @@
+#if defined _WIN32 || defined __CYGWIN__
+ __declspec(dllexport)
+#endif
+int somefunc(void) {
+ return 1984;
+}
diff --git a/meson/test cases/common/130 include order/sub1/some.h b/meson/test cases/common/130 include order/sub1/some.h
new file mode 100644
index 000000000..6479492ea
--- /dev/null
+++ b/meson/test cases/common/130 include order/sub1/some.h
@@ -0,0 +1,10 @@
+#pragma once
+
+#if defined _WIN32 || defined __CYGWIN__
+ #define DLL_PUBLIC __declspec(dllimport)
+#else
+ #define DLL_PUBLIC
+#endif
+
+DLL_PUBLIC
+int somefunc(void);
diff --git a/meson/test cases/common/130 include order/sub2/main.h b/meson/test cases/common/130 include order/sub2/main.h
new file mode 100644
index 000000000..b9c0da93a
--- /dev/null
+++ b/meson/test cases/common/130 include order/sub2/main.h
@@ -0,0 +1 @@
+#error "sub2/main.h included"
diff --git a/meson/test cases/common/130 include order/sub2/meson.build b/meson/test cases/common/130 include order/sub2/meson.build
new file mode 100644
index 000000000..b1e61900f
--- /dev/null
+++ b/meson/test cases/common/130 include order/sub2/meson.build
@@ -0,0 +1,2 @@
+j = include_directories('.')
+wronginc = declare_dependency(include_directories : j)
diff --git a/meson/test cases/common/130 include order/sub3/main.h b/meson/test cases/common/130 include order/sub3/main.h
new file mode 100644
index 000000000..1ab723141
--- /dev/null
+++ b/meson/test cases/common/130 include order/sub3/main.h
@@ -0,0 +1 @@
+#error "sub3/main.h included"
diff --git a/meson/test cases/common/130 include order/sub3/meson.build b/meson/test cases/common/130 include order/sub3/meson.build
new file mode 100644
index 000000000..0bd3906c1
--- /dev/null
+++ b/meson/test cases/common/130 include order/sub3/meson.build
@@ -0,0 +1 @@
+sub3 = meson.current_source_dir()
diff --git a/meson/test cases/common/130 include order/sub4/main.c b/meson/test cases/common/130 include order/sub4/main.c
new file mode 100644
index 000000000..89226a464
--- /dev/null
+++ b/meson/test cases/common/130 include order/sub4/main.c
@@ -0,0 +1,8 @@
+/* Use the <> include notation to force searching in include directories */
+#include <main.h>
+
+int main(void) {
+ if (somefunc() == 1984)
+ return 0;
+ return 1;
+}
diff --git a/meson/test cases/common/130 include order/sub4/main.h b/meson/test cases/common/130 include order/sub4/main.h
new file mode 100644
index 000000000..194d7fe5f
--- /dev/null
+++ b/meson/test cases/common/130 include order/sub4/main.h
@@ -0,0 +1,3 @@
+#pragma once
+
+#include "some.h"
diff --git a/meson/test cases/common/130 include order/sub4/meson.build b/meson/test cases/common/130 include order/sub4/meson.build
new file mode 100644
index 000000000..c01edaa20
--- /dev/null
+++ b/meson/test cases/common/130 include order/sub4/meson.build
@@ -0,0 +1,6 @@
+e = executable('someexe', 'main.c', ctfile,
+ c_args : ['-I' + sub3],
+ include_directories : j,
+ dependencies : dep)
+
+correctinc = declare_dependency(include_directories : include_directories('.'))