diff --git a/cmake/common.cmake b/cmake/common.cmake index 8fe927ca..cbeb9f6e 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -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) @@ -22,3 +38,4 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release") endif() include(ExternalProject) +include(CheckCXXCompilerFlag) diff --git a/lib/sources.cmake b/lib/sources.cmake index 3715757d..6e56efc7 100644 --- a/lib/sources.cmake +++ b/lib/sources.cmake @@ -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" 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" + ) + 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 @@ -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