From d725077ff790bd4abd1ffca4ea3de3c6a0642f33 Mon Sep 17 00:00:00 2001 From: Liviu Ionescu Date: Sun, 20 Jun 2021 17:28:59 +0300 Subject: [PATCH] [#6] - rework meson and use subdir() --- assets/sources/libs/adder/meson-liquid.build | 34 +++++++++++++++++ assets/sources/libs/meson.build | 14 +++++++ assets/sources/{meta => }/meson-liquid.build | 40 ++++++++++++++------ assets/sources/package-liquid.json | 4 +- lib/template.js | 9 ++++- 5 files changed, 85 insertions(+), 16 deletions(-) create mode 100644 assets/sources/libs/adder/meson-liquid.build create mode 100644 assets/sources/libs/meson.build rename assets/sources/{meta => }/meson-liquid.build (82%) diff --git a/assets/sources/libs/adder/meson-liquid.build b/assets/sources/libs/adder/meson-liquid.build new file mode 100644 index 0000000..d423383 --- /dev/null +++ b/assets/sources/libs/adder/meson-liquid.build @@ -0,0 +1,34 @@ +# +# This file is part of the xPack project (http://xpack.github.io). +# Copyright (c) 2021 Liviu Ionescu +# +# This Software is provided under the terms of the MIT License. +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +adderSourceFiles = files( + 'src/add.c' +) + +adderIncludeFolders = [ + 'include' +] + +# https://mesonbuild.com/Reference-manual.html#library +adderLibrary = static_library('adder', + sources: adderSourceFiles, + include_directories: adderIncludeFolders, + c_args: c_compiler_options, + # cpp_args: cpp_compiler_options, + link_args: linker_options, + implicit_include_directories: false +) + +# https://mesonbuild.com/Reference-manual.html#declare_dependency +adderLibraryDependency = declare_dependency( + include_directories: adderIncludeFolders +) + +# ----------------------------------------------------------------------------- diff --git a/assets/sources/libs/meson.build b/assets/sources/libs/meson.build new file mode 100644 index 0000000..8ae3037 --- /dev/null +++ b/assets/sources/libs/meson.build @@ -0,0 +1,14 @@ +# +# This file is part of the xPack project (http://xpack.github.io). +# Copyright (c) 2021 Liviu Ionescu +# +# This Software is provided under the terms of the MIT License. +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +# Add all other library folders here. +subdir('adder') + +# ----------------------------------------------------------------------------- diff --git a/assets/sources/meta/meson-liquid.build b/assets/sources/meson-liquid.build similarity index 82% rename from assets/sources/meta/meson-liquid.build rename to assets/sources/meson-liquid.build index 963eb2d..ed3b7f9 100644 --- a/assets/sources/meta/meson-liquid.build +++ b/assets/sources/meson-liquid.build @@ -29,8 +29,8 @@ compiler = meson.get_compiler('c') # ----------------------------------------------------------------------------- # A generic way to handle having the metadata files grouped in a folder. -xpack_project_folder = fs.parent(meson.current_source_dir()) -# xpack_project_folder = meson.current_source_dir() +# xpack_project_folder = fs.parent(meson.current_source_dir()) +xpack_project_folder = meson.current_source_dir() # ----------------------------------------------------------------------------- @@ -45,14 +45,12 @@ message('Project path: ' + xpack_project_folder) # All project source files. sourceFiles = files( - xpack_project_folder + '/src/hello-world.{{ fileExtension }}', - xpack_project_folder + '/libs/adder/src/add.c' + 'src/hello-world.{{ fileExtension }}', ) # All folders with header files. includeFolders = [ - xpack_project_folder + '/include', - xpack_project_folder + '/libs/adder/include' + 'include', ] # Compiler preprocessor definitions. @@ -73,15 +71,25 @@ common_options = [] if compiler.get_id() == 'gcc' or compiler.get_id().contains('clang') common_options += [ '-fmessage-length=0', - '-fsigned-char', + '-fsigned-char' + ] + # This is used in conjunction with linker `--gc-sections`. + common_options += [ '-ffunction-sections', '-fdata-sections' ] + if get_option('buildtype') == 'release' or get_option('buildtype') == 'debugoptimized' # Optional, comment it out to disable link time optimizations. - common_options += [ - '-flto' - ] + common_options += [ + '-flto' + ] + endif + if get_option('buildtype').contains('debug') + common_options += [ + '-fno-omit-frame-pointer' + ] + endif elif compiler.get_id() == 'msvc' common_options += [ # Add MSVC options here. @@ -102,8 +110,9 @@ if build_machine.system() == 'darwin' linker_options += [ '-Wl,-dead_strip' ] -else +else # Linux or Windows if compiler.get_id() == 'gcc' + # TODO: clang with gold might need it too. linker_options += [ '-Wl,--gc-sections' ] @@ -124,14 +133,21 @@ c_std = 'c11' # gnu++2a, gnu++20, vc++14, vc++17, vc++latest cpp_std = 'gnu++17' +{% endif -%} +# ----------------------------------------------------------------------------- + +# https://mesonbuild.com/Reference-manual.html#subdir +subdir('libs') + # ----------------------------------------------------------------------------- # Create the application. -{% endif -%} # https://mesonbuild.com/Reference-manual.html#executable application = executable(meson.project_name(), sources: sourceFiles, include_directories: includeFolders, + dependencies: [adderLibraryDependency], + link_with: [adderLibrary], c_args: c_compiler_options, {% if language == 'cpp' -%} cpp_args: cpp_compiler_options, diff --git a/assets/sources/package-liquid.json b/assets/sources/package-liquid.json index 32ec58b..3b10abd 100644 --- a/assets/sources/package-liquid.json +++ b/assets/sources/package-liquid.json @@ -64,11 +64,11 @@ {% if toolchain == "gcc" -%} "toolchainFileName": "toolchain-gcc-meson.ini", {% endif -%} - {% raw %}"commandPrepare": "meson setup --backend ninja --buildtype {{ properties.buildType }} {{ properties.buildFolderRelativePath }} meta",{% endraw %} + {% raw %}"commandPrepare": "meson setup --backend ninja --buildtype {{ properties.buildType }} {{ properties.buildFolderRelativePath }} .",{% endraw %} {% if toolchain == "gcc" -%} {% raw %}"commandPrepareWithToolchain": "{{ properties.commandPrepare }} --native-file meta/{{ properties.toolchainFileName }}",{% endraw %} {% endif -%} - {% raw %}"commandReconfigure": "meson setup --reconfigure {{ properties.buildFolderRelativePath }} meta", + {% raw %}"commandReconfigure": "meson setup --reconfigure {{ properties.buildFolderRelativePath }} .", "commandBuild": "meson compile -C {{ properties.buildFolderRelativePath }} -v", "commandClean": "meson compile -C {{ properties.buildFolderRelativePath }} --clean",{% endraw %} {% elsif buildGenerator == "autotools" -%} diff --git a/lib/template.js b/lib/template.js index 8eec981..79b5b0e 100644 --- a/lib/template.js +++ b/lib/template.js @@ -339,13 +339,18 @@ class XpmInitTemplate { await this.copyFile('libs/adder/src/add.c') if (liquidMap.buildGenerator === 'cmake') { - await this.render('meta/CMakeLists-liquid.txt', 'meta/CMakeLists.txt', + await this.render('meta/CMakeLists-liquid.txt', + 'meta/CMakeLists.txt', liquidMap) await this.copyFile('meta/toolchain-gcc.cmake') } else if (liquidMap.buildGenerator === 'meson') { - await this.render('meta/meson-liquid.build', 'meta/meson.build', + await this.render('meson-liquid.build', 'meson.build', liquidMap) await this.copyFile('meta/toolchain-gcc-meson.ini') + await this.copyFile('libs/meson.build') + await this.render('libs/adder/meson-liquid.build', + 'libs/adder/meson.build', + liquidMap) } else if (liquidMap.buildGenerator === 'autotools') { await this.copyFile('meta/configure') await this.copyFile('meta/make-template/libs/adder/src/folder.mk')