-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
101 lines (87 loc) · 2.69 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
cmake_minimum_required(VERSION 3.0)
project(embedjson C)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(fw)
include(CheckTypeSize)
set(EMBEDJSON_DEBUG FALSE CACHE BOOL
"Define to enable paranoid self-checking mode.")
set(EMBEDJSON_DYNAMIC_STACK FALSE CACHE BOOL
"Define to enable dynamic stack to hold parser's state.")
set(EMBEDJSON_STATIC_STACK_SIZE 16 CACHE STRING
"Size (in bytes) of the stack.")
set(EMBEDJSON_VALIDATE_UTF8 TRUE CACHE BOOL
"Enable UTF-8 validation")
set(EMBEDJSON_BIGNUM FALSE CACHE BOOL
"Enable big numbers support.")
set(EMBEDJSON_COVERAGE FALSE CACHE BOOL
"Enable collection of coverage statistics.")
set(EMBEDJSON_ENABLE_INT128 FALSE CACHE BOOL
"Enable 128-bit integers for EMBEDJSON_INT_T.")
if(EMBEDJSON_COVERAGE AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(FATAL_ERROR "Code coverage can be computed only for Debug builds")
endif()
if(EMBEDJSON_COVERAGE)
fw_c_flags("--coverage -O0")
endif()
if(EMBEDJSON_ENABLE_INT128)
check_type_size(__int128_t EMBEDJSON_SIZEOF_INT128_T)
check_type_size(__int128 EMBEDJSON_SIZEOF_INT128)
if(EMBEDJSON_SIZEOF_INT128_T STREQUAL 16)
set(EMBEDJSON_INT_T __int128_t)
elseif(EMBEDJSON_SIZEOF_INT128 STREQUAL 16)
set(EMBEDJSON_INT_T __int128)
else()
message(FATAL_ERROR "No suitable 128-bit integer type found. "
"__int128, __int128_t probed.")
endif()
else()
set(EMBEDJSON_INT_T "long long")
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.in"
${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
link_libraries(m)
fw_c99()
fw_c_flags("-Wall -Wextra -Wpedantic")
add_executable(ut-lexer
common.h
common.c
lexer.h
lexer.c
ut_lexer.c
)
add_executable(ut-parser
common.h
common.c
lexer.h
lexer.c
parser.h
parser.c
ut_parser.c
)
add_executable(ut-common
common.h
common.c
ut_common.c
)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/embedjson.c"
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/scripts/amalgamate.sh"
${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS common.h common.c lexer.h lexer.c parser.c parser.h LICENSE
)
add_custom_target(amalgamate
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/embedjson.c"
)
add_executable(embedjson-lint
embedjson_lint.c
)
add_dependencies(embedjson-lint amalgamate)
enable_testing()
add_test(NAME lexer COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ut-lexer)
add_test(NAME parser COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ut-parser)
add_test(NAME common COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ut-common)
add_test(NAME embedjson-lint
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/run.sh"
"${CMAKE_CURRENT_BINARY_DIR}/embedjson-lint"
"${CMAKE_CURRENT_SOURCE_DIR}/tests/cases")