Skip to content

Commit

Permalink
hosted/meson: Created a Meson build system for BMDA
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmux committed Dec 20, 2023
1 parent e624771 commit 03ca253
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 4 deletions.
8 changes: 8 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ if meson.is_subproject()
include_directories: bmd_core_includes,
link_with: libbmd,
)
else
# BMDA executable
bmda = executable(
'blackmagic',
dependencies: [libbmd_core, bmda_platform],
native: is_cross_build,
)
alias_target('bmda', bmda)
endif

# We report this at the end of the configuration, so it's easier to spot
Expand Down
7 changes: 3 additions & 4 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,20 @@ libbmd_core_sources = files(
'command.c',
'crc32.c',
'exception.c',
'gdb_hostio.c',
'gdb_main.c',
'gdb_packet.c',
'hex_utils.c',
'main.c',
'maths_utils.c',
'morse.c',
'remote.c',
'timing.c',
)

# Define sources used only by the firmware
bmd_core_sources = [
libbmd_core_sources,
files(
'gdb_hostio.c',
'remote.c',
),
]

bmd_core_args = []
Expand Down Expand Up @@ -114,6 +112,7 @@ if is_firmware_build
# Get probe host and platform dependencies
subdir('platforms')
endif
subdir('platforms/hosted')

summary(
{
Expand Down
123 changes: 123 additions & 0 deletions src/platforms/hosted/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# This file is part of the Black Magic Debug project.
#
# Copyright (C) 2023 1BitSquared <[email protected]>
# Written by Rachel Mant <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

bmda_includes = include_directories('.')

bmda_sources = files(
'platform.c',
'gdb_if.c',
'rtt_if.c',
'cli.c',
'utils.c',
'probe_info.c',
'debug.c',
'bmp_remote.c',
'bmp_libusb.c',
'cmsis_dap.c',
'dap.c',
'dap_command.c',
'dap_swd.c',
'dap_jtag.c',
'stlinkv2.c',
'stlinkv2_jtag.c',
'stlinkv2_swd.c',
'ftdi_bmp.c',
'ftdi_jtag.c',
'ftdi_swd.c',
'jlink.c',
'jlink_jtag.c',
'jlink_swd.c',
)
subdir('remote')

bmda_args = [
'-DPC_HOSTED=1',
'-DHOSTED_BMP_ONLY=0',
]
bmda_link_args = []
bmda_deps = []

cc = is_cross_build ? cc_native : cc_host

# Determine if we're on a MSYS2 environment of some kind
# If the compiler is MSYS2 GCC or Clang (but not Clang-cl)
if build_machine.system() == 'windows' and cc.has_define('__MINGW32__')
# Check if we're in a UCRT based environment or not
if cc.has_define('_UCRT', prefix: '#include <stddef.h>')
# Force linking against the correct C runtime DLL
if cc.get_id() != 'clang'
bmda_args += ['-mcrtdll=ucrt']
bmda_link_args += ['-mcrtdll=ucrt']
endif
elif
bmda_args += ['-mcrtdll=msvcrt']
bmda_link_args += ['-mcrtdll=msvcrt']
endif
endif

if build_machine.system() in ['windows', 'cygwin']
subdir('windows')

# Make sure we build for Windows Vista and above, where the
# 'SetupDiGetDevicePropertyW()' function is available
bmda_args += ['-D_WIN32_WINNT=0x600']
bmda_link_args += [
cxx.find_library('ws2_32'),
cxx.find_library('setupapi'),
]
bmda_sources += files('serial_win.c')
else
bmda_deps += [dependency('libftdi1', method: 'pkg-config', native: is_cross_build)]
bmda_sources += files('serial_unix.c')
endif

# Pick the appropriate HIDAPI depending on platform
if build_machine.system() == 'linux'
bmda_deps += [dependency('hidapi-hidraw', method: 'pkg-config', native: is_cross_build)]
else
bmda_deps += [dependency('hidapi', method: 'pkg-config', native: is_cross_build)]
endif
bmda_deps += [
dependency(
'libusb-1.0',
version: '>=1.0.13',
method: 'pkg-config',
fallback: 'libusb',
native: is_cross_build,
)
]

bmda_platform = declare_dependency(
include_directories: bmda_includes,
sources: bmda_sources,
compile_args: bmda_args,
link_args: bmda_link_args,
dependencies: [libbmd_core, bmda_deps],
)
41 changes: 41 additions & 0 deletions src/platforms/hosted/remote/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This file is part of the Black Magic Debug project.
#
# Copyright (C) 2023 1BitSquared <[email protected]>
# Written by Rachel Mant <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

bmda_sources += files(
'protocol_v0.c',
'protocol_v0_swd.c',
'protocol_v0_jtag.c',
'protocol_v0_adiv5.c',
'protocol_v1.c',
'protocol_v1_adiv5.c',
'protocol_v2.c',
'protocol_v3.c',
'protocol_v3_adiv5.c',
)
46 changes: 46 additions & 0 deletions src/platforms/hosted/windows/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This file is part of the Black Magic Debug project.
#
# Copyright (C) 2023 1BitSquared <[email protected]>
# Written by Rachel Mant <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

bmda_sources += files('ftdi.c')

bmda_includes += include_directories('@0@/3rdparty/ftdi'.format(meson.project_source_root()))

bmda_link_args += [
cc.find_library(
'ftd2xx',
dirs: '@0@/3rdparty/ftdi/@1@'.format(meson.project_source_root(), build_machine.cpu())
)
]

configure_file(
input: '@0@/3rdparty/ftdi/@1@/ftd2xx.dll'.format(meson.project_source_root(), build_machine.cpu()),
output: '@0@/src/ftd2xx.dll'.format(meson.project_build_root()),
copy: true,
)

0 comments on commit 03ca253

Please sign in to comment.