2021-04-23 21:24:56 +08:00
#
# Flags used by exes and by the simdjson library (project-wide flags)
#
add_library ( simdjson-internal-flags INTERFACE )
2021-07-25 22:36:22 +08:00
option ( SIMDJSON_CHECK_EOF "Check for the end of the input buffer. The setting is unnecessary since we require padding of the inputs. You should expect tests to fail with this option turned on." OFF )
if ( SIMDJSON_CHECK_EOF )
add_compile_definitions ( SIMDJSON_CHECK_EOF=1 )
endif ( )
2021-04-23 21:24:56 +08:00
option ( SIMDJSON_SANITIZE_UNDEFINED "Sanitize undefined behavior" OFF )
if ( SIMDJSON_SANITIZE_UNDEFINED )
add_compile_options ( -fsanitize=undefined -fno-sanitize-recover=all )
add_link_options ( -fsanitize=undefined -fno-sanitize-recover=all )
endif ( )
option ( SIMDJSON_SANITIZE "Sanitize addresses" OFF )
if ( SIMDJSON_SANITIZE )
if ( CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
message ( STATUS " The address sanitizer under Apple's clang appears to be \
i n c o m p a t i b l e w i t h t h e u n d e f i n e d - b e h a v i o r s a n i t i z e r . " )
message ( STATUS " You may set SIMDJSON_SANITIZE_UNDEFINED to sanitize \
u n d e f i n e d b e h a v i o r . " )
add_compile_options (
- f s a n i t i z e = a d d r e s s - f n o - o m i t - f r a m e - p o i n t e r - f n o - s a n i t i z e - r e c o v e r = a l l
)
add_compile_definitions ( ASAN_OPTIONS=detect_leaks=1 )
link_libraries (
- f s a n i t i z e = a d d r e s s - f n o - o m i t - f r a m e - p o i n t e r - f n o - s a n i t i z e - r e c o v e r = a l l
)
else ( )
message (
S T A T U S
" S e t t i n g b o t h t h e a d d r e s s s a n i t i z e r a n d t h e u n d e f i n e d s a n i t i z e r . "
)
add_compile_options (
- f s a n i t i z e = a d d r e s s - f n o - o m i t - f r a m e - p o i n t e r
- f s a n i t i z e = u n d e f i n e d - f n o - s a n i t i z e - r e c o v e r = a l l
)
link_libraries (
- f s a n i t i z e = a d d r e s s - f n o - o m i t - f r a m e - p o i n t e r
- f s a n i t i z e = u n d e f i n e d - f n o - s a n i t i z e - r e c o v e r = a l l
)
endif ( )
# Ubuntu bug for GCC 5.0+ (safe for all versions)
if ( CMAKE_COMPILER_IS_GNUCC )
link_libraries ( -fuse-ld=gold )
endif ( )
endif ( )
if ( SIMDJSON_SANITIZE_THREADS )
message ( STATUS " Setting both the thread sanitizer \
a n d t h e u n d e f i n e d - b e h a v i o r s a n i t i z e r . " )
add_compile_options (
- f s a n i t i z e = t h r e a d - f s a n i t i z e = u n d e f i n e d - f n o - s a n i t i z e - r e c o v e r = a l l
)
link_libraries (
- f s a n i t i z e = t h r e a d - f s a n i t i z e = u n d e f i n e d - f n o - s a n i t i z e - r e c o v e r = a l l
)
# Ubuntu bug for GCC 5.0+ (safe for all versions)
if ( CMAKE_COMPILER_IS_GNUCC )
link_libraries ( -fuse-ld=gold )
endif ( )
endif ( )
get_cmake_property ( is_multi_config GENERATOR_IS_MULTI_CONFIG )
if ( NOT is_multi_config AND NOT CMAKE_BUILD_TYPE )
# Deliberately not including SIMDJSON_SANITIZE_THREADS since thread behavior
# depends on the build type.
if ( SIMDJSON_SANITIZE OR SIMDJSON_SANITIZE_UNDEFINED )
message ( STATUS " No build type selected and you have enabled the sanitizer, \
d e f a u l t t o D e b u g . C o n s i d e r s e t t i n g C M A K E _ B U I L D _ T Y P E . " )
set ( CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE )
else ( )
message ( STATUS "No build type selected, default to Release" )
set ( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE )
endif ( )
endif ( )
if ( NOT MSVC )
option ( SIMDJSON_USE_LIBCPP "Use the libc++ library" OFF )
endif ( )
if ( MSVC AND BUILD_SHARED_LIBS )
# This will require special handling.
set ( SIMDJSON_WINDOWS_DLL TRUE )
endif ( )
# We compile tools, tests, etc. with C++ 17. Override yourself if you need on a
# target.
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_CXX_EXTENSIONS OFF )
set ( CMAKE_MACOSX_RPATH OFF )
set ( CMAKE_THREAD_PREFER_PTHREAD ON )
set ( THREADS_PREFER_PTHREAD_FLAG ON )
# LTO seems to create all sorts of fun problems. Let us
# disable temporarily.
#include(CheckIPOSupported)
#check_ipo_supported(RESULT ltoresult)
#if(ltoresult)
# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
#endif()
option ( SIMDJSON_VISUAL_STUDIO_BUILD_WITH_DEBUG_INFO_FOR_PROFILING " \
U n d e r V i s u a l S t u d i o , a d d Z i t o t h e c o m p i l e f l a g a n d D E B U G t o t h e l i n k f i l e t o \
a d d d e b u g g i n g i n f o r m a t i o n t o t h e r e l e a s e b u i l d f o r e a s i e r p r o f i l i n g i n s i d e \
t o o l s l i k e V T u n e " O F F )
if ( MSVC )
if ( MSVC_TOOLSET_VERSION STRLESS "142" )
set ( SIMDJSON_LEGACY_VISUAL_STUDIO TRUE )
message ( STATUS " A legacy Visual Studio version was detected. \
W e r e c o m m e n d V i s u a l S t u d i o 2 0 1 9 o r b e t t e r o n a 6 4 - b i t s y s t e m . " )
endif ( )
if ( MSVC_TOOLSET_VERSION STREQUAL "140" )
# Visual Studio 2015 issues warnings and we tolerate it
# cmake -G "Visual Studio 14" ..
target_compile_options ( simdjson-internal-flags INTERFACE /W0 /sdl )
else ( )
# Recent version of Visual Studio expected (2017, 2019...). Prior versions
# are unsupported.
# https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4714?view=vs-2019
target_compile_options ( simdjson-internal-flags INTERFACE /WX /W3 /sdl /w34714 )
2021-06-01 22:57:37 +08:00
if ( MSVC_VERSION GREATER 1910 )
target_compile_options ( simdjson-internal-flags INTERFACE /permissive- )
endif ( )
2021-04-23 21:24:56 +08:00
endif ( )
if ( SIMDJSON_VISUAL_STUDIO_BUILD_WITH_DEBUG_INFO_FOR_PROFILING )
add_link_options ( /DEBUG )
add_compile_options ( /Zi )
endif ( )
else ( )
if ( NOT WIN32 )
target_compile_options ( simdjson-internal-flags INTERFACE -fPIC )
endif ( )
target_compile_options (
s i m d j s o n - i n t e r n a l - f l a g s I N T E R F A C E
- W e r r o r - W a l l - W e x t r a - W e f f c + + - W s i g n - c o m p a r e - W s h a d o w - W w r i t e - s t r i n g s
- W p o i n t e r - a r i t h - W i n i t - s e l f - W c o n v e r s i o n - W n o - s i g n - c o n v e r s i o n
)
endif ( )
#
# Other optional flags
#
option ( SIMDJSON_BASH "Allow usage of bash within CMake" ON )
option (
S I M D J S O N _ V E R B O S E _ L O G G I N G
" E n a b l e v e r b o s e l o g g i n g f o r i n t e r n a l s i m d j s o n l i b r a r y d e v e l o p m e n t . "
O F F
)
if ( SIMDJSON_VERBOSE_LOGGING )
add_compile_definitions ( SIMDJSON_VERBOSE_LOGGING=1
)
endif ( )
if ( SIMDJSON_USE_LIBCPP )
link_libraries ( -stdlib=libc++ -lc++abi )
# instead of the above line, we could have used
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++
# -lc++abi")
# The next line is needed empirically.
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++" )
# we update CMAKE_SHARED_LINKER_FLAGS, this gets updated later as well
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lc++abi" )
endif ( )
# prevent shared libraries from depending on Intel provided libraries
if ( CMAKE_C_COMPILER_ID MATCHES "Intel" )
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel" )
endif ( )
include ( CheckSymbolExists )
check_symbol_exists ( fork unistd.h HAVE_POSIX_FORK )
check_symbol_exists ( wait sys/wait.h HAVE_POSIX_WAIT )