Skip to content

Commit

Permalink
Merge pull request #104 from jeromekelleher/meson-subproject
Browse files Browse the repository at this point in the history
Meson subproject
  • Loading branch information
jeromekelleher authored Jan 24, 2019
2 parents 65d7c97 + 8bbb5df commit 6072bc8
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 55 deletions.
11 changes: 7 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,17 @@ jobs:
ninja -C build-clang test
- run:
name: Install shared library
name: Test building with meson subproject
command: |
meson build-install c --prefix=/usr
sudo ninja -C build-install install
meson build-subproject c/tests/meson-subproject
ninja -C build-subproject
./build-subproject/example
- run:
name: Hand-compile some example programs
name: Install shared library and hand-compile program.
command: |
meson build-install c --prefix=/usr
sudo ninja -C build-install install
clang c/examples/api_structure.c -o api_structure -ltskit
./api_structure
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "c/kastore"]
path = c/kastore
path = c/subprojects/full-projects/kastore
url = https://github.com/tskit-dev/kastore.git
1 change: 0 additions & 1 deletion c/kastore
Submodule kastore deleted from fb5933
94 changes: 47 additions & 47 deletions c/meson.build
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
project('tskit', ['c', 'cpp'], default_options: ['c_std=c99', 'cpp_std=c++11'])

kastore_dir=join_paths(meson.source_root(), 'kastore/c')
add_global_arguments(['-I' + kastore_dir], language: ['c', 'cpp'])
kastore_proj = subproject('kastore')
kastore_dep = kastore_proj.get_variable('kastore_dep')

cc = meson.get_compiler('c')
m_dep = cc.find_library('m', required: false)
lib_deps = [m_dep]
lib_deps = [m_dep, kastore_dep]

extra_c_args = [
'-Wall', '-Wextra', '-Werror', '-Wpedantic', '-W',
Expand All @@ -15,85 +15,85 @@ extra_c_args = [
'-fshort-enums', '-fno-common']

lib_sources = [
'kastore/c/kastore.c', 'tskit/core.c', 'tskit/tables.c', 'tskit/trees.c',
'tskit/core.c', 'tskit/tables.c', 'tskit/trees.c',
'tskit/genotypes.c', 'tskit/stats.c', 'tskit/convert.c']
lib_headers = [
'tskit/core.h', 'tskit/tables.h', 'tskit/trees.h',
'tskit/genotypes.h', 'tskit/stats.h', 'tskit/convert.h']

# Subprojects use the static library for simplicity.
inc = include_directories(['.', 'tskit'])
tskit_lib = static_library('tskit',
sources: lib_sources, dependencies: lib_deps)
tskit_dep = declare_dependency(include_directories:inc, link_with: tskit_lib)

# Shared library install target.
shared_library('tskit',
sources: lib_sources, dependencies: lib_deps, c_args: extra_c_args, install: true)
# FIXME for now we include the kastore header because the shared lib won't
# work otherwise. Will need to come up with a better solution for this.
install_headers('kastore/c/kastore.h')
install_headers('tskit.h')
install_headers(lib_headers, subdir: 'tskit')
if not meson.is_subproject()

# Static library for building tests and examples.
tskit_lib = static_library('tskit',
sources: lib_sources, dependencies: lib_deps, c_args: extra_c_args)
# Shared library install target.
shared_library('tskit',
sources: lib_sources, dependencies: lib_deps, c_args: extra_c_args, install: true)
install_headers('tskit.h')
install_headers(lib_headers, subdir: 'tskit')

cunit_dep = dependency('cunit', required: false)
if cunit_dep.found()
cunit_dep = dependency('cunit')
# We don't specify extra C args here as CUnit won't pass the checks.
test_lib = static_library('testlib',
sources: ['tests/testlib.c'], dependencies: cunit_dep)
sources: ['tests/testlib.c'], dependencies: [cunit_dep, kastore_dep])

test_core = executable('test_core',
sources: ['tests/test_core.c'],
link_with: [tskit_lib, test_lib], c_args: extra_c_args)
link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep)
test('core', test_core)

test_tables = executable('test_tables',
sources: ['tests/test_tables.c'],
link_with: [tskit_lib, test_lib], c_args: extra_c_args)
link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep)
test('tables', test_tables)

test_trees = executable('test_trees',
sources: ['tests/test_trees.c'],
link_with: [tskit_lib, test_lib], c_args: extra_c_args)
link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep)
test('trees', test_trees)

test_genotypes = executable('test_genotypes',
sources: ['tests/test_genotypes.c'],
link_with: [tskit_lib, test_lib], c_args: extra_c_args)
link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep)
test('genotypes', test_genotypes)

test_convert = executable('test_convert',
sources: ['tests/test_convert.c'],
link_with: [tskit_lib, test_lib], c_args: extra_c_args)
link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep)
test('convert', test_convert)

test_stats = executable('test_stats',
sources: ['tests/test_stats.c'],
link_with: [tskit_lib, test_lib], c_args: extra_c_args)
link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep)
test('stats', test_stats)
endif

test_minimal_cpp = executable('test_minimal_cpp',
sources: ['tests/test_minimal_cpp.cpp'], link_with: [tskit_lib])
test('minimal_cpp', test_minimal_cpp)

# The development CLI. Don't use extra C args because argtable code won't pass
executable('dev-cli',
sources: ['dev-tools/dev-cli.c', 'dev-tools/argtable3.c'],
link_with: [tskit_lib], c_args:['-Dlint'])

# Example programs.
executable('api_structure',
sources: ['examples/api_structure.c'], link_with: [tskit_lib])
executable('error_handling',
sources: ['examples/error_handling.c'], link_with: [tskit_lib])
executable('tree_iteration',
sources: ['examples/tree_iteration.c'], link_with: [tskit_lib])

gsl_dep = dependency('gsl', required: false)
if gsl_dep.found()
executable('haploid_wright_fisher',
sources: ['examples/haploid_wright_fisher.c'], link_with: [tskit_lib],
dependencies: [gsl_dep])
test_minimal_cpp = executable('test_minimal_cpp',
sources: ['tests/test_minimal_cpp.cpp'], link_with: [tskit_lib],
dependencies: kastore_dep)
test('minimal_cpp', test_minimal_cpp)

# The development CLI. Don't use extra C args because argtable code won't pass
executable('dev-cli',
sources: ['dev-tools/dev-cli.c', 'dev-tools/argtable3.c'],
link_with: [tskit_lib], c_args:['-Dlint'], dependencies: kastore_dep)

# Example programs.
executable('api_structure',
sources: ['examples/api_structure.c'], link_with: [tskit_lib], dependencies: lib_deps)
executable('error_handling',
sources: ['examples/error_handling.c'], link_with: [tskit_lib], dependencies: lib_deps)
executable('tree_iteration',
sources: ['examples/tree_iteration.c'], link_with: [tskit_lib], dependencies: lib_deps)

gsl_dep = dependency('gsl', required: false)
if gsl_dep.found()
executable('haploid_wright_fisher',
sources: ['examples/haploid_wright_fisher.c'], link_with: [tskit_lib],
dependencies: [gsl_dep, lib_deps])
endif
endif

# TMP: until we've ported all the tests, keep this compilable.
Expand Down
1 change: 1 addition & 0 deletions c/subprojects/full-projects/kastore
Submodule kastore added at b15f21
1 change: 1 addition & 0 deletions c/subprojects/kastore
59 changes: 59 additions & 0 deletions c/tests/meson-subproject/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* Simple example testing that we compile and link in tskit and kastore
* when we use meson submodules.
*/
#include <stdio.h>
#include <tskit.h>
#include <assert.h>
#include <string.h>

void
test_kas_strerror()
{
printf("test_kas_strerror\n");
const char *str = kas_strerror(KAS_ERR_NO_MEMORY);
assert(strcmp(str, "Out of memory") == 0);
}

void
test_strerror()
{
printf("test_strerror\n");
const char *str = tsk_strerror(TSK_ERR_NO_MEMORY);
assert(strcmp(str, "Out of memory") == 0);
}

void
test_load_error()
{
printf("test_open_error\n");
tsk_treeseq_t ts;
int ret = tsk_treeseq_load(&ts, "no such file", 0);
assert(tsk_is_kas_error(ret));
tsk_treeseq_free(&ts);
}

void
test_table_basics()
{
printf("test_table_basics\n");
tsk_table_collection_t tables;
int ret = tsk_table_collection_init(&tables, 0);
assert(ret == 0);

ret = tsk_node_table_add_row(&tables.nodes, 0, 1.0, TSK_NULL, TSK_NULL, NULL, 0);
assert(ret == 0);
ret = tsk_node_table_add_row(&tables.nodes, 0, 2.0, TSK_NULL, TSK_NULL, NULL, 0);
assert(ret == 1);
assert(tables.nodes.num_rows == 2);

tsk_table_collection_free(&tables);
}

int main()
{
test_kas_strerror();
test_strerror();
test_load_error();
test_table_basics();
return 0;
}
12 changes: 12 additions & 0 deletions c/tests/meson-subproject/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
project('example', 'c')

kastore_proj = subproject('kastore')
kastore_dep = kastore_proj.get_variable('kastore_dep')
tskit_proj = subproject('tskit')
tskit_dep = tskit_proj.get_variable('tskit_dep')

executable('example',
'example.c',
dependencies : [kastore_dep, tskit_dep],
install : true)

1 change: 1 addition & 0 deletions c/tests/meson-subproject/subprojects/kastore
1 change: 1 addition & 0 deletions c/tests/meson-subproject/subprojects/tskit
2 changes: 1 addition & 1 deletion python/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include lib/kastore/c/kastore.h
include lib/subprojects/kastore/kastore.h
include lib/tskit.h
include lib/tskit/*.h
include LICENSE
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def finalize_options(self):


libdir = "lib"
kastore_dir = os.path.join(libdir, "kastore", "c")
kastore_dir = os.path.join(libdir, "subprojects", "kastore")
tsk_source_files = [
"core.c",
"tables.c",
Expand Down

0 comments on commit 6072bc8

Please sign in to comment.