2010-08-01 4 views
12

Pour lier un exécutable avec une bibliothèque qui se trouve dans un emplacement standard, on peut effectuer les opérations suivantes dans un fichier CMakeLists.txt:Comment trouver une bibliothèque avec cmake?

create_executable(generate_mesh generate_mesh.cpp) 
target_link_libraries(generate_mesh OpenMeshCore) 

Cela fonctionnerait si la bibliothèque, qui est liée contre, a été placé dans

/usr/local/lib/libOpenMeshCore.dylib 

Cependant, dans ce cas, la bibliothèque réside dans

/usr/local/lib/OpenMesh/libOpenMeshCore.dylib 

Comment puis-je préciser que TARGET_LINK_LIBRARIES shou LD lien vraiment contre une bibliothèque placée dans un sibdirectory? Je me demande s'il existe une option utile pour target_link_libraries qui spécifie que la bibliothèque se trouve dans un sous-répertoire dans un emplacement standard, par ex.

target_link_libraries(generate_mesh OpenMesh/OpenMeshCore) 

Si cela est impossible, il est un moyen d'utiliser find_library pour rechercher /usr/local/lib récursive, y compris ses sous-répertoires, pour le fichier de bibliothèque donné?

Répondre

21

Vous pouvez ajouter différents répertoires à find_library. Pour utiliser cette bibliothèque, appelez cmake par cmake -DFOO_PREFIX=/some/path ....

find_library(CPPUNIT_LIBRARY_DEBUG NAMES cppunit cppunit_dll cppunitd cppunitd_dll 
      PATHS ${FOO_PREFIX}/lib 
        /usr/lib 
        /usr/lib64 
        /usr/local/lib 
        /usr/local/lib64 
      PATH_SUFFIXES debug) 

find_library(CPPUNIT_LIBRARY_RELEASE NAMES cppunit cppunit_dll 
      PATHS ${FOO_PREFIX}/lib 
        /usr/lib 
        /usr/lib64 
        /usr/local/lib 
        /usr/local/lib64 
      PATH_SUFFIXES release) 

if(CPPUNIT_LIBRARY_DEBUG AND NOT CPPUNIT_LIBRARY_RELEASE) 
    set(CPPUNIT_LIBRARY_RELEASE ${CPPUNIT_LIBRARY_DEBUG}) 
endif(CPPUNIT_LIBRARY_DEBUG AND NOT CPPUNIT_LIBRARY_RELEASE) 

set(CPPUNIT_LIBRARY debug  ${CPPUNIT_LIBRARY_DEBUG} 
        optimized ${CPPUNIT_LIBRARY_RELEASE}) 

# ... 
target_link_libraries(foo ${CPPUNIT_LIBRARY}) 
+0

A travaillé un régal pour moi merci! – alexr

Questions connexes