Skip to content

Commit

Permalink
Add a folder deps
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Nov 29, 2023
1 parent b2f541e commit 61c5edd
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Libdl, Base.Sys

const DEPS_FILE = joinpath(dirname(@__FILE__), "deps.jl")

if isfile(DEPS_FILE)
rm(DEPS_FILE)
end

function write_depsfile(knpath, libpath)
open(DEPS_FILE, "w") do io
println(io, "const libknitro = \"$(escape_string(libpath))\"")
knitroampl = joinpath(knpath, "..", "knitroampl", "knitroampl")
println(io, "const amplexe = \"$(escape_string(knitroampl))\"")
return
end
return
end

function try_local_installation()
libname = string(Sys.iswindows() ? "" : "lib", "knitro", ".", Libdl.dlext)
paths_to_try = String[]
if haskey(ENV, "LD_LIBRARY_PATH")
append!(paths_to_try, split(ENV["LD_LIBRARY_PATH"], ':'))
end
if haskey(ENV, "KNITRODIR")
push!(paths_to_try, joinpath(ENV["KNITRODIR"], "lib"))
end
found_knitro = false
for path in reverse(paths_to_try)
l = joinpath(path, libname)
d = Libdl.dlopen_e(l)
if d != C_NULL
found_knitro = true
write_depsfile(path, l)
break
end
end
if !found_knitro
write_depsfile("", "")
end
return
end

function try_ci_installation()
local_filename = joinpath(@__DIR__, "libknitro.so")
download(ENV["SECRET_KNITRO_URL"], local_filename)
download(ENV["SECRET_KNITRO_LIBIOMP5"], joinpath(@__DIR__, "libiomp5.so"))
write_depsfile("", local_filename)
return
end

if get(ENV, "SECRET_KNITRO_URL", "") != ""
try_ci_installation()
else
try_local_installation()
end

0 comments on commit 61c5edd

Please sign in to comment.