project (Chat C CXX)

cmake_minimum_required(VERSION 2.8)

if(WIN32)
	file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} SOURCE_DIR)
	file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR} BINARY_DIR)
	add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/chat.exe
		COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build.bat
		MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/chat.cpp
		DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/MainFormUnit.cpp
			${CMAKE_CURRENT_SOURCE_DIR}/MainFormUnit.dfm
			${CMAKE_CURRENT_SOURCE_DIR}/MainFormUnit.h
			${CMAKE_CURRENT_SOURCE_DIR}/chat.bpr
			${CMAKE_CURRENT_SOURCE_DIR}/chat.res
		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
	)
	add_custom_target(chat ALL
		COMMAND copy \"${SOURCE_DIR}\\chat.exe\" \"${BINARY_DIR}\\\"
		DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/chat.exe
		SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/chat.cpp
			${CMAKE_CURRENT_SOURCE_DIR}/MainFormUnit.cpp
			${CMAKE_CURRENT_SOURCE_DIR}/MainFormUnit.dfm
			${CMAKE_CURRENT_SOURCE_DIR}/MainFormUnit.h
			${CMAKE_CURRENT_SOURCE_DIR}/chat.bpr
			${CMAKE_CURRENT_SOURCE_DIR}/chat.res
	)

	install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/chat.exe DESTINATION bin)
endif()
