Skip to content

Commit

Permalink
templates: use library() instead of shared_library() where it matters
Browse files Browse the repository at this point in the history
This allows the use of both_libraries, and by using
`<lang>_shared_args` we can get the best behavior
  • Loading branch information
dcbaker committed Jan 7, 2025
1 parent 65b0c48 commit e02b02e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 12 deletions.
11 changes: 9 additions & 2 deletions mesonbuild/templates/cpptemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
# Copyright © 2023-2025 Intel Corporation

from __future__ import annotations
import typing as T

from mesonbuild.templates.sampleimpl import FileHeaderImpl

if T.TYPE_CHECKING:
from ..minit import Arguments

hello_cpp_template = '''#include <iostream>
Expand Down Expand Up @@ -118,11 +121,11 @@ class {utoken}_PUBLIC {class_name} {{
# not the executables that use the library.
lib_args = ['-DBUILDING_{utoken}']
lib = shared_library(
lib = library(
'{lib_name}',
'{source_file}',
install : true,
cpp_args : lib_args,
cpp_shared_args : lib_args,
gnu_symbol_visibility : 'hidden',
dependencies : dependencies,
)
Expand Down Expand Up @@ -166,3 +169,7 @@ class CppProject(FileHeaderImpl):
lib_header_template = lib_hpp_template
lib_test_template = lib_cpp_test_template
lib_meson_template = lib_cpp_meson_template

def __init__(self, args: Arguments):
super().__init__(args)
self.meson_version = '1.3.0'
8 changes: 6 additions & 2 deletions mesonbuild/templates/ctemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
# Copyright © 2023-2025 Intel Corporation

from __future__ import annotations
import typing as T

from mesonbuild.templates.sampleimpl import FileHeaderImpl

if T.TYPE_CHECKING:
from ..minit import Arguments


lib_h_template = '''#pragma once
#if defined _WIN32 || defined __CYGWIN__
Expand Down Expand Up @@ -67,11 +71,11 @@
dependencies = [{dependencies}
]
lib = shared_library(
lib = library(
'{lib_name}',
'{source_file}',
install : true,
c_args : lib_args,
c_shared_args : lib_args,
gnu_symbol_visibility : 'hidden',
dependencies : dependencies,
)
Expand Down
12 changes: 10 additions & 2 deletions mesonbuild/templates/cudatemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
# Copyright © 2023-2025 Intel Corporation

from __future__ import annotations
import typing as T

from mesonbuild.templates.sampleimpl import FileHeaderImpl

if T.TYPE_CHECKING:
from ..minit import Arguments


hello_cuda_template = '''#include <iostream>
Expand Down Expand Up @@ -118,11 +122,11 @@ class {utoken}_PUBLIC {class_name} {{
dependencies = [{dependencies}
]
lib = shared_library(
lib = library(
'{lib_name}',
'{source_file}',
install : true,
cpp_args : lib_args,
cpp_shared_args : lib_args,
gnu_symbol_visibility : 'hidden',
dependencies : dependencies,
)
Expand Down Expand Up @@ -166,3 +170,7 @@ class CudaProject(FileHeaderImpl):
lib_header_template = lib_h_template
lib_test_template = lib_cuda_test_template
lib_meson_template = lib_cuda_meson_template

def __init__(self, args: Arguments):
super().__init__(args)
self.meson_version = '1.3.0'
12 changes: 10 additions & 2 deletions mesonbuild/templates/fortrantemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
# Copyright © 2023-2025 Intel Corporation

from __future__ import annotations
import typing as T

from mesonbuild.templates.sampleimpl import FileImpl

if T.TYPE_CHECKING:
from ..minit import Arguments

lib_fortran_template = '''
! This procedure will not be exported and is not
! directly callable by users of this library.
Expand Down Expand Up @@ -52,11 +56,11 @@
dependencies = [{dependencies}
]
lib = shared_library(
lib = library(
'{lib_name}',
'{source_file}',
install : true,
fortran_args : lib_args,
fortran_shared_args : lib_args,
gnu_symbol_visibility : 'hidden',
dependencies : dependencies,
)
Expand Down Expand Up @@ -125,3 +129,7 @@ class FortranProject(FileImpl):
lib_template = lib_fortran_template
lib_meson_template = lib_fortran_meson_template
lib_test_template = lib_fortran_test_template

def __init__(self, args: Arguments):
super().__init__(args)
self.meson_version = '1.3.0'
12 changes: 10 additions & 2 deletions mesonbuild/templates/objcpptemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
# Copyright © 2023-2025 Intel Corporation

from __future__ import annotations
import typing as T

from mesonbuild.templates.sampleimpl import FileHeaderImpl

if T.TYPE_CHECKING:
from ..minit import Arguments


lib_h_template = '''#pragma once
#if defined _WIN32 || defined __CYGWIN__
Expand Down Expand Up @@ -67,11 +71,11 @@
# not the executables that use the library.
lib_args = ['-DBUILDING_{utoken}']
lib = shared_library(
lib = library(
'{lib_name}',
'{source_file}',
install : true,
objcpp_args : lib_args,
objcpp_shared_args : lib_args,
dependencies : dependencies,
gnu_symbol_visibility : 'hidden',
)
Expand Down Expand Up @@ -150,3 +154,7 @@ class ObjCppProject(FileHeaderImpl):
lib_header_template = lib_h_template
lib_test_template = lib_objcpp_test_template
lib_meson_template = lib_objcpp_meson_template

def __init__(self, args: Arguments):
super().__init__(args)
self.meson_version = '1.3.0'
12 changes: 10 additions & 2 deletions mesonbuild/templates/objctemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
# Copyright © 2023-2025 Intel Corporation

from __future__ import annotations
import typing as T

from mesonbuild.templates.sampleimpl import FileHeaderImpl

if T.TYPE_CHECKING:
from ..minit import Arguments


lib_h_template = '''#pragma once
#if defined _WIN32 || defined __CYGWIN__
Expand Down Expand Up @@ -67,11 +71,11 @@
# not the executables that use the library.
lib_args = ['-DBUILDING_{utoken}']
lib = shared_library(
lib = library(
'{lib_name}',
'{source_file}',
install : true,
objc_args : lib_args,
objc_shared_args : lib_args,
dependencies : dependencies,
gnu_symbol_visibility : 'hidden',
)
Expand Down Expand Up @@ -149,3 +153,7 @@ class ObjCProject(FileHeaderImpl):
lib_header_template = lib_h_template
lib_test_template = lib_objc_test_template
lib_meson_template = lib_objc_meson_template

def __init__(self, args: Arguments):
super().__init__(args)
self.meson_version = '1.3.0'

0 comments on commit e02b02e

Please sign in to comment.