From 07da1dfb0927970b01b133ee4fe2b0338783d943 Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Tue, 18 Aug 2026 18:46:39 +0800 Subject: [PATCH 1/2] feat(iqa): add LLAR formula --- .../iqa_llar.gox | 143 ++++++++++++++++++ tjdistler/iqa/versions.json | 4 + 2 files changed, 147 insertions(+) create mode 100644 tjdistler/iqa/0559a8ff2acd9746864975834d35be6892cc9801/iqa_llar.gox create mode 100644 tjdistler/iqa/versions.json diff --git a/tjdistler/iqa/0559a8ff2acd9746864975834d35be6892cc9801/iqa_llar.gox b/tjdistler/iqa/0559a8ff2acd9746864975834d35be6892cc9801/iqa_llar.gox new file mode 100644 index 0000000..73e0cf4 --- /dev/null +++ b/tjdistler/iqa/0559a8ff2acd9746864975834d35be6892cc9801/iqa_llar.gox @@ -0,0 +1,143 @@ +import ( + "os" + "path/filepath" + "runtime" + "slices" + "strings" +) + +const cmakeLists = `cmake_minimum_required(VERSION 3.12) +project(iqa C) + +if(MSVC AND BUILD_SHARED_LIBS) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +endif() + +file(GLOB IQA_SOURCES $${IQA_SRC_DIR}/source/*.c) +file(GLOB IQA_HEADERS $${IQA_SRC_DIR}/include/*.h) + +add_library(iqa $${IQA_SOURCES}) +target_include_directories(iqa PUBLIC $${IQA_SRC_DIR}/include) + +include(GNUInstallDirs) +install(TARGETS iqa + RUNTIME DESTINATION $${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION $${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION $${CMAKE_INSTALL_LIBDIR}) +install(FILES $${IQA_HEADERS} DESTINATION $${CMAKE_INSTALL_INCLUDEDIR}) +` + +const consumerSource = `#include "math_utils.h" + +int main(void) { + _max(0, 1); + return 0; +} +` + +id "tjdistler/iqa" + +fromVer "0559a8ff2acd9746864975834d35be6892cc9801" + +defaults { + "shared": "OFF", + "fPIC": "ON", +} + +filter => { + for name, values in target.options { + if name != "shared" && name != "fPIC" { + return false + } + for value in values { + if value != "ON" && value != "OFF" { + return false + } + } + } + return true +} + +onBuild ctx => { + installDir := ctx.outputDir + projectDir := filepath.join(ctx.SourceDir, "_llar_cmake") + os.mkdirAll(projectDir, 0o755)! + os.writeFile(filepath.join(projectDir, "CMakeLists.txt"), []byte(cmakeLists), 0o644)! + + shared := slices.contains(target.options["shared"], "ON") + fPIC := slices.contains(target.options["fPIC"], "ON") + c := cmake.new(projectDir, filepath.join(ctx.SourceDir, "_build"), installDir) + c.define "IQA_SRC_DIR", ctx.SourceDir + c.defineBool "BUILD_SHARED_LIBS", shared + if !shared { + c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC + } + c.configure + c.build + c.install + + license := string(os.readFile(filepath.join(ctx.SourceDir, "include", "iqa.h"))!) + licenseEnd := strings.index(license, "*/") + license = strings.trimSpace(license[:licenseEnd]) + license = strings.replace(license, "/*", "", 1) + license = strings.replace(license, "\n * ", "\n", -1) + licenseDir := filepath.join(installDir, "licenses") + os.mkdirAll(licenseDir, 0o755)! + os.writeFile(filepath.join(licenseDir, "LICENSE"), []byte(license), 0o644)! + + osName := runtime.GOOS + osValues := target.require["os"] + if osValues.len > 0 { + osName = osValues[0] + } + flags := []string{ + "-I" + filepath.join(installDir, "include"), + "-L" + filepath.join(installDir, "lib"), + "-liqa", + } + if osName == "linux" { + flags <- "-lm" + } + ctx.setMetadata strings.join(flags, " ") +} + +onTest ctx => { + installDir := ctx.outputDir + testDir := filepath.join(ctx.SourceDir, "_llar_consumer") + os.mkdirAll(testDir, 0o755)! + + consumer := filepath.join(testDir, "consumer.c") + os.writeFile(consumer, []byte(consumerSource), 0o644)! + + osName := runtime.GOOS + osValues := target.require["os"] + if osValues.len > 0 { + osName = osValues[0] + } + shared := slices.contains(target.options["shared"], "ON") + binary := filepath.join(testDir, "consumer") + args := []string{ + consumer, + "-I" + filepath.join(installDir, "include"), + "-L" + filepath.join(installDir, "lib"), + "-liqa", + } + if osName == "linux" { + args <- "-lm" + } + args <- "-o", binary + exec "cc", args... + lastErr! + + if shared { + if osName == "windows" { + path := os.getenv("PATH") + os.setenv("PATH", filepath.join(installDir, "bin")+";"+path)! + } else { + os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + } + } + exec binary + lastErr! +} diff --git a/tjdistler/iqa/versions.json b/tjdistler/iqa/versions.json new file mode 100644 index 0000000..2939c40 --- /dev/null +++ b/tjdistler/iqa/versions.json @@ -0,0 +1,4 @@ +{ + "path": "tjdistler/iqa", + "deps": {} +} From d5e751d96a917f45ff45f36879befa1541f84a11 Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Wed, 19 Aug 2026 17:41:49 +0800 Subject: [PATCH 2/2] fix(iqa): publish relocatable pkg-config metadata --- .../iqa_llar.gox | 68 ++++++++++--------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/tjdistler/iqa/0559a8ff2acd9746864975834d35be6892cc9801/iqa_llar.gox b/tjdistler/iqa/0559a8ff2acd9746864975834d35be6892cc9801/iqa_llar.gox index 73e0cf4..8618e55 100644 --- a/tjdistler/iqa/0559a8ff2acd9746864975834d35be6892cc9801/iqa_llar.gox +++ b/tjdistler/iqa/0559a8ff2acd9746864975834d35be6892cc9801/iqa_llar.gox @@ -6,7 +6,7 @@ import ( "strings" ) -const cmakeLists = `cmake_minimum_required(VERSION 3.12) +var cmakeLists = `cmake_minimum_required(VERSION 3.12) project(iqa C) if(MSVC AND BUILD_SHARED_LIBS) @@ -27,11 +27,11 @@ install(TARGETS iqa install(FILES $${IQA_HEADERS} DESTINATION $${CMAKE_INSTALL_INCLUDEDIR}) ` -const consumerSource = `#include "math_utils.h" +const consumerSource = `#include "iqa.h" int main(void) { - _max(0, 1); - return 0; + const unsigned char image[1] = {0}; + return iqa_mse(image, image, 1, 1, 1) != 0.0f; } ` @@ -90,15 +90,27 @@ onBuild ctx => { if osValues.len > 0 { osName = osValues[0] } - flags := []string{ - "-I" + filepath.join(installDir, "include"), - "-L" + filepath.join(installDir, "lib"), - "-liqa", + libs := "-L$${libdir} -liqa" + if osName == "linux" || osName == "freebsd" { + libs += " -lm" } - if osName == "linux" { - flags <- "-lm" - } - ctx.setMetadata strings.join(flags, " ") + pc := `prefix=$${pcfiledir}/../.. +exec_prefix=$${prefix} +libdir=$${prefix}/lib +includedir=$${prefix}/include + +Name: iqa +Description: Image quality assessment library +Version: 0559a8ff2acd9746864975834d35be6892cc9801 +Libs: ` + libs + ` +Cflags: -I$${includedir} +` + pkgconfigDir := filepath.join(installDir, "lib", "pkgconfig") + os.mkdirAll(pkgconfigDir, 0o755)! + os.writeFile(filepath.join(pkgconfigDir, "iqa.pc"), []byte(pc), 0o644)! + + pkgconfig.use installDir + ctx.setMetadata pkgconfig.lookup("iqa")! } onTest ctx => { @@ -109,35 +121,29 @@ onTest ctx => { consumer := filepath.join(testDir, "consumer.c") os.writeFile(consumer, []byte(consumerSource), 0o644)! - osName := runtime.GOOS - osValues := target.require["os"] - if osValues.len > 0 { - osName = osValues[0] - } + pkgconfig.use installDir + flags := [strings.replace(flag, `\|`, "|", -1) for flag in strings.fields(pkgconfig.lookup("iqa")!)] + args := []string{consumer} + args <- flags... shared := slices.contains(target.options["shared"], "ON") binary := filepath.join(testDir, "consumer") - args := []string{ - consumer, - "-I" + filepath.join(installDir, "include"), - "-L" + filepath.join(installDir, "lib"), - "-liqa", - } - if osName == "linux" { - args <- "-lm" - } args <- "-o", binary - exec "cc", args... - lastErr! + cc! args... if shared { + osName := runtime.GOOS + osValues := target.require["os"] + if osValues.len > 0 { + osName = osValues[0] + } if osName == "windows" { path := os.getenv("PATH") os.setenv("PATH", filepath.join(installDir, "bin")+";"+path)! + } else if osName == "darwin" { + os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! } else { os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! - os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! } } - exec binary - lastErr! + exec! binary }