diff --git a/build-config/libcomposition/meson.build b/build-config/libcomposition/meson.build index ea1e027..6eae463 100644 --- a/build-config/libcomposition/meson.build +++ b/build-config/libcomposition/meson.build @@ -2,7 +2,8 @@ composition_p = subproject('libcomposition', default_options: [ 'pkg_config=' + get_option('pkg_config').to_string(), 'build_tests=' + get_option('build_tests').to_string(), - 'build_examples=false' + 'build_examples=false', + 'build_python=' + get_option('build_python').to_string() ]) comp_dep = composition_p.get_variable('composition_dep') libcomposition = composition_p.get_variable('libcomposition') diff --git a/build-config/libconfig/meson.build b/build-config/libconfig/meson.build index 8c7ec5d..d6f9c91 100644 --- a/build-config/libconfig/meson.build +++ b/build-config/libconfig/meson.build @@ -2,6 +2,7 @@ config_p = subproject('libconfig', default_options:[ 'pkg_config=' + get_option('pkg_config').to_string(), 'build_tests=' + get_option('build_tests').to_string(), - 'build_examples=false' - ]) + 'build_examples=false', + 'build_python=' + get_option('build_python').to_string() + ]) config_dep = config_p.get_variable('config_dep') diff --git a/build-config/libconstants/meson.build b/build-config/libconstants/meson.build index 7257a03..59158ae 100644 --- a/build-config/libconstants/meson.build +++ b/build-config/libconstants/meson.build @@ -1,8 +1,9 @@ const_p = subproject('libconstants', default_options: [ 'pkg_config=' + get_option('pkg_config').to_string(), 'build_tests=' + get_option('build_tests').to_string(), - 'build_examples=false' - ]) + 'build_examples=false', + 'build_python=' + get_option('build_python').to_string() + ]) const_dep = const_p.get_variable('const_dep') libconst = const_p.get_variable('libconst') diff --git a/build-config/liblogging/meson.build b/build-config/liblogging/meson.build index f52b0de..c807b19 100644 --- a/build-config/liblogging/meson.build +++ b/build-config/liblogging/meson.build @@ -1,7 +1,8 @@ logging_p = subproject('liblogging', default_options: [ 'pkg_config=' + get_option('pkg_config').to_string(), 'build_tests=' + get_option('build_tests').to_string(), - 'build_examples=false' + 'build_examples=false', + 'build_python=' + get_option('build_python').to_string() ]) liblogging = logging_p.get_variable('liblogging') diff --git a/build-config/meson.build b/build-config/meson.build index f56aa3b..bd1465d 100644 --- a/build-config/meson.build +++ b/build-config/meson.build @@ -1,16 +1,16 @@ -if get_option('build_lib_comp') or get_option('build_lib_all') or get_option('build_python') - subdir('libcomposition') -endif if get_option('build_lib_config') or get_option('build_lib_all') or get_option('build_python') subdir('libconfig') endif if get_option('build_lib_const') or get_option('build_lib_all') or get_option('build_python') subdir('libconstants') endif -if get_option('build_lib_log') or get_option('build_lib_all') +if get_option('build_lib_log') or get_option('build_lib_all') or get_option('build_python') subdir('liblogging') endif -if get_option('build_lib_plugin') or get_option('build_lib_all') +if get_option('build_lib_comp') or get_option('build_lib_all') or get_option('build_python') + subdir('libcomposition') +endif +if get_option('build_lib_plugin') or get_option('build_lib_all') and not get_option('build_python') subdir('libplugin') endif diff --git a/build-python/meson.build b/build-python/meson.build index 4d07bd7..cbd8c22 100644 --- a/build-python/meson.build +++ b/build-python/meson.build @@ -1,5 +1,10 @@ py_installation = import('python').find_installation('python3', pure: false) +if host_machine.system() == 'darwin' + fourdst_ext_rpath = '@loader_path/lib' +else + fourdst_ext_rpath = '$ORIGIN/lib' +endif py_mod = py_installation.extension_module( '_phys', sources: [ @@ -16,6 +21,8 @@ py_mod = py_installation.extension_module( ], cpp_args : ['-UNDEBUG'], install : true, + build_rpath: fourdst_ext_rpath, + install_rpath: fourdst_ext_rpath, subdir: 'fourdst', ) diff --git a/meson.build b/meson.build index 687d275..3586de1 100644 --- a/meson.build +++ b/meson.build @@ -1,8 +1,15 @@ -project('fourdst', 'cpp', version: 'v0.10.3', default_options: ['cpp_std=c++23'], meson_version: '>=1.5.0') +project('fourdst', 'cpp', version: 'v0.10.4', default_options: ['cpp_std=c++23'], meson_version: '>=1.5.0') add_project_arguments('-fvisibility=default', language: 'cpp') - +if get_option('build_python') + py_installation = import('python').find_installation('python3', pure: false) + fourdst_wheel_libdir = 'fourdst/lib' # relative to the python platlib + fourdst_wheel_headerdir = 'fourdst/include' +else + fourdst_wheel_libdir = '' + fourdst_wheel_headerdir = '' +endif # Configure vendor libraries subdir('build-config') diff --git a/pyproject.toml b/pyproject.toml index 7176efd..497ed61 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,5 @@ [build-system] -requires = [ - "meson-python>=0.15.0", # Use a recent version - "meson>=1.6.0", # Specify your Meson version requirement - "pybind11>=2.10" # pybind11 headers needed at build time -] +requires = ["meson-python>=0.19,<0.20", "meson>=1.9.1,<1.10", "pybind11>=2.10"] build-backend = "mesonpy" [project] @@ -33,6 +29,11 @@ dependencies = [ [project.scripts] fourdst-cli = "fourdst.cli.main:app" +fourdst-compiler-flags = "fourdst:get_compiler_flags_formatted" +fourdst-include-dirs = "fourdst:get_include_dirs" +fourdst-lib-dirs = "fourdst:get_lib_dirs" +fourdst-rpath-flags = "fourdst:get_rpath_flags" +fourdst-version = "fourdst:print_fourdst_version" [tool.meson-python.args] setup = [ diff --git a/src-pybind/fourdst/__init__.py b/src-pybind/fourdst/__init__.py index 9f581a6..b700d41 100644 --- a/src-pybind/fourdst/__init__.py +++ b/src-pybind/fourdst/__init__.py @@ -19,4 +19,46 @@ from importlib.metadata import version, PackageNotFoundError try: __version__ = version("fourdst") except PackageNotFoundError: - __version__ = "0.0.0+unknown" \ No newline at end of file + __version__ = "0.0.0+unknown" + +import os +from pathlib import Path +from typing import List + +_PACKAGE_DIR = Path(__file__).resolve().parent + +def get_lib_dirs() -> List[str]: + return [ + os.fspath(_PACKAGE_DIR / "lib"), + os.fspath(_PACKAGE_DIR / "lib" / "vendor"), + ] + +def get_include_dirs() -> List[str]: + return [ + os.fspath(_PACKAGE_DIR / "include"), + os.fspath(_PACKAGE_DIR / "include" / "fourdst" / "vendor"), + ] + +def get_rpath_flags() -> List[str]: + return ["-Wl,-rpath," + os.fspath(_PACKAGE_DIR / "lib")] + +def get_lib_flags() -> List[str]: + flags = ["-L" + d for d in get_lib_dirs()] + flags += ["-lcomposition", "-llogging", "-lconst", "-lreflect_cpp"] + flags += get_rpath_flags() + return flags + +def get_include_flags() -> List[str]: + return ["-I" + d for d in get_include_dirs()] + +def get_compiler_flags() -> List[str]: + return get_include_flags() + get_lib_flags() + +def get_compiler_flags_formatted() -> int: + flags = get_compiler_flags() + print(' '.join(flags)) + return 0 + +def print_fourdst_version() -> int: + print("fourdst version: " + __version__) + return 0 \ No newline at end of file diff --git a/subprojects/libcomposition.wrap b/subprojects/libcomposition.wrap index 77a0647..b5ce668 100644 --- a/subprojects/libcomposition.wrap +++ b/subprojects/libcomposition.wrap @@ -1,4 +1,4 @@ [wrap-git] url = https://github.com/4D-STAR/libcomposition.git -revision = v2.4.3 +revision = v2.4.8 depth = 1 diff --git a/subprojects/libconfig.wrap b/subprojects/libconfig.wrap index 49d98f4..0bd4637 100644 --- a/subprojects/libconfig.wrap +++ b/subprojects/libconfig.wrap @@ -1,4 +1,4 @@ [wrap-git] url = https://github.com/4D-STAR/libconfig.git -revision = v2.2.6 +revision = v2.2.10 depth = 1 diff --git a/subprojects/libconstants.wrap b/subprojects/libconstants.wrap index 6faca3d..ab6e243 100644 --- a/subprojects/libconstants.wrap +++ b/subprojects/libconstants.wrap @@ -1,4 +1,4 @@ [wrap-git] url = https://github.com/4D-STAR/libconstants.git -revision = v1.1.3 +revision = v1.1.7 depth = 1 diff --git a/subprojects/liblogging.wrap b/subprojects/liblogging.wrap index 04a4154..fcea9dc 100644 --- a/subprojects/liblogging.wrap +++ b/subprojects/liblogging.wrap @@ -1,4 +1,4 @@ [wrap-git] url = https://github.com/4D-STAR/liblogging.git -revision = v1.1.3 +revision = v1.1.7 depth = 1