File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed
tests/packages/sharedlib-in-package/mypkg Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 2
2
//
3
3
// SPDX-License-Identifier: MIT
4
4
5
- int sum (int a , int b );
5
+ #include "mypkg_dll.h"
6
+
7
+ MYPKG_DLL int sum (int a , int b );
Original file line number Diff line number Diff line change 2
2
#
3
3
# SPDX-License-Identifier: MIT
4
4
5
+ if meson .get_compiler(' c' ).get_id() in [' msvc' , ' clang-cl' , ' intel-cl' ]
6
+ export_dll_args = [' -DMYPKG_DLL_EXPORTS' ]
7
+ import_dll_args = [' -DMYPKG_DLL_IMPORTS' ]
8
+ else
9
+ export_dll_args = []
10
+ import_dll_args = []
11
+ endif
12
+
5
13
example_lib = shared_library (
6
14
' examplelib' ,
7
15
' examplelib.c' ,
16
+ c_args : export_dll_args,
8
17
install : true ,
9
18
install_dir : py.get_install_dir() / ' mypkg' ,
10
19
)
11
20
21
+ example_lib_dep = declare_dependency (
22
+ compile_args : import_dll_args,
23
+ link_with : example_lib,
24
+ )
25
+
12
26
py.extension_module(
13
27
' _example' ,
14
28
' _examplemod.c' ,
15
- link_with : example_lib ,
29
+ dependencies : example_lib_dep ,
16
30
install : true ,
17
31
subdir : ' mypkg' ,
18
32
install_rpath : ' $ORIGIN' ,
Original file line number Diff line number Diff line change
1
+ #pragma once
2
+
3
+ // MYPKG_DLL
4
+ // inspired by https://github.com/abseil/abseil-cpp/blob/20240116.2/absl/base/config.h#L736-L753
5
+ // and https://github.com/scipy/scipy/blob/9ded83b51099eee745418ccbb30196db96c81f3f/scipy/_build_utils/src/scipy_dll.h
6
+ //
7
+ // When building the `examplelib` DLL, this macro expands to `__declspec(dllexport)`
8
+ // so we can annotate symbols appropriately as being exported. When used in
9
+ // headers consuming a DLL, this macro expands to `__declspec(dllimport)` so
10
+ // that consumers know the symbol is defined inside the DLL. In all other cases,
11
+ // the macro expands to nothing.
12
+ // Note: MYPKG_DLL_{EX,IM}PORTS are set in mypkg/meson.build
13
+ #if defined(MYPKG_DLL_EXPORTS )
14
+ #define MYPKG_DLL __declspec(dllexport)
15
+ #elif defined(MYPKG_DLL_IMPORTS )
16
+ #define MYPKG_DLL __declspec(dllimport)
17
+ #else
18
+ #define MYPKG_DLL
19
+ #endif
You can’t perform that action at this time.
0 commit comments