J'ai une variable:CMake - Crée une liste de chemins absolus.
set(${PROJECT_NAME}_EXTERNAL_LIBRARIES
${PocoNetExternal_LIBRARIES}
)
qui vient de:
set(EXTERNAL_NAME PocoNetExternal)
set(${EXTERNAL_NAME}_LIBRARIES
${PROJECT_BINARY_DIR}/${EXTERNAL_NAME}/Foundation/${CMAKE_SHARED_LIBRARY_PREFIX}PocoFoundation${POCO_build_postfix}${CMAKE_STATIC_LIBRARY_SUFFIX}
${PROJECT_BINARY_DIR}/${EXTERNAL_NAME}/Util/${CMAKE_SHARED_LIBRARY_PREFIX}PocoUtil${POCO_build_postfix}${CMAKE_STATIC_LIBRARY_SUFFIX}
${PROJECT_BINARY_DIR}/${EXTERNAL_NAME}/Net/${CMAKE_SHARED_LIBRARY_PREFIX}PocoNet${POCO_build_postfix}${CMAKE_STATIC_LIBRARY_SUFFIX}
)
En raison de la question examinée dans This Question, je besoin de tous ces chemins sont relatifs.
J'ai essayé:
function(makeLibPathsAbsolute)
set(temp ${${PROJECT_NAME}_EXTERNAL_LIBRARIES}) #rename list
set(external_libraries_rel) #make empty list
list(LENGTH temp len1) #len1 is length of temp list
math(EXPR len2 "${len1} - 1") #len2 is len1 - 1
foreach(val RANGE ${len2}) #for val = 0 to len2
list(GET temp ${val} relPath) #relPath becomes the {val} entry of temp
get_filename_component(absPath ${relPath} ABSOLUTE) #make relPath Absolute and call it absPath
list(APPEND external_libraries_rel ${absPath}) #Append this to the external_libraries_rel list
endforeach()
endfunction()
Mais quand je l'utilise target_link_libraries(${name} ${external_libraries_rel})
-je obtenir une Undefined erreur de référence pour toutes les fonctions liées à la bibliothèque, je suis en train de créer un lien. Indique que la bibliothèque n'a pas été réellement liée.
Est-ce ma fonction makeLibPathsAbsolute()
correcte?
Vous ne semblez pas retourner quoi que ce soit de votre fonction. Pouvez-vous vérifier que la variable passée à 'target_link_libraries' n'est pas vide? – arrowd