-
Notifications
You must be signed in to change notification settings - Fork 84
/
common.cmake
59 lines (54 loc) · 2.33 KB
/
common.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#
# Copies a set of files to a directory (only if they already don't exist or are different)
# Usage example:
# set(media_src ${CMAKE_CURRENT_SOURCE_DIR}/../../media/brdfLut.dds )
# copyCommand("${media_src}" ${CMAKE_HOME_DIRECTORY}/bin)
#
# Sometimes a proper dependency between target and copied files cannot be created
# and you should try copyTargetCommand() below instead
#
function(copyCommand list dest)
foreach(fullFileName ${list})
get_filename_component(file ${fullFileName} NAME)
message("Generating custom command for ${fullFileName}")
add_custom_command(
OUTPUT ${dest}/${file}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${dest}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${fullFileName} ${dest}
MAIN_DEPENDENCY ${fullFileName}
COMMENT "Updating ${file} into ${dest}"
)
list(APPEND dest_files ${dest}/${file})
endforeach()
#return output file list
set(copyCommand_dest_files ${dest_files} PARENT_SCOPE)
endfunction()
#
# Same as copyCommand() but you can give a target name
# This custom target will depend on all those copied files
# Then the target can be properly set as a dependency of other executable or library
# Usage example:
# add_library(my_lib ...)
# set(media_src ${CMAKE_CURRENT_SOURCE_DIR}/../../media/brdfLut.dds )
# copyTargetCommand("${media_src}" ${CMAKE_HOME_DIRECTORY}/bin copied_media_src)
# add_dependencies(my_lib copied_media_src)
#
function(copyTargetCommand list dest returned_target_name)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
foreach(fullFileName ${list})
get_filename_component(file ${fullFileName} NAME)
message("Generating custom command for ${fullFileName}")
add_custom_command(
OUTPUT ${dest}/${file}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${dest}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${fullFileName} ${dest}
MAIN_DEPENDENCY ${fullFileName}
COMMENT "Updating ${file} into ${dest}"
)
list(APPEND dest_list ${dest}/${file})
endforeach()
add_custom_target(${returned_target_name} DEPENDS "${dest_list}")
set_target_properties(${returned_target_name} PROPERTIES FOLDER CopyTargets)
endfunction()