Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: command line parser enabled var #78

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion impl/command_line/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-License-Identifier: BSD-3-Clause
libSubstrateSrcs += files(
libSubstrateCommandLineSrcs = files(
'tokeniser.cxx', 'arguments.cxx', 'options.cxx'
)
50 changes: 34 additions & 16 deletions impl/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ libSubstrateSrcs = [
'socket.cxx', 'console.cxx', 'affinity.cxx', 'thread.cxx',
'utility.cxx', 'hash.cxx',
]
subdir('command_line')

deps = []
libSubstrateArgs = []
# Clone the sources list for the native build if it's required.
libSubstrateNativeSrcs = [] + libSubstrateSrcs

if target_machine.system() == 'windows'
deps += cxx.find_library('ws2_32', required: true)
Expand Down Expand Up @@ -125,11 +128,13 @@ if cxxVersion.version_compare('>=201703')
name: 'accepts nullptr as part of CTAD with pointer type values (GCC #85977)'
)

if friendTypenameTemplate and stdVariantGCC and stdFilesystemPath and initializerList
substrateCommandLineEnabled = friendTypenameTemplate and stdVariantGCC and stdFilesystemPath and initializerList
if substrateCommandLineEnabled
deps += [libstdcppFS]

subdir('command_line')
libSubstrateSrcs += libSubstrateCommandLineSrcs
endif
else
substrateCommandLineEnabled = false
endif

# This is by far not a complete set of conditions, however..
Expand Down Expand Up @@ -203,49 +208,62 @@ endif

# In a cross-build scenario, always build a version of the library for the host too.
if meson.is_cross_build()
hostCXX = meson.get_compiler('cpp', native: true)
buildCXX = meson.get_compiler('cpp', native: true)

depsNative = []

if build_machine.system() == 'windows'
depsNative += buildCXX.find_library('ws2_32', required: true)
depsNative += buildCXX.find_library('dbghelp', required: true)
else
libSubstrateNativeSrcs += 'pty.cxx'
endif

if hostCXX.get_define('__cplusplus').substring(0, -1).version_compare('>=201703')
depsNative += dependency('threads', native: true)

if buildCXX.get_define('__cplusplus').substring(0, -1).version_compare('>=201703')
# Re-check if we should or can enable the command line handling stuff by checking
# everything again against the host compiler
friendTypenameTemplate = hostCXX.compiles(
friendTypenameTemplate = buildCXX.compiles(
friendTypenameTest,
name: 'accepts friend declarations for auto functions (LLVM #31852, #33222)'
)

stdVariantGCC = hostCXX.compiles(
stdVariantGCC = buildCXX.compiles(
stdVariantGCCTest,
name: 'has a working std::variant implementation (GCC #80165)'
)

# GCC < 9.1 splits the filesystem module into a separate library
libstdcppFS = hostCXX.find_library('stdc++fs', required: false)
libstdcppFS = buildCXX.find_library('stdc++fs', required: false)

stdFilesystemPath = hostCXX.links(
stdFilesystemPath = buildCXX.links(
stdFilesystemPathTest,
name: 'has a working std::filesystem::path implementation (GCC >= 8 in macOS pre 10.15)',
dependencies: libstdcppFS,
)

initializerList = hostCXX.compiles(
initializerList = buildCXX.compiles(
initializerListTest,
name: 'accepts nullptr as part of CTAD with pointer type values (GCC #85977)'
)

if friendTypenameTemplate and stdVariantGCC and stdFilesystemPath and initializerList
deps += [libstdcppFS]

subdir('command_line')
substrateNativeCommandLineEnabled = friendTypenameTemplate and stdVariantGCC and stdFilesystemPath and initializerList
if substrateNativeCommandLineEnabled
depsNative += [libstdcppFS]
libSubstrateNativeSrcs += libSubstrateCommandLineSrcs
endif
else
substrateNativeCommandLineEnabled = false
endif

libSubstrateNative = library(
'substrateNative',
libSubstrateSrcs,
libSubstrateNativeSrcs,
c_args: ['-DSUBSTRATE_BUILD_INTERNAL'] + libSubstrateArgs,
cpp_args: ['-DSUBSTRATE_BUILD_INTERNAL'] + libSubstrateArgs,
include_directories: include_directories('..'),
dependencies: deps,
dependencies: depsNative,
gnu_symbol_visibility: 'inlineshidden',
implicit_include_directories: false,
pic: true,
Expand Down
9 changes: 7 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ if not meson.is_subproject() and get_option('build_library')
libraries: [libSubstrate, deps],
version: meson.project_version(),
extra_cflags: libSubstrateArgs,
variables: [
'command_line_enabled=@0@'.format(substrateCommandLineEnabled),
],
description: 'A collection of headers containing useful tools and gadgets for building C++ programs'
)
endif
Expand All @@ -155,6 +158,7 @@ variablesCompileArgs = [

variables = {
'compile_args': ' '.join(variablesCompileArgs),
'command_line_enabled': substrateCommandLineEnabled.to_string(),
}

nativeDeps = deps
Expand Down Expand Up @@ -187,13 +191,14 @@ endif
if meson.is_cross_build()
substrateNativeArgs = ' '.join(['-I@0@'.format(meson.current_source_dir())] + libSubstrateArgs)
substrateNative_dep = declare_dependency(
dependencies: deps,
dependencies: depsNative,
include_directories: include_directories('.'),
compile_args: substrateNativeArgs,
link_with: libSubstrateNative,
variables: {
'compile_args': substrateNativeArgs,
'link_args': libSubstrateNative.full_path()
'link_args': libSubstrateNative.full_path(),
'command_line_enabled': substrateNativeCommandLineEnabled.to_string(),
},
version: meson.project_version()
)
Expand Down