Bazel: Add optional support for GLPK.

Try it out:
bazel run --define USE_GLPK= cpp:linear_programming
This commit is contained in:
Clement Courbet
2017-04-11 15:03:01 +02:00
parent c9b8b7b3e6
commit 53c41b2ad6
5 changed files with 61 additions and 4 deletions

View File

@@ -28,3 +28,11 @@ http_archive(
strip_prefix = "protobuf-b4b0e304be5a68de3d0ee1af9b286f958750f5e4",
sha256 = "ff771a662fb6bd4d3cc209bcccedef3e93980a49f71df1e987f6afa3bcdcba3a",
)
new_http_archive(
name = "glpk",
url = "http://ftp.gnu.org/gnu/glpk/glpk-4.47.tar.gz",
sha256 = "c35438e3ba74a8d85236810e6b84879272c87cfa7473b4075201e2967839f48d",
build_file = "../src/glpk.BUILD",
)

View File

@@ -30,4 +30,12 @@ new_http_archive(
url = "https://github.com/google/googletest/archive/release-1.8.0.zip",
build_file = "gtest.BUILD",
strip_prefix = "googletest-release-1.8.0/googletest",
)
)
new_http_archive(
name = "glpk",
url = "http://ftp.gnu.org/gnu/glpk/glpk-4.47.tar.gz",
sha256 = "c35438e3ba74a8d85236810e6b84879272c87cfa7473b4075201e2967839f48d",
build_file = "glpk.BUILD",
)

20
src/glpk.BUILD Normal file
View File

@@ -0,0 +1,20 @@
cc_library(
name = "glpk",
srcs = glob([
"glpk-4.47/src/*.c",
"glpk-4.47/src/*/*.c",
"glpk-4.47/src/*.h",
"glpk-4.47/src/*/*.h",
]),
hdrs = [
"glpk-4.47/src/glpk.h",
],
copts = [
"-Wno-error",
"-w",
"-Iexternal/glpk/glpk-4.47/src",
"-DHAVE_ZLIB",
],
includes=["glpk-4.47/src"],
visibility = ["//visibility:public"],
)

View File

@@ -1,5 +1,12 @@
package(default_visibility = ["//visibility:public"])
# If you want to use the GLPK solver, build with '--define USE_GLPK=' (or add
# it to your bazel.rc file). This will download, build and link to GLPK.
config_setting(
name = "with_glpk",
values = { "define": "USE_GLPK=" }
)
proto_library(
name = "linear_solver_proto",
srcs = ["linear_solver.proto"],
@@ -20,7 +27,10 @@ cc_library(
"linear_solver.cc",
"model_exporter.cc",
"model_validator.cc",
],
] + select({
":with_glpk": ["glpk_interface.cc"],
"//conditions:default": [],
}),
hdrs = [
"glop_utils.h",
"linear_expr.h",
@@ -32,13 +42,21 @@ cc_library(
"-DUSE_GLOP",
"-DUSE_BOP",
],
defines = [
"HAVE_CONFIG_H"
] + select({
":with_glpk": ["USE_GLPK"],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
deps = [
":linear_solver_cc_proto",
"//base:timer",
"//base",
"//base:file",
"//base:hash",
"//base:map_util",
"//base:stl_util",
"//base:random",
"//bop:bop_parameters_cc_proto",
"//bop:integral_solver",
@@ -47,5 +65,9 @@ cc_library(
"//lp_data",
"//util:fp_utils",
"//util:proto_tools",
],
] + select({
":with_glpk": ["@glpk//:glpk"],
"//conditions:default": [],
}),
)

View File

@@ -149,7 +149,6 @@
#include "base/integral_types.h"
#include "base/logging.h"
#include "base/timer.h"
#include "glop/parameters.pb.h"
#include "linear_solver/linear_expr.h"
#include "linear_solver/linear_solver.pb.h"