Skip to content
Draft
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
9 changes: 9 additions & 0 deletions examples/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
foreach example_name : [
'cpp_class1',
'cpp_class2',
'cpp_class3',
'cpp_class4',
'cpp_inheritance',
]
executable(example_name, example_name + '.cpp', dependencies: internal_dep)
endforeach
197 changes: 197 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
project(
'libcppgenerate',
'cpp',
version: '0.2',
default_options: ['warning_level=3', 'cpp_std=c++11', 'default_library=both'],
)

# Version of dynamic library
library_version = '0.0.2'

src = files(
'cppgenerate/argument.cpp',
'cppgenerate/class.cpp',
'cppgenerate/codeblock.cpp',
'cppgenerate/constructor.cpp',
'cppgenerate/cppgenerateutils.cpp',
'cppgenerate/enum.cpp',
'cppgenerate/membervariable.cpp',
'cppgenerate/method.cpp',
'cppgenerate/printer.cpp',
'cppgenerate/variable.cpp',
)

# Set on Windows by default. When enabled, use .lib suffix for static libraries
# and do not build shared ones in Windows.
cmake_compatible_behavior = (
host_machine.system() in ['windows', 'cygwin']
and get_option('cmake-compatible-libraries')
)

shared_lib = []
building_shared_lib = (
not (
cmake_compatible_behavior
or meson.is_subproject()
) and get_option('default_library') in ['shared', 'both']
)
static_lib = []
building_static_lib = (
cmake_compatible_behavior
or meson.is_subproject()
or get_option('default_library') in ['shared', 'both']
)

if meson.is_subproject()
static_lib = static_library(
'cppgenerate',
src,
)
elif cmake_compatible_behavior
if (get_option('default_library') == 'shared')
warning(
'Shared libraries will not be generated on Windows.',
'Set -Dcmake-compatible-libraries=false to override',
)
endif
static_lib = static_library(
'cppgenerate',
src,
name_suffix: 'lib',
install: true,
)
elif building_shared_lib and building_static_lib
both_libs = both_libraries(
'cppgenerate',
src,
version: library_version,
install: true,
)
static_lib = both_libs.get_static_lib()
shared_lib = both_libs.get_shared_lib()
elif building_shared_lib
shared_lib = shared_library(
'cppgenerate',
src,
version: library_version,
install: true,
)
elif building_static_lib
static_lib = static_library(
'cppgenerate',
src,
install: true,
)
endif

if not meson.is_subproject()
install_headers(
'cppgenerate/accessmodifier.h',
'cppgenerate/argument.h',
'cppgenerate/class.h',
'cppgenerate/codeblock.h',
'cppgenerate/constructor.h',
'cppgenerate/cppgenerateutils.h',
'cppgenerate/enum.h',
'cppgenerate/membervariable.h',
'cppgenerate/method.h',
'cppgenerate/printer.h',
'cppgenerate/variable.h',
subdir: 'cppgenerate',
)
endif

# Configure .pc files
fs = import('fs')

# Base configuration object used for shared library
dynamic_lib_cfg = configuration_data()
dynamic_lib_cfg.set('PROJECT_VERSION', meson.project_version())
dynamic_lib_cfg.set('PKG_CONFIG_REQUIRES', '')
dynamic_lib_cfg.set('CMAKE_INSTALL_PREFIX', get_option('prefix'))
if fs.is_absolute(get_option('includedir'))
dynamic_lib_cfg.set('PKG_CONFIG_INCLUDEDIR', get_option('includedir'))
else
dynamic_lib_cfg.set(
'PKG_CONFIG_INCLUDEDIR',
'${prefix}' / get_option('includedir'),
)
endif
if fs.is_absolute(get_option('libdir'))
dynamic_lib_cfg.set('PKG_CONFIG_LIBDIR', get_option('libdir'))
else
dynamic_lib_cfg.set('PKG_CONFIG_LIBDIR', '${prefix}' / get_option('libdir'))
endif
dynamic_lib_cfg.set('PKG_CONFIG_LIBS', '-L${libdir} -lcppgenerate')
dynamic_lib_cfg.set('PKG_CONFIG_CFLAGS', '-I${includedir}')

# Static library configuration object based off of dynamic_lib_cfg
static_lib_cfg = dynamic_lib_cfg

static_lib_cfg.set('PKG_CONFIG_STATIC_LIBS', '-L${libdir} -l:libcppgenerate.a')

# Configure and install pkg-config files if the relevant library is being built
if host_machine.system() not in ['windows', 'cygwin'] and not meson.is_subproject()
if building_shared_lib
configure_file(
input: 'cppgenerate.pc.cmake',
output: 'cppgenerate.pc',
configuration: dynamic_lib_cfg,
format: 'cmake',
install: true,
install_dir: get_option('libdir') / 'pkgconfig',
)
endif
if building_static_lib
configure_file(
input: 'cppgenerate-static.pc.cmake',
output: 'cppgenerate-static.pc',
configuration: static_lib_cfg,
format: 'cmake',
install: true,
install_dir: get_option('libdir') / 'pkgconfig',
)
endif
endif

if meson.is_subproject()
shared_dep = declare_dependency(
link_with: static_lib,
include_directories: '.',
)
meson.override_dependency('cppgenerate-static', shared_dep)
endif

# Pick an appropriate dependency object for building tests and examples
if get_option('default_library') == 'both'
if meson.version().version_compare('>=1.6.0')
if (
get_option('default_both_libraries') in ['shared', 'auto']
and building_shared_lib
)
internal_lib = shared_lib
else
internal_lib = static_lib
endif
elif building_shared_lib
internal_lib = shared_lib
else
internal_lib = static_lib
endif
elif building_shared_lib
internal_lib = shared_lib
elif building_static_lib
internal_lib = static_lib
endif

internal_dep = declare_dependency(
link_with: internal_lib,
include_directories: '.',
)

if get_option('enable-tests')
subdir('tests')
endif
if get_option('enable-examples')
subdir('examples')
endif
20 changes: 20 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
option(
'enable-tests',
type: 'boolean',
value: false,
description: 'Enable the unit tests',
)

option(
'enable-examples',
type: 'boolean',
value: false,
description: 'Enable the examples',
)

option(
'cmake-compatible-libraries',
type: 'boolean',
value: true,
description: 'Use .lib suffix for static libraries and do not generate dynamic libraries on Windows. Uses default Meson behavior when false (this enables dynamic library generation on Windows).',
)
70 changes: 70 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#
# Class tests
#

# Iterate over list of test data. The list is comprised of:
# [generator name, [files generated by generator,], test name]
foreach test_data : [
['generate-class1', ['FooClass.h', 'FooClass.cpp'], 'test1'],
[
'generate-namespace-class',
['NamespaceClass.h', 'NamespaceClass.cpp'],
'namespace-class-test',
],
[
'generate-class-with-method',
['ClassWithMethod.h', 'ClassWithMethod.cpp'],
'class-with-method',
],
[
'generate-imperative-math',
['MathOperations.h', 'MathOperations.cpp'],
'math-class',
],
[
'generate-class-with-default-values',
['ClassWithDefaultValues.h', 'ClassWithDefaultValues.cpp'],
'test-default-function-values',
],
]
base_generator_name = test_data[0]
output_files = test_data[1]
test_name = test_data[2]

generator_exe = executable(
base_generator_name + '-generate',
base_generator_name + '.cpp',
dependencies: internal_dep,
)

generated_source_files = custom_target(
command: [
generator_exe,
meson.current_build_dir(),
],
output: output_files,
)

tested_exe = executable(test_name, test_name + '.cpp', generated_source_files)

test(test_name, tested_exe)
endforeach

#
# Enum tests
#

foreach test_name : [
'enum_name',
'enum_with_space',
'enum_single_value',
'enum_multiple_value',
'enum_name_bad_chars',
]
test_exe = executable(
'test-' + test_name,
test_name + '.cpp',
dependencies: internal_dep,
)
test(test_name, test_exe)
endforeach