# \[Feature:trunk\] mkmf (find|have)\_cxx\_header

**URL:** <https://www.ruby-forum.com/t/feature-trunk-mkmf-find-have-cxx-header/188984>\
**Category:** Development\
**Created:** [May 21, 2010, 12:39pm UTC](https://www.ruby-forum.com/t/feature-trunk-mkmf-find-have-cxx-header/188984 "2010-05-21T12:39:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![KISHIMOTOS\_Makoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8baadc/32.png) [@KISHIMOTOS\_Makoto](https://www.ruby-forum.com/u/KISHIMOTOS_Makoto)\
**Post date:** [May 21, 2010, 12:39pm UTC](https://www.ruby-forum.com/t/feature-trunk-mkmf-find-have-cxx-header/188984/1 "2010-05-21T12:39:00Z")

</div>

e$B$&$C$+$je(Bruby-liste$B$KEj$2$F$7$^$C$?$-$7$b$H$G$9e(B

[ruby-list:47092]  
e$B$G?6$C$F$\_$?OCBj$K4X78$7$F!"$J$N$G$9$,!J%D%j!\<$K$J$j$^$;$s$G$7$?$,!K!"e(B  
mkmf e$B$Ke(B C++ e$B$N%X%C%@$r%A%’%C%/$9$k5!G=$rDI2C$9$k%Q%C%A$G$9!#e(B

# Index: configure.in

# — configure.in (revision 27940) +++ configure.in (working copy) @@ -243,6 +243,7 @@ fi AC\_PROG\_CC AC\_PROG\_CXX +AC\_PROG\_CXXCPP AC\_PROG\_GCC\_TRADITIONAL 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 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  
+  
def libpathflag(libpath=$DEFLIBPATH|$LIBPATH)  
libpath.map{|x|  
case x  
@@ -454,8 +462,15 @@  
rm\_f “conftest\*”  
end

+def try\_cxxcpp(src, opt="", &b)

- try\_do(src, cxxcpp\_command(CPPOUTFILE, opt), &b)  
+ensure
- rm\_f “conftest\*”  
+end
- 

class Object  
alias\_method :try\_header, (config\_string(‘try\_header’) || :try\_cpp)

- alias\_method :try\_cxx\_header, (config\_string(‘try\_cxx\_header’) ||  
:try\_cxxcpp)  
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  
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
- 

# 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 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
- 

# 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
