1
1
include (CMakeParseArguments )
2
2
3
- # copy resource `FILES` and `FOLDERS` to `COPY_TO` folder
4
- function (cocos_copy_res )
3
+ # copy resource `FILES` and `FOLDERS` to TARGET_FILE_DIR/Resources
4
+ function (cocos_copy_target_res cocos_target )
5
5
set (oneValueArgs COPY_TO )
6
6
set (multiValueArgs FILES FOLDERS )
7
7
cmake_parse_arguments (opt "" "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
8
8
# copy files
9
9
foreach (cc_file ${opt_FILES} )
10
10
get_filename_component (file_name ${cc_file} NAME )
11
- configure_file (${cc_file} "${opt_COPY_TO} /${file_name} " COPYONLY )
11
+ add_custom_command (TARGET ${cocos_target} POST_BUILD
12
+ COMMAND ${CMAKE_COMMAND} -E echo "copy file into Resources: ${file_name} ..."
13
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cc_file} "${opt_COPY_TO} /${file_name} "
14
+ )
12
15
endforeach ()
13
16
# copy folders files
14
17
foreach (cc_folder ${opt_FOLDERS} )
@@ -17,7 +20,10 @@ function(cocos_copy_res)
17
20
foreach (res_file ${folder_files} )
18
21
get_filename_component (res_file_abs_path ${res_file} ABSOLUTE )
19
22
file (RELATIVE_PATH res_file_relat_path ${folder_abs_path} ${res_file_abs_path} )
20
- configure_file (${res_file} "${opt_COPY_TO} /${res_file_relat_path} " COPYONLY )
23
+ add_custom_command (TARGET ${cocos_target} POST_BUILD
24
+ COMMAND ${CMAKE_COMMAND} -E echo "copy file into Resources: ${res_file_relat_path} ..."
25
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${res_file} "${opt_COPY_TO} /${res_file_relat_path} "
26
+ )
21
27
endforeach ()
22
28
endforeach ()
23
29
endfunction ()
@@ -79,8 +85,9 @@ function(get_target_depends_ext_dlls cocos_target all_depend_dlls_out)
79
85
search_depend_libs_recursive (${cocos_target} depend_libs )
80
86
foreach (depend_lib ${depend_libs} )
81
87
if (TARGET ${depend_lib} )
82
- get_target_property (tmp_dlls ${depend_lib} CC_DEPEND_DLLS )
83
- if (tmp_dlls )
88
+ get_target_property (found_shared_lib ${depend_lib} IMPORTED_IMPLIB )
89
+ if (found_shared_lib )
90
+ get_target_property (tmp_dlls ${depend_lib} IMPORTED_LOCATION )
84
91
list (APPEND all_depend_ext_dlls ${tmp_dlls} )
85
92
endif ()
86
93
endif ()
@@ -89,20 +96,19 @@ function(get_target_depends_ext_dlls cocos_target all_depend_dlls_out)
89
96
set (${all_depend_dlls_out} ${all_depend_ext_dlls} PARENT_SCOPE )
90
97
endfunction ()
91
98
92
- # copy the `cocos_target` needed dlls into `COPY_TO` folder
99
+ # copy the `cocos_target` needed dlls into TARGET_FILE_DIR
93
100
function (cocos_copy_target_dll cocos_target )
94
- set (oneValueArgs COPY_TO )
95
- cmake_parse_arguments (opt "" "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
96
101
get_target_depends_ext_dlls (${cocos_target} all_depend_dlls )
97
102
# remove repeat items
98
103
if (all_depend_dlls )
99
104
list (REMOVE_DUPLICATES all_depend_dlls )
100
105
endif ()
101
- # todo, add a option to enable/disable debug print
102
- message (STATUS "prepare to copy external dlls for ${cocos_target} :${all_depend_dlls} " )
103
106
foreach (cc_dll_file ${all_depend_dlls} )
104
107
get_filename_component (cc_dll_name ${cc_dll_file} NAME )
105
- configure_file (${cc_dll_file} "${opt_COPY_TO} /${cc_dll_name} " COPYONLY )
108
+ add_custom_command (TARGET ${cocos_target} POST_BUILD
109
+ COMMAND ${CMAKE_COMMAND} -E echo "copy dll into target file dir: ${cc_dll_name} ..."
110
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cc_dll_file} "$<TARGET_FILE_DIR:${cocos_target} >/${cc_dll_name} "
111
+ )
106
112
endforeach ()
107
113
endfunction ()
108
114
@@ -168,31 +174,21 @@ function(source_group_single_file single_file)
168
174
source_group ("${ide_file_group} " FILES ${single_file} )
169
175
endfunction ()
170
176
171
- # setup a cocos application, include "APP_BIN_DIR", "APP_RES_DIR" config
177
+ # setup a cocos application
172
178
function (setup_cocos_app_config app_name )
173
- # set target PROPERTIES, depend different platforms
179
+ # put all output app into bin/${app_name}
180
+ set_target_properties (${app_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /bin/${app_name} " )
174
181
if (APPLE )
175
- set (APP_BIN_DIR "${CMAKE_BINARY_DIR} /bin" )
176
- set_target_properties (${app_name} PROPERTIES MACOSX_BUNDLE 1
177
- )
182
+ # output macOS/iOS .app
183
+ set_target_properties (${app_name} PROPERTIES MACOSX_BUNDLE 1 )
178
184
elseif (MSVC )
179
- # only Debug and Release mode was supported when using MSVC.
180
- set (APP_BIN_DIR "${CMAKE_BINARY_DIR} /bin/${APP_NAME} /$<CONFIG>" )
181
- set (APP_RES_DIR "${CMAKE_BINARY_DIR} /bin/${APP_NAME} /${CMAKE_BUILD_TYPE} /Resources" )
182
- #Visual Studio Defaults to wrong type
183
- set_target_properties (${app_name} PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS" )
184
- else (LINUX )
185
- set (APP_BIN_DIR "${CMAKE_BINARY_DIR} /bin/${CMAKE_BUILD_TYPE} /${APP_NAME} " )
186
- set (APP_RES_DIR "${APP_BIN_DIR} /Resources" )
185
+ # visual studio default is Console app, but we need Windows app
186
+ set_property (TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "/SUBSYSTEM:WINDOWS" )
187
187
endif ()
188
- set_target_properties (${app_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR} " )
189
-
190
188
# auto mark code files for IDE when mark app
191
189
if (XCODE OR VS )
192
- cocos_mark_code_files (${APP_NAME } )
190
+ cocos_mark_code_files (${app_name } )
193
191
endif ()
194
-
195
- set (APP_RES_DIR ${APP_RES_DIR} PARENT_SCOPE )
196
192
endfunction ()
197
193
198
194
# if cc_variable not set, then set it cc_value
0 commit comments