macro (vrut_module_base NAME SOURCES INCLUDE_DIRECTORIES LINK_LIBRARIES)
	if (wxWidgets_DEFINITIONS MATCHES ".*WXUSINGDLL.*")
		add_definitions(-DWXUSINGDLL)
	endif (wxWidgets_DEFINITIONS MATCHES ".*WXUSINGDLL.*")

	if (VRUT_SHARED)
		add_library(${NAME} SHARED ${SOURCES})
		add_dependencies(${NAME} ${VRUT_LIBRARY})
	else (VRUT_SHARED)
		add_library(${NAME} STATIC ${SOURCES})
		list (APPEND vrut_modules_libs ${NAME})
		set (vrut_modules_libs "${vrut_modules_libs}" PARENT_SCOPE)
		string(TOUPPER ${NAME} CAPS_NAME)
		list (APPEND vrut_modules_defines "-D${CAPS_NAME}_INTERNAL")
		set (vrut_modules_defines "${vrut_modules_defines}" PARENT_SCOPE)
		add_definitions(-DBASE_MODULES_INTERNAL)
	endif (VRUT_SHARED)

	if (UNIX)
		set_target_properties(${NAME} PROPERTIES PREFIX "")
	endif(UNIX)
	
	# AM: this definition not works for VRUT_SHARED, I not understand why...
	include_directories (
		${VRUT_CORE_DIR}
		${INCLUDE_DIRECTORIES}
	)
	
	if (VRUT_SHARED)
		target_link_libraries (${NAME}
			${wxWidgets_LIBRARIES}
			${LINK_LIBRARIES}
			debug ${VRUT_LIBRARY_DEBUG}
			optimized ${VRUT_LIBRARY_RELEASE}
		)
	else (VRUT_SHARED)
		target_link_libraries (${NAME} ${LINK_LIBRARIES})
	endif (VRUT_SHARED)
	
	set_target_properties(${NAME} PROPERTIES
		OUTPUT_NAME ${NAME}_d 
		DEBUG_OUTPUT_NAME ${NAME}_d 
		RELEASE_OUTPUT_NAME ${NAME}
		RELWITHDEBINFO_OUTPUT_NAME ${NAME}
		RUNTIME_OUTPUT_DIRECTORY ${VRUT_MODULES_DIR}
		RUNTIME_OUTPUT_DIRECTORY_DEBUG ${VRUT_MODULES_DIR}
		RUNTIME_OUTPUT_DIRECTORY_RELEASE ${VRUT_MODULES_DIR}
		RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${VRUT_MODULES_DIR}
	)
	
	if (NOT VRUT_SHARED)
		set_target_properties(${NAME} PROPERTIES COMPILE_FLAGS "-DVRUT_CORE_STATIC")
	endif (NOT VRUT_SHARED)
	
	if (WIN32)
		set_target_properties(${NAME} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMTD /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:LIBC")
	endif (WIN32)
endmacro (vrut_module_base)

macro (optional_module NAME CATHEGORY)
	string(TOUPPER ${NAME} CAPS_NAME)
	set(FULLQUALIF "VRUT_${CATHEGORY}_${CAPS_NAME}")
	option(${FULLQUALIF} "Build ${NAME} module" OFF)
endmacro (optional_module)

macro (vrut_render_module NAME SOURCES INCLUDE_DIRECTORIES LINK_LIBRARIES)

	optional_module(${NAME} "MODULE_RENDER")
	
	if(${FULLQUALIF})
		
		vrut_module_base(${NAME} "${SOURCES}" "${INCLUDE_DIRECTORIES}" "${LINK_LIBRARIES}")

		set_target_properties(${NAME} PROPERTIES 
			RUNTIME_OUTPUT_DIRECTORY ${VRUT_RENDER_MODULES_DIR}
			RUNTIME_OUTPUT_DIRECTORY_RELEASE ${VRUT_RENDER_MODULES_DIR}
			RUNTIME_OUTPUT_DIRECTORY_DEBUG ${VRUT_RENDER_MODULES_DIR}
			RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${VRUT_RENDER_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY ${VRUT_RENDER_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY_RELEASE ${VRUT_RENDER_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY_DEBUG ${VRUT_RENDER_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${VRUT_RENDER_MODULES_DIR}
			FOLDER "RenderModules"
		)
		
	endif(${FULLQUALIF})
	
endmacro(vrut_render_module)

macro (vrut_io_module NAME SOURCES INCLUDE_DIRECTORIES LINK_LIBRARIES)

	optional_module(${NAME} "MODULE_IO")
	
	if(${FULLQUALIF})
		vrut_module_base(${NAME} "${SOURCES}" "${INCLUDE_DIRECTORIES}" "${LINK_LIBRARIES}")
		set_target_properties(${NAME} PROPERTIES 
			RUNTIME_OUTPUT_DIRECTORY ${VRUT_IO_MODULES_DIR}
			RUNTIME_OUTPUT_DIRECTORY_RELEASE ${VRUT_IO_MODULES_DIR}
			RUNTIME_OUTPUT_DIRECTORY_DEBUG ${VRUT_IO_MODULES_DIR}
			RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${VRUT_IO_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY ${VRUT_IO_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY_RELEASE ${VRUT_IO_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY_DEBUG ${VRUT_IO_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${VRUT_IO_MODULES_DIR}
			FOLDER "IOModules"
		)
	endif(${FULLQUALIF})
	
endmacro(vrut_io_module)

macro (vrut_manip_module NAME SOURCES INCLUDE_DIRECTORIES LINK_LIBRARIES)

	optional_module(${NAME} "MODULE_MANIP")
	
	if(${FULLQUALIF})
		
		vrut_module_base(${NAME} "${SOURCES}" "${INCLUDE_DIRECTORIES}" "${LINK_LIBRARIES}")

		set_target_properties(${NAME} PROPERTIES 
			RUNTIME_OUTPUT_DIRECTORY ${VRUT_MANIP_MODULES_DIR}
			RUNTIME_OUTPUT_DIRECTORY_RELEASE ${VRUT_MANIP_MODULES_DIR}
			RUNTIME_OUTPUT_DIRECTORY_DEBUG ${VRUT_MANIP_MODULES_DIR}
			RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${VRUT_MANIP_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY ${VRUT_MANIP_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY_RELEASE ${VRUT_MANIP_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY_DEBUG ${VRUT_MANIP_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${VRUT_MANIP_MODULES_DIR}
		)
		
	endif(${FULLQUALIF})
	
endmacro(vrut_manip_module)

macro (vrut_module NAME SOURCES INCLUDE_DIRECTORIES LINK_LIBRARIES)

	optional_module(${NAME} "MODULE")
	
	if(${FULLQUALIF})
		
		vrut_module_base(${NAME} "${SOURCES}" "${INCLUDE_DIRECTORIES}" "${LINK_LIBRARIES}")
		
		set_target_properties(${NAME} PROPERTIES 
			RUNTIME_OUTPUT_DIRECTORY ${VRUT_MODULES_DIR}
			RUNTIME_OUTPUT_DIRECTORY_RELEASE ${VRUT_MODULES_DIR}
			RUNTIME_OUTPUT_DIRECTORY_DEBUG ${VRUT_MODULES_DIR}
			RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${VRUT_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY ${VRUT_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY_RELEASE ${VRUT_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY_DEBUG ${VRUT_MODULES_DIR}
			LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${VRUT_MODULES_DIR}
		)
	endif(${FULLQUALIF})
	
endmacro(vrut_module)
