-
Notifications
You must be signed in to change notification settings - Fork 2
feat(mikktspace): add LLAR formula #145
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,20 @@ | ||
| cmake_minimum_required(VERSION 3.15) | ||
| project(mikktspace LANGUAGES C) | ||
|
|
||
| add_library(mikktspace ${MIKKTSPACE_SRC_DIR}/mikktspace.c) | ||
| target_include_directories(mikktspace PUBLIC ${MIKKTSPACE_SRC_DIR}) | ||
| set_target_properties(mikktspace PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
|
|
||
| include(CheckFunctionExists) | ||
| check_function_exists(pow HAVE_MATH_SYSTEM) | ||
| if(NOT HAVE_MATH_SYSTEM) | ||
| target_link_libraries(mikktspace PRIVATE m) | ||
| endif() | ||
|
|
||
| include(GNUInstallDirs) | ||
| install(TARGETS mikktspace | ||
| RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
| ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| ) | ||
| install(FILES ${MIKKTSPACE_SRC_DIR}/mikktspace.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "slices" | ||
| "strings" | ||
| ) | ||
|
|
||
| const consumerSource = `#include <mikktspace.h> | ||
| #include <stdlib.h> | ||
|
|
||
| static int GetNumFaces(const SMikkTSpaceContext *pContext) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| SMikkTSpaceInterface sInterface = {NULL}; | ||
| sInterface.m_getNumFaces = GetNumFaces; | ||
|
|
||
| SMikkTSpaceContext sContext = {NULL}; | ||
| sContext.m_pInterface = &sInterface; | ||
|
|
||
| genTangSpaceDefault(&sContext); | ||
|
|
||
| return 0; | ||
| } | ||
| ` | ||
|
|
||
| id "mmikk/MikkTSpace" | ||
|
|
||
| fromVer "3e895b49d05ea07e4c2133156cfa94369e19e409" | ||
|
|
||
| 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("3e895b49d05ea07e4c2133156cfa94369e19e409/CMakeLists.txt")! | ||
| os.writeFile(filepath.join(ctx.SourceDir, "CMakeLists.txt"), cmakeLists, 0o644)! | ||
|
|
||
| shared := target.options["shared"][0] == "ON" | ||
| fPIC := target.options["fPIC"][0] == "ON" | ||
| c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) | ||
| c.define "MIKKTSPACE_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, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "mikktspace.h"))!, 0o644)! | ||
|
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. [P3] LICENSE file is the full mikktspace.h header This writes the entire |
||
|
|
||
| flags := []string{ | ||
| "-I" + filepath.join(installDir, "include"), | ||
| "-L" + filepath.join(installDir, "lib"), | ||
| "-lmikktspace", | ||
| } | ||
| if !shared && (slices.contains(target.require["os"], "linux") || slices.contains(target.require["os"], "freebsd")) { | ||
| flags <- "-lm" | ||
| } | ||
| ctx.setMetadata strings.join(flags, " ") | ||
| } | ||
|
|
||
| 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)! | ||
| binary := filepath.join(testDir, "consumer") | ||
| 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. [P2] onTest re-derives -lm from options; duplicates onBuild logic
|
||
| args := []string{ | ||
| "-I" + filepath.join(installDir, "include"), | ||
| sourcePath, | ||
| "-L" + filepath.join(installDir, "lib"), | ||
| "-lmikktspace", | ||
| "-o", binary, | ||
| } | ||
| if !shared && (slices.contains(target.require["os"], "linux") || slices.contains(target.require["os"], "freebsd")) { | ||
| args <- "-lm" | ||
| } | ||
| exec "cc", args... | ||
| lastErr! | ||
|
|
||
| if shared { | ||
| 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. [P3] setenv overwrites LD_LIBRARY_PATH instead of prepending
|
||
| os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| } | ||
| exec binary | ||
| lastErr! | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "mmikk/MikkTSpace", | ||
|
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. [P3] versions.json uses 2-space indent; siblings use tabs
|
||
| "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] Unchecked [0] index on target.options may crash
target.options["shared"][0]/target.options["fPIC"][0]index element 0 of a slice that may be empty.filteronly rejects unknown option names and non-ON/OFFvalues — it never guaranteesshared/fPICare present, so a target with those options absent passes the filter and then triggers an index-out-of-range here (and again at line 91 inonTest).The
recp/cglmformula avoids this by usingslices.contains, which is safe on an empty/absent slice and honors the default: