FUNCTION(SET_WARNING_LEVEL)
	IF(MSVC)
		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" PARENT_SCOPE)
	ELSEIF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic" PARENT_SCOPE)
	ENDIF(MSVC)
ENDFUNCTION()

FUNCTION(ENABLE_MULTIPROCESSOR_BUILD)
  IF (MSVC)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP" PARENT_SCOPE)
  ENDIF (MSVC)
ENDFUNCTION()

FUNCTION(DISABLE_COMPILER_EXTENSIONS)
  IF(MSVC)
	  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Za")
	ENDIF(MSVC)
ENDFUNCTION()

FUNCTION(SET_NEW_STANDARD_FLAGS)
	IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
	  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y" PARENT_SCOPE)
  ELSEIF(MSVC)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++14" PARENT_SCOPE)
	ENDIF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
ENDFUNCTION(SET_NEW_STANDARD_FLAGS)

FUNCTION(ENABLE_MULTITHREADING)
	IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
	    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread" PARENT_SCOPE)
	ENDIF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
ENDFUNCTION(ENABLE_MULTITHREADING)

FUNCTION(ADD_SANITIZERS_TO_BUILD)
	IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
	
	    SET(SANITIZER_FLAGS "")
	    IF(${USE_ADDRESS_SANITIZER})
		    SET(SANITIZER_FLAGS "address")
		ENDIF(${USE_ADDRESS_SANITIZER})
		
		IF(${USE_MEMORY_SANITIZER})
		    IF(NOT ${SANITIZER_FLAGS} STREQUAL "")
			    MESSAGE(FATAL_ERROR "Only one of sanitizers: Address, Memory, Thread may be used at once")
			ENDIF(NOT ${SANITIZER_FLAGS} STREQUAL "")
		
		    SET(SANITIZER_FLAGS "memory")
		ENDIF(${USE_MEMORY_SANITIZER})
		
		IF(${USE_THREAD_SANITIZER})
		    IF(NOT ${SANITIZER_FLAGS} STREQUAL "")
			    MESSAGE(FATAL_ERROR "Only one of sanitizers: Address, Memory, Thread may be used at once")
			ENDIF(NOT ${SANITIZER_FLAGS} STREQUAL "")
		
		    SET(SANITIZER_FLAGS "thread")
		ENDIF(${USE_THREAD_SANITIZER})
		
	    IF(${USE_UNDEFINED_BEHAVIOR_SANITIZER})
		    IF(NOT ${SANITIZER_FLAGS} STREQUAL "")
			    SET(SANITIZER_FLAGS "${SANITIZER_FLAGS},")
			ENDIF(NOT ${SANITIZER_FLAGS} STREQUAL "")

		    SET(SANITIZER_FLAGS "${SANITIZER_FLAGS}undefined")
		ENDIF(${USE_UNDEFINED_BEHAVIOR_SANITIZER})
		
        IF(NOT ${SANITIZER_FLAGS} STREQUAL "")
		    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${SANITIZER_FLAGS}" PARENT_SCOPE)
        ENDIF(NOT ${SANITIZER_FLAGS} STREQUAL "")

	ENDIF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
ENDFUNCTION(ADD_SANITIZERS_TO_BUILD)

FUNCTION(SET_PROPER_STANDARD_LIBRARY)
	IF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
	    IF(${USE_LIBCXX})
		    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++" PARENT_SCOPE)
	    ENDIF(${USE_LIBCXX})
	ENDIF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
ENDFUNCTION(SET_PROPER_STANDARD_LIBRARY)

FUNCTION(SET_CLANG_BOOST_COMPILER_FLAGS)
    STRING(REGEX MATCH "^([0-9]+).([0-9]+).[0-9]+$" CLANG_VERSION ${CMAKE_CXX_COMPILER_VERSION})
    SET(VERSION_POSTFIX "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
    SET(Boost_COMPILER "-clang${VERSION_POSTFIX}" PARENT_SCOPE)
ENDFUNCTION()
