-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeson.build
More file actions
149 lines (136 loc) · 5.38 KB
/
Copy pathmeson.build
File metadata and controls
149 lines (136 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
project('psqlodbc2', 'c',
version : '0.1.0',
meson_version : '>= 1.1',
default_options : ['c_std=c11', 'warning_level=2'],
license : 'PostgreSQL',
)
# Locate ODBC headers and libraries.
# The 'driver_manager' option lets the user force a specific driver manager;
# 'auto' tries odbc -> unixODBC -> iODBC -> header-only fallback.
dm_choice = get_option('driver_manager')
odbc_dep = dependency('', required : false) # start with nothing found
if dm_choice == 'none'
cc = meson.get_compiler('c')
assert(cc.has_header('sql.h'), 'ODBC headers not found. Install unixODBC or iODBC development package.')
odbc_dep = declare_dependency()
elif dm_choice == 'unixodbc'
odbc_dep = dependency('odbc', required : false)
if not odbc_dep.found()
odbc_dep = dependency('unixODBC', required : true)
endif
elif dm_choice == 'iodbc'
odbc_dep = dependency('iODBC', required : true)
else # auto
odbc_dep = dependency('odbc', required : false)
if not odbc_dep.found()
odbc_dep = dependency('unixODBC', required : false)
endif
if not odbc_dep.found()
odbc_dep = dependency('iODBC', required : false)
endif
if not odbc_dep.found()
cc = meson.get_compiler('c')
assert(cc.has_header('sql.h'), 'ODBC headers not found. Install unixODBC or iODBC development package.')
odbc_dep = declare_dependency()
endif
endif
# Locate PostgreSQL client library (libpq) for connecting to the database.
# Strategy: an explicit libpq_prefix wins (used on Windows/vcpkg, see below);
# otherwise try pkg-config, then probe common install locations per platform.
libpq_prefix = get_option('libpq_prefix')
if libpq_prefix != ''
# Explicit prefix: link via find_library rather than pkg-config. On MSVC,
# Meson's pkg-config backend drops vcpkg's "-llibpq" link flag, so a
# pkg-config-resolved libpq compiles but fails to link. find_library against
# the prefix's lib/ produces a correct, arch-matched link.
cc = meson.get_compiler('c')
# The import/shared library is named "libpq.lib" on Windows (vcpkg/MSVC) but
# "libpq.so"/"libpq.dylib" on Unix, whose canonical find_library name is
# "pq". Try the Windows name first, then the Unix name, so a single option
# works across platforms.
libpq_lib = cc.find_library('libpq',
dirs : [libpq_prefix / 'lib'],
required : false,
)
if not libpq_lib.found()
libpq_lib = cc.find_library('pq',
dirs : [libpq_prefix / 'lib'],
required : true,
)
endif
libpq_dep = declare_dependency(
dependencies : libpq_lib,
include_directories : include_directories(libpq_prefix / 'include'),
)
else
libpq_dep = dependency('libpq', required : false)
endif
if not libpq_dep.found()
cc = meson.get_compiler('c')
# Common library search paths by platform
libpq_search_dirs = []
libpq_include_args = []
if host_machine.system() == 'windows'
# Standard EDB/Chocolatey install paths on Windows
libpq_search_dirs = [
'C:/Program Files/PostgreSQL/17/lib',
'C:/Program Files/PostgreSQL/16/lib',
'C:/Program Files/PostgreSQL/15/lib',
]
libpq_include_candidates = [
'C:/Program Files/PostgreSQL/17/include',
'C:/Program Files/PostgreSQL/16/include',
'C:/Program Files/PostgreSQL/15/include',
]
else
# macOS source builds and Homebrew, Linux standard paths
libpq_search_dirs = [
'/usr/local/pgsql/18/lib',
'/usr/local/pgsql/17/lib',
'/opt/homebrew/opt/libpq/lib',
]
libpq_include_candidates = [
'/usr/local/pgsql/18/include',
'/usr/local/pgsql/17/include',
'/opt/homebrew/opt/libpq/include',
]
endif
libpq_lib = cc.find_library('pq', dirs : libpq_search_dirs, required : false)
if libpq_lib.found()
# Find the matching include directory
libpq_inc_dir = ''
foreach inc_path : libpq_include_candidates
if cc.has_header('libpq-fe.h', args : ['-I' + inc_path])
libpq_inc_dir = inc_path
break
endif
endforeach
if libpq_inc_dir != ''
libpq_dep = declare_dependency(
dependencies : libpq_lib,
include_directories : include_directories(libpq_inc_dir),
)
elif cc.has_header('libpq-fe.h')
# Header is in default include path already
libpq_dep = declare_dependency(dependencies : libpq_lib)
else
error('Found libpq library but not libpq-fe.h header. Install PostgreSQL development headers.')
endif
else
error('libpq not found. Install PostgreSQL client library or set PKG_CONFIG_PATH.')
endif
endif
# libodbcinst provides SQLGetPrivateProfileString for reading DSN parameters
# from odbc.ini. It's part of unixODBC and typically installed alongside libodbc.
# If not found, DSN lookup is disabled but the driver still works with connection strings.
odbcinst_dep = dependency('odbcinst', required : false)
if not odbcinst_dep.found()
cc = meson.get_compiler('c')
odbcinst_dep = cc.find_library('odbcinst', required : false)
endif
if odbcinst_dep.found()
add_project_arguments('-DHAVE_ODBCINST=1', language : 'c')
endif
inc = include_directories('include')
subdir('src')
subdir('tests')