Hi Nico In that case you need to do this:
add_library(${COMPONENT} IMPORTED) set_target_properties(${COMPONENT} PROPERTIES IMPORTED_LOCATION "${${COMPONENT}_LIBRARY}" LINK_INTERFACE_LIBRARIES "${${COMPONENT}_LINK_INTERFACE_LIBRARIES}" ) where each of the components X has a variable X_LIBRARY containing its path on the system (e.g. determined by find_library(X_LIBRARY ...)) and a variable X_LINK_INTERFACE_LIBRARIES which you have to set outside the foreach loop. HTH Michael On 7. Jan, 2010, at 11:51 , Nico Schlömer wrote: > Hi Michael, > > thanks for the explanations. > > I'm indeed about to write a FindModule.cmake for a library which I did > *not* write, but to certain components of which I'd like to link > against using CMake (in a clean fashion). > I'm FOREACHing through the components of the library, and upon trying to set > > ADD_LIBRARY( ${COMPONENT} ) > > cmake complains about > > add_library cannot create target "A" because another target with the > same name already exists. The existing target is a static library created > in source directory "/path/to/A". See > documentation for policy CMP0002 for more details. > > Okay, so it exists already? Fine. Let's then > > SET_TARGET_PROPERTIES( ${COMPONENT} PROPERTIES > LINK_INTERFACE_LIBRARIES "B;C;" ) > > -- but again, cmake complains that > > set_target_properties Can not find target to add properties to: A > > TARGET_LINK_LIBRARIES doesn't work anyway as I'm not *building the > libraries (cmake says). > > Hmmm... > Nico > > > > On Thu, Jan 7, 2010 at 11:08 AM, Michael Wild <them...@gmail.com> wrote: >> >> One quick question: Are these libraries created by you? In that case you >> shouldn't write a FindMymodule.cmake, but a MymoduleConfig.cmake (see the >> documentation of find_package). >> >> Anyhow, to define the transitive link dependencies you can either use >> target_link_libraries(A LINK_INTERFACE_LIBRARIES B C) if your CMake is new >> enough, or you can use set_target_properties(A PROPERTIES >> LINK_INTERFACE_LIBRARIES "B;C"). Both solutions require that you use >> add_library(X IMPORTED) (where X = A, B and C) and set their >> IMPORTED_LOCATION property to the location on the file system. All of this >> is full automatic if you write a MymoduleConfig.cmake, because then you can >> use >> >> install_targets(A B C EXPORT MymoduleExports >> ARCHIVE DESTINATION lib >> LIBRARY DESTINATION lib >> RUNTIME DESTINATION bin >> PUBLIC_HEADER DESTINATION include >> ) >> >> install(EXPORT MymoduleExports >> NAMESPACE Mymodule_ >> DESTINATION share/mymodule/cmake >> ) >> >> which will install a file >> ${CMAKE_INSTALL_PREFIX}/share/mymodule/cmake/MymoduleExports.cmake >> containing all the IMPORT stuff and which you can INCLUDE in your >> MymoduleConfig.cmake. >> >> >> I hope I could help a bit, otherwise tell us which case it is and I'll be >> able to help more. >> >> Michael >> >> _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake