Skip to content

Commit 187084c

Browse files
authored
Merge pull request simdjson#970 from simdjson/jkeiser/singleheader-tests
Make singleheader tests be test-only
2 parents 57f6838 + b6f9382 commit 187084c

10 files changed

+37
-12
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ set(SIMDJSON_LIB_SOVERSION "1" CACHE STRING "simdjson library soversion")
1313
set(SIMDJSON_GITHUB_REPOSITORY https://github.com/simdjson/simdjson)
1414

1515
include(GNUInstallDirs)
16-
include(simdjson-flags.cmake)
17-
include(simdjson-user-cmakecache.cmake)
16+
include(cmake/simdjson-flags.cmake)
17+
include(cmake/simdjson-user-cmakecache.cmake)
1818

1919
if(SIMDJSON_JUST_LIBRARY)
2020
MESSAGE( STATUS "Building just the library, omitting all tests, tools and benchmarks." )

tests/add_cpp_test.cmake renamed to cmake/add_cpp_test.cmake

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
# SOURCES defaults to testname.cpp if not specified.
44
function(add_cpp_test TEST_NAME)
55
# Parse arguments
6-
cmake_parse_arguments(PARSE_ARGV 1 ARGS "COMPILE_ONLY;WILL_FAIL" "" "SOURCES;LABELS")
6+
cmake_parse_arguments(PARSE_ARGV 1 ARGS "COMPILE_ONLY;LIBRARY;WILL_FAIL" "" "SOURCES;LABELS")
77
if (NOT ARGS_SOURCES)
88
list(APPEND ARGS_SOURCES ${TEST_NAME}.cpp)
99
endif()
10-
if (COMPILE_ONLY)
10+
if (ARGS_COMPILE_ONLY)
1111
list(APPEND ${ARGS_LABELS} compile)
1212
endif()
1313

14-
# Add executable
15-
add_executable(${TEST_NAME} ${ARGS_SOURCES})
14+
# Add the compile target
15+
if (ARGS_LIBRARY)
16+
add_library(${TEST_NAME} STATIC ${ARGS_SOURCES})
17+
else(ARGS_LIBRARY)
18+
add_executable(${TEST_NAME} ${ARGS_SOURCES})
19+
endif(ARGS_LIBRARY)
1620

1721
# Add test
18-
if (ARGS_COMPILE_ONLY)
22+
if (ARGS_COMPILE_ONLY OR ARGS_LIBRARY)
1923
add_test(
2024
NAME ${TEST_NAME}
2125
COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $<CONFIGURATION>
@@ -34,3 +38,12 @@ function(add_cpp_test TEST_NAME)
3438
set_property(TEST ${TEST_NAME} PROPERTY WILL_FAIL TRUE)
3539
endif()
3640
endfunction()
41+
42+
function(add_compile_only_test TEST_NAME)
43+
add_test(
44+
NAME ${TEST_NAME}
45+
COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $<CONFIGURATION>
46+
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
47+
)
48+
set_target_properties(${TEST_NAME} PROPERTIES EXCLUDE_FROM_ALL TRUE EXCLUDE_FROM_DEFAULT_BUILD TRUE)
49+
endfunction()

simdjson-flags.cmake renamed to cmake/simdjson-flags.cmake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
option(SIMDJSON_JUST_LIBRARY "Build just the library, omit tests, tools and benchmarks" OFF)
2+
23
#
34
# Flags used by exes and by the simdjson library (project-wide flags)
45
#
@@ -59,10 +60,8 @@ if(MSVC)
5960
target_compile_options(simdjson-internal-flags INTERFACE /WX /W3 /sdl)
6061
else()
6162
target_compile_options(simdjson-internal-flags INTERFACE -fPIC)
62-
if (NOT SIMDJSON_GOOGLE_BENCHMARKS) # Google Benchmark can't be compiled without warnings with -Weffc++
63-
target_compile_options(simdjson-internal-flags INTERFACE -Weffc++)
64-
endif()
65-
target_compile_options(simdjson-internal-flags INTERFACE -Werror -Wall -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion)
63+
target_compile_options(simdjson-internal-flags INTERFACE -Werror -Wall -Wextra -Weffc++)
64+
target_compile_options(simdjson-internal-flags INTERFACE -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion)
6665
endif()
6766

6867
# Optional flags
File renamed without changes.

include/simdjson/common_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
117117
SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
118118
SIMDJSON_DISABLE_GCC_WARNING(-Wattributes) \
119119
SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
120+
SIMDJSON_DISABLE_GCC_WARNING(-Wnon-virtual-dtor) \
120121
SIMDJSON_DISABLE_GCC_WARNING(-Wreturn-type) \
121122
SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
122123
SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \

singleheader/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include(${PROJECT_SOURCE_DIR}/cmake/add_cpp_test.cmake)
2+
13
#
24
# Amalgamation
35
#
@@ -122,6 +124,7 @@ install(FILES simdjson.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
122124

123125
add_library(simdjson-singleheader STATIC "")
124126
target_link_libraries(simdjson-singleheader simdjson-singleheader-source simdjson-internal-flags)
127+
add_compile_only_test(simdjson-singleheader)
125128

126129
#
127130
# Test the existing simdjson.cpp/simdjson.h using the existing amalgamate_demo.cpp, using

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ endfunction()
3737
# Most tests need test data, and many need windows headers.
3838
link_libraries(simdjson-internal-flags test-data simdjson-windows-headers)
3939

40-
include(${PROJECT_SOURCE_DIR}/tests/add_cpp_test.cmake)
40+
include(${PROJECT_SOURCE_DIR}/cmake/add_cpp_test.cmake)
4141

4242
#
4343
# These tests explicitly do #include "simdjson.cpp" so they can override stuff

tools/json2json.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include <iostream>
22
#include <unistd.h>
33
#include "simdjson.h"
4+
5+
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
46
#ifndef __cpp_exceptions
57
#define CXXOPTS_NO_EXCEPTIONS
68
#endif
79
#include "cxxopts.hpp"
10+
SIMDJSON_POP_DISABLE_WARNINGS
811

912
int main(int argc, char *argv[]) {
1013
#ifdef __cpp_exceptions

tools/jsonstats.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
#include <set>
33

44
#include "simdjson.h"
5+
6+
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
57
#ifndef __cpp_exceptions
68
#define CXXOPTS_NO_EXCEPTIONS
79
#endif
810
#include "cxxopts.hpp"
11+
SIMDJSON_POP_DISABLE_WARNINGS
912

1013
size_t count_nonasciibytes(const uint8_t *input, size_t length) {
1114
size_t count = 0;

tools/minify.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
#include <unistd.h>
66

77
#include "simdjson.h"
8+
9+
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
810
#ifndef __cpp_exceptions
911
#define CXXOPTS_NO_EXCEPTIONS
1012
#endif
1113
#include "cxxopts.hpp"
14+
SIMDJSON_POP_DISABLE_WARNINGS
1215

1316
cxxopts::Options options("minify", "Runs the parser against the given json files in a loop, measuring speed and other statistics.");
1417

0 commit comments

Comments
 (0)