Implements [Feature #3456]: Support pkgconf on windows
1. Store the `PKG_CONFIG` variable in Makefile.sub (or try to get it from the ENV var PKG_CONFIG in mkmf.rb) 2. Try to use --msvc-syntax, with a fallback to replacing -Lxxx with -libpath:xxx. --msvc-syntax has been in pkgconf since 1.4.0 (released 7 years ago). pkg-config (freedesktop), does not support it, hence the fallback. 3. The `try_ldflags` passes these `ldflags` as the `opt` parameter to the `link_command`, not as `ldflags`. Unix systems are forgiving in that regard, MSVC is not: as a result as passing them as `opt`, they (specifically the `/libpath:xxx` ones) end up passed before the `-link` command to `cl.exe` and it throws because it ignores it and therefore can't find the lib. ``` cl : Command line warning D9002 : ignoring unknown option '-libpath:C:/Users/julien/.conan2/p/libff3726d89a6255c/p/lib' ```
This commit is contained in:
parent
c695536cc8
commit
be7e5f1f85
Notes:
git
2024-12-23 02:52:33 +00:00
33
lib/mkmf.rb
33
lib/mkmf.rb
@ -604,9 +604,9 @@ MSG
|
|||||||
yield(opt, opts)
|
yield(opt, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def try_link0(src, opt = "", **opts, &b) # :nodoc:
|
def try_link0(src, opt = "", ldflags: "", **opts, &b) # :nodoc:
|
||||||
exe = CONFTEST+$EXEEXT
|
exe = CONFTEST+$EXEEXT
|
||||||
cmd = link_command("", opt)
|
cmd = link_command(ldflags, opt)
|
||||||
if $universal
|
if $universal
|
||||||
require 'tmpdir'
|
require 'tmpdir'
|
||||||
Dir.mktmpdir("mkmf_", oldtmpdir = ENV["TMPDIR"]) do |tmpdir|
|
Dir.mktmpdir("mkmf_", oldtmpdir = ENV["TMPDIR"]) do |tmpdir|
|
||||||
@ -750,7 +750,7 @@ MSG
|
|||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
def try_ldflags(flags, werror: $mswin, **opts)
|
def try_ldflags(flags, werror: $mswin, **opts)
|
||||||
try_link(MAIN_DOES_NOTHING, flags, werror: werror, **opts)
|
try_link(MAIN_DOES_NOTHING, "", ldflags: flags, werror: werror, **opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
# :startdoc:
|
# :startdoc:
|
||||||
@ -1968,7 +1968,7 @@ SRC
|
|||||||
if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
|
if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
|
||||||
# if and only if package specific config command is given
|
# if and only if package specific config command is given
|
||||||
elsif ($PKGCONFIG ||=
|
elsif ($PKGCONFIG ||=
|
||||||
(pkgconfig = with_config("pkg-config") {config_string("PKG_CONFIG") || "pkg-config"}) &&
|
(pkgconfig = with_config("pkg-config") {config_string("PKG_CONFIG") || ENV["PKG_CONFIG"] || "pkg-config"}) &&
|
||||||
find_executable0(pkgconfig) && pkgconfig) and
|
find_executable0(pkgconfig) && pkgconfig) and
|
||||||
xsystem([*envs, $PKGCONFIG, "--exists", pkg])
|
xsystem([*envs, $PKGCONFIG, "--exists", pkg])
|
||||||
# default to pkg-config command
|
# default to pkg-config command
|
||||||
@ -1980,11 +1980,34 @@ SRC
|
|||||||
pkgconfig = nil
|
pkgconfig = nil
|
||||||
end
|
end
|
||||||
if pkgconfig
|
if pkgconfig
|
||||||
|
has_ms_win_syntax = false
|
||||||
|
if $mswin
|
||||||
|
has_ms_win_syntax = xpopen([pkgconfig, "--help"]).read.include?('msvc-syntax')
|
||||||
|
if has_ms_win_syntax
|
||||||
|
args << "--msvc-syntax"
|
||||||
|
else
|
||||||
|
Logging.message("WARNING: #{pkgconfig} does not support the --msvc-syntax. Try using a recent pkgconf instead")
|
||||||
|
end
|
||||||
|
end
|
||||||
get = proc {|opts|
|
get = proc {|opts|
|
||||||
opts = Array(opts).map { |o| "--#{o}" }
|
opts = Array(opts).map { |o| "--#{o}" }
|
||||||
opts = xpopen([*envs, pkgconfig, *opts, *args], err:[:child, :out], &:read)
|
opts = xpopen([*envs, pkgconfig, *opts, *args], err:[:child, :out], &:read)
|
||||||
Logging.open {puts opts.each_line.map{|s|"=> #{s.inspect}"}}
|
Logging.open {puts opts.each_line.map{|s|"=> #{s.inspect}"}}
|
||||||
opts.strip if $?.success?
|
if $?.success?
|
||||||
|
opts = opts.strip
|
||||||
|
if $mswin and not has_ms_win_syntax
|
||||||
|
opts = Shellwords.shellwords(opts).map { |s|
|
||||||
|
if s.start_with?('-l')
|
||||||
|
"#{s[2..]}.lib"
|
||||||
|
elsif s.start_with?('-L')
|
||||||
|
"/libpath:#{s[2..]}"
|
||||||
|
else
|
||||||
|
s
|
||||||
|
end
|
||||||
|
}.quote.join(" ")
|
||||||
|
end
|
||||||
|
opts
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
orig_ldflags = $LDFLAGS
|
orig_ldflags = $LDFLAGS
|
||||||
|
@ -1168,6 +1168,7 @@ s,@top_srcdir@,$(srcdir),;t t
|
|||||||
s,@try_header@,try_compile,;t t
|
s,@try_header@,try_compile,;t t
|
||||||
s,@ruby_pc@,$(ruby_pc),;t t
|
s,@ruby_pc@,$(ruby_pc),;t t
|
||||||
s,@RJIT_SUPPORT@,$(RJIT_SUPPORT),;t t
|
s,@RJIT_SUPPORT@,$(RJIT_SUPPORT),;t t
|
||||||
|
s,@PKG_CONFIG@,$(PKG_CONFIG),;t t
|
||||||
<<KEEP
|
<<KEEP
|
||||||
|
|
||||||
!if "$(HAVE_BASERUBY)" != "yes" || "$(CROSS_COMPILING)" == "yes"
|
!if "$(HAVE_BASERUBY)" != "yes" || "$(CROSS_COMPILING)" == "yes"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user