mirror of
https://github.com/Rogiel/CMakeDependency
synced 2025-12-06 05:22:48 +00:00
Initial commit
This commit is contained in:
94
DependencyDeclaration.cmake.in
Normal file
94
DependencyDeclaration.cmake.in
Normal file
@@ -0,0 +1,94 @@
|
||||
set(@DEPENDENCY_NAME@_URL
|
||||
"@DEPENDENCY_URL@"
|
||||
CACHE STRING "A path that points to a @DEPENDENCY_NAME@ URL to be downloaded. CMake will use this URL to download the file if needed.")
|
||||
set(@DEPENDENCY_NAME@_DIR
|
||||
${CMDEP_ROOT_DIR}/@DEPENDENCY_NAME@
|
||||
CACHE PATH "A path that points to a @DEPENDENCY_NAME@ directory containing it's sources.")
|
||||
set(@DEPENDENCY_NAME@_LOCK ${CMDEP_ROOT_DIR})
|
||||
|
||||
set(@DEPENDENCY_NAME@_SOURCE_DIR
|
||||
${@DEPENDENCY_NAME@_DIR}
|
||||
CACHE PATH "A path that points to a @DEPENDENCY_NAME@ source directory. If manually set, no downloading or extraction will take place and this will be used instead.")
|
||||
set(@DEPENDENCY_NAME@_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/@DEPENDENCY_NAME@)
|
||||
|
||||
get_filename_component(@DEPENDENCY_NAME@_DOWNLOAD_NAME "${@DEPENDENCY_NAME@_URL}" NAME CACHE)
|
||||
set(@DEPENDENCY_NAME@_ZIP
|
||||
${CMDEP_ZIP_DIR}/${@DEPENDENCY_NAME@_DOWNLOAD_NAME}
|
||||
CACHE PATH "A path that points to a @DEPENDENCY_NAME@ zip file. If this file does not exists, it will be downloaded.")
|
||||
|
||||
# To prevent other concurrent CMake instances from trying to download or extract
|
||||
# the file, we lock the source directory. This will guarantee that only a single
|
||||
# CMake instance downloads or extracts a file.
|
||||
#
|
||||
file(LOCK ${@DEPENDENCY_NAME@_LOCK} DIRECTORY GUARD FILE)
|
||||
|
||||
if(NOT EXISTS ${@DEPENDENCY_NAME@_SOURCE_DIR})
|
||||
if(NOT EXISTS ${@DEPENDENCY_NAME@_ZIP})
|
||||
get_filename_component(@DEPENDENCY_NAME@_ZIP_DIRECTORY "${@DEPENDENCY_NAME@_ZIP}" DIRECTORY)
|
||||
|
||||
if(NOT EXISTS ${@DEPENDENCY_NAME@_ZIP_DIRECTORY})
|
||||
file(MAKE_DIRECTORY ${@DEPENDENCY_NAME@_ZIP_DIRECTORY})
|
||||
endif()
|
||||
|
||||
message(STATUS "@DEPENDENCY_NAME@: Downloading from ${@DEPENDENCY_NAME@_URL}")
|
||||
|
||||
file(DOWNLOAD ${@DEPENDENCY_NAME@_URL}
|
||||
${@DEPENDENCY_NAME@_ZIP}
|
||||
SHOW_PROGRESS
|
||||
# no TIMEOUT
|
||||
STATUS status
|
||||
LOG log)
|
||||
|
||||
list(GET status 0 status_code)
|
||||
list(GET status 1 status_string)
|
||||
|
||||
if(status_code EQUAL 0)
|
||||
message(STATUS "@DEPENDENCY_NAME@: Download complete")
|
||||
else()
|
||||
message(FATAL_ERROR "@DEPENDENCY_NAME@: error: downloading from '${@DEPENDENCY_NAME@_URL}' failed with error code ${status_code} (${status_string}) -- ${log}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Prepare a space for extracting:
|
||||
#
|
||||
set(tmp_dir "${CMAKE_CURRENT_BINARY_DIR}/@DEPENDENCY_NAME@-tmp")
|
||||
file(MAKE_DIRECTORY "${tmp_dir}")
|
||||
|
||||
# Extract it:
|
||||
#
|
||||
message(STATUS "@DEPENDENCY_NAME@: extracting...")
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz ${@DEPENDENCY_NAME@_ZIP}
|
||||
WORKING_DIRECTORY ${tmp_dir}
|
||||
RESULT_VARIABLE rv)
|
||||
if(NOT rv EQUAL 0)
|
||||
message(STATUS "@DEPENDENCY_NAME@: extracting... [error clean up]")
|
||||
file(REMOVE_RECURSE "${tmp_dir}")
|
||||
message(FATAL_ERROR "@DEPENDENCY_NAME@: error: extract of '${@DEPENDENCY_NAME@_DOWNLOAD_NAME}' failed")
|
||||
endif()
|
||||
|
||||
# Analyze what came out of the tar file:
|
||||
#
|
||||
message(STATUS "@DEPENDENCY_NAME@: extracting... [analysis]")
|
||||
file(GLOB contents "${tmp_dir}/*")
|
||||
list(REMOVE_ITEM contents "${tmp_dir}/.DS_Store")
|
||||
list(LENGTH contents n)
|
||||
if(NOT n EQUAL 1 OR NOT IS_DIRECTORY "${contents}")
|
||||
set(contents "${tmp_dir}")
|
||||
endif()
|
||||
|
||||
# Move "the one" directory to the final directory:
|
||||
#
|
||||
message(STATUS "@DEPENDENCY_NAME@: extracting... [rename]")
|
||||
file(REMOVE_RECURSE ${@DEPENDENCY_NAME@_DIR})
|
||||
get_filename_component(contents ${contents} ABSOLUTE)
|
||||
file(RENAME ${contents} ${@DEPENDENCY_NAME@_DIR})
|
||||
|
||||
# Clean up:
|
||||
#
|
||||
message(STATUS "@DEPENDENCY_NAME@: extracting... [clean up]")
|
||||
file(REMOVE_RECURSE "${tmp_dir}")
|
||||
endif()
|
||||
|
||||
# We are now done. We can unlock the CMake directory and proceed.
|
||||
#
|
||||
file(LOCK ${@DEPENDENCY_NAME@_LOCK} DIRECTORY RELEASE)
|
||||
Reference in New Issue
Block a user