Skip to content

Commit

Permalink
Merge 3c9fdca into c317439
Browse files Browse the repository at this point in the history
  • Loading branch information
cpjulia committed Jun 1, 2022
2 parents c317439 + 3c9fdca commit e114714
Show file tree
Hide file tree
Showing 10 changed files with 9,098 additions and 242 deletions.
22 changes: 20 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ endif()

option(BuildVelocyPackExamples "Build examples" ON)
option(Maintainer "Build maintainer tools" OFF)
option(BuildSseOpt "Build with SSE optimization instructions" ON)

set(HashType "xxhash" CACHE STRING "Hash type (fasthash, xxhash, wyhash)" )

Expand All @@ -57,6 +58,16 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)

#Compiler Setting
include(AR_CompilerSettings)
if(NOT BuildSseOpt OR NOT CAN_USE_SSE)
add_definitions("-DASM_OPTIMIZATIONS=0")
else()
if(ADD_SSE_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
elseif(IS_ARM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__ARM_NEON")
endif()
add_definitions("-DASM_OPTIMIZATIONS=1")
endif()

set(VELOCY_SOURCE
src/velocypack-common.cpp
Expand Down Expand Up @@ -98,8 +109,15 @@ endif()
message(STATUS "VelocyPack Building with hash type: ${HashType}")

add_library(velocypack STATIC ${VELOCY_SOURCE})
target_include_directories(velocypack PRIVATE src)
target_include_directories(velocypack PUBLIC include)
target_include_directories(
velocypack
PRIVATE ${PROJECT_SOURCE_DIR}/src
PUBLIC ${PROJECT_SOURCE_DIR}/include
)

if(IS_ARM)
target_include_directories(velocypack PRIVATE ${PROJECT_SOURCE_DIR}/external/sse2neon)
endif()

if(Maintainer)
add_executable(buildVersion scripts/build-version.cpp)
Expand Down
70 changes: 36 additions & 34 deletions cmake/Modules/AR_CompilerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@ find_package(SSE)
# compiler options

if(CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "Compiler type GNU: ${CMAKE_CXX_COMPILER}")
set(BASE_COMPILER_OPTIONS "-Wall -Wextra")
message(STATUS "Compiler type GNU: ${CMAKE_CXX_COMPILER}")
set(BASE_COMPILER_OPTIONS "-Wall -Wextra")

if(Coverage)
set(BASE_COMPILER_OPTIONS "${BASE_COMPILER_OPTIONS} -fprofile-arcs -ftest-coverage")
endif()
if(Coverage)
set(BASE_COMPILER_OPTIONS "${BASE_COMPILER_OPTIONS} -fprofile-arcs -ftest-coverage")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILER_OPTIONS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${BASE_COMPILER_OPTIONS} -O0 -g -DVELOCYPACK_DEBUG=1")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${BASE_COMPILER_OPTIONS} -Os")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${BASE_COMPILER_OPTIONS} -O3 -fomit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${BASE_COMPILER_OPTIONS} -O3 -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILER_OPTIONS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${BASE_COMPILER_OPTIONS} -O0 -g -DVELOCYPACK_DEBUG=1")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${BASE_COMPILER_OPTIONS} -Os")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${BASE_COMPILER_OPTIONS} -O3 -fomit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${BASE_COMPILER_OPTIONS} -O3 -g")

set(CanUseSSE42 ${SSE4_2_FOUND} CACHE BOOL "Use SSE4.2 optimizations")
set(CanUseSSE42 ${SSE4_2_FOUND} CACHE BOOL "Use SSE4.2 optimizations")
elseif(CMAKE_COMPILER_IS_CLANGCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# using regular Clang or AppleClang
message(STATUS "Compiler type CLANG: ${CMAKE_CXX_COMPILER}")
set(BASE_COMPILER_OPTIONS "-Wall -Wextra")
# using regular Clang or AppleClang
message(STATUS "Compiler type CLANG: ${CMAKE_CXX_COMPILER}")
set(BASE_COMPILER_OPTIONS "-Wall -Wextra")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILER_OPTIONS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${BASE_COMPILER_OPTIONS} -O0 -g -DVELOCYPACK_DEBUG=1")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${BASE_COMPILER_OPTIONS} -Os")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${BASE_COMPILER_OPTIONS} -O3 -fomit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${BASE_COMPILER_OPTIONS} -O3 -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILER_OPTIONS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${BASE_COMPILER_OPTIONS} -O0 -g -DVELOCYPACK_DEBUG=1")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${BASE_COMPILER_OPTIONS} -Os")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${BASE_COMPILER_OPTIONS} -O3 -fomit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${BASE_COMPILER_OPTIONS} -O3 -g")

set(CanUseSSE42 ${SSE4_2_FOUND} CACHE BOOL "Use SSE4.2 optimizations")
set(CanUseSSE42 ${SSE4_2_FOUND} CACHE BOOL "Use SSE4.2 optimizations")

elseif(MSVC)
message(STATUS "Compiler type MSVC: ${CMAKE_CXX_COMPILER}")
add_definitions("-D_CRT_SECURE_NO_WARNINGS=1")
elseif(MSVC)
message(STATUS "Compiler type MSVC: ${CMAKE_CXX_COMPILER}")
add_definitions("-D_CRT_SECURE_NO_WARNINGS=1")

foreach (flag_var
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO)
foreach (flag_var
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO)

# Make MSVC correctly report the C++ version in __cplusplus; without it,
# it always reports 199711L (i.e. C++98).
Expand Down Expand Up @@ -69,15 +69,17 @@ endif()

# options
if(CanUseSSE42)
option(EnableSSE "Build using SSE4.2 optimizations" ON)
option(EnableSSE "Build able to use SSE4.2 optimizations" ON)
else()
option(EnableSSE "Build using SSE4.2 optimizations" OFF)
endif()

message(STATUS "Building with SSE 4.2 optimizations enabled: ${EnableSSE}")
if(EnableSSE AND NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
add_definitions("-DASM_OPTIMIZATIONS=1")
set(ADD_SSE_FLAG ON)
endif()
if(IS_ARM OR (EnableSSE AND NOT MSVC))
set(CAN_USE_SSE ON)
else()
add_definitions("-DASM_OPTIMIZATIONS=0")
set(CAN_USE_SSE OFF)
endif()
3 changes: 3 additions & 0 deletions cmake/Modules/FindSSE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ if(ARCH MATCHES "i386" OR ARCH MATCHES "x86_64")
set(SSE4_1_FOUND false CACHE BOOL "SSE4.1 available on host")
endif(CMAKE_SYSTEM_NAME MATCHES "Linux")
endif(ARCH MATCHES "i386" OR ARCH MATCHES "x86_64")
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*|armv8.*|ARMV8.*)")
set(IS_ARM ON)
endif()

#message(STATUS "Hardware support for SSE2 on this machine: ${SSE2_FOUND}")
#message(STATUS "Hardware support for SSE3 on this machine: ${SSE3_FOUND}")
Expand Down
164 changes: 84 additions & 80 deletions cmake/Modules/TargetArch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
# "There are many more known variants/revisions that we do not handle/detect."

set(archdetect_c_code "
#if defined(__arm__) || defined(__TARGET_ARCH_ARM)
#if defined(__ARM_ARCH_7__) \\
#if defined(__arm__) || defined(__aarch64__) || defined(__TARGET_ARCH_ARM)
#if defined(__ARM_ARCH_8__) \\
|| defined(__ARM_ARCH_8A__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 8)
#error cmake_ARCH armv8
#elif defined(__ARM_ARCH_7__) \\
|| defined(__ARM_ARCH_7A__) \\
|| defined(__ARM_ARCH_7R__) \\
|| defined(__ARM_ARCH_7M__) \\
Expand Down Expand Up @@ -51,84 +55,84 @@ set(archdetect_c_code "
# will be treated as invalid architectures since they are no longer supported by Apple

function(target_architecture output_var)
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
# On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set
# First let's normalize the order of the values

# Note that it's not possible to compile PowerPC applications if you are using
# the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we
# disable it by default
# See this page for more information:
# http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4

# Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime.
# On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise.

foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
if("${osx_arch}" STREQUAL "ppc" AND ppc_support)
set(osx_arch_ppc TRUE)
elseif("${osx_arch}" STREQUAL "i386")
set(osx_arch_i386 TRUE)
elseif("${osx_arch}" STREQUAL "x86_64")
set(osx_arch_x86_64 TRUE)
elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support)
set(osx_arch_ppc64 TRUE)
else()
message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
endif()
endforeach()

# Now add all the architectures in our normalized order
if(osx_arch_ppc)
list(APPEND ARCH ppc)
endif()

if(osx_arch_i386)
list(APPEND ARCH i386)
endif()

if(osx_arch_x86_64)
list(APPEND ARCH x86_64)
endif()

if(osx_arch_ppc64)
list(APPEND ARCH ppc64)
endif()
else()
file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")

enable_language(C)

# Detect the architecture in a rather creative way...
# This compiles a small C program which is a series of ifdefs that selects a
# particular #error preprocessor directive whose message string contains the
# target architecture. The program will always fail to compile (both because
# file is not a valid C program, and obviously because of the presence of the
# #error preprocessor directives... but by exploiting the preprocessor in this
# way, we can detect the correct target architecture even when cross-compiling,
# since the program itself never needs to be run (only the compiler/preprocessor)
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/arch.c"
COMPILE_OUTPUT_VARIABLE ARCH
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
)

# Parse the architecture name from the compiler output
string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")

# Get rid of the value marker leaving just the architecture name
string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")

# If we are compiling with an unknown architecture this variable should
# already be set to "unknown" but in the case that it's empty (i.e. due
# to a typo in the code), then set it to unknown
if (NOT ARCH)
set(ARCH unknown)
endif()
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
# On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set
# First let's normalize the order of the values

# Note that it's not possible to compile PowerPC applications if you are using
# the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we
# disable it by default
# See this page for more information:
# http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4

# Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime.
# On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise.

foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
if("${osx_arch}" STREQUAL "ppc" AND ppc_support)
set(osx_arch_ppc TRUE)
elseif("${osx_arch}" STREQUAL "i386")
set(osx_arch_i386 TRUE)
elseif("${osx_arch}" STREQUAL "x86_64")
set(osx_arch_x86_64 TRUE)
elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support)
set(osx_arch_ppc64 TRUE)
else()
message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
endif()
endforeach()

# Now add all the architectures in our normalized order
if(osx_arch_ppc)
list(APPEND ARCH ppc)
endif()

set(${output_var} "${ARCH}" PARENT_SCOPE)
if(osx_arch_i386)
list(APPEND ARCH i386)
endif()

if(osx_arch_x86_64)
list(APPEND ARCH x86_64)
endif()

if(osx_arch_ppc64)
list(APPEND ARCH ppc64)
endif()
else()
file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")

enable_language(C)

# Detect the architecture in a rather creative way...
# This compiles a small C program which is a series of ifdefs that selects a
# particular #error preprocessor directive whose message string contains the
# target architecture. The program will always fail to compile (both because
# file is not a valid C program, and obviously because of the presence of the
# #error preprocessor directives... but by exploiting the preprocessor in this
# way, we can detect the correct target architecture even when cross-compiling,
# since the program itself never needs to be run (only the compiler/preprocessor)
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/arch.c"
COMPILE_OUTPUT_VARIABLE ARCH
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
)

# Parse the architecture name from the compiler output
string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")

# Get rid of the value marker leaving just the architecture name
string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")

# If we are compiling with an unknown architecture this variable should
# already be set to "unknown" but in the case that it's empty (i.e. due
# to a typo in the code), then set it to unknown
if(NOT ARCH)
set(ARCH unknown)
endif()
endif()

set(${output_var} "${ARCH}" PARENT_SCOPE)
endfunction()
1 change: 1 addition & 0 deletions external/sse2neon/emmintrin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <sse2neon.h>
1 change: 1 addition & 0 deletions external/sse2neon/smmintrin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <sse2neon.h>

0 comments on commit e114714

Please sign in to comment.