Skip to content

Commit 54ddbe7

Browse files
author
Alessandro Borile
committed
flatten submodule
1 parent 164d625 commit 54ddbe7

288 files changed

Lines changed: 69233 additions & 4 deletions

File tree

Some content is hidden

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

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "flatcc"]
2-
path = flatcc
3-
url = https://github.com/dvidelabs/flatcc

flatcc

Lines changed: 0 additions & 1 deletion
This file was deleted.

flatcc/CHANGELOG.md

Lines changed: 605 additions & 0 deletions
Large diffs are not rendered by default.

flatcc/CMakeLists.txt

Lines changed: 392 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,392 @@
1+
# Ubuntu 14.04 (Trusty)
2+
cmake_minimum_required (VERSION 2.8.12.2)
3+
# Centos 7
4+
#cmake_minimum_required (VERSION 2.8.11)
5+
#cmake_minimum_required (VERSION 2.8)
6+
7+
# Experimental for generating compile_commands.json so editors with
8+
# clangd language server support can use it. Symlink
9+
# build/Debug/compile_commands.json to project root where it is
10+
# gitignored.
11+
#set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
12+
13+
# Disable build of tests and samples. Due to custom build step
14+
# dependency on flatcc tool, some custom build configurations may
15+
# experience issues, and this option can then help.
16+
option(FLATCC_TEST "enable tests" ON)
17+
18+
# Only active if FLATCC_TEST is active. Used to ensure that C++ users
19+
# can include generatd C source. Old GCC pre 4.7 won't compile C++ test
20+
# project.
21+
option(FLATCC_CXX_TEST "enable C++ tests" ON)
22+
23+
# Note that linking with flatcc debug libraries may require souce code to also use
24+
# the sanitize flag.
25+
option(FLATCC_DEBUG_CLANG_SANITIZE "enable clang sanitize flag for debug build" ON)
26+
27+
# Conditionally set project languages based on FLATCC_TEST, as C++ is
28+
# only necessary if building the tests.
29+
if (FLATCC_TEST AND FLATCC_CXX_TEST)
30+
project (FlatCC C CXX)
31+
else()
32+
project (FlatCC C)
33+
endif()
34+
35+
#
36+
# NOTE: when changing build options, clean the build using on of:
37+
#
38+
# scripts/cleanall.sh
39+
# scripts/test.sh
40+
#
41+
42+
# Force use of portable shims such as providing `static_assert`, and
43+
# `stdaligh.h`. Otherwise this option is automatically enabled for some
44+
# known compiler configurations below.
45+
option (FLATCC_PORTABLE
46+
"include extra headers for compilers that do not support certain C11 features" OFF)
47+
48+
# It is not possible to detect posix_memalign when compiling with
49+
# -std=c11 but aligned_alloc is not always available either.
50+
# This options assumes that posix_memalign is then available.
51+
# Without C11, detection depends on _POSIX_C_SOURCE.
52+
option (FLATCC_GNU_POSIX_MEMALIGN
53+
"use posix_memalign on gnu systems also when C11 is configured" ON)
54+
55+
# Only build the runtime library - mostly intended in combination with
56+
# FLATCC_INSTALL for cross compiling targets.
57+
option(FLATCC_RTONLY "enable build of runtime library only" OFF)
58+
59+
# Use with or witout FLATCC_RTONLY to enable install targets.
60+
# Libraries are built statically by default, but can CMake's
61+
# cmake -DBUILD_SHARED_LIBS=on can override.
62+
option(FLATCC_INSTALL "enable install targets" OFF)
63+
64+
# Use with debug build with testing enabled only. Enables generation
65+
# of coverage information during build and run. Adds target "coverage"
66+
# which collects data and makes HTML report in build directory
67+
option(FLATCC_COVERAGE "enable coverage" OFF)
68+
69+
# Affects the flatbuffer verify operation. Normally a verify should just
70+
# quickly reject invalid buffers but for troubleshooting, assertions can
71+
# enabled. This requires rebuilding the runtime library and will likely
72+
# break test cases (those that tests that an invalid buffer is invalid).
73+
option (FLATCC_DEBUG_VERIFY
74+
"assert on verify failure in runtime lib" OFF)
75+
76+
# Print detailed traces of binary buffer contents when calling verify.
77+
option (FLATCC_TRACE_VERIFY
78+
"assert on verify failure in runtime lib" OFF)
79+
80+
# Some producers allow empty vectors to be misaligned.
81+
# The following setting will cause the verifier to require the index 0
82+
# position to be element aligned even if the vector is empty (otherwise that
83+
# position is only required to be aligned to the preceding size field).
84+
option (FLATCC_ENFORCE_ALIGNED_EMPTY_VECTORS
85+
"verify includes full alignment check for empty vectors" OFF)
86+
87+
# Reflection is the compilers ability to generate binary schema output
88+
# (.bfbs files). This requires using generated code from
89+
# `reflection.fbs`. During development it may not be possible to
90+
# compile with reflection enabled because it can become impossible to
91+
# fix broken builds. It may also be disabled simple because it isn't
92+
# needed.
93+
option (FLATCC_REFLECTION
94+
"generation of binary flatbuffer schema files" ON)
95+
96+
# FLATCC_NATIVE_OPTIM and FLATCC_FAST_DOUBLE affects json parsing,
97+
# especially if the content is pretty printed. But it is plenty
98+
# fast without these settings in most cases. Not recommended.
99+
option (FLATCC_NATIVE_OPTIM
100+
"use machine native optimizations like SSE 4.2" OFF)
101+
102+
# Fast grisu3 string/floating point conversion still depends on strtod
103+
# for about 1-2% of the conversions in order to produce an exact result.
104+
# By allowing a minor difference in the least significant bits, this
105+
# dependeny can be avoided, and speed improved. Some strtod
106+
# implementations call strlen which is really slow on large JSON
107+
# buffers, and catastrophic on buffers that are not zero-terminated -
108+
# regardless of size. Most platforms have a decent strtod these days.
109+
option (FLATCC_FAST_DOUBLE
110+
"faster but slightly incorrect floating point parser (json)" OFF)
111+
112+
# -Werror is only set for some compiler versions that are believed to
113+
# to not generate any warnings. If the assumption breaks, disable
114+
# this option if the warning is not significant.
115+
option (FLATCC_ALLOW_WERROR "allow -Werror to be configured" ON)
116+
117+
# Experimental setting - sometimes the code branches on a constant
118+
# expression in order to select the best option for a given type size or
119+
# similar. Sometimes compilers don't like that. If this issue surfaces,
120+
# try using this option.
121+
option (FLATCC_IGNORE_CONST_COND "silence const condition warnings" OFF)
122+
123+
if (FLATCC_RTONLY)
124+
set(FLATCC_TEST off)
125+
endif()
126+
127+
if (FLATCC_TEST)
128+
enable_testing()
129+
endif()
130+
131+
if (NOT FLATCC_TEST)
132+
set(FLATCC_COVERAGE off)
133+
endif()
134+
135+
if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
136+
set(FLATCC_COVERAGE off)
137+
endif()
138+
139+
if (FLATCC_COVERAGE)
140+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -DNDEBUG")
141+
endif()
142+
143+
if (FLATCC_DEBUG_VERIFY)
144+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFLATCC_DEBUG_VERIFY=1")
145+
endif()
146+
147+
if (FLATCC_TRACE_VERIFY)
148+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFLATCC_TRACE_VERIFY=1")
149+
endif()
150+
151+
if (FLATCC_ENFORCE_ALIGNED_EMPTY_VECTORS)
152+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFLATCC_ENFORCE_ALIGNED_EMPTY_VECTORS=1")
153+
endif()
154+
155+
156+
if (FLATCC_REFLECTION)
157+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFLATCC_REFLECTION=1")
158+
else()
159+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFLATCC_REFLECTION=0")
160+
endif()
161+
162+
163+
if (FLATCC_NATIVE_OPTIM)
164+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -DFLATCC_USE_SSE4_2=1")
165+
endif()
166+
167+
if (FLATCC_FAST_DOUBLE)
168+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGRISU3_PARSE_ALLOW_ERROR -DFLATCC_USE_GRISU3=1")
169+
endif()
170+
171+
if (NOT DEFINED FLATCC_INSTALL_LIB)
172+
set(lib_dir lib)
173+
else()
174+
set(lib_dir ${FLATCC_INSTALL_LIB})
175+
endif()
176+
177+
# The folder of this directory, as apposed to CMAKE_BINARY_DIR
178+
# which would usually be the build/Release and build/Debug paths
179+
set (dist_dir "${PROJECT_SOURCE_DIR}")
180+
# set (dist_dir "${CMAKE_BINARY_DIR}")
181+
182+
message(STATUS "dist install dir ${dist_dir}")
183+
message(STATUS "lib install dir ${dist_dir}/${lib_dir}")
184+
185+
# Note: for compiling generated C code, warnings of unused functions
186+
# and constants should be turned off - those are plentiful. They are
187+
# silenced for Clang, GCC and MSVC in generated headers.headers.
188+
189+
if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
190+
# Clang or AppleClang
191+
message(STATUS "Setting Clang compiler options")
192+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes")
193+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-conversion")
194+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion")
195+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -pedantic -Wall -Wextra")
196+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra")
197+
# Fix broken C++ alignas - either will do
198+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
199+
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPORTABLE_PATCH_CPLUSPLUS_STDALIGN")
200+
if (FLATCC_ALLOW_WERROR)
201+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
202+
endif()
203+
if (FLATCC_IGNORE_CONST_COND)
204+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-tautological-constant-out-of-range-compare")
205+
endif()
206+
if (FLATCC_DEBUG_CLANG_SANITIZE)
207+
if (CMAKE_BUILD_TYPE MATCHES Debug)
208+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
209+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
210+
endif()
211+
endif()
212+
# Suppress warning relaxed in clang-6, see https://reviews.llvm.org/D28148
213+
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 6)
214+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers")
215+
endif()
216+
217+
# To get assembly output
218+
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -save-temps")
219+
220+
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
221+
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
222+
OUTPUT_VARIABLE GCC_VERSION)
223+
if (GCC_VERSION VERSION_LESS 4.7)
224+
message(STATUS "Setting older GNU C compiler options with FLATCC_PORTABLE")
225+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
226+
# We need stdalign.h
227+
set(FLATCC_PORTABLE true)
228+
# Disable C++ test for old compilers known to break due to
229+
# missing stdalign.h and incomplete stdint.h which is not a
230+
# priority to fix in portable library for C++ use case.
231+
# Note: we test the C compiler version not the C++ compiler
232+
# version, but that is (hopefully) close enough.
233+
if (FLATCC_CXX_TEST)
234+
message(STATUS "Disabling C++ tests for GCC pre 4.7")
235+
set(FLATCC_CXX_TEST false)
236+
endif()
237+
else()
238+
message(STATUS "Setting GNU C compiler options with c11 and Posix")
239+
if (GCC_VERSION VERSION_LESS 8.0)
240+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -pedantic -Wall -Wextra")
241+
elseif (NOT (GCC_VERSION VERSION_LESS 8.0))
242+
# Disable some GCC checks:
243+
# (warnings exist since 8.0, but are more aggressive in 9.0)
244+
#
245+
# -Wstringop-truncation:
246+
# GCC 9 warns on truncated strncpy into char arrays in FlatBuffer
247+
# structs, but these are valid as zero-paddded, not zero terminated.
248+
#
249+
# -Wno-format-overflow:
250+
# GCC 9 warns on mistakenly assumed NULL string when
251+
# printing from a required FlatBuffer string field.
252+
#
253+
message(STATUS "Disabling -pedantic for GCC >= 8.0")
254+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall -Wextra")
255+
message(STATUS "Disabling GNU C compiler warnings: -Wstringop-truncation -Wno-format-overflow")
256+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-stringop-truncation -Wno-format-overflow")
257+
endif()
258+
if (NOT (GCC_VERSION VERSION_LESS 11.0))
259+
# Disable warning on misleading indentation it become more aggressive in 11.0
260+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-misleading-indentation")
261+
endif()
262+
if (FLATCC_GNU_POSIX_MEMALIGN)
263+
# -std=c11 prevents detection of posix_memalign and aligned_alloc might be missing
264+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPORTABLE_POSIX_MEMALIGN=1")
265+
endif()
266+
if (FLATCC_ALLOW_WERROR)
267+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
268+
endif()
269+
endif()
270+
if (FLATCC_IGNORE_CONST_COND)
271+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-type-limits")
272+
endif()
273+
274+
# Too aggressive, e.g. main() is not permitted and main with
275+
# args then yields unused arg warning.
276+
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes")
277+
278+
# In gcc 4.8 it is not possible to suppress this warning using
279+
# #pragma GCC diagnostic ignored "-Wunused-function"
280+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
281+
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-type-limits")
282+
283+
if (GCC_VERSION VERSION_LESS 4.8)
284+
# -Wsign-conversion broken for GCC 4.7 conditional operator
285+
else()
286+
# Might be disabled if GCC keeps getting more agressive.
287+
# Incorrectly warns on explicit char to uint32_t casts.
288+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-conversion")
289+
290+
# Too aggressive, warns on `x = x + 1;` or `n = -n;`.
291+
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion")
292+
endif()
293+
294+
elseif (CMAKE_C_COMPILER_ID STREQUAL "Intel")
295+
message(STATUS "Setting Intel C (ICC) compiler options")
296+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall -Wextra")
297+
# warning #169: expected a declaration
298+
# Fallthrough attribute does not like semicolon.
299+
# this is fixed in Intel ICC 2021.5.0, but we only have 2021.4.0 in current CI build.
300+
# warning #279: controlling expression is constant
301+
# We have these everywhere in flatcc generated code.
302+
# warning #188: enumerated type mixed with another type
303+
# This is not very noisy, but still annoying, e.g. when zeroing an enum.
304+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd169 -wd279 -wd188")
305+
elseif (MSVC) # using STREQUAL here conflicts with string interpretation changes in CMake
306+
message(STATUS "Setting MSVC C compiler options")
307+
# -DFLATCC_PORTABLE also required, but set earlier
308+
# -W3 is the highest warning level that is reasonable.
309+
# See include/flatcc/portable/pwarnings.h for disabled warnings.
310+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W3 -D_CRT_SECURE_NO_WARNINGS")
311+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W3 -D_CRT_SECURE_NO_WARNINGS")
312+
# MSVC 2013 (1800) supports inline variable declations
313+
# while MSVC 2010 (1600) does not.
314+
if (MSVC_VERSION STRLESS "1800")
315+
# Disables monster sample build which uses C99 style variable decls.
316+
set (FLATCC_NEED_C89_VAR_DECLS true)
317+
endif()
318+
set(FLATCC_PORTABLE true)
319+
elseif (CMAKE_C_COMPILER_ID STREQUAL "XL")
320+
# IBM's native XLC C compiler in extended C99 mode
321+
322+
message(STATUS "Setting IBM XL C compiler options")
323+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qlanglvl=extc99")
324+
else()
325+
# Best effort
326+
message(STATUS "Best effort settings for compiler: ${CMAKE_C_COMPILER_ID}")
327+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
328+
set(FLATCC_PORTABLE true)
329+
endif()
330+
331+
if (FLATCC_PORTABLE)
332+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFLATCC_PORTABLE")
333+
endif()
334+
335+
if (CLANG_VERSION)
336+
message(STATUS "CLANG_VERSION: ${CLANG_VERSION}")
337+
endif()
338+
if (GCC_VERSION)
339+
message(STATUS "GCC_VERSION: ${GCC_VERSION}")
340+
endif()
341+
message(STATUS "Configured C_FLAGS: ${CMAKE_C_FLAGS}")
342+
343+
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/${lib_dir})
344+
345+
set(CMAKE_DEBUG_POSTFIX "_d")
346+
347+
if (CMAKE_BUILD_TYPE MATCHES "Debug")
348+
set(CMAKE_EXECUTABLE_SUFFIX "_d${CMAKE_EXECUTABLE_SUFFIX}")
349+
endif()
350+
351+
352+
if (FLATCC_RTONLY)
353+
# The targets we copy to bin and lib directories, i.e. not tests.
354+
set(dist_targets
355+
flatccrt
356+
)
357+
add_subdirectory(src/runtime)
358+
else()
359+
# The targets we copy to bin and lib directories, i.e. not tests.
360+
set(dist_targets
361+
flatcc
362+
flatccrt
363+
flatcc_cli
364+
)
365+
add_subdirectory(src/runtime)
366+
add_subdirectory(src/compiler)
367+
add_subdirectory(src/cli)
368+
endif()
369+
370+
# disabled by FLATCC_RTONLY
371+
if (FLATCC_TEST)
372+
add_subdirectory(test)
373+
add_subdirectory(samples)
374+
endif()
375+
376+
if (FLATCC_COVERAGE)
377+
add_custom_target(coverage
378+
COMMAND lcov --capture --directory src --output-file coverage.info
379+
COMMAND genhtml coverage.info --output-directory coverage)
380+
endif()
381+
382+
set_target_properties(${dist_targets}
383+
PROPERTIES
384+
ARCHIVE_OUTPUT_DIRECTORY "${dist_dir}/${lib_dir}"
385+
LIBRARY_OUTPUT_DIRECTORY "${dist_dir}/${lib_dir}"
386+
RUNTIME_OUTPUT_DIRECTORY "${dist_dir}/bin"
387+
)
388+
389+
if (FLATCC_INSTALL)
390+
install(DIRECTORY include/flatcc DESTINATION include)
391+
endif()
392+

0 commit comments

Comments
 (0)