https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17097754782012-03-18T15:56:36ZRuby Issue Tracking SystemRuby master - Feature #3333: mkmf (have|find)_cxx_headerhttps://bugs.ruby-lang.org/issues/3333?journal_id=247152012-03-18T15:56:36Znahi (Hiroshi Nakamura)nakahiro@gmail.com
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/24715/diff?detail_id=18009">diff</a>)</li></ul><p>Imported from <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: mkmf (find|have)_cxx_header (Rejected)" href="https://bugs.ruby-lang.org/issues/3330">#3330</a></p>
<p>うっかりruby-listに投げてしまったきしもとです</p>
<p>[ruby-list:47092] で振ってみた話題に関係して、なのですが(ツリーになりませんでしたが)、<br>
mkmf に C++ のヘッダをチェックする機能を追加するパッチです。</p>
<pre><code class="diff syntaxhl" data-language="diff"><span class="gh">Index: configure.in
===================================================================
</span><span class="gd">--- configure.in (revision 27940)
</span><span class="gi">+++ configure.in (working copy)
</span><span class="p">@@ -243,6 +243,7 @@</span>
fi
AC_PROG_CC
AC_PROG_CXX
<span class="gi">+AC_PROG_CXXCPP
</span> AC_PROG_GCC_TRADITIONAL
AC_SUBST(GCC)
if test "$GCC" = yes; then
<span class="gh">Index: lib/mkmf.rb
===================================================================
</span><span class="gd">--- lib/mkmf.rb (revision 27940)
</span><span class="gi">+++ lib/mkmf.rb (working copy)
</span><span class="p">@@ -408,6 +408,14 @@</span>
conf)
end
<span class="err">
</span><span class="gi">+def cxxcpp_command(outfile, opt="")
+ conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
+ 'arch_hdrdir' => "#$arch_hdrdir",
+ 'top_srcdir' => $top_srcdir.quote)
+ RbConfig::expand("$(CXXCPP) #$INCFLAGS #$CPPFLAGS #$CXXFLAGS #{opt} #{CONFTEST_C} #{outfile}",
+ conf)
+end
+
</span> def libpathflag(libpath=$DEFLIBPATH|$LIBPATH)
libpath.map{|x|
case x
<span class="p">@@ -454,8 +462,15 @@</span>
rm_f "conftest*"
end
<span class="err">
</span><span class="gi">+def try_cxxcpp(src, opt="", &b)
+ try_do(src, cxxcpp_command(CPPOUTFILE, opt), &b)
+ensure
+ rm_f "conftest*"
+end
+
</span> class Object
alias_method :try_header, (config_string('try_header') || :try_cpp)
<span class="gi">+ alias_method :try_cxx_header, (config_string('try_cxx_header') || :try_cxxcpp)
</span> end
<span class="err">
</span> def cpp_include(header)
<span class="p">@@ -840,6 +855,24 @@</span>
end
end
<span class="err">
</span><span class="gi">+# Returns whether or not the given C plus plus +header+ file can be found on
+# your system. If found, a macro is passed as a preprocessor constant to the
+# compiler using the header file name, in uppercase, prepended with 'HAVE_'.
+#
+# For example, if have_header('foo.h') returned true, then the HAVE_FOO_H
+# preprocessor macro would be passed to the compiler.
+#
+def have_cxx_header(header, preheaders = nil, &b)
+ checking_for header do
+ if try_cxx_header(cpp_include(preheaders)+cpp_include(header), &b)
+ $defs.push(format("-DHAVE_%s", header.tr_cpp))
+ true
+ else
+ false
+ end
+ end
+end
+
</span> # Instructs mkmf to search for the given +header+ in any of the +paths+
# provided, and returns whether or not it was found in those paths.
#
<span class="p">@@ -867,6 +900,33 @@</span>
end
end
<span class="err">
</span><span class="gi">+# Instructs mkmf to search for the given C plus plus +header+ in any of the
+# +paths+ provided, and returns whether or not it was found in those paths.
+#
+# If the header is found then the path it was found on is added to the list
+# of included directories that are sent to the compiler (via the -I switch).
+#
+def find_cxx_header(header, *paths)
+ message = checking_message(header, paths)
+ header = cpp_include(header)
+ checking_for message do
+ if try_cxx_header(header)
+ true
+ else
+ found = false
+ paths.each do |dir|
+ opt = "-I#{dir}".quote
+ if try_cxx_header(header, opt)
+ $INCFLAGS << " " << opt
+ found = true
+ break
+ end
+ end
+ found
+ end
+ end
+end
+
</span> # Returns whether or not the struct of type +type+ contains +member+. If
# it does not, or the struct type can't be found, then false is returned. You
# may optionally specify additional +headers+ in which to look for the struct
</code></pre> Ruby master - Feature #3333: mkmf (have|find)_cxx_headerhttps://bugs.ruby-lang.org/issues/3333?journal_id=247162012-03-18T16:06:03Znahi (Hiroshi Nakamura)nakahiro@gmail.com
<ul><li><strong>Assignee</strong> set to <i>nobu (Nobuyoshi Nakada)</i></li></ul> Ruby master - Feature #3333: mkmf (have|find)_cxx_headerhttps://bugs.ruby-lang.org/issues/3333?journal_id=248652012-03-18T18:46:38Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li></ul> Ruby master - Feature #3333: mkmf (have|find)_cxx_headerhttps://bugs.ruby-lang.org/issues/3333?journal_id=332182012-11-20T21:17:34Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Target version</strong> set to <i>2.6</i></li></ul> Ruby master - Feature #3333: mkmf (have|find)_cxx_headerhttps://bugs.ruby-lang.org/issues/3333?journal_id=446372014-01-27T22:35:19Zrogerdpack (Roger Pack)rogerpack2005@gmail.com
<ul></ul><p>could I request an update on this please?</p> Ruby master - Feature #3333: mkmf (have|find)_cxx_headerhttps://bugs.ruby-lang.org/issues/3333?journal_id=679312017-11-27T11:04:04Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul><p>望み薄なので一旦閉じます。<br>
今でも必要とお思いでしたら、議論を進める材料(<code>lang: "C++"</code> の方針でのパッチとか)を用意すると良いかも知れません。</p> Ruby master - Feature #3333: mkmf (have|find)_cxx_headerhttps://bugs.ruby-lang.org/issues/3333?journal_id=682342017-12-08T13:23:04Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-2 priority-4 priority-default" href="/issues/4924">Feature #4924</a>: mkmf have_header fails with C++ headers</i> added</li></ul> Ruby master - Feature #3333: mkmf (have|find)_cxx_headerhttps://bugs.ruby-lang.org/issues/3333?journal_id=682362017-12-08T13:23:27Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Related to</strong> deleted (<i><a class="issue tracker-2 status-2 priority-4 priority-default" href="/issues/4924">Feature #4924</a>: mkmf have_header fails with C++ headers</i>)</li></ul> Ruby master - Feature #3333: mkmf (have|find)_cxx_headerhttps://bugs.ruby-lang.org/issues/3333?journal_id=682382017-12-08T13:23:34Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-2 status-2 priority-4 priority-default" href="/issues/4924">Feature #4924</a>: mkmf have_header fails with C++ headers</i> added</li></ul>