2010-11-09 4 views
0

J'ai actuellement un fichier Cmake de base qui définit certains répertoires de bibliothèque. Je voudrais intitaliser conditionnellement basé sur le générateur de cible - dans mon cas, le générateur détermine quels répertoires de base à utiliser (générateur de studio visuel 64 bits vs un générateur de studio visuel régulier).CMAKE: initialisation conditionnelle d'une variable de cache dépendant du type de générateur

fichier

Mes CMakeLists se présente comme suit:

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" 

Comment puis-je initialiser les variables sous condition afin qu'ils se préparent à des versions 64 bits lorsque je produis à des générateurs 64 bits. Le paramètre par défaut devrait apparaître dans le Cmake Gui/ccmake avant de choisir l'option "générer".

Répondre

1

Pour Windows, la syntaxe suivante est apt. CMAKE_CL_64 définit spécifiquement le compilateur 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() 
+0

C'est une façon beaucoup plus agréable de faire les choses. Merci. –

4

Essayez:

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() 
+0

Merci je rentre à la maison maintenant. Mais je vais l'essayer demain. J'essayais if (0) ou if (off), mais il semble que l'analyseur cmake ne respecte pas les conditionnels. Idéalement, je voudrais faire quelque chose comme (psuedocode): 'if (Generator est Visual Studio - 64) //...// endif()'. Donc de toute façon qu'est ce que CMAKE_SIZEOF_VOID_P? –

+1

'CMAKE_SIZEOF_VOID_P': http://cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_SIZEOF_VOID_P. Taille d'un pointeur vide La taille d'un pointeur sur la machine est déterminée par une compilation d'essai Si une taille de 64 bits est trouvée, le chemin de recherche de la bibliothèque est modifié pour rechercher des bibliothèques 64 bits premier." –

+1

Soyez prudent avec les commandes 'SET (... CACHE ...)': les données sont écrites uniquement la première fois que vous exécutez cmake. Vous devez effacer le cache si vous souhaitez tester à nouveau vos valeurs par défaut. – tibur

Questions connexes