-
Notifications
You must be signed in to change notification settings - Fork 213
/
FileCopyTargets.cmake
106 lines (94 loc) · 2.98 KB
/
FileCopyTargets.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# - Add a target for files that just need to be copied
#
# include(FileCopyTargets)
# add_file_copy_target(<target_name> <directory to copy to> <filename> [<filename>...])
# Creates a custom target that copies the files to a directory, if needed.
# Relative paths for the destination directory are considered with
# with respect to CMAKE_CURRENT_BINARY_DIR
# You can use this target in all the usual ways, including
# add_dependencies(some_other_target this_target) to specify that another
# target depends on this.
#
# install_file_copy_target(<target_name> [arguments to INSTALL(PROGRAMS ...) ])
# Works just the same as INSTALL(PROGRAMS ...) because it wraps it to install
# the files you specified in add_file_copy_target
#
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Rylie Pavlik <[email protected]>
# https://ryliepavlik.com/
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright 2009-2010, Iowa State University
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# SPDX-License-Identifier: BSL-1.0
if(__add_file_copy_target)
return()
endif()
set(__add_file_copy_target YES)
define_property(TARGET
PROPERTY
FILE_COPY_TARGET
BRIEF_DOCS
"File Copy target"
FULL_DOCS
"Is this a target created by add_file_copy_target?")
function(add_file_copy_target _target _dest)
if(NOT ARGN)
message(WARNING
"In add_file_copy_target call for target ${_target}, no source files were specified!")
return()
endif()
set(ALLFILES)
set(SOURCES)
foreach(fn ${ARGN})
# Produce an absolute path to the input file
if(IS_ABSOLUTE "${fn}")
get_filename_component(fullpath "${fn}" ABSOLUTE)
get_filename_component(fn "${fn}" NAME)
else()
get_filename_component(fullpath
"${CMAKE_CURRENT_SOURCE_DIR}/${fn}"
ABSOLUTE)
endif()
# Clean up output file name
get_filename_component(absout "${_dest}/${fn}" ABSOLUTE)
add_custom_command(OUTPUT "${absout}"
COMMAND
${CMAKE_COMMAND}
ARGS -E make_directory "${_dest}"
COMMAND
${CMAKE_COMMAND}
ARGS -E copy "${fullpath}" "${_dest}"
MAIN_DEPENDENCY "${fullpath}"
VERBATIM
COMMENT "Copying ${fn} to ${absout}")
list(APPEND SOURCES "${fullpath}")
list(APPEND ALLFILES "${absout}")
endforeach()
# Custom target depending on all the file copy commands
add_custom_target(${_target}
SOURCES ${SOURCES}
DEPENDS ${ALLFILES})
set_property(TARGET ${_target} PROPERTY FILE_COPY_TARGET YES)
endfunction()
function(install_file_copy_target _target)
get_target_property(_isFCT ${_target} FILE_COPY_TARGET)
if(NOT _isFCT)
message(WARNING
"install_file_copy_target called on a target not created with add_file_copy_target!")
return()
endif()
# Get sources
get_target_property(_srcs ${_target} SOURCES)
# Remove the "fake" file forcing build
list(REMOVE_AT _srcs 0)
# Forward the call to install
install(PROGRAMS ${_srcs} ${ARGN})
endfunction()