【问题标题】:Detect preprocessor macro in another library with Autoconf使用 Autoconf 在另一个库中检测预处理器宏
【发布时间】:2017-11-09 03:36:15
【问题描述】:

我有一个已安装的库,我们将其称为“custom_lib”,我正在链接它。

我想检查该库是否使用特定选项安装。

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

#undef THIS
#define THIS

#undef THAT
#define THAT

#undef WE_WANT_THIS_ONE
#define WE_WANT_THIS_ONE

在另一个项目中,我的 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

然后我 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

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

【问题讨论】:

    标签: gnu autotools configure autoconf autoreconf


    【解决方案1】:

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

    来自autoconf manual

    — 宏:AC_EGREP_HEADER(模式、头文件、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"])
    

    【讨论】:

    • 有效!太感谢了。我不得不修改您的包含行,因为它是一个已安装的库:#include
    猜你喜欢
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多