-
Notifications
You must be signed in to change notification settings - Fork 2
feat(cqrlib): add CQRlib formula #152
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,19 @@ | ||
| cmake_minimum_required(VERSION 3.15) | ||
| project(CQRlib LANGUAGES C) | ||
|
|
||
| add_library(CQRlib ${CQRLIB_SRC_DIR}/cqrlib.c) | ||
| target_include_directories(CQRlib PRIVATE ${CQRLIB_SRC_DIR}) | ||
| set_target_properties(CQRlib PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) | ||
|
|
||
| find_library(M_LIB m) | ||
| if(M_LIB) | ||
| target_link_libraries(CQRlib PRIVATE ${M_LIB}) | ||
| endif() | ||
|
|
||
| include(GNUInstallDirs) | ||
| install(TARGETS CQRlib | ||
| RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
| LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| ) | ||
| install(FILES ${CQRLIB_SRC_DIR}/cqrlib.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "slices" | ||
| "strings" | ||
| ) | ||
|
|
||
| const cConsumerSource = `#include <cqrlib.h> | ||
|
|
||
| int main(void) { | ||
| CQRQuaternionHandle q; | ||
| CQRCreateEmptyQuaternion(&q); | ||
| return 0; | ||
| } | ||
| ` | ||
|
|
||
| const cppConsumerSource = `#include <cqrlib.h> | ||
|
|
||
| int main() { | ||
| CPPQR<double> q; | ||
| return 0; | ||
| } | ||
| ` | ||
|
|
||
| id "yayahjb/cqrlib" | ||
|
|
||
| // CQRlib-1.0.4 is the first upstream tag with the C++ CPPQR consumer API. | ||
| fromVer "CQRlib-1.0.4" | ||
|
|
||
| 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 | ||
|
|
||
| cmakeLists := ctx.Proj.readFile("CQRlib-1.0.4/CMakeLists.txt")! | ||
| os.writeFile(filepath.join(ctx.SourceDir, "CMakeLists.txt"), cmakeLists, 0o644)! | ||
|
|
||
| shared := slices.contains(target.options["shared"], "ON") | ||
| fPIC := slices.contains(target.options["fPIC"], "ON") | ||
|
|
||
| c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) | ||
| c.define "CQRLIB_SRC_DIR", ctx.SourceDir | ||
| c.defineBool "BUILD_SHARED_LIBS", shared | ||
| c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC | ||
| c.configure | ||
| c.build | ||
| c.install | ||
|
|
||
| licenseDir := filepath.join(installDir, "licenses") | ||
| os.mkdirAll(licenseDir, 0o755)! | ||
| os.writeFile(filepath.join(licenseDir, "lgpl.txt"), os.readFile(filepath.join(ctx.SourceDir, "lgpl.txt"))!, 0o644)! | ||
|
|
||
| libs := []string{"-L$${libdir}", "-lCQRlib"} | ||
| if slices.contains(target.require["os"], "linux") || slices.contains(target.require["os"], "freebsd") { | ||
| libs <- "-lm" | ||
| } | ||
|
|
||
| pcDir := filepath.join(installDir, "lib", "pkgconfig") | ||
| os.mkdirAll(pcDir, 0o755)! | ||
| version := "" | ||
| makefile := string(os.readFile(filepath.join(ctx.SourceDir, "Makefile"))!) | ||
| for line in makefile.split("\n") { | ||
| parts := line.splitN("=", 2) | ||
| if parts.len == 2 && strings.trimSpace(parts[0]) == "RELEASE" { | ||
| version = strings.trimSpace(parts[1]) | ||
| break | ||
| } | ||
| } | ||
| if version == "" { | ||
| panic "CQRlib Makefile has no RELEASE" | ||
| } | ||
| pc := `prefix=$${pcfiledir}/../.. | ||
| exec_prefix=$${prefix} | ||
| libdir=$${prefix}/lib | ||
| includedir=$${prefix}/include | ||
|
|
||
| Name: CQRlib | ||
| Description: C quaternion rotation library | ||
| Version: ` + version + ` | ||
| Libs: ` + strings.join(libs, " ") + ` | ||
| Cflags: -I$${includedir} | ||
| ` | ||
| os.writeFile(filepath.join(pcDir, "cqrlib.pc"), []byte(pc), 0o644)! | ||
|
|
||
| pkgconfig.use installDir | ||
| ctx.setMetadata pkgconfig.lookup("cqrlib")! | ||
| } | ||
|
|
||
| onTest ctx => { | ||
| installDir := ctx.outputDir | ||
| testDir := filepath.join(ctx.SourceDir, "_llar_consumer") | ||
| os.mkdirAll(testDir, 0o755)! | ||
|
|
||
| cSource := filepath.join(testDir, "consumer.c") | ||
| os.writeFile(cSource, []byte(cConsumerSource), 0o644)! | ||
| cBinary := filepath.join(testDir, "consumer-c") | ||
| pkgconfig.use installDir | ||
| flags := strings.fields(pkgconfig.lookup("cqrlib")!) | ||
| cArgs := []string{cSource} | ||
| cArgs <- flags... | ||
| cArgs <- "-o", cBinary | ||
| cc! cArgs... | ||
|
|
||
| cppSource := filepath.join(testDir, "consumer.cpp") | ||
| os.writeFile(cppSource, []byte(cppConsumerSource), 0o644)! | ||
| cppBinary := filepath.join(testDir, "consumer-cpp") | ||
| cppArgs := []string{cppSource} | ||
| cppArgs <- flags... | ||
| cppArgs <- "-o", cppBinary | ||
| exec! "c++", cppArgs... | ||
|
|
||
| if slices.contains(target.options["shared"], "ON") { | ||
| os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
|
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. [P2] LD_LIBRARY_PATH/DYLD_LIBRARY_PATH overwritten instead of prepended
|
||
| os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| if slices.contains(target.require["os"], "windows") { | ||
| path := os.getenv("PATH") | ||
| os.setenv("PATH", filepath.join(installDir, "bin")+";"+path)! | ||
| } | ||
| } | ||
|
|
||
| exec! cBinary | ||
| exec! cppBinary | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "yayahjb/cqrlib", | ||
| "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.
[P1] Hardcoded
libbreaks where GNUInstallDirs useslib64The bundled
CMakeLists.txtinstalls the library to${CMAKE_INSTALL_LIBDIR}viaGNUInstallDirs. On many 64-bit distros (Fedora, RHEL, openSUSE)CMAKE_INSTALL_LIBDIRresolves tolib64, but the recipe hardcodesfilepath.join(installDir, "lib")for the metadata-Lflag, both consumer-Lflags (lines 72, 92, 108), and theLD_LIBRARY_PATH/DYLD_LIBRARY_PATHexports (lines 119–120). On such a platform the install lands inlib64while all flags point atlib, so the emitted metadata is wrong and the consumer link/run fails.Recommend mirroring the
json-crecipe, which pins the layout withc.define "CMAKE_INSTALL_LIBDIR", "lib"so the hardcodedlibassumption holds across platforms.