
if(WIN32)
	set(link_libs psapi.lib iphlpapi.lib Shell32.lib Advapi32.lib Gdi32.lib)
else()
	if(APPLE)
		set(link_libs /System/Library/Frameworks/CoreServices.framework)
	elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
		if(EMCC)
			add_definitions(-D__linux__=1)
			add_definitions(-D__USE_MISC=1)
			add_definitions(-DEMCC=1)
			SET(CMAKE_EXECUTABLE_SUFFIX ".html")
			set(GCC_COVERAGE_LINK_FLAGS    "-g -O2 --llvm-lto 1 -s DOUBLE_MODE=0 -s ASM_JS=1")
			set( CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" )
		endif()
		if(NOT ANDROID)
			set(link_libs rt pthread m dl)
		else()
			set(link_libs  log  android EGL GLESv2)
		endif()
	elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
		if(FLASCC)
			set(GCC_COVERAGE_LINK_FLAGS    "-lAS3++ -lFlash++ -pthread -g -O3 -emit-swf -lSDL -lvgl")
			set( CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" )
			SET(CMAKE_EXECUTABLE_SUFFIX ".swf")
			set(link_libs )
		else()
			set(link_libs m kvm pthread)
		endif()
	elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
		set(link_libs m kvm pthread)
	elseif(CMAKE_SYSTEM_NAME STREQUAL "DragonFly")
		set(link_libs m kvm pthread)
	elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
		set(link_libs m kvm pthread)
	elseif(CMAKE_SYSTEM_NAME STREQUAL "solaris")
		set(link_libs nsl socket kstat)
	endif()
endif()

if(NOT WIN32)
include(cmake/FindGLES.cmake)
include(cmake/FindX11.cmake)
endif()


function(tng_library_with_type name type)
	add_library(${name} ${type} ${ARGN})
	target_link_libraries(${name} ${link_libs})
	if( ${link_libs_debug})
	target_link_libraries( ${name} debug ${link_libs_debug})
	endif()
	if( ${link_libs_opt})
	target_link_libraries( ${name} optimized  ${link_libs_opt})
	endif()
endfunction()
function(tng_shared_library name)
	if(FLASCC OR EMCC)
		tng_library_with_type(${name} STATIC ${ARGN})
	else()
		tng_library_with_type(${name} SHARED ${ARGN})
	endif()
endfunction()

function(tng_library name)
  tng_library_with_type(${name} STATIC ${ARGN})
endfunction()

function(tng_exe_with_type name)
	add_executable(${name} ${ARGN})
	target_link_libraries(${name} ${link_libs})
	if( ${link_libs_debug})
	target_link_libraries( ${name} debug ${link_libs_debug})
	endif()
	if( ${link_libs_opt})
	target_link_libraries( ${name} optimized  ${link_libs_opt})
	endif()
endfunction()

function(tng_exe name)
  tng_exe_with_type(${name} ${ARGN})
endfunction()

function(tng_game name)
if(NOT ANDROID)
	tng_exe(${name} ${ARGN})  
else()
	tng_shared_library(${name} ${ARGN})
	#set(APP_SHARED_LIBRARIES ${LIBRARY_OUTPUT_PATH}/lib${name}.so)
	#android_create_apk(${name} "${CMAKE_BINARY_DIR}/apk" "${APP_SHARED_LIBRARIES}" "" "Data")
endif()
endfunction()