Cmake download and extract file

Cmake download and extract file

cmake download and extract file

This is useful when downloading a file that CMake does not know how to extract, test to cover custom extraction of a self-extracting zip file. This is typically not needed if using CMake, as the cmake generator will handle the from conans import tools # Extract only files inside relative folder "small" Just a high level wrapper for download, unzip, and remove the temporary zip file​. Using CMake to download, verify the checksum of files and extract compressed files is easy and seamless. While this could be done more.

[CMake] Is there a better way to retrieve content from a remote zip file?

Chuck Atkinschuck.atkins at
Thu Apr 28 11:58:12 EDT 2016
This looks well suited to ExternalProject. Just give it an empty configure and build steps and then have the install step perform the copy: include(ExternalProject) if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(3rdParty_SUBDIR x64) else() set(3rdParty_SUBDIR x86) endif() ExternalProject_Add( 3rdParty URL URL_MD5 c9294a16b39783cba8c4c55df182b24b BUILD_IN_SOURCE 1 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ${3rdParty_SUBDIR}/ ${CMAKE_INSTALL_PREFIX} ) This created a "3rdParty" target that should do everything you need and only if necessary. - Chuck On Thu, Apr 28, 2016 at 11:19 AM, Lee Butler <iraytrace at> wrote: > I am looking for a better way to do something than having a sequence of > "if (NOT EXISTS)" statements. My package being built depends on some > external libraries and headers, that are available in a zip file on an > external website. So for example: zlib.h,zlib.dll and zlib.lib are (along > with other stuff) in available from a remote URL. I don't > want to build these things, I want to fetch the zip file, unpack it and > copy the relevant portions into place only as needed. >> At the moment I have the code below, which feels "unclean" on so many > levels: >> if (NOT EXISTS "${CMAKE_INSTALL_PREFIX}/include/zlib.h") > if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/3rdParty_x86_x64") > if (NOT EXISTS > "${CMAKE_CURRENT_BINARY_DIR}/3rdParty_VS2013_v120_x86_x64_V9_small.7z") > MESSAGE(STATUS "Downloading 3rdParty") > file(DOWNLOAD >> "${CMAKE_CURRENT_BINARY_DIR}/3rdParty_VS2013_v120_x86_x64_V9_small.7z" > SHOW_PROGRESS) > endif() >> message(STATUS "expanding 3rdParty Archive") > execute_process( COMMAND ${CMAKE_COMMAND} -E tar xzf > "${CMAKE_CURRENT_BINARY_DIR}/3rdParty_VS2013_v120_x86_x64_V9_small.7z" ) > endif() > foreach(dir bin data include lib ssl) > file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/3rdParty_x86_x64/x64/${dir}" > "${CMAKE_INSTALL_PREFIX}/${dir}") > endforeach(dir) > file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/3rdParty_x86_x64") > endif() >> This has the property of fetching the 7z file, extracting the contents and > leaving the 7z file around for later rebuilds. I hope there is a cleaner > way of saying the same thing. BTW, I would be just as happy putting > "products" from the zip file in the current build destinations instead of > the install destinations. > -- >> Powered by >> Please keep messages on-topic and check the CMake FAQ at: >>> Kitware offers various services to support the CMake community. For more > information on each offering, please visit: >> CMake Support:> CMake Consulting:> CMake Training Courses:>> Visit other Kitware open-source projects at >>> Follow this link to subscribe/unsubscribe: >>-------------- next part -------------- An HTML attachment was scrubbed... URL: <>

More information about the CMake mailing list
Источник: []

Cmake download and extract file

2 thoughts to “Cmake download and extract file”

Leave a Reply

Your email address will not be published. Required fields are marked *