mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Merge pull request #658 from OrfeasZ/feature/meson
Add meson build configuration files
This commit is contained in:
commit
2777b6ad15
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -82,6 +82,10 @@ main2.cpp
|
|||
main.cpp
|
||||
|
||||
# Local Lua Testbeds
|
||||
lua-5.4.0-cxx/
|
||||
lua-5.4.0/
|
||||
lua-5.4.0-work1-cxx/
|
||||
lua-5.4.0-work1/
|
||||
lua-5.3.4-cxx/
|
||||
lua-5.3.4/
|
||||
lua-5.3.2/
|
||||
|
@ -117,4 +121,5 @@ scratch/
|
|||
cmake-build-debug/
|
||||
cmake-build-relwithdebinfo/
|
||||
cmake-build-release/
|
||||
lua-5.4.0-work1/
|
||||
/subprojects/*
|
||||
!/subprojects/*.wrap
|
||||
|
|
85
list-headers.py
Normal file
85
list-headers.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
description = "Lists all primary sol2 header files"
|
||||
|
||||
script_path = os.path.normpath(os.path.dirname(os.path.realpath(__file__)))
|
||||
working_dir = os.getcwd()
|
||||
os.chdir(script_path)
|
||||
|
||||
includes = set([])
|
||||
local_include = re.compile(r'#(\s*?)include "(.*?)"')
|
||||
project_include = re.compile(r'#(\s*?)include <sol/(.*?)>')
|
||||
pragma_once_cpp = re.compile(r'(\s*)#(\s*)pragma(\s+)once')
|
||||
ifndef_cpp = re.compile(r'#ifndef SOL_.*?_HPP')
|
||||
define_cpp = re.compile(r'#define SOL_.*?_HPP')
|
||||
endif_cpp = re.compile(r'#endif // SOL_.*?_HPP')
|
||||
|
||||
|
||||
def get_include(line, base_path):
|
||||
local_match = local_include.match(line)
|
||||
if local_match:
|
||||
# local include found
|
||||
full_path = os.path.normpath(
|
||||
os.path.join(base_path, local_match.group(2))).replace(
|
||||
'\\', '/')
|
||||
return full_path
|
||||
project_match = project_include.match(line)
|
||||
if project_match:
|
||||
# local include found
|
||||
full_path = os.path.normpath(
|
||||
os.path.join(base_path, project_match.group(2))).replace(
|
||||
'\\', '/')
|
||||
return full_path
|
||||
return None
|
||||
|
||||
|
||||
def is_include_guard(line):
|
||||
return ifndef_cpp.match(line) or define_cpp.match(
|
||||
line) or endif_cpp.match(line) or pragma_once_cpp.match(line)
|
||||
|
||||
|
||||
def process_file(filename):
|
||||
global includes
|
||||
filename = os.path.normpath(filename)
|
||||
relativefilename = filename.replace(script_path + os.sep, "").replace(
|
||||
"\\", "/")
|
||||
|
||||
rel_filename = os.path.relpath(filename, script_path).replace('\\', '/')
|
||||
|
||||
if rel_filename in includes:
|
||||
return
|
||||
|
||||
empty_line_state = True
|
||||
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
includes.add(rel_filename)
|
||||
|
||||
for line in f:
|
||||
# skip comments
|
||||
if line.startswith('//'):
|
||||
continue
|
||||
|
||||
# skip include guard non-sense
|
||||
if is_include_guard(line):
|
||||
continue
|
||||
|
||||
# get relative directory
|
||||
base_path = os.path.dirname(filename)
|
||||
|
||||
# see if it's an include file
|
||||
name = get_include(line, base_path)
|
||||
|
||||
if name:
|
||||
process_file(name)
|
||||
continue
|
||||
|
||||
processed_files = [os.path.join(script_path, x) for x in ['sol.hpp']]
|
||||
|
||||
for processed_file in processed_files:
|
||||
process_file(processed_file)
|
||||
|
||||
for include in includes:
|
||||
print(include)
|
60
meson.build
Normal file
60
meson.build
Normal file
|
@ -0,0 +1,60 @@
|
|||
project('sol2', 'cpp')
|
||||
|
||||
# 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)
|
||||
|
||||
if not python.found()
|
||||
python = find_program('python', required: false)
|
||||
endif
|
||||
|
||||
if not python.found()
|
||||
error('Could not locate Python. Python is required when building a single header.')
|
||||
endif
|
||||
|
||||
# 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
|
||||
|
||||
# Create our custom target to generate the single header file.
|
||||
sol2_single = custom_target('sol2_single',
|
||||
input: cmd.stdout().strip().split('\n'),
|
||||
output: 'sol.hpp',
|
||||
command: [ python, files('single.py'), '--output', '@OUTPUT@' ]
|
||||
)
|
||||
|
||||
# Expose the dependency.
|
||||
sol2_dep = declare_dependency(
|
||||
sources: [ sol2_single ],
|
||||
compile_args: compile_args,
|
||||
dependencies: [ lua_dep ],
|
||||
)
|
||||
endif
|
2
meson_options.txt
Normal file
2
meson_options.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
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')
|
20
single.py
20
single.py
|
@ -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
10
subprojects/lua.wrap
Normal 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 = 400ca3e7f2a7e2a8363abe7a25f339b87488d56a1351ad843931a4d097624e57
|
Loading…
Reference in New Issue
Block a user