Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 21 additions & 27 deletions pkgs/by-name/li/libultrahdr/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ stdenv.mkDerivation (finalAttrs: {
(replaceVars ./gtest.patch {
GTEST_INCLUDE_DIRS = "${lib.getDev gtest}/include";
})

# Remove platform and architecture detection logic
# Also drop arch-specific compile and optimization flags to ensure
# packaging friendliness.
# Based on https://github.com/google/libultrahdr/pull/383
# modified to target 1.4.0 instead of main
./remove-platform-and-detection-logic.patch

# fix tests on big-endian
# https://github.com/google/libultrahdr/pull/396
(fetchpatch {
url = "https://github.com/google/libultrahdr/commit/13a058f452d846e43d4691f6885eeeaa8b0ea8d0.patch";
hash = "sha256-2ZVvBMz8wQLEThuXdRJbbx5m2ouRZpxVWoH88RLmit4=";
})
];

# CMake incorrect absolute include/lib paths: https://github.com/NixOS/nixpkgs/issues/144170
Expand All @@ -53,6 +67,12 @@ stdenv.mkDerivation (finalAttrs: {
'includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@'
'';

# use sse2 for floating point math to fix tests
env = lib.optionalAttrs stdenv.hostPlatform.isi686 {
CFLAGS = "-mfpmath=sse -msse2";
CXXFLAGS = "-mfpmath=sse -msse2";
};

cmakeFlags = [
(lib.cmakeBool "UHDR_BUILD_TESTS" true)
# Build disables install target in cross-compilation mode so
Expand Down Expand Up @@ -102,33 +122,7 @@ stdenv.mkDerivation (finalAttrs: {
maintainers = with lib.maintainers; [
yzx9
];
# CMake script rejects non-approved platform targets
# https://github.com/google/libultrahdr/pull/383 would get rid of that
platforms =
let
# Values from the "Detect system" section in /CMakeLists.txt
# https://github.com/google/libultrahdr/blob/d52a0d13814ca399fc8a07e23de1d2c63f0e8404/CMakeLists.txt#L34
oss = [
"linux"
"windows"
"darwin"
];
archs = [
"i686"
"x86_64"
"aarch64"
"armv7l"
"riscv64"
"riscv32"
"loongarch64"
];
in
lib.lists.intersectLists lib.platforms.all (
lib.lists.crossLists (arch: os: "${arch}-${os}") [
archs
oss
]
);
platforms = lib.platforms.all;
license = with lib.licenses; [
asl20
];
Expand Down
142 changes: 142 additions & 0 deletions pkgs/by-name/li/libultrahdr/remove-platform-and-detection-logic.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
From e2daed8da97d8857dcec2fd68d2f6f3326170f67 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <github@kleisauke.nl>
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,44 +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(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()
-
###########################################################
# 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})
Loading