Skip to content

Commit 7480b87

Browse files
authored
Merge pull request simdjson#693 from simdjson/jkeiser/cmake-quickstartcpp
Add C++11 tests to cmake
2 parents befa642 + fd418f5 commit 7480b87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+510
-314
lines changed

.appveyor.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ build_script:
2020
- mkdir build
2121
- cd build
2222
- cmake -DSIMDJSON_BUILD_STATIC=%SIMDJSON_BUILD_STATIC% -DSIMDJSON_ENABLE_THREADS=%SIMDJSON_ENABLE_THREADS% -DCMAKE_BUILD_TYPE=%Configuration% -DCMAKE_GENERATOR_PLATFORM=x64 -DSIMDJSON_GOOGLE_BENCHMARKS=OFF ..
23-
- cmake --build . --config %Configuration%
23+
- cmake -LH ..
24+
- cmake --build . --config %Configuration% --verbose
2425

2526
test_script:
26-
- ctest --verbose --output-on-failure -C %Configuration%
27+
- ctest --output-on-failure -C %Configuration% --verbose
2728

2829
matrix:
2930
fast_finish: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ objs
8787
/examples/quickstart/twitter.json
8888
/fuzz/fuzz_dump
8989
/fuzz/fuzz_dump_raw_tape
90+
/fuzz/fuzz_minify
9091
/fuzz/fuzz_parser
9192
/fuzz/fuzz_print_json
9293
/get_corpus_benchmark

CMakeLists.txt

Lines changed: 97 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@ project(simdjson
1212
LANGUAGES CXX C
1313
)
1414

15-
# LTO seems to create all sorts of fun problems. Let us
16-
# disable temporarily.
17-
#include(CheckIPOSupported)
18-
#check_ipo_supported(RESULT ltoresult)
19-
#if(ltoresult)
20-
# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
21-
#endif()
22-
23-
set(CMAKE_CXX_STANDARD 17)
24-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
25-
set(CMAKE_MACOSX_RPATH OFF)
26-
set(CMAKE_THREAD_PREFER_PTHREAD ON)
27-
set(THREADS_PREFER_PTHREAD_FLAG ON)
28-
2915
set(PROJECT_VERSION_MAJOR 0)
3016
set(PROJECT_VERSION_MINOR 3)
3117
set(PROJECT_VERSION_PATCH 1)
@@ -35,19 +21,109 @@ set(SIMDJSON_LIB_SOVERSION "1" CACHE STRING "simdjson library soversion")
3521
if(MSVC)
3622
option(SIMDJSON_BUILD_STATIC "Build a static library" ON) # turning it on disables the production of a dynamic library
3723
option(SIMDJSON_COMPETITION "Compile competitive benchmarks" OFF)
38-
else()
24+
else()
3925
option(SIMDJSON_BUILD_STATIC "Build a static library" OFF) # turning it on disables the production of a dynamic library
4026
option(SIMDJSON_COMPETITION "Compile competitive benchmarks" ON)
4127
endif()
4228
option(SIMDJSON_GOOGLE_BENCHMARKS "compile the Google Benchmark benchmarks" OFF)
4329

4430
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake")
4531

32+
# We compile tools, tests, etc. with C++ 17. Override yourself if you need on a target.
33+
set(CMAKE_CXX_STANDARD 17)
34+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
35+
set(CMAKE_CXX_EXTENSIONS OFF)
36+
set(CMAKE_MACOSX_RPATH OFF)
37+
set(CMAKE_THREAD_PREFER_PTHREAD ON)
38+
set(THREADS_PREFER_PTHREAD_FLAG ON)
39+
40+
# LTO seems to create all sorts of fun problems. Let us
41+
# disable temporarily.
42+
#include(CheckIPOSupported)
43+
#check_ipo_supported(RESULT ltoresult)
44+
#if(ltoresult)
45+
# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
46+
#endif()
47+
48+
#
49+
# Flags used by exes and by the simdjson library (project-wide flags)
50+
#
51+
add_library(simdjson-flags INTERFACE)
52+
if(MSVC)
53+
target_compile_options(simdjson-flags INTERFACE /nologo /D_CRT_SECURE_NO_WARNINGS)
54+
target_compile_options(simdjson-flags INTERFACE /W3 /wd4005 /wd4996 /wd4267 /wd4244 /wd4113)
55+
else()
56+
target_compile_options(simdjson-flags INTERFACE -fPIC)
57+
target_compile_options(simdjson-flags INTERFACE -Wall -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self)
58+
endif()
59+
60+
# Optional flags
61+
option(SIMDJSON_IMPLEMENTATION_HASWELL "Include the haswell implementation" ON)
62+
if(NOT SIMDJSON_IMPLEMENTATION_HASWELL)
63+
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_IMPLEMENTATION_HASWELL=0)
64+
endif()
65+
option(SIMDJSON_IMPLEMENTATION_WESTMERE "Include the westmere implementation" ON)
66+
if(NOT SIMDJSON_IMPLEMENTATION_WESTMERE)
67+
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_IMPLEMENTATION_WESTMERE=0)
68+
endif()
69+
option(SIMDJSON_IMPLEMENTATION_ARM64 "Include the arm64 implementation" ON)
70+
if(NOT SIMDJSON_IMPLEMENTATION_ARM64)
71+
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_IMPLEMENTATION_ARM64=0)
72+
endif()
73+
option(SIMDJSON_IMPLEMENTATION_FALLBACK "Include the fallback implementation" ON)
74+
if(NOT SIMDJSON_IMPLEMENTATION_FALLBACK)
75+
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_IMPLEMENTATION_FALLBACK=0)
76+
endif()
77+
78+
option(SIMDJSON_EXCEPTIONS "Enable simdjson's exception-throwing interface" ON)
79+
if(NOT SIMDJSON_EXCEPTIONS)
80+
message(STATUS "simdjson exception interface turned off. Code that does not check error codes will not compile.")
81+
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_EXCEPTIONS=0)
82+
endif()
83+
84+
option(SIMDJSON_ENABLE_THREADS "Enable threaded operation" ON)
85+
if(SIMDJSON_ENABLE_THREADS)
86+
find_package(Threads REQUIRED)
87+
target_link_libraries(simdjson-flags INTERFACE Threads::Threads)
88+
endif()
89+
90+
option(SIMDJSON_SANITIZE "Sanitize addresses" OFF)
91+
if(SIMDJSON_SANITIZE)
92+
# Not sure which
93+
target_compile_options(simdjson-flags INTERFACE -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all)
94+
target_link_libraries(simdjson-flags INTERFACE -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all)
95+
96+
# Ubuntu bug for GCC 5.0+ (safe for all versions)
97+
if (CMAKE_COMPILER_IS_GNUCC)
98+
target_link_libraries(simdjson-flags INTERFACE -fuse-ld=gold)
99+
endif()
100+
endif()
101+
102+
# prevent shared libraries from depending on Intel provided libraries
103+
if(${CMAKE_C_COMPILER_ID} MATCHES "Intel") # icc / icpc
104+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel")
105+
endif()
106+
107+
# Workaround for https://gitlab.kitware.com/cmake/cmake/issues/15415#note_633938:
108+
function(export_private_library NAME)
109+
install(TARGETS ${NAME}
110+
EXPORT ${NAME}-config
111+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
112+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
113+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
114+
)
115+
install(EXPORT ${NAME}-config
116+
FILE ${NAME}-config.cmake
117+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/simdjson-private
118+
)
119+
endfunction()
120+
121+
export_private_library(simdjson-flags)
122+
46123
#
47124
# Create the top level simdjson library (must be done at this level to use both src/ and include/
48125
# directories)
49126
#
50-
add_subdirectory(windows)
51127
add_subdirectory(include)
52128
add_subdirectory(src)
53129

@@ -60,10 +136,11 @@ add_library(test-data INTERFACE)
60136
target_compile_definitions(test-data INTERFACE SIMDJSON_TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/jsonchecker/")
61137
target_compile_definitions(test-data INTERFACE SIMDJSON_BENCHMARK_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/jsonexamples/")
62138

139+
add_subdirectory(windows)
63140
add_subdirectory(dependencies)
64-
add_subdirectory(tools)
65141
add_subdirectory(tests)
66142
add_subdirectory(examples)
143+
add_subdirectory(tools)
67144
add_subdirectory(benchmark)
68145

69146
# for fuzzing, read the comments in the fuzz/CMakeLists.txt file
@@ -72,11 +149,9 @@ if(ENABLE_FUZZING)
72149
add_subdirectory(fuzz)
73150
endif()
74151

75-
if(${CMAKE_C_COMPILER_ID} MATCHES "Intel") # icc / icpc
76-
# prevent shared libraries from depending on Intel provided libraries
77-
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel")
78-
endif()
79-
152+
#
153+
# CPack
154+
#
80155
set(CPACK_PACKAGE_VENDOR "Daniel Lemire")
81156
set(CPACK_PACKAGE_CONTACT "lemire@gmail.com")
82157
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Parsing gigabytes of JSON per second")
@@ -91,5 +166,3 @@ set(CPACK_RPM_PACKAGE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
91166
set(CPACK_SOURCE_GENERATOR "TGZ;ZIP")
92167

93168
include(CPack)
94-
95-

HACKING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ simdjson's source structure, from the top level, looks like this:
2626
compiled multiple times, from whichever architectures use them. They assume they are already
2727
enclosed in a namespace, e.g.:
2828
```c++
29-
namespace simdjson::haswell {
30-
#include "generic/stage1_find_marks.h"
29+
namespace simdjson {
30+
namespace haswell {
31+
#include "generic/stage1_find_marks.h"
32+
}
3133
}
3234
```
3335

benchmark/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include_directories( . linux )
2-
link_libraries(simdjson)
3-
# add_executable(benchfeatures benchfeatures.cpp)
2+
link_libraries(simdjson simdjson-flags)
3+
# add_executable(benchfeatures benchfeatures.cpp) # doesn't presently compile at all
44
add_executable(get_corpus_benchmark get_corpus_benchmark.cpp)
55
add_executable(perfdiff perfdiff.cpp)
66
add_executable(parse parse.cpp)

examples/quickstart/CMakeLists.txt

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,57 @@
1-
if(SIMDJSON_EXCEPTIONS)
2-
add_executable(quickstart quickstart.cpp)
3-
target_link_libraries(quickstart PRIVATE simdjson)
1+
#
2+
# Quickstart compile tests don't require any flags
3+
#
4+
5+
# TODO haven't quite decided the right way to run quickstart on Windows. Needs README update.
6+
if (NOT MSVC)
7+
# TODO run amalgamate first!
8+
function(add_quickstart_test TEST_NAME SOURCE_FILE)
9+
# Second argument is C++ standard name
10+
if (MSVC)
11+
if (${ARGV2})
12+
set(QUICKSTART_FLAGS /std:${ARGV2})
13+
else()
14+
set(QUICKSTART_FLAGS /WX)
15+
endif()
16+
set(QUICKSTART_INCLUDE /I${PROJECT_SOURCE_DIR}/include /I${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/simdjson.cpp)
17+
else()
18+
if (${ARGV2})
19+
set(QUICKSTART_FLAGS -Werror -std=${ARGV2})
20+
else()
21+
set(QUICKSTART_FLAGS -Werror)
22+
endif()
23+
set(QUICKSTART_INCLUDE -I${PROJECT_SOURCE_DIR}/include -I${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/simdjson.cpp)
24+
endif()
25+
26+
# Third argument tells whether to compile with -fno-exceptions
27+
if (${ARGV3})
28+
if (NOT MSVC)
29+
set(QUICKSTART_FLAGS ${QUICKSTART_FLAGS} -fno-exceptions)
30+
endif()
31+
endif()
32+
33+
message(STATUS ${TEST_NAME})
34+
add_test(
35+
NAME ${TEST_NAME}
36+
COMMAND ${CMAKE_CXX_COMPILER} ${QUICKSTART_FLAGS} -I${PROJECT_SOURCE_DIR}/include -I${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/simdjson.cpp ${SOURCE_FILE}
37+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/examples/quickstart
38+
)
39+
set_property(
40+
TEST ${TEST_NAME}
41+
APPEND PROPERTY DEPENDS simdjson-source ${PROJECT_SOURCE_DIR}/examples/quickstart/${SOURCE_FILE}
42+
)
43+
endfunction(add_quickstart_test)
44+
45+
if (SIMDJSON_EXCEPTIONS)
46+
add_quickstart_test(quickstart quickstart.cpp)
47+
add_quickstart_test(quickstart11 quickstart.cpp c++11)
48+
add_quickstart_test(quickstart14 quickstart.cpp c++14)
49+
set_property( TEST quickstart quickstart11 APPEND PROPERTY LABELS quicktests )
50+
set_property( TEST quickstart14 APPEND PROPERTY LABELS slowtests )
51+
endif()
52+
53+
add_quickstart_test(quickstart_noexceptions quickstart_noexceptions.cpp "" true)
54+
add_quickstart_test(quickstart_noexceptions11 quickstart_noexceptions.cpp c++11 true)
55+
set_property( TEST quickstart_noexceptions APPEND PROPERTY LABELS quicktests )
56+
set_property( TEST quickstart_noexceptions11 APPEND PROPERTY LABELS slowtests )
457
endif()
5-
add_executable(quickstart_noexceptions quickstart_noexceptions.cpp)
6-
target_link_libraries(quickstart_noexceptions PRIVATE simdjson)

fuzz/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro(implement_fuzzer sourcefile)
4444
if (SIMDJSON_FUZZ_LINKMAIN)
4545
target_sources(${name} PRIVATE main.cpp)
4646
endif ()
47-
target_link_libraries(${name} PRIVATE simdjson)
47+
target_link_libraries(${name} PRIVATE simdjson simdjson-flags)
4848
if (SIMDJSON_FUZZ_LDFLAGS)
4949
target_link_libraries(${name} PRIVATE ${SIMDJSON_FUZZ_LDFLAGS})
5050
endif ()

include/CMakeLists.txt

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,12 @@
11
#
2-
# simdjson headers and flags required to compile them
2+
# Provides the simdjson headers.
3+
#
4+
# target_link_libraries(my-project simdjson-headers) grants the headers. It does not provide the
5+
# source, libraries or any compiler flags.
36
#
4-
57
add_library(simdjson-headers INTERFACE)
6-
7-
# Include directory
8-
target_include_directories(simdjson-headers INTERFACE
9-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
10-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
11-
12-
# Flags absolutely needed to compile simdjson at all
13-
target_compile_features(simdjson-headers INTERFACE cxx_std_17)
14-
if(MSVC) # Windows
15-
# C++ standard flags
16-
target_compile_options(simdjson-headers INTERFACE /std:c++17)
17-
# Base flags
18-
target_compile_options(simdjson-headers INTERFACE /nologo)
19-
# Warning flags
20-
target_compile_options(simdjson-headers INTERFACE /W3 /D_CRT_SECURE_NO_WARNINGS /wd4005 /wd4996 /wd4267 /wd4244 /wd4113)
21-
else() # Linux
22-
# Base flags
23-
target_compile_options(simdjson-headers INTERFACE -fPIC)
24-
# C++ standard flags
25-
target_compile_options(simdjson-headers INTERFACE -std=c++17)
26-
# Warning flags
27-
target_compile_options(simdjson-headers INTERFACE -Wall -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self)
28-
# Debug and release specific flags
29-
target_compile_options(simdjson-headers INTERFACE $<$<CONFIG:DEBUG>:-ggdb>)
30-
target_compile_options(simdjson-headers INTERFACE $<$<CONFIG:RELEASE>:-O3 -DNDEBUG>)
31-
endif()
32-
33-
34-
# Optional flags
35-
option(SIMDJSON_IMPLEMENTATION_HASWELL "Include the haswell implementation" ON)
36-
option(SIMDJSON_IMPLEMENTATION_WESTMERE "Include the westmere implementation" ON)
37-
option(SIMDJSON_IMPLEMENTATION_ARM64 "Include the arm64 implementation" ON)
38-
option(SIMDJSON_IMPLEMENTATION_FALLBACK "Include the fallback implementation" ON)
39-
40-
option(SIMDJSON_EXCEPTIONS "Enable simdjson's exception-throwing interface" ON)
41-
if(NOT SIMDJSON_EXCEPTIONS)
42-
message(STATUS "simdjson exception interface turned off. Code that does not check error codes will not compile.")
43-
target_compile_definitions(simdjson-headers INTERFACE SIMDJSON_EXCEPTIONS=0)
44-
if(UNIX)
45-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
46-
endif(UNIX)
47-
endif()
48-
49-
option(SIMDJSON_ENABLE_THREADS "Enable threaded operation" ON)
50-
if(SIMDJSON_ENABLE_THREADS)
51-
find_package(Threads REQUIRED)
52-
target_link_libraries(simdjson-headers INTERFACE Threads::Threads)
53-
endif()
54-
55-
option(SIMDJSON_SANITIZE "Sanitize addresses" OFF)
56-
if(SIMDJSON_SANITIZE)
57-
# Not sure which
58-
target_compile_options(simdjson-headers INTERFACE -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all)
59-
target_link_libraries(simdjson-headers INTERFACE -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all)
60-
61-
# Ubuntu bug for GCC 5.0+ (safe for all versions)
62-
if (CMAKE_COMPILER_IS_GNUCC)
63-
target_link_libraries(simdjson-headers INTERFACE -fuse-ld=gold)
64-
endif()
65-
endif()
8+
target_compile_features(simdjson-headers INTERFACE cxx_std_11) # headers require at least C++11
9+
target_include_directories(simdjson-headers INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
6610

6711
install(TARGETS simdjson-headers
6812
EXPORT simdjson-headers-config

include/simdjson.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
#include "simdjson/document.h"
1818
#include "simdjson/document_stream.h"
1919

20-
// Deprecated API
20+
// // Deprecated API
2121
#include "simdjson/jsonparser.h"
2222
#include "simdjson/parsedjson.h"
2323
#include "simdjson/parsedjson_iterator.h"
2424

25-
// Inline functions
25+
// // Inline functions
2626
#include "simdjson/inline/document.h"
2727
#include "simdjson/inline/document_stream.h"
2828
#include "simdjson/inline/error.h"

include/simdjson/common_defs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
108108
SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
109109
SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
110110
SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
111-
SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough)
111+
SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
112+
SIMDJSON_DISABLE_GCC_WARNING(-Wreturn-type)
112113
#define SIMDJSON_PRAGMA(P) _Pragma(#P)
113114
#define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING)
114115
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations)

0 commit comments

Comments
 (0)