|
9 | 9 | if inc || lib
|
10 | 10 | inc ||= "/usr/local/include"
|
11 | 11 | 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") |
13 | 33 | else
|
14 | 34 | # download
|
15 | 35 | require_relative "vendor"
|
|
21 | 41 | # use double dollar sign and single quotes to escape properly
|
22 | 42 | rpath_prefix = RbConfig::CONFIG["host_os"] =~ /darwin/ ? "@loader_path" : "$$ORIGIN"
|
23 | 43 | rpath = "'#{rpath_prefix}/../../tmp/or-tools/lib'"
|
| 44 | + |
| 45 | + $INCFLAGS << " -I#{inc}" |
| 46 | + $LDFLAGS.prepend("-Wl,-rpath,#{rpath} -L#{lib} #{lib}/libprotobuf.a ") |
24 | 47 | end
|
25 | 48 |
|
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") |
34 | 49 |
|
35 | 50 | create_makefile("or_tools/ext")
|
0 commit comments