From e9c67d6c39b1a4ee9508825c02d1cc475f36b4db Mon Sep 17 00:00:00 2001 From: Aesara Binder Date: Sat, 21 Sep 2024 12:09:55 +0930 Subject: [PATCH] Draft final replacement for build_ext Signed-off-by: Aesara Binder --- meson.build | 7 ++-- meson.options | 72 +++++++++++------------------------------ src/platlib/meson.build | 48 ++++++++++++++------------- 3 files changed, 48 insertions(+), 79 deletions(-) diff --git a/meson.build b/meson.build index b50b5f629..b49771e50 100644 --- a/meson.build +++ b/meson.build @@ -8,8 +8,7 @@ # /meson.build -- The root buildfile for Meson project('MyPaint', 'cpp', - version : '2.1.0-alpha', - default_options : ['warning_level=3', 'cpp_std=c++14']) + version : '2.1.0-alpha') # Lint version number ver_prerel_valid = ['', 'alpha', 'beta', 'rc'] @@ -93,7 +92,9 @@ endforeach # Helper commands git = find_program('git', required : true) linguas_cmd = find_program('build-aux/meson/get_locales.py', required : true) -numpy_include_cmd = find_program('build-aux/meson/numpy_include.py', required : true) +numpy_include_cmd = find_program('build-aux/meson/numpy_include.py', required : true) # FIXME: meson issue #9598 +pkgconfig = find_program('pkg-config', required: true) +swig = find_program('swig', required: true) ## Supported locales opt_translation_threshold = get_option('translation_threshold').to_string() diff --git a/meson.options b/meson.options index 0d266263b..05e598e4b 100644 --- a/meson.options +++ b/meson.options @@ -16,66 +16,32 @@ option('libdir_noarch', type : 'string', option('brushes_dir', type : 'string', description : 'use the provided argument as brush directory path') option('libmypaint_locale_dir', type : 'string', - description : 'Set the location of the libmypaint message catalogs.\n' + - 'If libmypaint_locale_pkgconf is true, using this ' + - 'flag will raise an error. If neither flag is used, or the value ' + - 'passed is the empty string, the directory used for mypaint\'s own ' + - 'locale data is used for libmypaint\'s as well.') + description : 'Set the location of the libmypaint message catalogs. If libmypaint_locale_pkgconf is true, using ' + + 'this flag will raise an error. If neither flag is used, or the value passed is the empty string, the directory ' + + 'used for mypaint\'s own locale data is used for libmypaint\'s as well.') option('libmypaint_locale_pkgconfig', type : 'boolean', value : false, - description: 'Set the location of libmypaint\'s message catalogs using pkg-config.\n' + - 'The path is set to {prefix}/share/locale, where "prefix" is ' + - 'fetched from libmypaint\'s pkg-config data.') + description: 'Set the location of libmypaint\'s message catalogs using pkg-config. The path is set to ' + + '{prefix}/share/locale, where "prefix" is fetched from libmypaint\'s pkg-config data.') option('translation_threshold', type : 'integer', min : 0, max : 100, value : 0, - description : 'Limit translations to those with a completion percentage' + - 'at or above the given threshold. Argument range: [0..100]') + description : 'Limit translations to those with a completion percentage at or above the given threshold. Argument ' + + 'range: [0..100]') # Options for configuring C++ extensions -option('set_rpath', type : 'boolean', value : false, - description : '[MyPaint] Add dependency library paths from pkg-config ' + - 'to the rpath of mypaintlib (linux/bsd only)') - -option('disable_openmp', type: 'boolean', value : false, +option('disable_openmp', type : 'boolean', value : false, description : 'Don\'t use openmp, even if the platform supports it.') +option('openmp_cflag', type : 'string', value : '-fopenmp', + description : 'Some versions of clang require different openmp flags than gcc to link correctly, use this to ' + + 'change the openmp flag used during compilation') + +option('openmp_ldflag', type : 'string', value : '-fopenmp', + description : 'Like the \'openmp_cflag\' option, but for the linking step') +option('use_optimisations', type : 'boolean', value : true, + description : 'Enable autovectorisation and other compiler optimisations. It is recommended that this is disabled ' + + 'if libmypaint was not built using compiler optimisations.') -# ('build-lib=', 'b', "directory for compiled extension modules"), -# ('build-temp=', 't', "directory for temporary files (build by-products)"), -# ( -# 'plat-name=', -# 'p', -# "platform name to cross-compile for, if supported " -# f"[default: {get_platform()}]", -# ), -# ( -# 'inplace', -# 'i', -# "ignore build-lib and put compiled extensions into the source " -# "directory alongside your pure Python modules", -# ), -# ( -# 'include-dirs=', -# 'I', -# "list of directories to search for header files" + sep_by, -# ), -# ('define=', 'D', "C preprocessor macros to define"), -# ('undef=', 'U', "C preprocessor macros to undefine"), -# ('libraries=', 'l', "external C libraries to link with"), -# ( -# 'library-dirs=', -# 'L', -# "directories to search for external C libraries" + sep_by, -# ), -# ('rpath=', 'R', "directories to search for shared C libraries at runtime"), -# ('link-objects=', 'O', "extra explicit link objects to include in the link"), -# ('debug', 'g', "compile/link with debugging information"), -# ('force', 'f', "forcibly build everything (ignore file timestamps)"), -# ('compiler=', 'c', "specify the compiler type"), -# ('parallel=', 'j', "number of parallel build jobs"), -# ('swig-cpp', None, "make SWIG create C++ files (default is C)"), -# ('swig-opts=', None, "list of SWIG command line options"), -# ('swig=', None, "path to the SWIG executable"), -# ('user', None, "add user include, library and rpath"), -# ] +option('debug_optimisations', type : 'boolean', value : false, + description : 'Enable optimisations for debug builds (see \'use_optimisations\' option') diff --git a/src/platlib/meson.build b/src/platlib/meson.build index 3f22ff964..842f2422a 100644 --- a/src/platlib/meson.build +++ b/src/platlib/meson.build @@ -9,29 +9,8 @@ # /src/lib_ext/meson.build # Basic declarations -swig = find_program('swig', required: true) -pkgconfig = find_program('pkg-config', required: true) numpy_include = '-I' + run_command(numpy_include_cmd, check: true).stdout().strip() -# Platform stuff -opt_set_rpath = get_option('set_rpath') -rpath_os = ['linux', 'freebsd', 'netbsd', 'openbsd'] - -if opt_set_rpath - if (rpath_os.contains(host_os)) - error('Testing') #TODO - else - error('Option set_rpath is active but host machine not linux/bsd') - endif - # The directories in runtime_library_dirs will be added to the linker - # args as '-Wl,-R{dirs}' This _should_ be compatible with the --rpath= - # build_ext option - #for ext in self.extensions: - #rt_libs = uniq(ext.library_dirs + ext.runtime_library_dirs) - # Retain original list reference, just in case - #ext.runtime_library_dirs[:] = rt_libs -endif - # swig configuration ## Check command version and set python opts accordingly @@ -67,11 +46,11 @@ mypaintlib_swig = custom_target( mypaintlib_compile_args = [ numpy_include, '--std=c++11', - '-Wall', + '-Wall', # FIXME: this is duplicated in the final command '-Wno-sign-compare', '-Wno-write-strings', '-D_POSIX_C_SOURCE=200809L', - '-g'] # always include symbols, for profiling + '-g'] # always include symbols, for profiling, FIXME: this is duplicated in the final command. mypaintlib_compile_args += ['-DNO_TESTS'] # FIXME: we're building against shared libmypaint now mypaintlib_link_args = [] @@ -94,6 +73,29 @@ mypaintlib_sources = [ 'fill/blur.cpp', 'fill/morphology.cpp'] +## openmp +## macOS doesn't ship with openmp by default, but there should be ways to work around it +## https://mac.r-project.org/openmp/ +if not get_option('disable_openmp') and host_os != 'darwin' + mypaintlib_compile_args += get_option('openmp_cflag') + mypaintlib_link_args += get_option('openmp_ldflag') +endif + +## Optimisations +if get_option('use_optimisations') + optimised_builds = ['debugoptimized', 'release'] + if optimised_builds.contains(get_option('buildtype')) or get_option('debug_optimisations') + mypaintlib_compile_args += [ + '-Ofast', + '-ftree-vectorize', + '-fopt-info-vec-optimized', + '-march=native', + '-mtune=native', + '-funsafe-math-optimizations', + '-funsafe-loop-optimizations'] + endif +endif + # Build shared library shared_library( # The old build system produced "_mypaintlib.cpython-311-x86_64-linux-gnu.so". While we can try to match it, this is