Skip to content

Commit efb218f

Browse files
committed
Allow use as a header-only library or as a standard library.
1 parent c1521f6 commit efb218f

13 files changed

+704
-567
lines changed

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,16 @@ include_directories(SYSTEM ${MASON_PACKAGE_benchmark_INCLUDE_DIRS})
4747
include_directories("${PROJECT_SOURCE_DIR}/include")
4848

4949
file(GLOB TEST_SOURCES test/*.cpp)
50+
set(TEST_SOURCES ${TEST_SOURCES} include/delaunator.cpp)
5051
add_executable(unit-tests ${TEST_SOURCES})
5152

53+
file(GLOB TEST_SOURCES test-header-only/*.cpp)
54+
add_executable(header-only-unit-tests ${TEST_SOURCES})
55+
5256
# libbenchmark.a supports threads and therefore needs pthread support
5357
find_package(Threads REQUIRED)
5458
file(GLOB BENCH_SOURCES bench/*.cpp)
59+
set(BENCH_SOURCES ${BENCH_SOURCES} include/delaunator.cpp)
5560
add_executable(bench-tests ${BENCH_SOURCES})
5661
if(BENCHMARK_BIG_O)
5762
message("-- BENCHMARK_BIG_O=1")
@@ -67,8 +72,8 @@ if(BENCHMARK_10M)
6772
endif()
6873

6974
#examples
70-
add_executable(triangulate-geojson examples/triangulate_geojson.cpp)
71-
add_executable(basic examples/basic.cpp)
75+
add_executable(triangulate-geojson examples/triangulate_geojson.cpp include/delaunator.cpp)
76+
add_executable(basic examples/basic.cpp include/delaunator.cpp)
7277

7378

7479
# link benchmark static library to the bench-tests binary so the bench tests know where to find the benchmark impl code

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ xcode:
1616
mkdir -p ./$(XCODE_PROJ_DIR) && cd ./$(XCODE_PROJ_DIR) && cmake -G Xcode ../
1717

1818
test:
19-
@if [ -f ./$(BUILD_DIR)/unit-tests ]; then ./$(BUILD_DIR)/unit-tests; else echo "Please run 'make release' or 'make debug' first" && exit 1; fi
19+
@if [ -f ./$(BUILD_DIR)/unit-tests ]; then ./$(BUILD_DIR)/unit-tests; ./$(BUILD_DIR)/header-only-unit-tests; else echo "Please run 'make release' or 'make debug' first" && exit 1; fi
2020

2121
bench:
2222
@if [ -f ./$(BUILD_DIR)/bench-tests ]; then ./$(BUILD_DIR)/bench-tests; else echo "Please run 'make release' or 'make debug' first" && exit 1; fi
@@ -44,4 +44,4 @@ distclean: clean
4444
format:
4545
./scripts/format.sh
4646

47-
.PHONY: test bench
47+
.PHONY: test bench

include/delaunator-header-only.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#define DELAUNATOR_HEADER_ONLY
4+
5+
#include "delaunator.hpp"
6+
7+
#include "delaunator.cpp"
8+
9+
#undef DELAUNATOR_HEADER_ONLY

0 commit comments

Comments
 (0)