# MSVC PrecompiledHeader 
FUNCTION( MSVC_SET_PCH Target PrecompiledHeader PrecompiledSource)
  IF( MSVC )
	GET_PROPERTY(TARGET_COMPILE_FLAGS TARGET ${Target} PROPERTY COMPILE_FLAGS)
	GET_PROPERTY(SOURCE_COMPILE_FLAGS SOURCE ${PrecompiledSource} PROPERTY COMPILE_FLAGS)
    GET_FILENAME_COMPONENT(PrecompiledBasename
       ${PrecompiledHeader} NAME)

    SET_PROPERTY(SOURCE ${PrecompiledSource}
      PROPERTY
        COMPILE_FLAGS
          "${SOURCE_COMPILE_FLAGS} /Yc\"${PrecompiledBasename}\"")

	SET_PROPERTY(TARGET ${Target}
      PROPERTY
        COMPILE_FLAGS
          "${TARGET_COMPILE_FLAGS} /Yu\"${PrecompiledBasename}\"")

  ENDIF( MSVC )
ENDFUNCTION()

MACRO(RUNTIME_LIBRARY_OPTION Config Option)
	STRING(TOUPPER ${Config} Config2)
	SET(CXX_FLAGS_VARNAME "CMAKE_CXX_FLAGS_${Config2}")
	SET(CXX_FLAGS ${${CXX_FLAGS_VARNAME}})
	SET(C_FLAGS_VARNAME "CMAKE_C_FLAGS_${Config2}")
	SET(C_FLAGS ${${C_FLAGS_VARNAME}})

	# CXX
	IF(${CXX_FLAGS} MATCHES "/MDd")
		STRING(REGEX REPLACE "/MDd" "${Option}" CXX_FLAGS ${CXX_FLAGS})
	ELSEIF(${CXX_FLAGS} MATCHES "/MTd")
		STRING(REGEX REPLACE "/MTd" "${Option}" CXX_FLAGS ${CXX_FLAGS})
	ELSEIF(${CXX_FLAGS} MATCHES "/MD")
		STRING(REGEX REPLACE "/MD" "${Option}" CXX_FLAGS ${CXX_FLAGS})
	ELSEIF(${CXX_FLAGS} MATCHES "/MT")
		STRING(REGEX REPLACE "/MT" "${Option}" CXX_FLAGS ${CXX_FLAGS})
	ENDIF()

	if(NOT ${CXX_FLAGS} MATCHES "${Option}")
		SET(CXX_FLAGS "${CXX_FLAGS} ${Option}")
	ENDIF()
	SET(${CXX_FLAGS_VARNAME} ${CXX_FLAGS})
	
	# C
	IF(${C_FLAGS} MATCHES "/MDd")
		STRING(REGEX REPLACE "/MDd" "${Option}" C_FLAGS ${C_FLAGS})
	ELSEIF(${C_FLAGS} MATCHES "/MTd")
		STRING(REGEX REPLACE "/MTd" "${Option}" C_FLAGS ${C_FLAGS})
	ELSEIF(${C_FLAGS} MATCHES "/MD")
		STRING(REGEX REPLACE "/MD" "${Option}" C_FLAGS ${C_FLAGS})
	ELSEIF(${C_FLAGS} MATCHES "/MT")
		STRING(REGEX REPLACE "/MT" "${Option}" C_FLAGS ${C_FLAGS})
	ENDIF()

	if(NOT ${C_FLAGS} MATCHES "${Option}")
		SET(C_FLAGS "${C_FLAGS} ${Option}")
	ENDIF()
	SET(${C_FLAGS_VARNAME} ${C_FLAGS})
ENDMACRO()

MACRO(SET_PROJECT_COMPILE_FLAG Target Option)
	GET_PROPERTY(TARGET_COMPILE_FLAGS TARGET ${Target} PROPERTY COMPILE_FLAGS)
	SET_PROPERTY(TARGET ${Target} PROPERTY COMPILE_FLAGS "${TARGET_COMPILE_FLAGS} ${Option}")
ENDMACRO()