Add python3-setuptools dependency for python 3.12
[platform/upstream/opencv.git] / cmake / copy_files.cmake
1 include("${CONFIG_FILE}")
2 set(prefix "COPYFILES: ")
3
4 set(use_symlink 0)
5 if(IS_SYMLINK "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/symlink_test")
6   set(use_symlink 1)
7 endif()
8
9 set(update_dephelper 0)
10 if(DEFINED DEPHELPER AND NOT EXISTS "${DEPHELPER}")
11   set(update_dephelper 1)
12 endif()
13
14 set(__state "")
15
16 macro(copy_file_ src dst prefix)
17   string(REPLACE "${CMAKE_BINARY_DIR}/" "" dst_name "${dst}")
18   set(local_update 0)
19   if(NOT EXISTS "${dst}")
20     set(local_update 1)
21   endif()
22   if(use_symlink)
23     if(local_update OR NOT IS_SYMLINK "${dst}")
24       message("${prefix}Symlink: '${dst_name}' ...")
25     endif()
26     get_filename_component(target_path "${dst}" PATH)
27     file(MAKE_DIRECTORY "${target_path}")
28     execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${src}" "${dst}"
29         RESULT_VARIABLE SYMLINK_RESULT)
30     if(NOT SYMLINK_RESULT EQUAL 0)
31       #message("Symlink failed, fallback to 'copy'")
32       set(use_symlink 0)
33     endif()
34   endif()
35   if(NOT use_symlink)
36     if("${src}" IS_NEWER_THAN "${dst}" OR IS_SYMLINK "${dst}")
37       file(REMOVE "${dst}") # configure_file(COPYONLY) doesn't update timestamp sometimes
38       set(local_update 1)
39     endif()
40     if(local_update)
41       message("${prefix}Copying: '${dst_name}' ...")
42       configure_file(${src} ${dst} COPYONLY)
43     else()
44       #message("${prefix}Up-to-date: '${dst_name}'")
45     endif()
46   endif()
47   if(local_update)
48     set(update_dephelper 1)
49   endif()
50   file(TIMESTAMP "${dst}" dst_t UTC)
51   set(__state "${__state}${dst_t} ${dst}\n")
52 endmacro()
53
54 if(NOT DEFINED COPYLIST_VAR)
55   set(COPYLIST_VAR "COPYLIST")
56 endif()
57 list(LENGTH ${COPYLIST_VAR} __length)
58 message("${prefix}... ${__length} entries (${COPYLIST_VAR})")
59 foreach(id ${${COPYLIST_VAR}})
60   set(src "${${COPYLIST_VAR}_SRC_${id}}")
61   set(dst "${${COPYLIST_VAR}_DST_${id}}")
62   if(NOT EXISTS ${src})
63     message(FATAL_ERROR "Source file/dir is missing: ${src} (${CONFIG_FILE})")
64   endif()
65   set(_mode "COPYFILE")
66   if(DEFINED ${COPYLIST_VAR}_MODE_${id})
67     set(_mode "${${COPYLIST_VAR}_MODE_${id}}")
68   endif()
69   if(_mode STREQUAL "COPYFILE")
70     #message("... COPY ${src} => ${dst}")
71     copy_file_("${src}" "${dst}" "${prefix}    ")
72   elseif(_mode STREQUAL "COPYDIR")
73     get_filename_component(src_name "${src}" NAME)
74     get_filename_component(src_path "${src}" PATH)
75     get_filename_component(src_name2 "${src_path}" NAME)
76
77     set(src_glob "${src}/*")
78     if(DEFINED ${COPYLIST_VAR}_GLOB_${id})
79       set(src_glob "${${COPYLIST_VAR}_GLOB_${id}}")
80     endif()
81     file(GLOB_RECURSE _files RELATIVE "${src}" ${src_glob})
82     list(LENGTH _files __length)
83     message("${prefix}    ... directory '.../${src_name2}/${src_name}' with ${__length} files")
84     foreach(f ${_files})
85       if(NOT EXISTS "${src}/${f}")
86         message(FATAL_ERROR "COPY ERROR: Source file is missing: ${src}/${f}")
87       endif()
88       copy_file_("${src}/${f}" "${dst}/${f}" "${prefix}        ")
89     endforeach()
90   endif()
91 endforeach()
92
93 set(STATE_FILE "${CONFIG_FILE}.state")
94 if(EXISTS "${STATE_FILE}")
95   file(READ "${STATE_FILE}" __prev_state)
96 else()
97   set(__prev_state "")
98 endif()
99 if(NOT "${__state}" STREQUAL "${__prev_state}")
100   file(WRITE "${STATE_FILE}" "${__state}")
101   message("${prefix}Updated!")
102   set(update_dephelper 1)
103 endif()
104
105 if(NOT update_dephelper)
106   message("${prefix}All files are up-to-date.")
107 elseif(DEFINED DEPHELPER)
108   file(WRITE "${DEPHELPER}" "")
109 endif()