CMAKE:根据生成器类型有条件地初始化缓存变量

发布于 2024-10-01 09:25:19 字数 559 浏览 9 评论 0原文

我目前有一个基本的 Cmake 文件,用于设置某些库目录。我想根据目标生成器有条件地初始化——在我的例子中,生成器确定要使用哪些基本目录(64 位 Visual Studio 生成器与常规 Visual Studio 生成器)。

我的 CMakeLists 文件如下所示:

PROJECT(STAT_AUTH)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

SET(BOOST_DIR "c:\\dev_32\\Boost" CACHE PATH "The Boost Directory Path")
SET(PROTOBUF_DIR "c:\\dev_32\\Protobuf" CACHE PATH "The Protobuf directory Path")
SET(OPENSSL_DIR "c:\\dev_32\\OpenSSL" CACHE PATH "The OpenSSL Directory Path"

如何有条件地初始化变量,以便在生成 64 位生成器时将它们设置为 64 位版本。在我选择“生成”选项之前,默认设置应该显示在 Cmake Gui / ccmake 中。

I currently have a basic Cmake file that sets certain library directories. I would like to conditionally intitalise based on the target generator -- in my case the generator determines which base directories to use (64-bit visual studio generator vs a regular visual studio generator).

My CMakeLists file looks as follows:

PROJECT(STAT_AUTH)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

SET(BOOST_DIR "c:\\dev_32\\Boost" CACHE PATH "The Boost Directory Path")
SET(PROTOBUF_DIR "c:\\dev_32\\Protobuf" CACHE PATH "The Protobuf directory Path")
SET(OPENSSL_DIR "c:\\dev_32\\OpenSSL" CACHE PATH "The OpenSSL Directory Path"

How do I conditionally initialise the variables so they get set to 64-bit versions when I generate to 64-bit generators. The default setting should show up in the Cmake Gui / ccmake before I choose the "generate" option.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我乃一代侩神 2024-10-08 09:25:19

尝试:

if(CMAKE_SIZEOF_VOID_P MATCHES 4)
  SET(BOOST_DIR "c:\\dev_32\\Boost" CACHE PATH "The Boost Directory Path")
  SET(PROTOBUF_DIR "c:\\dev_32\\Protobuf" CACHE PATH "The Protobuf directory Path")
  SET(OPENSSL_DIR "c:\\dev_32\\OpenSSL" CACHE PATH "The OpenSSL Directory Path"
else()
  SET(BOOST_DIR "c:\\dev_64\\Boost" CACHE PATH "The Boost Directory Path")
  SET(PROTOBUF_DIR "c:\\dev_64\\Protobuf" CACHE PATH "The Protobuf directory Path")
  SET(OPENSSL_DIR "c:\\dev_64\\OpenSSL" CACHE PATH "The OpenSSL Directory Path"
endif()

Try:

if(CMAKE_SIZEOF_VOID_P MATCHES 4)
  SET(BOOST_DIR "c:\\dev_32\\Boost" CACHE PATH "The Boost Directory Path")
  SET(PROTOBUF_DIR "c:\\dev_32\\Protobuf" CACHE PATH "The Protobuf directory Path")
  SET(OPENSSL_DIR "c:\\dev_32\\OpenSSL" CACHE PATH "The OpenSSL Directory Path"
else()
  SET(BOOST_DIR "c:\\dev_64\\Boost" CACHE PATH "The Boost Directory Path")
  SET(PROTOBUF_DIR "c:\\dev_64\\Protobuf" CACHE PATH "The Protobuf directory Path")
  SET(OPENSSL_DIR "c:\\dev_64\\OpenSSL" CACHE PATH "The OpenSSL Directory Path"
endif()
在风中等你 2024-10-08 09:25:19

对于 Windows,以下语法是合适的。 CMAKE_CL_64专门定义了x86_64编译器。

if(MSVC)
    if(CMAKE_CL_64)
        SET(BOOST_DIR "c:\\dev_64\\Boost" CACHE PATH "The Boost Directory Path")
        SET(PROTOBUF_DIR "c:\\dev_64\\Protobuf" CACHE PATH "The Protobuf directory Path")
        SET(OPENSSL_DIR "c:\\dev_64\\OpenSSL" CACHE PATH "The OpenSSL Directory Path")
        SET(DEPLOY_DIR "c:\\root_64" CACHE PATH "The Deploy Path for the components built" )
    else()
        SET(BOOST_DIR "c:\\dev_32\\Boost" CACHE PATH "The Boost Directory Path")
        SET(PROTOBUF_DIR "c:\\dev_32\\Protobuf" CACHE PATH "The Protobuf directory Path")
        SET(OPENSSL_DIR "c:\\dev_32\\OpenSSL" CACHE PATH "The OpenSSL Directory Path")
        SET(DEPLOY_DIR "c:\\root_32" CACHE PATH 
            "The Deploy Path for the components built" )
    endif()
endif()

For Windows the following syntax is apt. CMAKE_CL_64 defines the x86_64 compiler specifically.

if(MSVC)
    if(CMAKE_CL_64)
        SET(BOOST_DIR "c:\\dev_64\\Boost" CACHE PATH "The Boost Directory Path")
        SET(PROTOBUF_DIR "c:\\dev_64\\Protobuf" CACHE PATH "The Protobuf directory Path")
        SET(OPENSSL_DIR "c:\\dev_64\\OpenSSL" CACHE PATH "The OpenSSL Directory Path")
        SET(DEPLOY_DIR "c:\\root_64" CACHE PATH "The Deploy Path for the components built" )
    else()
        SET(BOOST_DIR "c:\\dev_32\\Boost" CACHE PATH "The Boost Directory Path")
        SET(PROTOBUF_DIR "c:\\dev_32\\Protobuf" CACHE PATH "The Protobuf directory Path")
        SET(OPENSSL_DIR "c:\\dev_32\\OpenSSL" CACHE PATH "The OpenSSL Directory Path")
        SET(DEPLOY_DIR "c:\\root_32" CACHE PATH 
            "The Deploy Path for the components built" )
    endif()
endif()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文