Feature #3333

mkmf (have|find)_cxx_header

Added by Nobuyoshi Nakada almost 4 years ago. Updated 3 months ago.

[ruby-dev:41394]
Status:Assigned
Priority:Low
Assignee:Nobuyoshi Nakada
Category:-
Target version:next minor

Description

=begin
なかだです。

ruby-devに移動します。

At Fri, 21 May 2010 17:30:06 +0900,
KISHIMOTO, Makoto wrote in :

で振ってみた話題に関係して、なのですが(ツリーになりませんでしたが)、

redmine.ruby-lang.orgに登録されるのはruby-devかruby-coreだけです。

mkmf に C++ のヘッダをチェックする機能を追加するパッチです。

チェックするのはヘッダだけでいいんでしょうか。havelibraryや
find
library、havefunc、havetypeなども全部havecxx…を追加す
るんでしょうか。また、mkmf.rbではObjective-Cのソースも探すように
なっていますが、こちらにも対応しようと思うとhaveobjc…などとど
んどん数が増えてしまうので、どちらかというと、lang: "C++"のよう
なオプション引数を追加するほうがいいのではないかという気がしてい
ます。

--
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
中田 伸悦
=end

History

#1 Updated by Hiroshi Nakamura about 2 years ago

  • Description updated (diff)

Imported from #3330

うっかりruby-listに投げてしまったきしもとです

で振ってみた話題に関係して、なのですが(ツリーになりませんでしたが)、
mkmf に C++ のヘッダをチェックする機能を追加するパッチです。

Index: configure.in

--- configure.in (revision 27940)
+++ configure.in (working copy)
@@ -243,6 +243,7 @@
fi
ACPROGCC
ACPROGCXX
+ACPROGCXXCPP
ACPROGGCCTRADITIONAL
AC
SUBST(GCC)
if test "$GCC" = yes; then

Index: lib/mkmf.rb

--- lib/mkmf.rb (revision 27940)
+++ lib/mkmf.rb (working copy)
@@ -408,6 +408,14 @@
conf)
end

+def cxxcppcommand(outfile, opt="")
+ conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
+ 'arch
hdrdir' => "#$archhdrdir",
+ 'top
srcdir' => $topsrcdir.quote)
+ RbConfig::expand("$(CXXCPP) #$INCFLAGS #$CPPFLAGS #$CXXFLAGS #{opt} #{CONFTEST
C} #{outfile}",
+ conf)
+end
+
def libpathflag(libpath=$DEFLIBPATH|$LIBPATH)
libpath.map{|x|
case x
@@ -454,8 +462,15 @@
rm_f "conftest*"
end

+def trycxxcpp(src, opt="", &b)
+ try
do(src, cxxcppcommand(CPPOUTFILE, opt), &b)
+ensure
+ rm
f "conftest*"
+end
+
class Object
aliasmethod :tryheader, (configstring('tryheader') || :trycpp)
+ alias
method :trycxxheader, (configstring('trycxxheader') || :trycxxcpp)
end

def cpp_include(header)
@@ -840,6 +855,24 @@
end
end

+# 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 HAVEFOOH
+# preprocessor macro would be passed to the compiler.
+#
+def havecxxheader(header, preheaders = nil, &b)
+ checkingfor header do
+ if try
cxxheader(cppinclude(preheaders)+cppinclude(header), &b)
+ $defs.push(format("-DHAVE
%s", header.tr_cpp))
+ true
+ else
+ false
+ end
+ end
+end
+
# 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.
#
@@ -867,6 +900,33 @@
end
end

+# 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 findcxxheader(header, *paths)
+ message = checkingmessage(header, paths)
+ header = cpp
include(header)
+ checkingfor message do
+ if try
cxxheader(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
+
# 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

#2 Updated by Hiroshi Nakamura about 2 years ago

  • Assignee set to Nobuyoshi Nakada

#3 Updated by Shyouhei Urabe about 2 years ago

  • Status changed from Open to Assigned

#4 Updated by Yusuke Endoh over 1 year ago

  • Target version set to next minor

#5 Updated by Roger Pack 3 months ago

could I request an update on this please?

Also available in: Atom PDF