Skip to content
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

Switch selection of GLPK to Dune virtual libraries #24

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .travis-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

case $TRAVIS_OS_NAME in
linux)
sudo apt-get install coinor-libclp-dev coinor-libcbc-dev coinor-libsymphony-dev mccs
sudo apt-get install coinor-libclp-dev coinor-libcbc-dev coinor-libsymphony-dev mccs libglpk-dev
;;
osx)
;;
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ install:
- call "%APPVEYOR_BUILD_FOLDER%\appveyor.cmd"

build_script:
- del "src\glpk-shared\dune"
- del "src\glpk-static\dune"
- dune build
- dune build test/cbclp.exe

Expand Down
3 changes: 2 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
(lang dune 1.0)
(lang dune 1.7)
(using library_variants 0.1)
(name mccs)
8 changes: 5 additions & 3 deletions mccs.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ bug-reports: "https://github.com/AltGr/ocaml-mccs/issues"
license: "LGPL-2.1 with OCaml linking exception, BSD-3-clause, GPL-3.0"
dev-repo: "git+https://github.com/AltGr/ocaml-mccs.git"
build: [
["dune" "build" "-p" name]
["rm" "src/glpk-shared/dune" "src/glpk-static/dune"] {!conf-glpk:installed}
["dune" "build" "-p" name "-j" jobs]
["sh" "-c" "dune build @settests --auto-promote || true"] {with-test}
["dune" "runtest"] {with-test}
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
depends: [
"ocaml"
"dune" {>= "1.0"}
"dune" {>= "1.9.2"}
"cudf" {>= "0.7"}
]
depopts: "conf-glpk"
synopsis: "MCCS (which stands for Multi Criteria CUDF Solver) is a CUDF problem solver
developed at UNS during the European MANCOOSI project"
83 changes: 24 additions & 59 deletions src/context_flags.ml
Original file line number Diff line number Diff line change
@@ -1,62 +1,27 @@
#directory "+compiler-libs";;
#load "ocamlcommon.cma";;

let backends =
try
let be = Sys.getenv "MCCS_BACKENDS" in
let bel = String.length be in
let rec aux i =
if i >= bel then [] else
try
let j = String.index_from be i ' ' in
String.sub be i (j - i) :: aux (j+1)
with Not_found -> [String.sub be i (String.length be - i)]
in List.filter (( <> ) "") (aux 0)
with Not_found -> ["GLPK"]

let useGLPK = List.mem "GLPK" backends
let useSYM = List.mem "SYMPHONY" backends
let useCBC = List.mem "CBC" backends
let useCLP = List.mem "CLP" backends || useCBC
let useCOIN = useCLP || useCBC || useSYM

let ifc c x = if c then x else []

let cxxflags =
let flags =
(ifc (Config.system = "macosx") ["-x"; "c++"]) @
(ifc (Sys.win32 && Config.ccomp_type = "msvc") ["\"/EHsc\""]) @
(ifc useGLPK ["-DUSEGLPK"]) @
(ifc useCOIN ["-DUSECOIN"]) @
(ifc useCLP ["-DUSECLP"]) @
(ifc useCBC ["-DUSECBC"]) @
(ifc useSYM ["-DUSESYM"])
in
"(" ^ String.concat " " flags ^ ")"

let clibs =
let flags =
(ifc (Config.ccomp_type = "cc") ["-lstdc++"]) @
(ifc useCOIN ["-lCoinUtils"]) @
(ifc useCLP ["-lOsiClp"]) @
(ifc useCBC ["-lOsiCbc";"-lCbc"]) @
(ifc useSYM ["-lgomp";"-lOsiSym"])
in
"(" ^ String.concat " " flags ^ ")"

let flags =
let cflags =
(ifc (Config.system = "mingw") ["-link -shared-libgcc"])
in
let flags = List.map (fun fl -> "(-ccopt \"" ^ fl ^ "\")") cflags in
"(" ^ String.concat " " flags ^ ")"

let write f s =
let oc = open_out f in
output_string oc s;
close_out oc

let () =
write "cxxflags.sexp" cxxflags;
write "clibs.sexp" clibs;
write "flags.sexp" flags
match Sys.argv.(1) with
| "clibs" ->
if Sys.win32 && Config.ccomp_type = "msvc" then
print_string "(glpk_4_63.lib)"
else
let glpk =
if Array.length Sys.argv > 2 && Sys.argv.(2) = "static" then
(* flexlink doesn't (yet) support -l: *)
if Sys.win32 then
"libglpk.a"
else
"-l:libglpk.a"
else
"-lglpk"
in
Printf.printf "(-lstdc++ %s)" glpk
| "cflags" ->
if Config.ccomp_type = "cc" then
print_string "(-Wno-parentheses)"
else
print_string "()"
| _ ->
Printf.eprintf "Unrecognised context instruction: %s\n" Sys.argv.(1);
exit 1
62 changes: 62 additions & 0 deletions src/context_flags_all.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#directory "+compiler-libs";;
#load "ocamlcommon.cma";;

let backends =
try
let be = Sys.getenv "MCCS_BACKENDS" in
let bel = String.length be in
let rec aux i =
if i >= bel then [] else
try
let j = String.index_from be i ' ' in
String.sub be i (j - i) :: aux (j+1)
with Not_found -> [String.sub be i (String.length be - i)]
in List.filter (( <> ) "") (aux 0)
with Not_found -> ["GLPK"]

let useGLPK = List.mem "GLPK" backends
let useSYM = List.mem "SYMPHONY" backends
let useCBC = List.mem "CBC" backends
let useCLP = List.mem "CLP" backends || useCBC
let useCOIN = useCLP || useCBC || useSYM

let ifc c x = if c then x else []

let cxxflags =
let flags =
(ifc (Config.system = "macosx") ["-x"; "c++"]) @
(ifc (Sys.win32 && Config.ccomp_type = "msvc") ["\"/EHsc\""]) @
(ifc useGLPK ["-DUSEGLPK"]) @
(ifc useCOIN ["-DUSECOIN"]) @
(ifc useCLP ["-DUSECLP"]) @
(ifc useCBC ["-DUSECBC"]) @
(ifc useSYM ["-DUSESYM"])
in
"(" ^ String.concat " " flags ^ ")"

let clibs =
let flags =
(ifc (Config.ccomp_type = "cc") ["-lstdc++"]) @
(ifc useCOIN ["-lCoinUtils"]) @
(ifc useCLP ["-lOsiClp"]) @
(ifc useCBC ["-lOsiCbc";"-lCbc"]) @
(ifc useSYM ["-lgomp";"-lOsiSym"])
in
"(" ^ String.concat " " flags ^ ")"

let flags =
let cflags =
(ifc (Config.system = "mingw") ["-link -shared-libgcc"])
in
let flags = List.map (fun fl -> "(-ccopt \"" ^ fl ^ "\")") cflags in
"(" ^ String.concat " " flags ^ ")"

let write f s =
let oc = open_out f in
output_string oc s;
close_out oc

let () =
write "cxxflags.sexp" cxxflags;
write "clibs.sexp" clibs;
write "flags.sexp" flags
40 changes: 5 additions & 35 deletions src/dune
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
(library
(name mccs)
(cxx_names changed_criteria constraint_generation count_criteria
cudf_reductions cudf_tools glpk_solver lp_solver lexagregate_combiner
new_criteria notuptodate_criteria removed_criteria mccscudf mccs_stubs)
(public_name mccs)
(modules :standard \ context_flags)
(cxx_flags
:standard
-I
.
(:include cxxflags.sexp))
(c_library_flags
:standard
(:include clibs.sexp))
(library_flags
:standard
(:include flags.sexp))
(wrapped false)
(libraries
cudf
(select
config.h
from
(mccs.glpk.internal -> config_internal.h)
(mccs.glpk.shared -> config_external.h)
(mccs.glpk.static -> config_external.h)
(-> _))))
(modules :standard \ context_flags_all context_flags)
(virtual_modules glpk)
(default_implementation mccs.internal)
(libraries cudf))

(rule
(with-stdout-to config_internal.h (echo "#include \"glpk/glpk.h\"")))

(rule
(with-stdout-to config_external.h (echo "#include <glpk.h>")))

(rule
(targets cxxflags.sexp clibs.sexp flags.sexp)
(deps context_flags.ml (universe))
(action
(run ocaml %{deps})))
(with-stdout-to glpk.mli (echo "")))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 34 additions & 6 deletions src/glpk/dune → src/glpk-internal/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(library
(name mccs_glpk)
(public_name mccs.glpk.internal)
(modules ocaml_mccs_glpk)
(name mccs_internal)
(public_name mccs.internal)
(implements mccs)
(modules glpk)
(c_names ; Core GLPK
bfd
glpapi06
Expand Down Expand Up @@ -88,10 +89,23 @@
spychuzc
spychuzr
spydual)
(cxx_names changed_criteria constraint_generation count_criteria
cudf_reductions cudf_tools glpk_solver lp_solver lexagregate_combiner
new_criteria notuptodate_criteria removed_criteria mccscudf mccs_stubs)
(cxx_flags
:standard
-I
.
(:include cxxflags.sexp))
(c_library_flags
:standard
(:include clibs.sexp))
(library_flags
:standard
(:include flags.sexp))
(c_flags
:standard
(:include cflags.sexp))
(wrapped false))
(:include cflags.sexp)))

(copy_files# api/*.{c,h})

Expand All @@ -107,10 +121,24 @@

(copy_files# simplex/*.{c,h})

(copy_files# ../mccs/*.{cpp,h})

(rule
(targets cflags.sexp)
(deps context_flags.ml)
(deps ../context_flags.ml)
(action
(with-stdout-to
%{targets}
(run ocaml %{deps} cflags))))

(rule
(targets cxxflags.sexp clibs.sexp flags.sexp)
(deps ../context_flags_all.ml (universe) config.h)
(action
(run ocaml %{deps})))

(rule
(with-stdout-to config.h (echo "#include \"glpk.h\"")))

(rule
(with-stdout-to glpk.ml (echo "")))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions src/glpk-shared/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(library
(name mccs_shared)
(public_name mccs.shared)
(implements mccs)
(cxx_names changed_criteria constraint_generation count_criteria
cudf_reductions cudf_tools glpk_solver lp_solver lexagregate_combiner
new_criteria notuptodate_criteria removed_criteria mccscudf mccs_stubs)
(cxx_flags
:standard
-I
.
(:include cxxflags.sexp))
(c_library_flags
:standard
(:include clibs-shared.sexp)))

(copy_files# ../mccs/*.{cpp,h})

(rule
(targets clibs-shared.sexp)
(deps ../context_flags.ml)
(action
(with-stdout-to
%{targets}
(run ocaml %{deps} clibs))))

(rule
(with-stdout-to config.h (echo "#include <glpk.h>")))

(rule
(targets cxxflags.sexp clibs.sexp flags.sexp)
(deps ../context_flags_all.ml (universe) config.h)
(action
(run ocaml %{deps})))

(rule
(with-stdout-to glpk.ml (echo "")))
48 changes: 48 additions & 0 deletions src/glpk-static/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
(library
(name mccs_static)
(public_name mccs.static)
(implements mccs)
(modules :standard \ static_linking)
(c_library_flags
:standard
(:include clibs-static.sexp))
(libraries mccs_static_solver))

(library
(name mccs_static_solver)
(public_name mccs.static.solver)
(modules static_linking)
(cxx_names changed_criteria constraint_generation count_criteria
cudf_reductions cudf_tools glpk_solver lp_solver lexagregate_combiner
new_criteria notuptodate_criteria removed_criteria mccscudf mccs_stubs)
(cxx_flags
:standard
-I
.
(:include cxxflags.sexp))
(wrapped false))

(rule
(with-stdout-to static_linking.ml (echo "")))

(copy_files# ../mccs/*.{cpp,h})

(rule
(targets clibs-static.sexp)
(deps ../context_flags.ml)
(action
(with-stdout-to
%{targets}
(run ocaml %{deps} clibs static))))

(rule
(with-stdout-to config.h (echo "#include <glpk.h>")))

(rule
(targets cxxflags.sexp clibs.sexp flags.sexp)
(deps ../context_flags_all.ml (universe) config.h)
(action
(run ocaml %{deps})))

(rule
(with-stdout-to glpk.ml (echo "")))
Loading