From 61c5edd7e43ba6ebea4523c055d6e0b060bfcc15 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Wed, 29 Nov 2023 14:42:28 -0600 Subject: [PATCH] Add a folder deps --- deps/build.jl | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 deps/build.jl diff --git a/deps/build.jl b/deps/build.jl new file mode 100644 index 0000000..db5cc80 --- /dev/null +++ b/deps/build.jl @@ -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