使用Autoconf检测另一个库中的预处理器宏

Kal*_*leb 4 autoconf gnu autotools configure autoreconf

我有一个已安装的库,我们称之为"custom_lib",我正在链接它.

我想检查该库是否安装了特定选项.

该库中的options.h头文件有一个预处理器宏列表,如下所示:

#undef THIS
#define THIS

#undef THAT
#define THAT

#undef WE_WANT_THIS_ONE
#define WE_WANT_THIS_ONE
Run Code Online (Sandbox Code Playgroud)

在我的configure.ac文件中的另一个项目中,这个测试:

 OPTION_FOUND="no"
 AC_CHECK_HEADERS(custom_lib/options.h)                                             
 AC_MSG_CHECKING([is libary configured with --enable-we_want_this_one])

 #AC_EGREP_HEADER([ string to match ],                                            
 #                [ header file ],                                               
 #                [ action if found ],                                           
 #                [ action if not found ])

 AC_EGREP_HEADER([[WE_WANT_THIS_ONE]],                                                      
                 [custom_lib/options.h],                                          
                 [OPTION_FOUND="yes"],                                    
                 [OPTION_FOUND="no"])                                     

 if test "$OPTION_FOUND" = "yes"                                            
 then                                                                            
     # If we have WE_WANT_THIS_ONE check to see which compiler is being used                
     if test "$GCC" = "yes"                                                      
     then                                                                        
         if test "$CC" != "icc"                                                  
         then                                                                    
             #if compiler is not icc then add these flags                        
             CFLAGS="$CFLAGS -maes -msse4"                                       
         fi                                                                      
     fi                                                                          
     AC_MSG_RESULT([yes])                                                        
else                                                                            
     AC_MSG_RESULT([no])                                                         
fi
Run Code Online (Sandbox Code Playgroud)

我然后autreconf并运行./configure,它总是返回此消息:

checking custom_lib/options.h usability... yes                                     
checking custom_lib/options.h presence... yes                                      
checking for custom_lib/options.h... yes
checking is library configured with --enable-we_want_this_one... no
Run Code Online (Sandbox Code Playgroud)

难道我做错了什么.在configure.ac中的测试需要改变什么,以便autoconf可以检测options.h中的预处理器宏?

baf*_*baf 5

AC_EGREP_HEADER 宏不会对测试标题的文本执行grep,而是对该文件上运行的预处理器的输出执行grep.

autoconf手册:

- Macro:AC_EGREP_HEADER(pattern,header-file,action-if-found,[action-if-not-found])

如果在系统头文件头文件上运行预处理器输出与扩展正则表达式模式匹配,则执行shell命令action-if-found,否则执行action-if-not-found.

你可以用AC_COMPILE_IFELSE宏代替.例如(未测试):

AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include "custom_lib/options.h"
#ifndef WE_WANT_THIS_ONE
# error macro not defined
#endif
]])], [OPTION_FOUND="yes"], [OPTION_FOUND="no"])
Run Code Online (Sandbox Code Playgroud)