simdjson/cmake/implementation-flags.cmake

107 lines
3.5 KiB
CMake
Raw Normal View History

CMake refactor stage1 (#1512) * Remove CMP0025 policy This policy is already set to NEW by the minimum required version. * Use HOMEPAGE_URL in the project call * Use VERSION in the project call * Detect if this is the top project * Port simdjson-user-cmakecache to a CMake script * Create a developer mode The SIMDJSON_DEVELOPER_MODE option set to ON will enable targets that are only useful for developers of simdjson. * Consolidate root CML commands into logical sections * Warn about intended use of developer mode * Prettify the just_ascii test * Remove redundant CMake variables * Inline CML contents from include and src * Raise minimum CMake requirement to 3.14 * Define proper install rules * Restore thread support variable * Add BUILD_SHARED_LIBS as a top level only option * Force developer mode to be on in CI * Include flags earlier in developer mode * Set CMAKE_BUILD_TYPE conditionally CMAKE_BUILD_TYPE is used only by single configuration generators and is otherwise completely ignored. * Remove useless static/shared options simdjson now uses the CMake builtin BUILD_SHARED_LIBS to switch the built artifact's type. * Remove unused CMAKE_MODULE_PATH variable * Refactor implementation switching into a module * Factor exception option out into a module * Reformat simdjson-flags.cmake * Rename simdjson-flags to developer-options * Accumulate properties into an include module This is done this way to avoid using utility targets that must be exported and installed, which could potentially be misused by users of the library. * Port impl definitions to props * Port exception options to props * Lift normal options to the top * Port developer options to props * Remove simdjson-flags from benchmark * Document the developer mode in HACKING * Fix include path in installed config file * Fix formatting of prop commands * Fix tests that include .cpp files * Change GCC AVX fixes back to compile options * Deprecate SIMDJSON_BUILD_STATIC * Always link fuzz targets to simdjson * Install CMake from simdjson's debian repo * Add gnupg for apt-key * Make sure ASan link flags come first * Pass CI env variable to cmake invocation * Install package for apt-add-repository * Remove return() from flush macro * Use directory level commands instead of props * Restore the github repository variable * Set developer mode unconditionally for checkperf The CI env variable is only set in the CI and this target is always run in developer mode. * Attempt to fix ODR violation in parsing checks These tests were compiling the simdjson.cpp file again and linking to the simdjson library target causes ODR violations. Instead of linking to the target, just inherit its props. * Move variables before the source dir * Mark props to be flushed after adding more * Use props for every command for the library * Use keyword form for linking libs * Handle deprecation of SIMDJSON_JUST_LIBRARY * Handle deprecations in a separate module Co-authored-by: friendlyanon <friendlyanon@users.noreply.github.com>
2021-04-23 21:24:56 +08:00
#
# Implementation selection
#
set(SIMDJSON_ALL_IMPLEMENTATIONS fallback westmere haswell arm64 ppc64)
set(
SIMDJSON_IMPLEMENTATION ""
CACHE STRING "\
Semicolon-separated list of implementations to include \
(${SIMDJSON_ALL_IMPLEMENTATIONS}). If this is not set, any implementations \
that are supported at compile time and may be selected at runtime will be \
included."
)
set(
SIMDJSON_EXCLUDE_IMPLEMENTATION ""
CACHE STRING "\
Semicolon-separated list of implementations to exclude \
(haswell/westmere/arm64/ppc64/fallback). By default, excludes any \
implementations that are unsupported at compile time or cannot be selected at \
runtime."
)
foreach(var IN ITEMS IMPLEMENTATION EXCLUDE_IMPLEMENTATION)
set(var "SIMDJSON_${var}")
foreach(impl IN LISTS "${var}")
if(NOT impl IN_LIST SIMDJSON_ALL_IMPLEMENTATIONS)
message(ERROR "\
Implementation ${impl} found in ${var} not supported by simdjson. \
Possible implementations: ${SIMDJSON_ALL_IMPLEMENTATIONS}")
endif()
endforeach()
endforeach()
macro(flag_action action var val)
message(STATUS "${action} implementation ${impl} due to ${var}=${${var}}")
simdjson_add_props(
target_compile_definitions PUBLIC
"SIMDJSON_IMPLEMENTATION_${impl_upper}=${val}"
)
endmacro()
foreach(impl IN LISTS SIMDJSON_ALL_IMPLEMENTATIONS)
string(TOUPPER "${impl}" impl_upper)
if(impl IN_LIST SIMDJSON_EXCLUDE_IMPLEMENTATION)
flag_action(Excluding SIMDJSON_EXCLUDE_IMPLEMENTATION 0)
elseif(impl IN_LIST SIMDJSON_IMPLEMENTATION)
flag_action(Including SIMDJSON_IMPLEMENTATION 1)
elseif(SIMDJSON_IMPLEMENTATION)
flag_action(Excluding SIMDJSON_IMPLEMENTATION 0)
endif()
endforeach()
# TODO make it so this generates the necessary compiler flags to select the
# given impl as the builtin automatically!
set(
SIMDJSON_BUILTIN_IMPLEMENTATION ""
CACHE STRING "\
Select the implementation that will be used for user code. Defaults to the \
most universal implementation in SIMDJSON_IMPLEMENTATION (in the order \
${SIMDJSON_ALL_IMPLEMENTATIONS}) if specified; otherwise, by default the \
compiler will pick the best implementation that can always be selected given \
the compiler flags."
)
if(NOT SIMDJSON_BUILTIN_IMPLEMENTATION STREQUAL "")
simdjson_add_props(
target_compile_definitions PUBLIC
"SIMDJSON_BUILTIN_IMPLEMENTATION=${SIMDJSON_BUILTIN_IMPLEMENTATION}"
)
else()
# Pick the most universal implementation out of the selected implementations
# (if any)
foreach(impl IN LISTS SIMDJSON_ALL_IMPLEMENTATIONS)
if(
impl IN_LIST SIMDJSON_IMPLEMENTATION
AND NOT impl IN_LIST SIMDJSON_EXCLUDE_IMPLEMENTATION
)
message(STATUS "\
Selected implementation ${impl} as builtin implementation based on \
${SIMDJSON_IMPLEMENTATION}")
simdjson_add_props(
target_compile_definitions PUBLIC
"SIMDJSON_BUILTIN_IMPLEMENTATION=${impl}"
)
break()
endif()
endforeach()
endif()
foreach(impl IN LISTS SIMDJSON_ALL_IMPLEMENTATIONS)
string(TOUPPER "${impl}" impl_upper)
option(
"SIMDJSON_IMPLEMENTATION_${impl_upper}"
"Include the ${impl} implementation"
ON
)
mark_as_advanced("SIMDJSON_IMPLEMENTATION_${impl_upper}")
if(NOT "${SIMDJSON_IMPLEMENTATION_${impl_upper}}")
message(DEPRECATION "\
SIMDJSON_IMPLEMENTATION_${impl_upper} is deprecated. \
Use SIMDJSON_IMPLEMENTATION=-${impl} instead")
simdjson_add_props(
target_compile_definitions PUBLIC
"SIMDJSON_IMPLEMENTATION_${impl_upper}=0"
)
endif()
endforeach()