Skip to content

Commit

Permalink
Add: additional checks for platform and compiler flags
Browse files Browse the repository at this point in the history
  • Loading branch information
dnzbk committed Dec 3, 2024
1 parent 534665f commit 0a41680
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 34 deletions.
17 changes: 17 additions & 0 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
if (CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|x86|x86_64|x64|amd64|AMD64|win32|Win32")
set(IS_X86 TRUE)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|x64|amd64|AMD64")
set(IS_X64 TRUE)
endif()
endif()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM|aarch64|arm64|ARM64|armeb|aarch64be|aarch64_be")
set(IS_ARM TRUE)
endif()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64|rv64")
set(IS_RISCV64 TRUE)
endif()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "riscv32|rv32")
set(IS_RISCV32 TRUE)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
add_compile_options(-Weverything -Wno-c++98-compat)
Expand All @@ -22,3 +38,4 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
endif()

include(ExternalProject)
include(CheckCXXCompilerFlag)
72 changes: 38 additions & 34 deletions lib/sources.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
if(CMAKE_SYSTEM_PROCESSOR MATCHES "i?86|x86_64")
set(SSE2_CXXFLAGS "-msse2")
set(SSSE3_CXXFLAGS "-mssse3")
set(PCLMUL_CXXFLAGS "-msse4.1 -mpclmul")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
set(ACLECRC_CXXFLAGS "-march=armv8-a+crc -fpermissive")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm.*")
set(NEON_CXXFLAGS "-mfpu=neon")
set(ACLECRC_CXXFLAGS "-march=armv8-a+crc -fpermissive")
if(IS_ARM)
CHECK_CXX_COMPILER_FLAG("-mfpu=neon -march=armv7-a" COMPILER_SUPPORTS_ARM32_NEON)
if(COMPILER_SUPPORTS_ARM32_NEON)
set_source_files_properties(
${CMAKE_SOURCE_DIR}/lib/yencode/NeonDecoder.cpp
PROPERTIES COMPILE_FLAGS "-mfpu=neon -march=armv7-a"
)
else()
CHECK_CXX_COMPILER_FLAG("-march=armv8-a+crc" COMPILER_SUPPORTS_ARM_CRC)
set_source_files_properties(
${CMAKE_SOURCE_DIR}/lib/yencode/AcleCrc.cpp
PROPERTIES COMPILE_FLAGS "-march=armv8-a+crc"
)
endif()
endif()

if(IS_X86)
CHECK_CXX_COMPILER_FLAG("-msse2" COMPILER_SUPPORTS_SSE2)
if(COMPILER_SUPPORTS_SSE2)
set_source_files_properties(
${CMAKE_SOURCE_DIR}/lib/yencode/Sse2Decoder.cpp
PROPERTIES COMPILE_FLAGS "-msse2"
)
endif()
CHECK_CXX_COMPILER_FLAG("-mssse3" COMPILER_SUPPORTS_SSSE3)
if(COMPILER_SUPPORTS_SSSE3)
set_source_files_properties(
${CMAKE_SOURCE_DIR}/lib/yencode/Ssse3Decoder.cpp
PROPERTIES COMPILE_FLAGS "-mssse3"
)
endif()
CHECK_CXX_COMPILER_FLAG("-msse4.1 -mpclmul" COMPILER_SUPPORTS_SSE41_PCLMUL)
if(COMPILER_SUPPORTS_SSE41_PCLMUL)
set_source_files_properties(
${CMAKE_SOURCE_DIR}/lib/yencode/PclmulCrc.cpp
PROPERTIES COMPILE_FLAGS "-msse4.1 -mpclmul"
)
endif()
endif()

add_library(regex STATIC
Expand All @@ -17,31 +46,6 @@ target_include_directories(regex PUBLIC
${CMAKE_SOURCE_DIR}/lib/regex
)

set_source_files_properties(
${CMAKE_SOURCE_DIR}/lib/yencode/Sse2Decoder.cpp
PROPERTIES COMPILE_FLAGS "${SSE2_CXXFLAGS}"
)

set_source_files_properties(
${CMAKE_SOURCE_DIR}/lib/yencode/Ssse3Decoder.cpp
PROPERTIES COMPILE_FLAGS "${SSSE3_CXXFLAGS}"
)

set_source_files_properties(
${CMAKE_SOURCE_DIR}/lib/yencode/PclmulCrc.cpp
PROPERTIES COMPILE_FLAGS "${PCLMUL_CXXFLAGS}"
)

set_source_files_properties(
${CMAKE_SOURCE_DIR}/lib/yencode/NeonDecoder.cpp
PROPERTIES COMPILE_FLAGS "${NEON_CXXFLAGS}"
)

set_source_files_properties(
${CMAKE_SOURCE_DIR}/lib/yencode/AcleCrc.cpp
PROPERTIES COMPILE_FLAGS "${ACLECRC_CXXFLAGS}"
)

add_library(yencode STATIC
${CMAKE_SOURCE_DIR}/lib/yencode/SimdInit.cpp
${CMAKE_SOURCE_DIR}/lib/yencode/SimdDecoder.cpp
Expand Down

0 comments on commit 0a41680

Please sign in to comment.