-
Notifications
You must be signed in to change notification settings - Fork 8
/
mrbgem.rake
49 lines (46 loc) · 1.82 KB
/
mrbgem.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
MRuby::Gem::Specification.new('mruby-zmq') do |spec|
spec.license = 'MPL-2.0'
spec.author = 'Hendrik Beskow'
spec.summary = 'mruby bindings for libzmq4'
spec.add_conflict 'mruby-czmq'
spec.add_dependency 'mruby-errno'
spec.add_dependency 'mruby-objectspace'
spec.add_dependency 'mruby-pack'
spec.add_dependency 'mruby-env'
spec.add_dependency 'mruby-print'
spec.add_dependency 'mruby-time'
spec.add_dependency 'mruby-sprintf'
spec.add_dependency 'mruby-class-ext'
spec.add_dependency 'mruby-metaprog'
spec.add_test_dependency 'mruby-sleep'
def build_libzmq(spec, build)
unless File.exists?("#{spec.build_dir}/build/lib/libzmq.a")
warn "mruby-zmq: cannot find libzmq, building it"
sh "mkdir -p #{spec.build_dir}/build && cd #{spec.build_dir}/build && cmake -DCMAKE_INSTALL_PREFIX=\"#{spec.build_dir}\" -DWITH_LIBSODIUM=ON -DENABLE_CURVE=ON -DENABLE_DRAFTS=ON #{spec.dir}/deps/libzmq/ && cmake --build . -j$(nproc) --target libzmq-static && make -j$(nproc) install"
end
spec.linker.flags_before_libraries << "\"#{spec.build_dir}/build/lib/libzmq.a\""
`pkg-config --cflags \"#{spec.build_dir}/build/libzmq.pc\"`.split("\s").each do |cflag|
spec.cxx.flags << cflag
spec.cc.flags << cflag
end
`pkg-config --static --libs \"#{spec.build_dir}/build/libzmq.pc\"`.split("\s").each do |lib|
next if lib == '-lzmq'
spec.linker.flags_before_libraries << lib
end
end
if spec.cc.search_header_path 'ifaddrs.h'
spec.cc.defines << 'HAVE_IFADDRS_H'
end
if spec.build.toolchains.include? 'visualcpp'
spec.linker.libraries << 'libzmq'
else
if ENV['BUILD_LIBZMQ']
build_libzmq(spec, build)
else
unless spec.search_package('libzmq')
build_libzmq(spec, build)
end
end
spec.linker.flags_before_libraries << '-pthread'
end
end