diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d0042afe..cd5530188 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ option(WITH_DEBUG_LOG "Enable debug log output" OFF) option(WITH_TLS "Enable OpenSSL support" ON) option(WITH_ASM "Enable ASM PoW implementations" ON) option(BUILD_STATIC "Build static binary" OFF) +option(ARM_TARGET "Force use specific ARM target 8 or 7" 0) include (CheckIncludeFile) include (cmake/cpu.cmake) diff --git a/cmake/cpu.cmake b/cmake/cpu.cmake index 96e61e2b6..2fdebad81 100644 --- a/cmake/cpu.cmake +++ b/cmake/cpu.cmake @@ -7,19 +7,37 @@ if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$") add_definitions(/DRAPIDJSON_SSE2) endif() - -if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64)$") - set(XMRIG_ARM ON) - set(XMRIG_ARMv8 ON) - set(WITH_LIBCPUID OFF) - - add_definitions(/DXMRIG_ARM) - add_definitions(/DXMRIG_ARMv8) -elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7|armv7f|armv7s|armv7k|armv7-a|armv7l)$") - set(XMRIG_ARM ON) - set(XMRIG_ARMv7 ON) - set(WITH_LIBCPUID OFF) - - add_definitions(/DXMRIG_ARM) - add_definitions(/DXMRIG_ARMv7) +if (NOT ARM_TARGET) + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|armv8-a)$") + set(ARM_TARGET 8) + elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7|armv7f|armv7s|armv7k|armv7-a|armv7l)$") + set(ARM_TARGET 7) + endif() +endif() + +if (ARM_TARGET AND ARM_TARGET GREATER 6) + set(XMRIG_ARM ON) + set(WITH_LIBCPUID OFF) + add_definitions(/DXMRIG_ARM) + + message(STATUS "Use ARM_TARGET=${ARM_TARGET} (${CMAKE_SYSTEM_PROCESSOR})") + + include(CheckCXXCompilerFlag) + + if (ARM_TARGET EQUAL 8) + set(XMRIG_ARMv8 ON) + add_definitions(/DXMRIG_ARMv8) + + CHECK_CXX_COMPILER_FLAG(-march=armv8-a+crypto XMRIG_ARM_CRYPTO) + + if (XMRIG_ARM_CRYPTO) + add_definitions(/DXMRIG_ARM_CRYPTO) + set(ARM8_CXX_FLAGS "-march=armv8-a+crypto") + else() + set(ARM8_CXX_FLAGS "-march=armv8-a") + endif() + elseif (ARM_TARGET EQUAL 7) + set(XMRIG_ARMv7 ON) + add_definitions(/DXMRIG_ARMv7) + endif() endif() diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 8bc148042..3989cb71b 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -19,8 +19,8 @@ if (CMAKE_CXX_COMPILER_ID MATCHES GNU) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -s") if (XMRIG_ARMv8) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crypto") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crypto -flax-vector-conversions") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM8_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM8_CXX_FLAGS} -flax-vector-conversions") elseif (XMRIG_ARMv7) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -flax-vector-conversions") @@ -60,8 +60,8 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -funroll-loops -fmerge-all-constants") if (XMRIG_ARMv8) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crypto") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crypto") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM8_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM8_CXX_FLAGS}") elseif (XMRIG_ARMv7) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon -march=${CMAKE_SYSTEM_PROCESSOR}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -march=${CMAKE_SYSTEM_PROCESSOR}")