diff --git a/tjdistler/iqa/0559a8ff2acd9746864975834d35be6892cc9801/iqa_llar.gox b/tjdistler/iqa/0559a8ff2acd9746864975834d35be6892cc9801/iqa_llar.gox new file mode 100644 index 0000000..8618e55 --- /dev/null +++ b/tjdistler/iqa/0559a8ff2acd9746864975834d35be6892cc9801/iqa_llar.gox @@ -0,0 +1,149 @@ +import ( + "os" + "path/filepath" + "runtime" + "slices" + "strings" +) + +var 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 "iqa.h" + +int main(void) { + const unsigned char image[1] = {0}; + return iqa_mse(image, image, 1, 1, 1) != 0.0f; +} +` + +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] + } + libs := "-L$${libdir} -liqa" + if osName == "linux" || osName == "freebsd" { + libs += " -lm" + } + 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 => { + 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)! + + 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 <- "-o", binary + 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"))! + } + } + exec! binary +} 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": {} +}