如何跳过xxxConfigVersion.cmake中的32 / 64bit-ness检查

时间:2018-08-02 17:19:04

标签: cmake

有一个仅标头的C ++库。 当我使用write_basic_package_version_file()时, 创建... ConfigVersion.cmake文件, 不仅检查版本,而且检查32/64位兼容性:

# if the installed or the using project don't
# have CMAKE_SIZEOF_VOID_P set, ignore it:
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "")
   return()
endif()

# check that the installed version has the 
# same 32/64bit-ness as the one which is currently searching:
if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8")
  math(EXPR installedBits "8 * 8")
  set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
  set(PACKAGE_VERSION_UNSUITABLE TRUE)
endif()

这对于仅标头的lib没有任何意义。 我可以手动删除该代码,但是有一种绝妙的方法不生成此“添加”吗?

1 个答案:

答案 0 :(得分:1)

如果您在调用CMAKE_SIZEOF_VOID_P之前将变量write_basic_package_version_file()设置为未设置(或设置为空字符串),这将确保禁用对位的检查。

实际上,以下所有BasicConfigVersion-*.in模板上都使用了以下代码段:

# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "@CMAKE_SIZEOF_VOID_P@" STREQUAL "")
    return()
endif()

将配置为

if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "" STREQUAL "")
    return()
endif()

总是返回。