Skip to content

Commit d9a37a6

Browse files
committed
Allow to pass multiple lib dirs split by a colon
i.e: --with-or-tools-lib=/usr/local/lib:/usr/local/lib64
1 parent 65039f7 commit d9a37a6

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

ext/or-tools/extconf.rb

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,27 @@
99
if inc || lib
1010
inc ||= "/usr/local/include"
1111
lib ||= "/usr/local/lib"
12-
rpath = lib
12+
13+
lib_dirs = lib.split(':')
14+
rpath = lib_dirs.join(':')
15+
16+
$INCFLAGS << " -I#{inc}"
17+
18+
lib_dirs.each do |lib_dir|
19+
$LDFLAGS.prepend("-L#{lib_dir} ")
20+
end
21+
22+
# Add rpath for all lib directories
23+
$LDFLAGS.prepend("-Wl,-rpath,#{rpath} ")
24+
25+
# Check for libprotobuf.a in any of the lib directories
26+
libprotobuf_found = lib_dirs.any? { |dir| File.exist?("#{dir}/libprotobuf.a") }
27+
raise "libprotobuf.a not found" unless libprotobuf_found
28+
29+
# Add libprotobuf.a to LDFLAGS
30+
$LDFLAGS << " #{lib_dirs.find { |dir| File.exist?("#{dir}/libprotobuf.a") }}/libprotobuf.a"
31+
32+
raise "OR-Tools not found" unless have_library("ortools")
1333
else
1434
# download
1535
require_relative "vendor"
@@ -21,15 +41,10 @@
2141
# use double dollar sign and single quotes to escape properly
2242
rpath_prefix = RbConfig::CONFIG["host_os"] =~ /darwin/ ? "@loader_path" : "$$ORIGIN"
2343
rpath = "'#{rpath_prefix}/../../tmp/or-tools/lib'"
44+
45+
$INCFLAGS << " -I#{inc}"
46+
$LDFLAGS.prepend("-Wl,-rpath,#{rpath} -L#{lib} #{lib}/libprotobuf.a ")
2447
end
2548

26-
# find_header and find_library first check without adding path
27-
# which can cause them to find system library
28-
$INCFLAGS << " -I#{inc}"
29-
# could support shared libraries for protobuf and abseil
30-
# but keep simple for now
31-
raise "libprotobuf.a not found" unless File.exist?("#{lib}/libprotobuf.a")
32-
$LDFLAGS.prepend("-Wl,-rpath,#{rpath} -L#{lib} #{lib}/libprotobuf.a ")
33-
raise "OR-Tools not found" unless have_library("ortools")
3449

3550
create_makefile("or_tools/ext")

0 commit comments

Comments
 (0)