function(ExternalSource_Download PREFIX URL)
+ nnfw_include(StampTools)
+
get_filename_component(FILENAME ${URL} NAME)
set(CACHE_DIR "${NNFW_EXTERNALS_DIR}")
file(MAKE_DIRECTORY "${CACHE_DIR}")
endif(NOT EXISTS "${CACHE_DIR}")
+ # Compare URL in STAMP file and the given URL
+ Stamp_Check(URL_CHECK "${STAMP_PATH}" "${URL}")
+
# TODO Check MD5 for correctness
- set(MATCH_URL FALSE)
- if(EXISTS "${STAMP_PATH}")
- file(READ "${STAMP_PATH}" SAVED_URL)
- if("${SAVED_URL}" STREQUAL "${URL}")
- set(MATCH_URL TRUE)
- endif("${SAVED_URL}" STREQUAL "${URL}")
- endif(EXISTS "${STAMP_PATH}")
-
- if(NOT EXISTS "${STAMP_PATH}" OR NOT EXISTS "${OUT_DIR}" OR NOT MATCH_URL)
+
+ if(NOT EXISTS "${OUT_DIR}" OR NOT URL_CHECK)
file(REMOVE_RECURSE "${OUT_DIR}")
file(REMOVE_RECURSE "${TMP_DIR}")
endfunction(ExternalSource_Download)
function(ExternalSource_Get PREFIX DOWNLOAD_FLAG URL)
+ nnfw_include(StampTools)
+
set(CACHE_DIR "${NNFW_EXTERNALS_DIR}")
set(OUT_DIR "${CACHE_DIR}/${PREFIX}")
set(STAMP_PATH "${CACHE_DIR}/${PREFIX}.stamp")
file(MAKE_DIRECTORY "${CACHE_DIR}")
endif(NOT EXISTS "${CACHE_DIR}")
+ # Compare URL in STAMP file and the given URL
+ Stamp_Check(URL_CHECK "${STAMP_PATH}" "${URL}")
+
# TODO Check MD5 for correctness
- set(MATCH_URL FALSE)
- if(EXISTS "${STAMP_PATH}")
- file(READ "${STAMP_PATH}" SAVED_URL)
- if("${SAVED_URL}" STREQUAL "${URL}")
- set(MATCH_URL TRUE)
- endif("${SAVED_URL}" STREQUAL "${URL}")
- endif(EXISTS "${STAMP_PATH}")
set(SOURCE_GET TRUE)
- if(NOT EXISTS "${STAMP_PATH}" OR NOT EXISTS "${OUT_DIR}" OR NOT MATCH_URL)
+ if(NOT EXISTS "${OUT_DIR}" OR NOT URL_CHECK)
if(NOT DOWNLOAD_FLAG)
set(SOURCE_GET FALSE)
else(NOT DOWNLOAD_FLAG)
--- /dev/null
+# Stamp_Check(VARNAME PATH CONTENT)
+# Stamp_Check sets VARNAME as TRUE if a file exists at "PATH", and its content is same as "CONTENT"
+# Stamp_Check sets VARNAME as FALSE otherwise
+function(Stamp_Check VARNAME PATH EXPECTED_CONTENT)
+ if(NOT EXISTS "${PATH}")
+ set(${VARNAME} FALSE PARENT_SCOPE)
+ return()
+ endif(NOT EXISTS "${PATH}")
+
+ file(READ ${PATH} OBTAINED_CONTENT)
+
+ if(NOT EXPECTED_CONTENT STREQUAL OBTAINED_CONTENT)
+ set(${VARNAME} FALSE PARENT_SCOPE)
+ return()
+ endif(NOT EXPECTED_CONTENT STREQUAL OBTAINED_CONTENT)
+
+ set(${VARNAME} TRUE PARENT_SCOPE)
+endfunction(Stamp_Check)