Skip to content
Open
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
19 changes: 19 additions & 0 deletions yayahjb/cqrlib/CQRlib-1.0.4/CMakeLists.txt
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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Hardcoded lib breaks where GNUInstallDirs uses lib64

The bundled CMakeLists.txt installs the library to ${CMAKE_INSTALL_LIBDIR} via GNUInstallDirs. On many 64-bit distros (Fedora, RHEL, openSUSE) CMAKE_INSTALL_LIBDIR resolves to lib64, but the recipe hardcodes filepath.join(installDir, "lib") for the metadata -L flag, both consumer -L flags (lines 72, 92, 108), and the LD_LIBRARY_PATH/DYLD_LIBRARY_PATH exports (lines 119–120). On such a platform the install lands in lib64 while all flags point at lib, so the emitted metadata is wrong and the consumer link/run fails.

Recommend mirroring the json-c recipe, which pins the layout with c.define "CMAKE_INSTALL_LIBDIR", "lib" so the hardcoded lib assumption holds across platforms.

ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(FILES ${CQRLIB_SRC_DIR}/cqrlib.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
140 changes: 140 additions & 0 deletions yayahjb/cqrlib/CQRlib-1.0.4/cqrlib_llar.gox
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"))!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] LD_LIBRARY_PATH/DYLD_LIBRARY_PATH overwritten instead of prepended

LD_LIBRARY_PATH and DYLD_LIBRARY_PATH are set to a single path, discarding any inherited value — unlike the Windows branch just below (line 123) which correctly reads and prepends to PATH. If the test binary depends on other shared libraries reachable only via an inherited loader path, the test could fail spuriously. Recommend reading the existing value and prepending, e.g. join installDir/lib with os.getenv("LD_LIBRARY_PATH") using :, for parity with the PATH handling. (Minor; the written value is trusted here.)

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
}
4 changes: 4 additions & 0 deletions yayahjb/cqrlib/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "yayahjb/cqrlib",
"deps": {}
}
Loading