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 中。

4

2 回答 2

4

尝试:

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()
于 2010-11-09T19:02:50.227 回答
1

对于 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()
于 2010-11-12T15:32:07.413 回答