From e2daed8da97d8857dcec2fd68d2f6f3326170f67 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Wed, 10 Dec 2025 15:01:28 +0100 Subject: [PATCH] Remove platform and architecture detection logic Also drop arch-specific compile and optimization flags to ensure packaging friendliness. --- CMakeLists.txt | 104 +++----------------------------------------- cmake/package.cmake | 3 -- 2 files changed, 5 insertions(+), 102 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51283356..07ed9100 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,65 +25,6 @@ project(libuhdr LANGUAGES C CXX DESCRIPTION "Library for encoding and decoding ultrahdr images") -########################################################### -# Detect system -########################################################### -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten") -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android") -elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") -elseif(WIN32) -elseif(APPLE) -else() - message(FATAL_ERROR "Platform ${CMAKE_SYSTEM_NAME} not recognized") -endif() - -if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*") - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(ARCH "amd64") - else() - set(ARCH "i386") - endif() -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*") - set(ARCH "i386") -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*)") - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(ARCH "aarch64") - else() - set(ARCH "arm") - endif() -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)") - set(ARCH "arm") -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^riscv64") - set(ARCH "riscv64") -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^riscv32") - set(ARCH "riscv32") -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^loongarch64") - set(ARCH "loong64") -else() - message(FATAL_ERROR "Architecture: ${CMAKE_SYSTEM_PROCESSOR} not recognized") -endif() - -# Cross compiling on macOS. The cross compiling architecture should override -# auto-detected system architecture settings. -if(CMAKE_OSX_ARCHITECTURES) - if(APPLE) - if(CMAKE_OSX_ARCHITECTURES STREQUAL "arm64") - set(ARCH "aarch64") - elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64") - set(ARCH "x86_64") - elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "i386") - set(ARCH "x86") - else() - message(FATAL_ERROR "Architecture ${CMAKE_OSX_ARCHITECTURES} is not " - "supported. Only one architecture (arm64, x86_64 " - "or i386) could be specified at build time.") - endif() - else() - message(WARNING "ignoring setting CMAKE_OSX_ARCHITECTURES:= ${CMAKE_OSX_ARCHITECTURES}") - endif() -endif() - ########################################################### # Directories ########################################################### @@ -287,45 +228,9 @@ elseif(EMSCRIPTEN) or try 'cmake -DUHDR_BUILD_DEPS=1'") endif() endif() -else() - add_compile_options(-ffunction-sections) - add_compile_options(-fdata-sections) - add_compile_options(-fomit-frame-pointer) - add_compile_options(-ffp-contract=fast) - if(ARCH STREQUAL "i386") - add_compile_options(-m32) - add_compile_options(-march=i386) - add_compile_options(-mtune=generic) - elseif(ARCH STREQUAL "amd64") - add_compile_options(-m64) - add_compile_options(-march=x86-64) - add_compile_options(-mtune=generic) - elseif(ARCH STREQUAL "arm") - add_compile_options(-march=armv7-a) - add_compile_options(-marm) - if(NOT ANDROID_ABI) - add_compile_options(-mfloat-abi=hard) - endif() - add_compile_options(-mfpu=neon-vfpv3) - add_compile_options(-fno-lax-vector-conversions) - elseif(ARCH STREQUAL "aarch64") - add_compile_options(-march=armv8-a) - add_compile_options(-fno-lax-vector-conversions) - elseif(ARCH STREQUAL "riscv64") - add_compile_options(-march=rv64gc) - add_compile_options(-mabi=lp64d) - elseif(ARCH STREQUAL "riscv32") - add_compile_options(-march=rv32gc) - add_compile_options(-mabi=ilp32d) - elseif(ARCH STREQUAL "loong64") - add_compile_options(-march=loongarch64) - add_compile_options(-mabi=lp64d) - endif() - - if(UHDR_ENABLE_WERROR) - CheckCompilerOption("-Werror" SUPPORTS_WERROR) - set(UHDR_WERROR_FLAGS "-Werror") - endif() +elseif(UHDR_ENABLE_WERROR) + CheckCompilerOption("-Werror" SUPPORTS_WERROR) + set(UHDR_WERROR_FLAGS "-Werror") endif() ########################################################### @@ -585,7 +490,8 @@ set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ########################################################### file(GLOB UHDR_CORE_SRCS_LIST "${SOURCE_DIR}/src/*.cpp") if(UHDR_ENABLE_INTRINSICS) - if(ARCH STREQUAL "arm" OR ARCH STREQUAL "aarch64") + string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} CMAKE_SYSTEM_PROCESSOR_LC) + if(CMAKE_SYSTEM_PROCESSOR_LC STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR_LC MATCHES "^arm") file(GLOB UHDR_CORE_NEON_SRCS_LIST "${SOURCE_DIR}/src/dsp/arm/*.cpp") list(APPEND UHDR_CORE_SRCS_LIST ${UHDR_CORE_NEON_SRCS_LIST}) endif() diff --git a/cmake/package.cmake b/cmake/package.cmake index 2e3649aa..5a416c22 100644 --- a/cmake/package.cmake +++ b/cmake/package.cmake @@ -29,9 +29,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "") message(FATAL_ERROR "Failed to determine CPACK_SYSTEM_NAME. Is CMAKE_SYSTEM_NAME set?" ) endif() string(TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME) -set(CPACK_PACKAGE_ARCHITECTURE ${ARCH}) set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}") -set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CPACK_PACKAGE_ARCHITECTURE}") set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE) set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) @@ -46,7 +44,6 @@ elseif(UNIX) set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CPACK_PACKAGE_HOMEPAGE_URL}) elseif(EXISTS "/etc/redhat-release") set(CPACK_GENERATOR "RPM") - set(CPACK_RPM_PACKAGE_ARCHITECTURE ${CPACK_PACKAGE_ARCHITECTURE}) set(CPACK_RPM_PACKAGE_RELEASE 1) set(CPACK_RPM_PACKAGE_LICENSE "Apache 2.0") set(CPACK_RPM_PACKAGE_URL ${CPACK_PACKAGE_HOMEPAGE_URL})