Add lua dependency and fix custom target step

This commit is contained in:
Orfeas Zafeiris 2018-06-06 09:49:40 +03:00
parent a5dc5b59f8
commit d301dcc152
4 changed files with 68 additions and 25 deletions

View File

@ -1,44 +1,60 @@
project('sol2', 'cpp')
# Expose standard dependency
# Find lua dependency
if get_option('lua_cpp')
lua_cpp = 'true'
else
lua_cpp = 'false'
endif
lua_dep = dependency('lua', fallback: [ 'lua', 'lua_dep' ], default_options: [ 'lua_cpp=' + lua_cpp ])
# Set compiler flags if we're compiling lua as C++.
compile_args = []
if get_option('lua_cpp')
compile_args = [ '-DSOL_USING_CXX_LUA=1' ]
endif
# Expose standard dependency.
sol2_dep = declare_dependency(
include_directories: include_directories('.'),
compile_args: compile_args,
dependencies: [ lua_dep ],
)
# Single header targets requested.
if get_option('single')
# Check if we have python installed (required for creating single)
python = find_program('python3', required: false)
# Check if we have python installed (required for creating single).
python = find_program('python3', required: false)
if not python.found()
python = find_program('python', required: false)
endif
if not python.found()
python = find_program('python', required: false)
endif
single_opt = get_option('single')
if not python.found()
error('Could not locate Python. Python is required when building a single header.')
endif
if not python.found() and single_opt
error('Could not locate Python. Python is required when building a single header.')
endif
# Single header targets requested
if single_opt
# Get sol header files
# List all headers that the single header comprises of.
cmd = run_command(python, 'list-headers.py')
if cmd.returncode() != 0
error('Could not list sol2 header files.')
endif
# Setup the single generation target
sol2_single = custom_target('sol2_single',
output: 'sol2.hpp',
# Create our custom target to generate the single header file.
sol2_single = custom_target('sol2_single',
input: cmd.stdout().strip().split('\n'),
command: [ python, 'single.py', '--output', '@OUTPUT@' ],
output: 'sol.hpp',
command: [ python, files('single.py'), '--output', '@OUTPUT@' ]
)
# Create the dependency
sol2_single_dep = declare_dependency(
# Expose the dependency.
sol2_dep = declare_dependency(
sources: [ sol2_single ],
compile_args: compile_args,
dependencies: [ lua_dep ],
)
endif

View File

@ -1 +1,2 @@
option('single', type: 'boolean', value: false, description: 'Generate the sol2 single header and expose the corresponding build targets')
option('single', type: 'boolean', value: false, description: 'Generate the sol2 single header and expose the corresponding build targets')
option('lua_cpp', type: 'boolean', value: false, description: 'Compile lua as C++ code')

View File

@ -30,15 +30,29 @@ args = parser.parse_args()
single_file = ''
forward_single_file = ''
single_file = args.output[0]
if len(args.output) > 1:
forward_single_file = args.output[1]
else:
a, b = os.path.splitext(single_file)
forward_single_file = a + '_forward' + b
single_file_dir = os.path.dirname(single_file)
forward_single_file_dir = os.path.dirname(forward_single_file)
script_path = os.path.normpath(os.path.dirname(os.path.realpath(__file__)))
working_dir = os.getcwd()
os.chdir(script_path)
# If the user didn't provide absolute paths then construct them based on the current working dir.
if not os.path.isabs(single_file):
single_file = os.path.join(working_dir, single_file)
single_file_dir = os.path.join(working_dir, single_file_dir)
if not os.path.isabs(forward_single_file):
forward_single_file = os.path.join(working_dir, forward_single_file)
forward_single_file_dir = os.path.join(working_dir, forward_single_file_dir)
intro = """// The MIT License (MIT)
// Copyright (c) 2013-2018 Rapptz, ThePhD and contributors
@ -70,8 +84,6 @@ intro = """// The MIT License (MIT)
"""
module_path = os.path.join(script_path)
includes = set([])
standard_include = re.compile(r'#include <(.*?)>')
local_include = re.compile(r'#(\s*?)include "(.*?)"')
@ -226,6 +238,10 @@ forward_ss.close()
if not args.quiet:
print('finished creating single forward declaration header for sol\n')
# Create the output directories if they don't already exist.
os.makedirs(single_file_dir, exist_ok=True)
os.makedirs(forward_single_file_dir, exist_ok=True)
with open(single_file, 'w', encoding='utf-8') as f:
if not args.quiet:
print('writing {}...'.format(single_file))

10
subprojects/lua.wrap Normal file
View File

@ -0,0 +1,10 @@
[wrap-file]
directory = lua-5.3.4
source_url = https://www.lua.org/ftp/lua-5.3.4.tar.gz
source_filename = lua-5.3.4.tar.gz
source_hash = f681aa518233bc407e23acf0f5887c884f17436f000d453b2491a9f11a52400c
patch_url = https://github.com/OrfeasZ/lua-meson/releases/download/v5.3.4/lua-5.3.4-wrap.zip
patch_filename = lua-5.3.4-wrap.zip
patch_hash = 950424da95331eabdbc57afee5e1168ba5890adaf8127f3be507ed4a1b23a876