Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to the Meson build to fix portability issues and warnings #1737

Merged
merged 7 commits into from Apr 27, 2024
4 changes: 2 additions & 2 deletions check/meson.build
Expand Up @@ -63,7 +63,7 @@ foreach test : test_array
test.get(1),
highs_conf_file],
dependencies : _deps,
link_with : _linkto ,
link_with : highslib,
cpp_args : _args,
include_directories: _incdirs,
),
Expand All @@ -75,6 +75,6 @@ if get_option('with_c')
test('test_capi',
executable('capi_unit_tests', 'TestCAPI.c',
include_directories: _incdirs,
link_with : _linkto ,
link_with : highslib,
))
endif
31 changes: 15 additions & 16 deletions meson.build
@@ -1,5 +1,5 @@
project('highs', 'cpp',
version : '1.6.0',
project('highs', 'cpp', 'c',
version : '1.7.0',
meson_version: '>= 1.1.0',
default_options : ['warning_level=1',
'cpp_std=c++17',
Expand All @@ -10,10 +10,8 @@ project('highs', 'cpp',
# Add C++ compiler options
_args = [] # Extra arguments
_deps = [] # Dependencies
_linkto = [] # All the sub-libraries
_incdirs = [] # All the includes

add_languages('c', required: true)
cc = meson.get_compiler('c')
cppc = meson.get_compiler('cpp')

Expand All @@ -23,13 +21,16 @@ is_windows = host_system == 'windows'
is_mingw = is_windows and cc.get_id() == 'gcc'

# Conditional arguments
if host_system == 'linux'
_args += '-Wno-return-type'
_args += '-Wno-switch'
_args += '-Wno-unused-variable'
_args += '-Wno-unused-but-set-variable'
_args += '-Wno-unused-const-variable'
endif
_args += cppc.get_supported_arguments([
'-Wno-return-type',
'-Wno-switch',
'-Wno-comment',
'-Wno-unused-variable',
'-Wno-unused-but-set-variable',
'-Wno-unused-const-variable',
'-Wno-unused-function',
'-Wno-unused-label',
])

if cppc.get_id() == 'msvc'
add_project_arguments(
Expand Down Expand Up @@ -60,10 +61,10 @@ endif
cpu_family = host_machine.cpu_family()

if cpu_family in ['x86_64', 'i686'] and not is_windows
add_project_arguments('-mpopcnt', language: 'cpp')
add_project_arguments(cppc.get_supported_arguments('-mpopcnt'), language: 'cpp')
endif
if cpu_family in ['ppc64', 'powerpc64'] and not meson.is_cross_build()
add_project_arguments('-mpopcntd', language: 'cpp')
add_project_arguments(cppc.get_supported_arguments('-mpopcntd'), language: 'cpp')
endif

if is_mingw
Expand All @@ -72,9 +73,7 @@ if is_mingw
endif

# --------------------- Dependencies
# Required
threads_dep = dependency('threads',
required: false)
threads_dep = dependency('threads', required: false)
_deps += threads_dep

# Determine whether it is necessary to link libatomic. This could be the case
Expand Down
31 changes: 20 additions & 11 deletions src/meson.build
Expand Up @@ -36,9 +36,12 @@ build_date = datetime.datetime.utcfromtimestamp(
build_date_str = build_date.strftime('%Y-%m-%d')
print(build_date_str)
'''
# Note: this is not guaranteed to work on Windows. This should be removed
# (as proposed in gh-1735), and otherwise moved into a .py script with
# a `#!/usr/bin/env python3` shebang, and `python3 -c` dropped.
today_cmd = run_command('python3', '-c',
python_getdate,
check: false)
check: false)
today_str = today_cmd.stdout().strip()
endif
conf_data.set_quoted('HIGHS_COMPILATION_DATE',
Expand Down Expand Up @@ -300,13 +303,20 @@ highslib_srcs = [
]


symbol_visibility = 'default'
if get_option('default_library') == 'static'
# Ensure that if we link a static library into a shared library,
# private symbols don't get re-exported.
symbol_visibility = 'inlineshidden'
endif

highslib = library('highs',
highslib_srcs,
dependencies: _deps,
cpp_args: _args,
c_args: _args,
link_with: _linkto,
include_directories: _incdirs,
gnu_symbol_visibility: symbol_visibility,
pic: true,
install: true)

Expand All @@ -322,7 +332,7 @@ if get_option('with_fortran')
_fsrcs,
dependencies: _deps,
cpp_args: _args,
link_with: [ _linkto, highslib ],
link_with: highslib,
include_directories: _incdirs,
pic: true,
install: true)
Expand All @@ -338,7 +348,7 @@ if get_option('with_csharp')
_cs_srcs,
dependencies: _deps,
cpp_args: _args,
link_with: [ _linkto, highslib ],
link_with: highslib,
include_directories: _incdirs,
pic: true,
install: true)
Expand All @@ -358,24 +368,23 @@ if get_option('with_c')
_c_src,
dependencies: _deps,
cpp_args: _args,
link_with: [ _linkto, highslib ],
link_with: highslib,
include_directories: _incdirs,
pic: true,
install: true)
endif


_linkto += highslib

highs_dep = declare_dependency(link_with: _linkto,
highs_dep = declare_dependency(link_with: highslib,
dependencies: _deps,
include_directories: _incdirs,
)

if get_option('with_pybind11')
py_mod = import('python')
py = py_mod.find_installation(pure: false)
py = import('python').find_installation(pure: false)

pyb11_dep = [
# py_dep is auto-added for Python >= 3.9, so it can be dropped here when
# that is the minimum supported Python version
py.dependency(),
dependency('pybind11')
]
Expand Down