build(meson): more robust python build

This commit is contained in:
2026-06-11 10:58:32 -04:00
parent 86f10d1521
commit 51d927b28d
4 changed files with 25 additions and 10 deletions

1
.gitignore vendored
View File

@@ -86,3 +86,4 @@ output/
.idea/ .idea/
scratch/ scratch/
subprojects/.wraplock

View File

@@ -18,11 +18,32 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# *********************************************************************** # # *********************************************************************** #
project('libconstants', 'cpp', version: 'v1.1.5', default_options: ['cpp_std=c++23'], meson_version: '>=1.5.0') project('libconstants', 'cpp', version: 'v1.1.6', default_options: ['cpp_std=c++23'], meson_version: '>=1.5.0')
# Add default visibility for all C++ targets # Add default visibility for all C++ targets
add_project_arguments('-fvisibility=default', language: 'cpp') add_project_arguments('-fvisibility=default', language: 'cpp')
if get_option('build_python')
local_py_install = import('python').find_installation('python3', pure: false)
fourdst_pkg = local_py_install.get_install_dir() / 'fourdst'
constants_libdir = fourdst_pkg / 'lib'
constants_header_install_dir = fourdst_pkg / 'include' / 'fourdst' / 'constants'
vendor_lib_dir = fourdst_pkg / 'lib' / 'vendor'
vendor_header_dir = fourdst_pkg / 'include' / 'fourdst' / 'vendor'
message('Installing libconfig in python mode. Install locations are...')
else
constants_libdir = get_option('libdir')
constants_header_install_dir = get_option('includedir') / 'fourdst' / 'constants'
message('Installing libconfig in non python (normal) mode. Install locations are...')
endif
message(' Libraries: ' + constants_libdir)
message(' Headers: ' + constants_header_install_dir)
cpp = meson.get_compiler('cpp') cpp = meson.get_compiler('cpp')
subdir('assets/static') subdir('assets/static')
@@ -45,7 +66,6 @@ if get_option('pkg_config')
description: 'Physical Constants for SERiF and related projects', description: 'Physical Constants for SERiF and related projects',
version: meson.project_version(), version: meson.project_version(),
libraries: [libconst, '-Wl,-rpath,${libdir}'], libraries: [libconst, '-Wl,-rpath,${libdir}'],
subdirs: ['fourdst'],
filebase: 'fourdst_constants', filebase: 'fourdst_constants',
install_dir: join_paths(get_option('libdir'), 'pkgconfig') install_dir: join_paths(get_option('libdir'), 'pkgconfig')
) )

View File

@@ -1,5 +1,4 @@
option('pkg_config', type: 'boolean', value: true, description: 'generate pkg-config file for libconstants (fourdst_constants.pc)') option('pkg_config', type: 'boolean', value: true, description: 'generate pkg-config file for libconstants (fourdst_constants.pc)')
option('build_tests', type: 'boolean', value: true, description: 'control if tests are built or not') option('build_tests', type: 'boolean', value: true, description: 'control if tests are built or not')
option('build_examples', type: 'boolean', value: true, description: 'control if examples is built or not') option('build_examples', type: 'boolean', value: true, description: 'control if examples is built or not')
option('lib_install_dir', type: 'string', value: '', description: 'Override install dir for the shared library (used by the fourdst umbrella to place libs inside the Python package in wheel builds). Empty = default libdir.') option('build_python', type: 'boolean', value: false, description: 'Build in python mode. Note that this does not generate a wheel; rather, this is the appropriate option to turn on when packaging this component inside of a wheel.')
option('header_install_dir', type: 'string', value: '', description: 'Override the header install root (used by the fourdst umbrella to place headers inside the Python package in wheel builds). Empty = default includedir.')

View File

@@ -5,14 +5,13 @@ const_sources = files(
# Define the libconst library so it can be linked against by other parts of the build system # Define the libconst library so it can be linked against by other parts of the build system
fourdst_component_libdir = get_option('lib_install_dir') != '' ? get_option('lib_install_dir') : get_option('libdir')
libconst = library('const', libconst = library('const',
const_sources, const_sources,
include_directories: include_directories('include'), include_directories: include_directories('include'),
cpp_args: ['-fvisibility=default'], cpp_args: ['-fvisibility=default'],
dependencies: [const_data_dep], dependencies: [const_data_dep],
install : true, install : true,
install_dir: fourdst_component_libdir) install_dir: constants_libdir)
const_dep = declare_dependency( const_dep = declare_dependency(
include_directories: include_directories('include'), include_directories: include_directories('include'),
@@ -24,8 +23,4 @@ const_headers = files(
'include/fourdst/constants/const.h' 'include/fourdst/constants/const.h'
) )
constants_header_install_dir = get_option('header_install_dir') != '' \
? get_option('header_install_dir') / 'fourdst' / 'constants' \
: get_option('includedir') / 'fourdst' / 'constants'
install_headers(const_headers, install_dir: constants_header_install_dir) install_headers(const_headers, install_dir: constants_header_install_dir)