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

Kay-Uwe 'Kiwi' Lorenz kay at moduleworks.com
Wed Nov 28 08:40:47 EST 2012


Hi Martin,

you have to add a custom command to generate your lib and make your custom
target depending on it:

add_custom_command(
	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xxx.a
	COMMAND
		unzip -o ${CMAKE_CURRENT_SOURCE_DIR}/${ZIPFILE}
	DEPENDS
		${CMAKE_CURRENT_SOURCE_DIR}/${ZIPFILE}
	)

add_custom_target(
	${TARGET}_lib
	DEPENDS
		${CMAKE_CURRENT_BINARY_DIR}/xxx.a
	)

This will unzip the xxx.a only if your zipfile has changed.

Regards, Kiwi
	

On 28.11.2012 13:41, Martin Koller wrote:
> 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 ...
>

-- 

Kay-Uwe (Kiwi) Lorenz
IT Department
ModuleWorks GmbH
Ritterstr. 12a
52072 Aachen
Germany

HRB 11871
Amtsgericht Aachen
Geschäftsführer Yavuz Murtezaoglu


More information about the CMake mailing list