summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-01-06 15:36:45 -0800
committerDylan Baker <dylan@pnwbakers.com>2025-01-08 10:04:42 -0800
commit55e3a5ece5d90ea29dcb8ab2d0bb6898a71e8971 (patch)
treecdf1d0214f5fac25f65dd111c6baf7c7fec0b10e
parent484ac23b512f2ccc008ad9b9520016fbaa3645f0 (diff)
downloadmeson-55e3a5ece5d90ea29dcb8ab2d0bb6898a71e8971.tar.gz
templates: plumb dependencies into the new project template
The command line value exists, and we'll want it soon.
-rw-r--r--mesonbuild/templates/cpptemplates.py10
-rw-r--r--mesonbuild/templates/cstemplates.py10
-rw-r--r--mesonbuild/templates/ctemplates.py10
-rw-r--r--mesonbuild/templates/cudatemplates.py10
-rw-r--r--mesonbuild/templates/dlangtemplates.py11
-rw-r--r--mesonbuild/templates/fortrantemplates.py10
-rw-r--r--mesonbuild/templates/javatemplates.py10
-rw-r--r--mesonbuild/templates/objcpptemplates.py10
-rw-r--r--mesonbuild/templates/objctemplates.py10
-rw-r--r--mesonbuild/templates/rusttemplates.py9
-rw-r--r--mesonbuild/templates/sampleimpl.py12
-rw-r--r--mesonbuild/templates/valatemplates.py5
12 files changed, 113 insertions, 4 deletions
diff --git a/mesonbuild/templates/cpptemplates.py b/mesonbuild/templates/cpptemplates.py
index 2d7955ed7..2e16f8d0d 100644
--- a/mesonbuild/templates/cpptemplates.py
+++ b/mesonbuild/templates/cpptemplates.py
@@ -29,10 +29,14 @@ hello_cpp_meson_template = '''project(
default_options : ['warning_level=3', 'cpp_std=c++14'],
)
+dependencies = [{dependencies}
+]
+
exe = executable(
'{exe_name}',
'{source_name}',
install : true,
+ dependencies : dependencies,
)
test('basic', exe)
@@ -107,6 +111,9 @@ lib_cpp_meson_template = '''project(
default_options : ['warning_level=3', 'cpp_std=c++14'],
)
+dependencies = [{dependencies}
+]
+
# These arguments are only used to build the shared library
# not the executables that use the library.
lib_args = ['-DBUILDING_{utoken}']
@@ -117,11 +124,13 @@ shlib = shared_library(
install : true,
cpp_args : lib_args,
gnu_symbol_visibility : 'hidden',
+ dependencies : dependencies,
)
test_exe = executable(
'{test_exe_name}',
'{test_source_file}',
+ dependencies : dependencies,
link_with : shlib,
)
test('{test_name}', test_exe)
@@ -129,6 +138,7 @@ test('{test_name}', test_exe)
# Make this library usable as a Meson subproject.
{ltoken}_dep = declare_dependency(
include_directories : include_directories('.'),
+ dependencies : dependencies,
link_with : shlib,
)
diff --git a/mesonbuild/templates/cstemplates.py b/mesonbuild/templates/cstemplates.py
index 7ab1548d2..040debc15 100644
--- a/mesonbuild/templates/cstemplates.py
+++ b/mesonbuild/templates/cstemplates.py
@@ -32,10 +32,14 @@ hello_cs_meson_template = '''project(
default_options : ['warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
exe = executable(
'{exe_name}',
'{source_name}',
install : true,
+ dependencies : dependencies,
)
test('basic', exe)
@@ -76,15 +80,20 @@ lib_cs_meson_template = '''project(
default_options : ['warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
stlib = shared_library(
'{lib_name}',
'{source_file}',
+ dependencies : dependencies,
install : true,
)
test_exe = executable(
'{test_exe_name}',
'{test_source_file}',
+ dependencies : dependencies,
link_with : stlib,
)
test('{test_name}', test_exe)
@@ -92,6 +101,7 @@ test('{test_name}', test_exe)
# Make this library usable as a Meson subproject.
{ltoken}_dep = declare_dependency(
include_directories : include_directories('.'),
+ dependencies : dependencies,
link_with : stlib,
)
diff --git a/mesonbuild/templates/ctemplates.py b/mesonbuild/templates/ctemplates.py
index cfb5a4003..5772dc2eb 100644
--- a/mesonbuild/templates/ctemplates.py
+++ b/mesonbuild/templates/ctemplates.py
@@ -64,17 +64,22 @@ lib_c_meson_template = '''project(
# not the executables that use the library.
lib_args = ['-DBUILDING_{utoken}']
+dependencies = [{dependencies}
+]
+
shlib = shared_library(
'{lib_name}',
'{source_file}',
install : true,
c_args : lib_args,
gnu_symbol_visibility : 'hidden',
+ dependencies : dependencies,
)
test_exe = executable(
'{test_exe_name}',
'{test_source_file}',
+ dependencies : dependencies,
link_with : shlib,
)
test('{test_name}', test_exe)
@@ -82,6 +87,7 @@ test('{test_name}', test_exe)
# Make this library usable as a Meson subproject.
{ltoken}_dep = declare_dependency(
include_directories : include_directories('.'),
+ dependencies : dependencies,
link_with : shlib,
)
@@ -122,9 +128,13 @@ hello_c_meson_template = '''project(
default_options : ['warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
exe = executable(
'{exe_name}',
'{source_name}',
+ dependencies : dependencies,
install : true,
)
diff --git a/mesonbuild/templates/cudatemplates.py b/mesonbuild/templates/cudatemplates.py
index 189fe9847..80b72c750 100644
--- a/mesonbuild/templates/cudatemplates.py
+++ b/mesonbuild/templates/cudatemplates.py
@@ -29,9 +29,13 @@ hello_cuda_meson_template = '''project(
default_options : ['warning_level=3', 'cpp_std=c++14'],
)
+dependencies = [{dependencies}
+]
+
exe = executable(
'{exe_name}',
'{source_name}',
+ dependencies : dependencies,
install : true,
)
@@ -111,24 +115,30 @@ lib_cuda_meson_template = '''project(
# not the executables that use the library.
lib_args = ['-DBUILDING_{utoken}']
+dependencies = [{dependencies}
+]
+
shlib = shared_library(
'{lib_name}',
'{source_file}',
install : true,
cpp_args : lib_args,
gnu_symbol_visibility : 'hidden',
+ dependencies : dependencies,
)
test_exe = executable(
'{test_exe_name}',
'{test_source_file}',
link_with : shlib,
+ dependencies : dependencies,
)
test('{test_name}', test_exe)
# Make this library usable as a Meson subproject.
{ltoken}_dep = declare_dependency(
include_directories : include_directories('.'),
+ dependencies : dependencies,
link_with : shlib,
)
diff --git a/mesonbuild/templates/dlangtemplates.py b/mesonbuild/templates/dlangtemplates.py
index 85968e1f5..00ac3bcc3 100644
--- a/mesonbuild/templates/dlangtemplates.py
+++ b/mesonbuild/templates/dlangtemplates.py
@@ -32,9 +32,13 @@ hello_d_meson_template = '''project(
default_options : ['warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
exe = executable(
'{exe_name}',
'{source_name}',
+ dependencies : dependencies,
install : true,
)
@@ -77,23 +81,30 @@ lib_d_meson_template = '''project(
default_options : ['warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
+
stlib = static_library(
'{lib_name}',
'{source_file}',
install : true,
gnu_symbol_visibility : 'hidden',
+ dependencies : dependencies,
)
test_exe = executable(
'{test_exe_name}',
'{test_source_file}',
link_with : stlib,
+ dependencies : dependencies,
)
test('{test_name}', test_exe)
# Make this library usable as a Meson subproject.
{ltoken}_dep = declare_dependency(
include_directories : include_directories('.'),
+ dependencies : dependencies,
link_with : stlib,
)
diff --git a/mesonbuild/templates/fortrantemplates.py b/mesonbuild/templates/fortrantemplates.py
index c1a6e0148..3d139612a 100644
--- a/mesonbuild/templates/fortrantemplates.py
+++ b/mesonbuild/templates/fortrantemplates.py
@@ -49,24 +49,30 @@ lib_fortran_meson_template = '''project(
# not the executables that use the library.
lib_args = ['-DBUILDING_{utoken}']
+dependencies = [{dependencies}
+]
+
shlib = shared_library(
'{lib_name}',
'{source_file}',
install : true,
fortran_args : lib_args,
gnu_symbol_visibility : 'hidden',
+ dependencies : dependencies,
)
test_exe = executable(
'{test_exe_name}',
'{test_source_file}',
link_with : shlib,
+ dependencies : dependencies,
)
test('{test_name}', test_exe)
# Make this library usable as a Meson subproject.
{ltoken}_dep = declare_dependency(
include_directories : include_directories('.'),
+ dependencies : dependencies,
link_with : shlib,
)
@@ -99,9 +105,13 @@ hello_fortran_meson_template = '''project(
default_options : ['warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
exe = executable(
'{exe_name}',
'{source_name}',
+ dependencies : dependencies,
install : true,
)
diff --git a/mesonbuild/templates/javatemplates.py b/mesonbuild/templates/javatemplates.py
index 8596ad946..c79a8e751 100644
--- a/mesonbuild/templates/javatemplates.py
+++ b/mesonbuild/templates/javatemplates.py
@@ -32,10 +32,14 @@ hello_java_meson_template = '''project(
default_options : ['warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
exe = jar(
'{exe_name}',
'{source_name}',
main_class : '{exe_name}',
+ dependencies : dependencies,
install : true,
)
@@ -79,9 +83,13 @@ lib_java_meson_template = '''project(
default_options : ['warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
jarlib = jar(
'{class_name}',
'{source_file}',
+ dependencies : dependencies,
main_class : '{class_name}',
install : true,
)
@@ -90,6 +98,7 @@ test_jar = jar(
'{class_test}',
'{test_source_file}',
main_class : '{class_test}',
+ dependencies : dependencies,
link_with : jarlib,
)
test('{test_name}', test_jar)
@@ -97,6 +106,7 @@ test('{test_name}', test_jar)
# Make this library usable as a Meson subproject.
{ltoken}_dep = declare_dependency(
include_directories : include_directories('.'),
+ dependencies : dependencies,
link_with : jarlib,
)
'''
diff --git a/mesonbuild/templates/objcpptemplates.py b/mesonbuild/templates/objcpptemplates.py
index a9e1099a2..dd67c3748 100644
--- a/mesonbuild/templates/objcpptemplates.py
+++ b/mesonbuild/templates/objcpptemplates.py
@@ -60,6 +60,9 @@ lib_objcpp_meson_template = '''project(
default_options : ['warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
# These arguments are only used to build the shared library
# not the executables that use the library.
lib_args = ['-DBUILDING_{utoken}']
@@ -69,12 +72,14 @@ shlib = shared_library(
'{source_file}',
install : true,
objcpp_args : lib_args,
+ dependencies : dependencies,
gnu_symbol_visibility : 'hidden',
)
test_exe = executable(
'{test_exe_name}',
'{test_source_file}',
+ dependencies : dependencies,
link_with : shlib,
)
test('{test_name}', test_exe)
@@ -82,6 +87,7 @@ test('{test_name}', test_exe)
# Make this library usable as a Meson subproject.
{ltoken}_dep = declare_dependency(
include_directories : include_directories('.'),
+ dependencies : dependencies,
link_with : shlib,
)
@@ -122,9 +128,13 @@ hello_objcpp_meson_template = '''project(
default_options : ['warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
exe = executable(
'{exe_name}',
'{source_name}',
+ dependencies : dependencies,
install : true,
)
diff --git a/mesonbuild/templates/objctemplates.py b/mesonbuild/templates/objctemplates.py
index 64141e456..30f480424 100644
--- a/mesonbuild/templates/objctemplates.py
+++ b/mesonbuild/templates/objctemplates.py
@@ -60,6 +60,9 @@ lib_objc_meson_template = '''project(
default_options : ['warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
# These arguments are only used to build the shared library
# not the executables that use the library.
lib_args = ['-DBUILDING_{utoken}']
@@ -69,18 +72,21 @@ shlib = shared_library(
'{source_file}',
install : true,
objc_args : lib_args,
+ dependencies : dependencies,
gnu_symbol_visibility : 'hidden',
)
test_exe = executable(
'{test_exe_name}',
'{test_source_file}',
+ dependencies : dependencies,
link_with : shlib)
test('{test_name}', test_exe)
# Make this library usable as a Meson subproject.
{ltoken}_dep = declare_dependency(
include_directories : include_directories('.'),
+ dependencies : dependencies,
link_with : shlib,
)
@@ -121,9 +127,13 @@ hello_objc_meson_template = '''project(
default_options : ['warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
exe = executable(
'{exe_name}',
'{source_name}',
+ dependencies : dependencies,
install : true,
)
diff --git a/mesonbuild/templates/rusttemplates.py b/mesonbuild/templates/rusttemplates.py
index a012afb85..7eab663bb 100644
--- a/mesonbuild/templates/rusttemplates.py
+++ b/mesonbuild/templates/rusttemplates.py
@@ -47,9 +47,13 @@ lib_rust_meson_template = '''project(
rust = import('rust')
+dependencies = [{dependencies}
+]
+
shlib = static_library(
'{lib_name}',
'{source_file}',
+ dependencies : dependencies,
install : true,
)
@@ -58,6 +62,7 @@ rust.test('{test_name}', shlib)
# Make this library usable as a Meson subproject.
{ltoken}_dep = declare_dependency(
include_directories : include_directories('.'),
+ dependencies : dependencies,
link_with : shlib,
)
'''
@@ -77,9 +82,13 @@ hello_rust_meson_template = '''project(
default_options : ['rust_std=2021', 'warning_level=3'],
)
+dependencies = [{dependencies}
+]
+
exe = executable(
'{exe_name}',
'{source_name}',
+ dependencies : dependencies,
install : true,
)
diff --git a/mesonbuild/templates/sampleimpl.py b/mesonbuild/templates/sampleimpl.py
index 7d2b4dd7c..d033f3c14 100644
--- a/mesonbuild/templates/sampleimpl.py
+++ b/mesonbuild/templates/sampleimpl.py
@@ -23,6 +23,7 @@ class SampleImpl(metaclass=abc.ABCMeta):
self.capitalized_token = self.lowercase_token.capitalize()
self.meson_version = '1.0.0'
self.force = args.force
+ self.dependencies = args.deps.split(',') if args.deps else []
@abc.abstractmethod
def create_executable(self) -> None:
@@ -62,6 +63,9 @@ class SampleImpl(metaclass=abc.ABCMeta):
def source_ext(self) -> str:
pass
+ def _format_dependencies(self) -> str:
+ return ''.join(f"\n dependency('{d}')," for d in self.dependencies)
+
class ClassImpl(SampleImpl):
@@ -79,7 +83,8 @@ class ClassImpl(SampleImpl):
exe_name=self.name,
source_name=source_name,
version=self.version,
- meson_version=self.meson_version))
+ meson_version=self.meson_version,
+ dependencies=self._format_dependencies()))
def create_library(self) -> None:
lib_name = f'{self.capitalized_token}.{self.source_ext}'
@@ -96,6 +101,7 @@ class ClassImpl(SampleImpl):
'test_name': self.lowercase_token,
'version': self.version,
'meson_version': self.meson_version,
+ 'dependencies': self._format_dependencies(),
}
if not os.path.exists(lib_name):
with open(lib_name, 'w', encoding='utf-8') as f:
@@ -123,7 +129,8 @@ class FileImpl(SampleImpl):
exe_name=self.name,
source_name=source_name,
version=self.version,
- meson_version=self.meson_version))
+ meson_version=self.meson_version,
+ dependencies=self._format_dependencies()))
def lib_kwargs(self) -> T.Dict[str, str]:
"""Get Language specific keyword arguments
@@ -145,6 +152,7 @@ class FileImpl(SampleImpl):
'test_name': self.lowercase_token,
'version': self.version,
'meson_version': self.meson_version,
+ 'dependencies': self._format_dependencies(),
}
def create_library(self) -> None:
diff --git a/mesonbuild/templates/valatemplates.py b/mesonbuild/templates/valatemplates.py
index b8ae6e067..41cee2925 100644
--- a/mesonbuild/templates/valatemplates.py
+++ b/mesonbuild/templates/valatemplates.py
@@ -21,7 +21,7 @@ hello_vala_meson_template = '''project(
dependencies = [
dependency('glib-2.0'),
- dependency('gobject-2.0'),
+ dependency('gobject-2.0'),{dependencies}
]
exe = executable(
@@ -64,7 +64,7 @@ lib_vala_meson_template = '''project(
dependencies = [
dependency('glib-2.0'),
- dependency('gobject-2.0'),
+ dependency('gobject-2.0'),{dependencies}
]
# These arguments are only used to build the shared library
@@ -88,6 +88,7 @@ test('{test_name}', test_exe)
# Make this library usable as a Meson subproject.
{ltoken}_dep = declare_dependency(
include_directories : include_directories('.'),
+ dependencies : dependencies,
link_with : shlib,
)