Skip to content

Commit

Permalink
[#6] - rework meson and use subdir()
Browse files Browse the repository at this point in the history
  • Loading branch information
ilg-ul committed Jun 20, 2021
1 parent 9418609 commit d725077
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 16 deletions.
34 changes: 34 additions & 0 deletions assets/sources/libs/adder/meson-liquid.build
Original file line number Diff line number Diff line change
@@ -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
)

# -----------------------------------------------------------------------------
14 changes: 14 additions & 0 deletions assets/sources/libs/meson.build
Original file line number Diff line number Diff line change
@@ -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')

# -----------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -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()

# -----------------------------------------------------------------------------

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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'
]
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions assets/sources/package-liquid.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" -%}
Expand Down
9 changes: 7 additions & 2 deletions lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit d725077

Please sign in to comment.