[CMake] how to add_library with an already compiled lib in a zip file ?

Martin Koller martin.koller at etm.at
Wed Nov 28 07:41:19 EST 2012


Hi,

I'm struggling with the following requirement:
I have a lib stored in a zip file (the lib is not built via cmake, e.g. delivered from external company).

I want a target to link against this lib and want to extract the lib from the zip file only if
this specific target is being built, and only if it is not already unzipped.

What I tried in the libs directory:

set(TARGET xxx)

add_library(${TARGET} STATIC IMPORTED GLOBAL)

set_target_properties(${TARGET} PROPERTIES IMPORTED_LOCATION
                      ${CMAKE_CURRENT_BINARY_DIR}/xxx.a)

set(ZIPFILE xxx.zip)

add_custom_target(${TARGET}_lib
                  COMMAND unzip -o ${CMAKE_CURRENT_SOURCE_DIR}/${ZIPFILE}
                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${ZIPFILE}
                  )
add_dependencies(${TARGET} ${TARGET}_lib)


Then I can use this target in e.g.
target_link_libraries(myTarget xxx)

The above however unzips the lib every time, even if it is already existing.
Is it possible to avoid that ?

P.S:This is the simple example. I have other similar problems when the zip file not only
holds 1 library but also a bunch of headerfiles and more than 1 lib ...

-- 
Best regards/Schöne Grüße

Martin

A: Because it breaks the logical sequence of discussion
Q: Why is top posting bad?

()  ascii ribbon campaign - against html e-mail 
/\  www.asciiribbon.org   - against proprietary attachments

This mail was not scanned before sending.
It was sent from a secure Linux desktop.


More information about the CMake mailing list