11include (CMakeParseArguments)
22
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 )
55 set (oneValueArgs COPY_TO)
66 set (multiValueArgs FILES FOLDERS)
77 cmake_parse_arguments (opt "" "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
88 # copy files
99 foreach (cc_file ${opt_FILES} )
1010 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+ )
1215 endforeach ()
1316 # copy folders files
1417 foreach (cc_folder ${opt_FOLDERS} )
@@ -17,7 +20,10 @@ function(cocos_copy_res)
1720 foreach (res_file ${folder_files} )
1821 get_filename_component (res_file_abs_path ${res_file} ABSOLUTE )
1922 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+ )
2127 endforeach ()
2228 endforeach ()
2329endfunction ()
@@ -79,8 +85,9 @@ function(get_target_depends_ext_dlls cocos_target all_depend_dlls_out)
7985 search_depend_libs_recursive(${cocos_target} depend_libs)
8086 foreach (depend_lib ${depend_libs} )
8187 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 )
8491 list (APPEND all_depend_ext_dlls ${tmp_dlls} )
8592 endif ()
8693 endif ()
@@ -89,20 +96,19 @@ function(get_target_depends_ext_dlls cocos_target all_depend_dlls_out)
8996 set (${all_depend_dlls_out} ${all_depend_ext_dlls} PARENT_SCOPE)
9097endfunction ()
9198
92- # copy the `cocos_target` needed dlls into `COPY_TO` folder
99+ # copy the `cocos_target` needed dlls into TARGET_FILE_DIR
93100function (cocos_copy_target_dll cocos_target)
94- set (oneValueArgs COPY_TO)
95- cmake_parse_arguments (opt "" "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
96101 get_target_depends_ext_dlls(${cocos_target} all_depend_dlls)
97102 # remove repeat items
98103 if (all_depend_dlls)
99104 list (REMOVE_DUPLICATES all_depend_dlls)
100105 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} " )
103106 foreach (cc_dll_file ${all_depend_dlls} )
104107 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+ )
106112 endforeach ()
107113endfunction ()
108114
@@ -168,31 +174,21 @@ function(source_group_single_file single_file)
168174 source_group ("${ide_file_group} " FILES ${single_file} )
169175endfunction ()
170176
171- # setup a cocos application, include "APP_BIN_DIR", "APP_RES_DIR" config
177+ # setup a cocos application
172178function (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} " )
174181 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)
178184 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" )
187187 endif ()
188- set_target_properties (${app_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR} " )
189-
190188 # auto mark code files for IDE when mark app
191189 if (XCODE OR VS)
192- cocos_mark_code_files(${APP_NAME } )
190+ cocos_mark_code_files(${app_name } )
193191 endif ()
194-
195- set (APP_RES_DIR ${APP_RES_DIR} PARENT_SCOPE)
196192endfunction ()
197193
198194# if cc_variable not set, then set it cc_value
0 commit comments