yapb-noob-edition/meson.build

259 lines
6.6 KiB
Meson
Raw Normal View History

2020-06-12 18:52:38 +03:00
#
# YaPB - Counter-Strike Bot based on PODBot by Markus Klinge.
# Copyright © 2004-2023 YaPB Project <yapb@jeefo.net>.
2020-06-12 18:52:38 +03:00
#
# SPDX-License-Identifier: MIT
2020-06-12 18:52:38 +03:00
#
# version is now passed into the bot dll
2020-06-12 18:52:38 +03:00
project (
'yapb',
'cpp',
2023-01-28 18:58:00 +03:00
version: '4.3',
license: 'MIT',
default_options: [
'buildtype=release',
'b_ndebug=if-release',
'cpp_std=c++14',
'warning_level=3',
'werror=true',
'backend=ninja',
'optimization=3',
'default_library=static',
'cpp_eh=none',
'cpp_rtti=false',
2021-09-11 02:03:49 +03:00
'b_vscrt=static_from_buildtype',
2021-09-12 13:07:11 +03:00
'b_lto=true',
'b_lto_mode=default',
2021-09-12 16:29:49 +03:00
'b_lundef=true',
],
meson_version: '>=0.58.0')
2020-06-12 18:52:38 +03:00
find_program('ninja', required: true)
2020-06-12 18:52:38 +03:00
compiler= meson.get_compiler('cpp')
cross = meson.is_cross_build ()
os = host_machine.system()
cpu = host_machine.cpu_family()
cxx = compiler.get_id()
build_type = get_option ('buildtype')
2020-06-12 18:52:38 +03:00
# cpp and ldflags from scratch
cxxflags = []
ldflags = []
2020-06-12 18:52:38 +03:00
# custom flags
flags_versioned = ['-DVERSION_GENERATED']
# git is optional, but it's setups our version info
git = find_program('git', required: false)
if git.found()
run_command('git', 'config', '--global', '--add', 'safe.directory', '*', check: false)
2020-06-12 18:52:38 +03:00
# get the commit data
count = run_command('git', 'rev-list', '--count', 'HEAD', check: false).stdout().strip()
hash = run_command ('git', 'rev-parse', '--short', 'HEAD', check: false).stdout().strip()
author = run_command ('git', 'log', '--pretty="%ae"', '-1', check: false).stdout().strip()
2020-06-12 18:52:38 +03:00
hostname = find_program('hostname', required: false)
2020-06-12 18:52:38 +03:00
if hostname.found()
machine = run_command('hostname', check: false).stdout().strip()
else
machine = 'unknown'
endif
2020-06-12 18:52:38 +03:00
bot_version = meson.project_version()
cxx_version = compiler.version()
if os == 'windows'
winver = ','.join(bot_version.split('.'))
else
winver = bot_version
endif
2020-06-12 18:52:38 +03:00
cxxflags += flags_versioned
version_data = configuration_data()
2020-06-12 18:52:38 +03:00
version_data.set('count', count)
version_data.set('hash', hash)
version_data.set('author', author)
version_data.set('machine', machine)
version_data.set('version', bot_version)
version_data.set('winver', winver)
version_data.set('compiler', '@0@ @1@'.format (cxx, cxx_version))
2020-06-12 18:52:38 +03:00
configure_file (input: 'inc/version.h.in', output: 'version.build.h', configuration: version_data)
endif
2020-06-12 18:52:38 +03:00
# configure flags gcc and clang
if cxx == 'clang' or cxx == 'gcc'
cxxflags += [
'-mtune=generic', '-fno-threadsafe-statics'
]
2021-09-11 02:03:49 +03:00
if cpu == 'aarch64'
cxxflags += [
'-march=armv8-a+fp+simd',
]
else
cxxflags += [
'-march=x86-64', '-mmmx', '-msse', '-msse2', '-msse3', '-mssse3', '-mfpmath=sse'
]
endif
2021-09-11 02:03:49 +03:00
# setup optimization flags
if build_type == 'release'
cxxflags += [
'-funroll-loops', '-fomit-frame-pointer', '-fno-stack-protector', '-fvisibility=hidden', '-fvisibility-inlines-hidden'
]
if os != 'darwin' and os != 'windows' and cpu != 'aarch64'
cxxflags += [
'-fdata-sections',
'-ffunction-sections'
]
2021-09-11 02:03:49 +03:00
ldflags += [
'-Wl,--version-script=../ext/ldscripts/version.lds',
'-Wl,--gc-sections'
]
if cxx == 'gcc'
cxxflags += [
'-fgraphite-identity', '-floop-nest-optimize'
]
2021-09-11 02:03:49 +03:00
ldflags += [
'-fgraphite-identity', '-floop-nest-optimize', '-flto-partition=none'
2021-09-11 02:03:49 +03:00
]
endif
endif
else
cxxflags += ['-g3', '-ggdb', '-DDEBUG', '-D_FORTIFY_SOURCE=2']
endif
# special script for mingw-64 builds
if os == 'windows' and cxx == 'gcc' and compiler.version().version_compare('<12.0')
ldflags += [
'-Xlinker', '--script', '-Xlinker', '../ext/ldscripts/i386pe.lds'
]
endif
2020-06-12 18:52:38 +03:00
# always statically link libgcc on non darwin platforms
if os != 'darwin'
if cross or (cxx != 'clang' and os == 'windows')
ldflags += '-static-libgcc'
endif
else
cxxflags += '-mmacosx-version-min=10.9'
ldflags += [
'-lstdc++', '-mmacosx-version-min=10.9'
]
endif
2021-09-11 02:03:49 +03:00
# by default we buid 32bit binaries
if cpu != 'aarch64' and not get_option('64bit')
cxxflags += '-m32'
ldflags += '-m32'
if cross and cxx == 'clang' and os == 'windows'
ldflags += '-Wl,/MACHINE:X86'
cxxflags += '-Wl,/MACHINE:X86'
2021-09-11 02:03:49 +03:00
endif
endif
2021-09-11 02:03:49 +03:00
# link needed libraries
if os == 'linux'
ldflags += [
'-lm','-ldl'
]
elif os == 'windows'
if cxx == 'gcc' or (cross and cxx == 'clang')
ldflags += '-Wl,--kill-at'
endif
ldflags += [
'-luser32', '-lws2_32'
]
endif
elif os == 'windows' and (cxx =='msvc' or cxx == 'clang-cl')
if not get_option('64bit') and cxx == 'clang'
cxxflags += '/MACHINE:X86'
ldflags += '/MACHINE:X86'
endif
2020-06-12 18:52:38 +03:00
cxxflags += [
'/TP', '/D _WIN32_WINNT=0x0501', '/D _USING_V110_SDK71_', '/Zc:threadSafeInit-'
]
# minor optimizations for release build
if build_type == 'release'
cxxflags += [
'/GS-', '/Ob2', '/Oy', '/Oi', '/Ot', '/fp:precise', '/GF', '/GS-', '/GF', '/arch:SSE2'
]
# add wpo if msvc
if cxx == 'msvc'
cxxflags += [
'/GL'
]
endif
# add linker flags
ldflags += [
'/LTCG', 'delayimp.lib', '/DELAYLOAD:user32.dll', '/DELAYLOAD:ws2_32.dll', '/SUBSYSTEM:WINDOWS,5.01',
]
endif
ldflags += [
'user32.lib', 'ws2_32.lib'
]
2020-06-12 18:52:38 +03:00
endif
# pass our hell to meson
add_global_arguments (cxxflags, language: 'cpp')
2020-11-11 16:54:58 +03:00
add_global_link_arguments (ldflags, language: 'cpp')
2020-06-12 18:52:38 +03:00
# add the sources
2020-11-11 16:54:58 +03:00
sources = files (
'src/botlib.cpp',
'src/chatlib.cpp',
'src/combat.cpp',
'src/config.cpp',
'src/control.cpp',
'src/engine.cpp',
'src/graph.cpp',
'src/linkage.cpp',
'src/manager.cpp',
'src/module.cpp',
'src/message.cpp',
'src/navigate.cpp',
'src/support.cpp'
2020-06-12 18:52:38 +03:00
)
# add the include directories
2020-06-12 18:52:38 +03:00
includes = include_directories ([
'.', 'inc', 'ext', 'ext/crlib'
2020-06-12 18:52:38 +03:00
], is_system: true)
# if have git and on windows add windows-specific version info
if os == 'windows' and git.found()
sources += import('windows').compile_resources (
'vc/yapb.rc',
include_directories: includes,
args: flags_versioned
)
2020-06-12 18:52:38 +03:00
endif
# instruct meson we're want our little shared lib bot
shared_library(
meson.project_name(),
sources,
include_directories: includes,
gnu_symbol_visibility: 'hidden',
name_prefix: '')
2020-11-11 16:54:58 +03:00
run_target('package',
command: ['python3', meson.project_source_root() + '/package.py', '@0@.@1@'.format(bot_version, count)])