Skip to content

Commit a116e68

Browse files
authored
Merge pull request simdjson#729 from simdjson/jkeiser/cmake-amalgamate
Add amalgamation support to cmake
2 parents e7084de + d3e44b1 commit a116e68

File tree

17 files changed

+333
-271
lines changed

17 files changed

+333
-271
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*
22
!.git
33
!Makefile
4-
!amalgamation.sh
4+
!amalgamate.sh
55
!benchmark
66
!dependencies
77
!include

.drone.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ platform:
4747
steps:
4848
- name: build
4949
image: gcc:8
50-
commands: [ make, make amalgamate ]
50+
commands: [ make, make amalgamate_test ]
5151
---
5252
kind: pipeline
5353
name: x64-slowtests
@@ -87,7 +87,7 @@ steps:
8787
image: gcc:8
8888
environment:
8989
EXTRA_FLAGS: -fno-exceptions
90-
commands: [ make, make amalgamate ]
90+
commands: [ make, make amalgamate_test ]
9191
---
9292
kind: pipeline
9393
name: x64-noexceptions-slowtests
@@ -139,7 +139,7 @@ platform:
139139
steps:
140140
- name: build
141141
image: gcc:8
142-
commands: [ make, make amalgamate ]
142+
commands: [ make, make amalgamate_test ]
143143
---
144144
kind: pipeline
145145
name: arm64-slowtests

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ objs
133133
/tests/allparserscheckfile
134134
/tests/basictests
135135
/tests/checkimplementation
136+
/tests/compilation_failure_tests/dangling_parser_load_should_compile
137+
/tests/compilation_failure_tests/dangling_parser_parse_padstring_should_compile
138+
/tests/compilation_failure_tests/dangling_parser_parse_stdstring_should_compile
139+
/tests/compilation_failure_tests/dangling_parser_parse_uchar_should_compile
140+
/tests/compilation_failure_tests/dangling_parser_parse_uint8_should_compile
136141
/tests/compilation_failure_tests/example_compiletest_should_compile
137142
/tests/errortests
138143
/tests/extracting_values_example

CMakeLists.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ if (NOT MSVC)
138138
add_custom_target(simdjson-user-cmakecache ALL DEPENDS ${SIMDJSON_USER_CMAKECACHE})
139139
endif()
140140

141+
#
142+
# Set up test data
143+
#
144+
enable_testing()
145+
add_subdirectory(jsonchecker)
146+
add_subdirectory(jsonexamples)
147+
add_library(test-data INTERFACE)
148+
target_link_libraries(test-data INTERFACE jsonchecker-data jsonexamples-data)
149+
141150
#
142151
# Create the top level simdjson library (must be done at this level to use both src/ and include/
143152
# directories) and tools
@@ -146,16 +155,11 @@ add_subdirectory(include)
146155
add_subdirectory(src)
147156
add_subdirectory(windows)
148157
add_subdirectory(tools)
158+
add_subdirectory(singleheader)
149159

150160
#
151161
# Compile tools / tests / benchmarks
152162
#
153-
enable_testing()
154-
155-
add_library(test-data INTERFACE)
156-
target_compile_definitions(test-data INTERFACE SIMDJSON_TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/jsonchecker/")
157-
target_compile_definitions(test-data INTERFACE SIMDJSON_BENCHMARK_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/jsonexamples/")
158-
set(EXAMPLE_JSON ${CMAKE_CURRENT_SOURCE_DIR}/jsonexamples/twitter.json)
159163

160164
add_subdirectory(dependencies)
161165
add_subdirectory(tests)

HACKING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Other important files and directories:
3737
* **.drone.yml:** Definitions for Drone CI.
3838
* **.appveyor.yml:** Definitions for Appveyor CI (Windows).
3939
* **.circleci:** Definitions for Circle CI.
40-
* **amalgamation.sh:** Generates singleheader/simdjson.h and singleheader/simdjson.cpp for release.
40+
* **amalgamate.sh:** Generates singleheader/simdjson.h and singleheader/simdjson.cpp for release.
4141
* **benchmark:** This is where we do benchmarking. Benchmarking is core to every change we make; the
4242
cardinal rule is don't regress performance without knowing exactly why, and what you're trading
4343
for it. If you're not sure what else to do to check your performance, this is always a good start:
@@ -73,7 +73,7 @@ you can regenerate them by running this at the top level:
7373
make amalgamate
7474
```
7575
76-
The amalgamator is at `amalgamation.sh` at the top level. It generates singleheader/simdjson.h by
76+
The amalgamator is at `amalgamate.sh` at the top level. It generates singleheader/simdjson.h by
7777
reading through include/simdjson.h, copy/pasting each header file into the amalgamated file at the
7878
point it gets included (but only once per header). singleheader/simdjson.cpp is generated from
7979
src/simdjson.cpp the same way, except files under generic/ may be included and copy/pasted multiple

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,16 @@ quicktests: run_basictests run_quickstart readme_examples readme_examples_noexce
178178
slowtests: run_testjson2json_sh run_issue150_sh
179179

180180
amalgamate:
181-
./amalgamation.sh
181+
singleheader/amalgamate.sh
182182

183-
singleheader/simdjson.h singleheader/simdjson.cpp singleheader/amalgamation_demo.cpp: amalgamation.sh src/simdjson.cpp $(SRCHEADERS) $(INCLUDEHEADERS)
184-
./amalgamation.sh
183+
singleheader/simdjson.h singleheader/simdjson.cpp singleheader/amalgamate_demo.cpp: singleheader/amalgamate.sh src/simdjson.cpp $(SRCHEADERS) $(INCLUDEHEADERS)
184+
singleheader/amalgamate.sh
185185

186-
singleheader/demo: singleheader/simdjson.h singleheader/simdjson.cpp singleheader/amalgamation_demo.cpp
187-
$(CXX) $(CXXFLAGS) -o singleheader/demo singleheader/amalgamation_demo.cpp -Isingleheader
186+
singleheader/demo: singleheader/simdjson.h singleheader/simdjson.cpp singleheader/amalgamate_demo.cpp
187+
$(CXX) $(CXXFLAGS) -o singleheader/demo singleheader/amalgamate_demo.cpp -Isingleheader
188+
189+
amalgamate_test: singleheader/demo jsonexamples/twitter.json jsonexamples/amazon_cellphones.ndjson
190+
singleheader/demo jsonexamples/twitter.json jsonexamples/amazon_cellphones.ndjson
188191

189192
submodules:
190193
-git submodule update --init --recursive

jsonchecker/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set(SIMDJSON_TEST_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
2+
add_library(jsonchecker-data INTERFACE)
3+
target_compile_definitions(jsonchecker-data INTERFACE SIMDJSON_TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/")

jsonexamples/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set(SIMDJSON_BENCHMARK_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
2+
set(EXAMPLE_JSON ${CMAKE_CURRENT_SOURCE_DIR}/twitter.json PARENT_SCOPE)
3+
set(EXAMPLE_NDJSON ${CMAKE_CURRENT_SOURCE_DIR}/amazon_cellphones.ndjson PARENT_SCOPE)
4+
add_library(jsonexamples-data INTERFACE)
5+
target_compile_definitions(jsonexamples-data INTERFACE SIMDJSON_BENCHMARK_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/")

singleheader/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Amalgamation
3+
#
4+
if (NOT MSVC)
5+
set(SINGLEHEADER_FILES simdjson.h simdjson.cpp amalgamate_demo.cpp README.md)
6+
add_custom_command(
7+
OUTPUT ${SINGLEHEADER_FILES}
8+
COMMAND ${CMAKE_COMMAND} -E env
9+
AMALGAMATE_SOURCE_PATH=${PROJECT_SOURCE_DIR}/src
10+
AMALGAMATE_INPUT_PATH=${PROJECT_SOURCE_DIR}/include
11+
AMALGAMATE_OUTPUT_PATH=${CMAKE_CURRENT_BINARY_DIR}
12+
${CMAKE_CURRENT_SOURCE_DIR}/amalgamate.sh
13+
DEPENDS simdjson-source amalgamate.sh
14+
)
15+
16+
add_custom_target(amalgamate DEPENDS ${SINGLEHEADER_FILES})
17+
18+
add_executable(amalgamate_demo amalgamate_demo.cpp)
19+
target_link_libraries(amalgamate_demo simdjson-include-source)
20+
add_test(amalgamate_demo amalgamate_demo ${EXAMPLE_JSON} ${EXAMPLE_NDJSON})
21+
endif()

singleheader/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
c++ -O3 -std=c++17 -pthread -o amalgamation_demo amalgamation_demo.cpp && ./amalgamation_demo ../jsonexamples/twitter.json ../jsonexamples/amazon_cellphones.ndjson
1+
Try :
2+
c++ -O3 -std=c++17 -pthread -o amalgamate_demo amalgamate_demo.cpp && ./amalgamate_demo ../jsonexamples/twitter.json ../jsonexamples/amazon_cellphones.ndjson

0 commit comments

Comments
 (0)