if( CMAKE_CL_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8 ) 
	set(ARCH_TYPE "x64")
	message(STATUS "ARCH_TYPE = x64")
else( CMAKE_CL_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8 ) 
	set(ARCH_TYPE "x86")
	message(STATUS "ARCH_TYPE = x86")
endif( CMAKE_CL_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8 )

SET(RTMAPS_DIR $ENV{RTMAPS_SDKDIR})
message(STATUS "RTMAPS_DIR = ${RTMAPS_DIR}")
if(WIN32 AND MSVC)
	if(MSVC80)
		set(IDE_VERSION "vc.net2005")
	elseif(MSVC90)
		set(IDE_VERSION "vc.net2008")
	elseif(MSVC10)
		set(IDE_VERSION "vc.net2010")
	elseif(MSVC11)
		set(IDE_VERSION "vc.net2012")
	elseif(MSVC12)
		set(IDE_VERSION "vc.net2013")
	elseif(MSVC14)
		set(IDE_VERSION "vc.net2015")
	else()
		message( FATAL_ERROR " msvc was not found !")
	endif (MSVC80)	
endif()
message( STATUS "IDE_VERSION = ${IDE_VERSION}")
if(ARCH_TYPE STREQUAL "x64")
	set(IDE_VERSION "${IDE_VERSION}_x64")
endif()
message( STATUS "IDE_VERSION = ${IDE_VERSION}")

find_path( RTMAPS_INCLUDE maps.hpp PATHS ${RTMAPS_DIR}/include ${RTMAPS_DIR}/sdk/${IDE_VERSION}/include )
if( ${RTMAPS_INCLUDE} STREQUAL "RTMAPS_INCLUDE-NOTFOUND" ) 
	message(STATUS "FATAL_ERROR : RTMaps is not found ! ")
	set(RTMAPS_FOUND "FALSE")
else ()
	set(RTMAPS_FOUND "TRUE")
	message(STATUS "Found RTMaps in ${RTMAPS_INCLUDE}")
endif()

if(RTMAPS_FOUND STREQUAL "TRUE" )
	if(WIN32)
		if(MSVC) 
			find_library (RTMAPS_LIBRARY rtmaps_pck.lib PATHS 
			${RTMAPS_DIR}/lib/${IDE_VERSION} 
			${RTMAPS_DIR}/sdk/${IDE_VERSION}/lib )
			find_path (RTMAPS_LIB_DIR rtmaps_pck.lib PATHS 
			${RTMAPS_DIR}/lib/${IDE_VERSION} 
			${RTMAPS_DIR}/sdk/${IDE_VERSION}/lib )
			message( STATUS "===> ${RTMAPS_DIR}/sdk/${IDE_VERSION}/lib")
		else(MSVC) 
			message( FATAL_ERROR "not link lib RTMaps without msvc ! ")
		endif(MSVC)
	else(WIN32) 	
		SET(RTMAPS_LIB_DIR ${RTMAPS_DIR}/lib)
	endif(WIN32)
endif( )

message( STATUS "RTMAPS_INCLUDE = ${RTMAPS_INCLUDE}")
message( STATUS "RTMAPS_LIBRARY = ${RTMAPS_LIB_DIR}")

if(NOT RTMAPS_INCLUDE MATCHES NOTFOUND)
  if(NOT RTMAPS_LIBRARY MATCHES NOTFOUND)
	set( RTMAPS_FOUND TRUE )
	include_directories( ${RTMAPS_INCLUDE} )
	link_directories( ${RTMAPS_LIB_DIR} )
  endif( )
endif( )

if(NOT DEFINED RTMAPS_FOUND)
  message( STATUS "RTMaps was not found (required)!")
else ( )
  message( STATUS "RTMaps was found here ${RTMAPS_DIR}")
endif( )

if(ARCH_TYPE STREQUAL "x86")
	set(PLATFORM_TYPE Win32)
else()
	set(PLATFORM_TYPE x64)
endif()

macro(configure_rtmaps pck_name )
	if(ARCH_TYPE STREQUAL "x86")
		SET_TARGET_PROPERTIES(${pck_name} PROPERTIES LINK_FLAGS_DEBUG "${LINK_FLAGS} /NODEFAULTLIB:MSVCRT /INCLUDE:_MAPSPckInit /INCLUDE:_MAPSGetModulesDefStruct" DEBUG_POSTFIX "_d")
		SET_TARGET_PROPERTIES(${pck_name} PROPERTIES LINK_FLAGS_RELEASE "${LINK_FLAGS} /NODEFAULTLIB:LIBCMTD /INCLUDE:_MAPSPckInit /INCLUDE:_MAPSGetModulesDefStruct" RELEASE_POSTFIX "_r")
	else()
		SET_TARGET_PROPERTIES(${pck_name} PROPERTIES LINK_FLAGS_DEBUG "${LINK_FLAGS} /NODEFAULTLIB:MSVCRT /INCLUDE:MAPSPckInit /INCLUDE:MAPSGetModulesDefStruct" DEBUG_POSTFIX "_d")
		SET_TARGET_PROPERTIES(${pck_name} PROPERTIES LINK_FLAGS_RELEASE "${LINK_FLAGS} /NODEFAULTLIB:LIBCMTD /INCLUDE:MAPSPckInit /INCLUDE:MAPSGetModulesDefStruct" RELEASE_POSTFIX "_r")
	endif()
	SET_TARGET_PROPERTIES(${pck_name} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH")
	SET_TARGET_PROPERTIES(${pck_name} PROPERTIES SUFFIX ".pck")
	add_custom_command(TARGET ${pck_name} POST_BUILD COMMAND $ENV{RTMAPS_SDKDIR}/bin/rtmaps_package_sign.exe -platform ${PLATFORM_TYPE} -package $<TARGET_FILE:${pck_name}> -info $<TARGET_FILE:${pck_name}>.pckinfo )
endmacro()