代码之家  ›  专栏  ›  技术社区  ›  Hassan Syed

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

  •  0
  • Hassan Syed  · 技术社区  · 14 年前

    我现在有一个基本的Cmake文件,用来设置某些库目录。我想根据目标生成器有条件地初始化——在我的例子中,生成器确定要使用哪个基本目录(64位visual studio生成器与普通visualstudio生成器)。

    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位版本。在选择“generate”选项之前,默认设置应该显示在Cmake Gui/ccmake中。

    2 回复  |  直到 14 年前
        1
  •  4
  •   tibur    14 年前

    尝试:

    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()
    
        2
  •  1
  •   Hassan Syed    14 年前

    对于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()