
# 
# 用户应用安装
# 
FUNCTION(_dios_builder_module_exe_copy_to_prebuilt)	

	set( CMAKE_INSTALL_PREFIX ${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt CACHE PATH "project install prefix" FORCE )
	_dios_builder_module_exe_copy_to_prebuilt_impl()

ENDFUNCTION()

# 
# 用户库安装
# 
FUNCTION(_dios_builder_module_lib_copy_to_prebuilt)

	set( CMAKE_INSTALL_PREFIX ${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt CACHE PATH "project install prefix" FORCE )
	_dios_builder_module_lib_copy_to_prebuilt_impl()

ENDFUNCTION()

# 
# 拷贝到安装目录
# 
FUNCTION(_dios_builder_module_copy_to_install)

	# 安装bin文件夹和symbols文件夹;
	IF(DIOS_CMAKE_PLATFORM_WIN32 OR DIOS_CMAKE_PLATFORM_WIN64)
		dios_file_mkdir(${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/bin/${DIOS_CMAKE_COMPILER}/debug)
		INSTALL(DIRECTORY ${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/bin/${DIOS_CMAKE_COMPILER}/debug/
			CONFIGURATIONS debug
			DESTINATION ${DIOS_CMAKE_INSTALL_DIRECTORY}/bin/${DIOS_CMAKE_COMPILER}/debug
			PATTERN ".svn" EXCLUDE
			PATTERN "*"
		)
		dios_file_mkdir(${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/bin/${DIOS_CMAKE_COMPILER}/release)
		INSTALL(DIRECTORY ${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/bin/${DIOS_CMAKE_COMPILER}/release/
			CONFIGURATIONS release
			DESTINATION ${DIOS_CMAKE_INSTALL_DIRECTORY}/bin/${DIOS_CMAKE_COMPILER}/release
			PATTERN ".svn" EXCLUDE
			PATTERN "*"
		)
		dios_file_mkdir(${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/symbols/${DIOS_CMAKE_COMPILER}/debug)
		INSTALL(DIRECTORY ${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/symbols/${DIOS_CMAKE_COMPILER}/debug/
			CONFIGURATIONS debug
			DESTINATION ${DIOS_CMAKE_INSTALL_DIRECTORY}/symbols/${DIOS_CMAKE_COMPILER}/debug
			PATTERN ".svn" EXCLUDE
			PATTERN "*"
		)
		dios_file_mkdir(${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/symbols/${DIOS_CMAKE_COMPILER}/release)
		INSTALL(DIRECTORY ${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/symbols/${DIOS_CMAKE_COMPILER}/release/
			CONFIGURATIONS release
			DESTINATION ${DIOS_CMAKE_INSTALL_DIRECTORY}/symbols/${DIOS_CMAKE_COMPILER}/release
			PATTERN ".svn" EXCLUDE
			PATTERN "*"
		)
	ELSEIF(DIOS_CMAKE_PLATFORM_UNIX)	
		# dios_file_mkdir(${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/bin/${DIOS_CMAKE_COMPILER})
		# INSTALL(DIRECTORY ${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/bin/${DIOS_CMAKE_COMPILER}/
		#	CONFIGURATIONS debug
		#	DESTINATION ${DIOS_CMAKE_INSTALL_DIRECTORY}/bin/${DIOS_CMAKE_COMPILER}
		#	PATTERN ".svn" EXCLUDE
		#	PATTERN "*"
		# )
	ELSEIF(DIOS_CMAKE_PLATFORM_IOS OR DIOS_CMAKE_PLATFORM_MAC)	
		dios_file_mkdir(${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/bin/${DIOS_CMAKE_COMPILER}/debug)
		INSTALL(DIRECTORY ${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/bin/${DIOS_CMAKE_COMPILER}/debug/
			CONFIGURATIONS debug
			DESTINATION ${DIOS_CMAKE_INSTALL_DIRECTORY}/bin/${DIOS_CMAKE_COMPILER}/debug
			PATTERN ".svn" EXCLUDE
			PATTERN "*"
		)
		dios_file_mkdir(${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/bin/${DIOS_CMAKE_COMPILER}/release)
		INSTALL(DIRECTORY ${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/prebuilt/bin/${DIOS_CMAKE_COMPILER}/release/
			CONFIGURATIONS release
			DESTINATION ${DIOS_CMAKE_INSTALL_DIRECTORY}/bin/${DIOS_CMAKE_COMPILER}/release
			PATTERN ".svn" EXCLUDE
			PATTERN "*"
		)	
	ENDIF()

ENDFUNCTION()

# 
# 拷贝到prebuilt
# 
FUNCTION(_dios_builder_module_exe_copy_to_prebuilt_impl)	
	IF(DIOS_CMAKE_PLATFORM_WIN32 OR DIOS_CMAKE_PLATFORM_WIN64)	
		# 安装文件到目录
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			CONFIGURATIONS debug
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}/debug
		)	
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			CONFIGURATIONS release
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}/release
		)	

		# 打包符号文件和bin文件;
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			CONFIGURATIONS debug
			RUNTIME DESTINATION symbols/${DIOS_CMAKE_COMPILER}/debug
		)		
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			CONFIGURATIONS release
			RUNTIME DESTINATION symbols/${DIOS_CMAKE_COMPILER}/release
		)

		install(DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/debug/
			CONFIGURATIONS debug
		 	DESTINATION symbols/${DIOS_CMAKE_COMPILER}/debug
		 	FILES_MATCHING PATTERN "*.pdb")

		install(DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/release/
			CONFIGURATIONS release
		 	DESTINATION symbols/${DIOS_CMAKE_COMPILER}/release
		 	FILES_MATCHING PATTERN "*.pdb")

	ELSEIF(DIOS_CMAKE_PLATFORM_UNIX)	
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}
			LIBRARY DESTINATION bin/${DIOS_CMAKE_COMPILER}
			ARCHIVE DESTINATION lib/${DIOS_CMAKE_COMPILER}
		)
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			RUNTIME DESTINATION ${DIOS_CMAKE_INSTALL_DIRECTORY}/bin/${DIOS_CMAKE_COMPILER}
			LIBRARY DESTINATION ${DIOS_CMAKE_INSTALL_DIRECTORY}/bin/${DIOS_CMAKE_COMPILER}
		)		
	ELSEIF(DIOS_CMAKE_PLATFORM_IOS OR DIOS_CMAKE_PLATFORM_MAC)	
		# 安装文件到目录
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			CONFIGURATIONS debug
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}/debug
			BUNDLE DESTINATION bin/${DIOS_CMAKE_COMPILER}/debug
		)	
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			CONFIGURATIONS release
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}/release
			BUNDLE DESTINATION bin/${DIOS_CMAKE_COMPILER}/release
		)
	ELSEIF(DIOS_CMAKE_PLATFORM_ANDROID)	
		# 安装文件到目录
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}
			LIBRARY DESTINATION bin/${DIOS_CMAKE_COMPILER}
			ARCHIVE DESTINATION lib/${DIOS_CMAKE_COMPILER}
		)	
	ENDIF()

	IF(DIOS_CMAKE_PLATFORM_WIN32 OR DIOS_CMAKE_PLATFORM_WIN64)	
		# 方便调试拷贝 DIOS_CMAKE_INSTALL_DIRECTORY_WIN32 的bin内容拷贝到运行目录;
		set(DEPENDENCIES_DLL_FILES ${DIOS_CMAKE_INSTALL_DIRECTORY_WIN32}\\bin\\${DIOS_CMAKE_COMPILER}\\"$(ConfigurationName)"\\*.dll)
		add_custom_command( TARGET ${DIOS_BUILDER_MODULE}
			PRE_LINK 
			COMMAND if exist ${DEPENDENCIES_DLL_FILES} (copy ${DEPENDENCIES_DLL_FILES} output\\"$(ConfigurationName)"\\)
			)
			
		set(DEPENDENCIES_MANIFEST_FILES ${DIOS_CMAKE_INSTALL_DIRECTORY_WIN32}\\bin\\${DIOS_CMAKE_COMPILER}\\"$(ConfigurationName)"\\*.manifest)
		add_custom_command( TARGET ${DIOS_BUILDER_MODULE}
			PRE_LINK 
			COMMAND if exist ${DEPENDENCIES_MANIFEST_FILES} (copy ${DEPENDENCIES_MANIFEST_FILES} output\\"$(ConfigurationName)"\\)
			)
		
		# 方便调试拷贝EXE相关的到 DIOS_CMAKE_INSTALL_DIRECTORY_WIN32
		set(OUTPUT_EXE_FILES output\\"$(ConfigurationName)"\\*.exe)
		add_custom_command(TARGET ${DIOS_BUILDER_MODULE}
			POST_BUILD 
			COMMAND if exist ${OUTPUT_EXE_FILES} (copy ${OUTPUT_EXE_FILES} ${DIOS_CMAKE_INSTALL_DIRECTORY_WIN32}\\bin\\${DIOS_CMAKE_COMPILER}\\"$(ConfigurationName)"\\)
			)
	ENDIF()
ENDFUNCTION()

# 
# 拷贝到prebuilt
# 
FUNCTION(_dios_builder_module_lib_copy_to_prebuilt_impl)
	IF(DIOS_CMAKE_PLATFORM_WIN32 OR DIOS_CMAKE_PLATFORM_WIN64)	
		# 安装文件到目录
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			CONFIGURATIONS debug
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}/debug
			LIBRARY DESTINATION lib/${DIOS_CMAKE_COMPILER}/debug
			ARCHIVE DESTINATION lib/${DIOS_CMAKE_COMPILER}/debug
		)		
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			CONFIGURATIONS release
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}/release
			LIBRARY DESTINATION lib/${DIOS_CMAKE_COMPILER}/release
			ARCHIVE DESTINATION lib/${DIOS_CMAKE_COMPILER}/release
		)		

		# 打包符号文件和bin文件;
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			CONFIGURATIONS debug
			RUNTIME DESTINATION symbols/${DIOS_CMAKE_COMPILER}/debug
			ARCHIVE DESTINATION lib/${DIOS_CMAKE_COMPILER}/debug
		)		
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			CONFIGURATIONS release
			RUNTIME DESTINATION symbols/${DIOS_CMAKE_COMPILER}/release
			ARCHIVE DESTINATION lib/${DIOS_CMAKE_COMPILER}/release
		)

		install(DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/debug/
			CONFIGURATIONS debug
		 	DESTINATION symbols/${DIOS_CMAKE_COMPILER}/debug
		 	FILES_MATCHING PATTERN "*.pdb")

		install(DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/release/
			CONFIGURATIONS release
		 	DESTINATION symbols/${DIOS_CMAKE_COMPILER}/release
		 	FILES_MATCHING PATTERN "*.pdb")

	ELSEIF(DIOS_CMAKE_PLATFORM_UNIX)	
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}
			LIBRARY DESTINATION lib/${DIOS_CMAKE_COMPILER}
			ARCHIVE DESTINATION lib/${DIOS_CMAKE_COMPILER}
		)	
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			RUNTIME DESTINATION ${DIOS_CMAKE_INSTALL_DIRECTORY}/bin/${DIOS_CMAKE_COMPILER}
			LIBRARY DESTINATION ${DIOS_CMAKE_INSTALL_DIRECTORY}/bin/${DIOS_CMAKE_COMPILER}
			ARCHIVE DESTINATION lib/${DIOS_CMAKE_COMPILER}
		)		
	ELSEIF(DIOS_CMAKE_PLATFORM_IOS OR DIOS_CMAKE_PLATFORM_MAC)	
		# 安装文件到目录
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			CONFIGURATIONS debug
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}/debug
			LIBRARY DESTINATION lib/${DIOS_CMAKE_COMPILER}/debug
			ARCHIVE DESTINATION lib/${DIOS_CMAKE_COMPILER}/debug
		)		
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			CONFIGURATIONS release
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}/release
			LIBRARY DESTINATION lib/${DIOS_CMAKE_COMPILER}/release
			ARCHIVE DESTINATION lib/${DIOS_CMAKE_COMPILER}/release
		)	
	ELSEIF(DIOS_CMAKE_PLATFORM_ANDROID)	
		# 安装文件到目录
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}
			LIBRARY DESTINATION bin/${DIOS_CMAKE_COMPILER}
			ARCHIVE DESTINATION lib/${DIOS_CMAKE_COMPILER}
		)	
		INSTALL(TARGETS ${DIOS_BUILDER_MODULE}
			RUNTIME DESTINATION bin/${DIOS_CMAKE_COMPILER}
			LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/src.android/java/libs/${ANDROID_NDK_ABI_NAME}
			ARCHIVE DESTINATION lib/${DIOS_CMAKE_COMPILER}
		)			
	ENDIF()
	
	# 安装头文件	
	dios_file_mkdir(${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/inc)
	INSTALL(DIRECTORY ${DIOS_MODULE_${DIOS_BUILDER_MODULE}_DIRECTORY}/inc/
		DESTINATION inc
		PATTERN ".svn" EXCLUDE
		PATTERN "*" PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
	)

	IF(DIOS_CMAKE_PLATFORM_WIN32 OR DIOS_CMAKE_PLATFORM_WIN64)		
		add_custom_command(TARGET ${DIOS_BUILDER_MODULE}
			POST_BUILD 
			COMMAND echo %cd%
			)
		# 方便调试拷贝DLL相关的到 DIOS_CMAKE_INSTALL_DIRECTORY_WIN32
		set(OUTPUT_DLL_FILES output\\"$(ConfigurationName)"\\*.dll)
		add_custom_command(TARGET ${DIOS_BUILDER_MODULE}
			POST_BUILD 
			COMMAND if exist ${OUTPUT_DLL_FILES} (copy ${OUTPUT_DLL_FILES} ${DIOS_CMAKE_INSTALL_DIRECTORY_WIN32}\\bin\\${DIOS_CMAKE_COMPILER}\\"$(ConfigurationName)"\\)
			)
	ENDIF()
ENDFUNCTION()

