Skip to content

Commit

Permalink
meson rework
Browse files Browse the repository at this point in the history
  • Loading branch information
ilg-ul committed Oct 23, 2023
1 parent 95ec308 commit 4de3322
Show file tree
Hide file tree
Showing 32 changed files with 1,418 additions and 1,583 deletions.
39 changes: 22 additions & 17 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ message('Processing xPack @micro-os-plus/micro-test-plus...')

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

xpack_common_args = []
xpack_c_args = []
xpack_cpp_args = []
xpack_include_directories = []
xpack_sources = []
xpack_compile_definitions = []
_local_compile_args = [] # Common C/C++ args.
_local_compile_c_args = []
_local_compile_cpp_args = []
_local_include_directories = []
_local_sources = []
_local_compile_definitions = []
_local_dependencies = []
_local_link_args = []
_local_link_with = []

xpack_include_directories += [
_local_include_directories += [
'include',
]

xpack_sources += [
_local_sources += [
'src/micro-test-plus.cpp',
'src/test-runner.cpp',
'src/test-reporter.cpp',
Expand All @@ -49,19 +52,21 @@ xpack_sources += [

# https://mesonbuild.com/Reference-manual_functions.html#declare_dependency
micro_os_plus_micro_test_plus_dependency = declare_dependency(
include_directories: include_directories(xpack_include_directories),
compile_args: xpack_common_args,
sources: files(xpack_sources),
dependencies: []
include_directories: include_directories(_local_include_directories),
compile_args: _local_compile_args,
sources: files(_local_sources),
dependencies: _local_dependencies,
link_args: _local_link_args,
link_with: _local_link_with,
)
# meson dependencies cannot differentiate c/cpp args; pass them separately.
micro_os_plus_micro_test_plus_dependency_compile_c_args = _local_compile_c_args
micro_os_plus_micro_test_plus_dependency_compile_cpp_args = _local_compile_cpp_args

# micro_os_plus_micro_test_plus_dependency_c_args = xpack_c_args
# micro_os_plus_micro_test_plus_dependency_cpp_args = xpack_cpp_args

foreach name : xpack_include_directories
foreach name : _local_include_directories
message('+ -I ' + name)
endforeach
foreach name : xpack_sources + xpack_common_args
foreach name : _local_sources + _local_compile_definitions + _local_compile_args + _local_compile_c_args + _local_compile_cpp_args
message('+ ' + name)
endforeach
message('> micro_os_plus_micro_test_plus_dependency')
Expand Down
28 changes: 18 additions & 10 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ project('micro-os-plus-micro-test-plus-tests',
# c++2a, c++1z, gnu++03, gnu++11, gnu++14, gnu++17, gnu++1z,
# gnu++2a, gnu++20, vc++14, vc++17, vc++latest

# -----------------------------------------------------------------------------
# Global definitions #

enable_sample_test = true
enable_unit_test = true

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

fs = import('fs')
Expand Down Expand Up @@ -71,22 +77,20 @@ message('Build type: ' + get_option('buildtype'))
message('Platform name: ' + xpack_platform_name)

# -----------------------------------------------------------------------------
## Global definitions ##

enable_sample_test = true
enable_unit_test = true

# https://mesonbuild.com/Reference-manual.html#subdir
subdir('meson/common')
subdir('meson/common-options')
subdir('xpacks/@micro-os-plus/build-helper/meson/enable-all-warnings')
subdir('platform-'+ xpack_platform_name + '/meson/common')

# Since the order of processing is significative, include it in dependencies.
# subdir('platform-'+ xpack_platform_name + '/meson/platform-options')

# -----------------------------------------------------------------------------
## Dependencies ##
# Dependencies #

subdir('platform-'+ xpack_platform_name + '/meson/dependencies')
# Set `xpack_dependencies_folders` with the platform specific dependencies.
subdir('platform-'+ xpack_platform_name + '/meson/dependencies-folders')

# xpack_dependencies_folders[] must be set in the platform.
foreach dep: xpack_dependencies_folders
message('Adding ' + dep + '...')
subdir(dep)
Expand All @@ -95,9 +99,13 @@ endforeach
# -----------------------------------------------------------------------------

# Include the project library, defined one level above.
message('Adding top library...')
subdir('top')

# Include the platform specific code.
# -----------------------------------------------------------------------------
# Platform specifics #

# Include the platform specific targets and tests.
subdir('platform-' + xpack_platform_name)

# -----------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@

message('Including top common definitions...')

xpack_global_common_args = []
xpack_global_include_directories = []
xpack_global_compile_definitions = []
_local_compile_args = [] # Common C/C++ args.
_local_compile_c_args = []
_local_compile_cpp_args = []
_local_include_directories = []
_local_sources = []
_local_compile_definitions = []
_local_dependencies = []
_local_link_args = []
_local_link_with = []

# Assume GCC or clang, for MSVC things are different
# https://mesonbuild.com/Reference-tables.html#c_compiler-ids
Expand All @@ -26,34 +32,34 @@ if c_compiler.get_id() == 'gcc' or c_compiler.get_id().contains('clang')
# Global compiler preprocessor definitions.
# Native builds may not use them.
if get_option('buildtype').contains('debug')
xpack_global_compile_definitions += [ '-DDEBUG' ]
xpack_global_compile_definitions += [ '-DMICRO_OS_PLUS_DEBUG' ]
xpack_global_compile_definitions += [ '-DMICRO_OS_PLUS_TRACE' ]
_local_compile_definitions += [ '-DDEBUG' ]
_local_compile_definitions += [ '-DMICRO_OS_PLUS_DEBUG' ]
_local_compile_definitions += [ '-DMICRO_OS_PLUS_TRACE' ]
endif
if get_option('buildtype') == 'release'
xpack_global_compile_definitions += [ '-DNDEBUG' ]
_local_compile_definitions += [ '-DNDEBUG' ]
endif
xpack_global_compile_definitions += [ '-DMICRO_OS_PLUS_INCLUDE_CONFIG_H' ]
_local_compile_definitions += [ '-DMICRO_OS_PLUS_INCLUDE_CONFIG_H' ]

# DO NOT define it globally, one test does not need it!
# xpack_global_compile_definitions += ['-DMICRO_OS_PLUS_TRACE']
# _local_compile_definitions += ['-DMICRO_OS_PLUS_TRACE']

# Options for both compilers and linkers. When using `-flto`, all options
# must also be passed to the linker.

if get_option('buildtype') == 'debug'
# xpack_global_common_args += [ '-O0' ]
# _local_compile_args += [ '-O0' ]
elif get_option('buildtype') == 'debugoptimized'
xpack_global_common_args += [ '-Og' ] # Override -O2
_local_compile_args += [ '-Og' ] # Override -O2
elif get_option('buildtype') == 'minsize'
# xpack_global_common_args += [ '-Os' ]
# _local_compile_args += [ '-Os' ]
elif get_option('buildtype') == 'release'
# xpack_global_common_args += [ '-O3' ]
# _local_compile_args += [ '-O3' ]
else
xpack_global_common_args += [ '-O' ]
_local_compile_args += [ '-O' ]
endif

xpack_global_common_args += [
_local_compile_args += [
'-fmessage-length=0',
'-fsigned-char',

Expand All @@ -62,23 +68,25 @@ if c_compiler.get_id() == 'gcc' or c_compiler.get_id().contains('clang')
'-fdata-sections'
]

add_global_arguments(
xpack_global_include_directories + xpack_global_common_args + xpack_global_compile_definitions,

language: [ 'c', 'cpp' ]
common_options_dependency = declare_dependency(
include_directories: include_directories(_local_include_directories),
sources: files(_local_sources),
compile_args: _local_compile_args + _local_compile_definitions,
# When `-flto` is used, the compile options must be passed to the linker too.
dependencies: _local_dependencies,
link_args: _local_compile_args + _local_link_args,
link_with: _local_link_with,
)
common_options_dependency_compile_c_args = _local_compile_c_args
common_options_dependency_compile_cpp_args = _local_compile_cpp_args

foreach xn : xpack_global_include_directories + xpack_global_common_args + xpack_global_compile_definitions
foreach xn : _local_include_directories
message('G+ -I ' + xn)
endforeach
foreach xn : _local_sources + _local_compile_definitions + _local_compile_args + _local_compile_c_args + _local_compile_cpp_args + _local_link_args
message('G+ ' + xn)
endforeach

# When `-flto` is used, the compile options must be passed to the linker too.
add_global_link_arguments(
xpack_global_common_args,

language: [ 'c', 'cpp' ]
)

# Warnings must be included from the tests.

else
Expand Down
38 changes: 25 additions & 13 deletions tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4de3322

Please sign in to comment.