-
Notifications
You must be signed in to change notification settings - Fork 2
feat(libccd): add LLAR formula #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "slices" | ||
| "strings" | ||
| ) | ||
|
|
||
| const consumerSource = `#include <ccd/ccd.h> | ||
|
|
||
| int main(void) { | ||
| ccd_t ccd; | ||
| CCD_INIT(&ccd); | ||
| return 0; | ||
| } | ||
| ` | ||
|
|
||
| id "danfis/libccd" | ||
|
|
||
| fromVer "v2.1" | ||
|
|
||
| defaults { | ||
| "shared": "OFF", | ||
| "fPIC": "ON", | ||
| "enable_double_precision": "OFF", | ||
| } | ||
|
|
||
| filter => { | ||
| for name, values in target.options { | ||
| if name != "shared" && name != "fPIC" && name != "enable_double_precision" { | ||
| return false | ||
| } | ||
| for value in values { | ||
| if value != "ON" && value != "OFF" { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| onBuild ctx => { | ||
| installDir := ctx.outputDir | ||
| shared := target.options["shared"][0] == "ON" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| fPIC := target.options["fPIC"][0] == "ON" | ||
| enableDoublePrecision := target.options["enable_double_precision"][0] == "ON" | ||
|
|
||
| c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) | ||
| c.define "CMAKE_INSTALL_LIBDIR", "lib" | ||
| c.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5" | ||
| c.defineBool "BUILD_DOCUMENTATION", false | ||
| c.defineBool "BUILD_SHARED_LIBS", shared | ||
| c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC | ||
| c.defineBool "ENABLE_DOUBLE_PRECISION", enableDoublePrecision | ||
| c.defineBool "CCD_HIDE_ALL_SYMBOLS", !shared | ||
| c.configure | ||
| c.build | ||
| c.install | ||
|
|
||
| licenseDir := filepath.join(installDir, "licenses") | ||
| os.mkdirAll(licenseDir, 0o755)! | ||
| os.writeFile(filepath.join(licenseDir, "BSD-LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "BSD-LICENSE"))!, 0o644)! | ||
|
|
||
| // Upstream installs ccd.pc with CMAKE_INSTALL_PREFIX-expanded paths. | ||
| // Keep its verified flags while making the installed metadata relocatable. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment describes only the prefix relocation, but the code below also augments upstream flags for static builds — appending |
||
| pcPath := filepath.join(installDir, "lib", "pkgconfig", "ccd.pc") | ||
| pc := string(os.readFile(pcPath)!) | ||
| pc = strings.replace(pc, "prefix="+installDir, "prefix=$${pcfiledir}/../..", 1) | ||
| pc = strings.replace(pc, "exec_prefix="+installDir, "exec_prefix=$${prefix}", 1) | ||
| pc = strings.replace(pc, "libdir="+filepath.join(installDir, "lib"), "libdir=$${prefix}/lib", 1) | ||
| pc = strings.replace(pc, "includedir="+filepath.join(installDir, "include"), "includedir=$${prefix}/include", 1) | ||
| lines := pc.split("\n") | ||
| if !shared { | ||
| for i, line in lines { | ||
| if line.hasPrefix("Cflags:") && !strings.contains(line, "CCD_STATIC_DEFINE") { | ||
| lines[i] = line + " -DCCD_STATIC_DEFINE" | ||
| } | ||
| if slices.contains(target.require["os"], "linux") && line.hasPrefix("Libs:") && !strings.contains(line, " -lm") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| lines[i] = line + " -lm" | ||
| } | ||
| } | ||
| } | ||
| os.writeFile(pcPath, []byte(strings.join(lines, "\n")), 0o644)! | ||
|
|
||
| pkgconfig.use installDir | ||
| ctx.setMetadata pkgconfig.lookup("ccd")! | ||
| } | ||
|
|
||
| onTest ctx => { | ||
| installDir := ctx.outputDir | ||
| testDir := filepath.join(ctx.SourceDir, "_llar_consumer") | ||
| os.mkdirAll(testDir, 0o755)! | ||
|
|
||
| sourcePath := filepath.join(testDir, "consumer.c") | ||
| os.writeFile(sourcePath, []byte(consumerSource), 0o644)! | ||
|
|
||
| pkgconfig.use installDir | ||
| flagsFile := filepath.join(testDir, "ccd.flags") | ||
| os.writeFile(flagsFile, []byte(pkgconfig.lookup("ccd")!), 0o644)! | ||
|
|
||
| binary := filepath.join(testDir, "consumer") | ||
| cc! sourcePath, "-o", binary, "@"+flagsFile | ||
|
|
||
| if target.options["shared"][0] == "ON" { | ||
| os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| } | ||
| exec! binary | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "danfis/libccd", | ||
| "deps": {} | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The consumer test only uses
CCD_INIT, which is a header-only macro (field initialization). It compiles and links even if the libccd library itself fails to link, so it doesn't validate theLibs:/-lm/CCD_STATIC_DEFINEflags this recipe adds inonBuild. Peer consumers call a real exported function to force a link (e.g.de265_new_decoderinlibde265,crc32c::Crc32cincrc32c). Consider calling an actual exported symbol such asccdVec3Dist2so the test exercises the link.