CMAKE_MINIMUM_REQUIRED (VERSION 3.0)
if(NOT CompillerSetupParams)
macro (CompillerSetupParams)
	if(NOT CMAKE_BUILD_TYPE)
		set(CMAKE_BUILD_TYPE RELEASE)
	endif(NOT CMAKE_BUILD_TYPE)
	if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
		SET(EXTEND_WARNINGS_GCC_C "-Wall -Wextra")
		SET(EXTEND_WARNINGS_GCC_CXX "-Wdelete-non-virtual-dtor ${EXTEND_WARNINGS_GCC_C}")
                set(REMOVING_REGEX "(-Wl,)?-flto" "-O([0,1,2,3,s,g]|fast)?" "-Wl,--as-needed" "-Wl,--strip-all" "-fomit-frame-pointer")
		unset(APPEND_SYMBOL)
		foreach(GCC_REGEX ${REMOVING_REGEX})
			set(REMOVING_FLAGS_GCC_REGEX "${REMOVING_FLAGS_GCC_REGEX}${APPEND_SYMBOL}${GCC_REGEX}[ ]?")
			set(APPEND_SYMBOL "|")
		endforeach(GCC_REGEX ${REMOVING_REGEX})
		foreach(_lang C CXX)
			foreach(configs RELEASE RELWITHDEBINFO MINSIZEREL DEBUG)
                                string(REGEX REPLACE "-O([0,1,2,3,s,g]|fast)?[ ]?" "" CMAKE_${_lang}_FLAGS_${configs} "${CMAKE_${_lang}_FLAGS_${configs}}" )
			endforeach(configs RELEASE RELWITHDEBINFO MINSIZEREL DEBUG)
			string(REGEX MATCHALL "${REMOVING_FLAGS_GCC_REGEX}" OPTLEVEL_${_lang}_RELEASE "${CMAKE_${_lang}_FLAGS}")
			string(REGEX REPLACE ";" "" OPTLEVEL_${_lang}_RELEASE "${OPTLEVEL_${_lang}_RELEASE}")
			set(CMAKE_${_lang}_FLAGS "${CMAKE_${_lang}_FLAGS} ${EXTEND_WARNINGS_GCC_${_lang}}")
			if(CMAKE_BUILD_TYPE)
				string(REGEX REPLACE "${REMOVING_FLAGS_GCC_REGEX}" "" CMAKE_${_lang}_FLAGS "${CMAKE_${_lang}_FLAGS}")
				set(CMAKE_${_lang}_FLAGS_RELEASE "${OPTLEVEL_${_lang}_RELEASE} ${CMAKE_${_lang}_FLAGS_RELEASE}")
			else(CMAKE_BUILD_TYPE)
				MESSAGE(STATUS "CMAKE_BUILD_TYPE NOT SETUPING")
				set(CMAKE_${_lang}_FLAGS_RELEASE "${CMAKE_${_lang}_FLAGS} ${CMAKE_${_lang}_FLAGS_RELEASE}")
			endif(CMAKE_BUILD_TYPE)
                        SET(CMAKE_${_lang}_FLAGS_DEBUG "${CMAKE_${_lang}_FLAGS_DEBUG} -Og ${EXTEND_WARNINGS_GCC_CXX}")
		endforeach(_lang C CXX)
		# APPLAY LINKER OPTION ONLY FOR RELEASE AND MINSIZERELEASE
		foreach(val EXE MODULE SHARED STATIC)
			foreach(configs RELEASE MINSIZEREL)
				set(CMAKE_${val}_LINKER_FLAGS_${configs} "${CMAKE_${val}_LINKER_FLAGS_${configs}} ${CMAKE_${val}_LINKER_FLAGS}")
			endforeach(configs RELEASE RELWITHDEBINFO MINSIZEREL DEBUG)
			set(CMAKE_${val}_LINKER_FLAGS "")
		endforeach(val CXX C LINK)
	elseif(MSCV)
		foreach(_lang C CXX)
			string(REGEX "/MTd" "/MT" CMAKE_${_lang}_FLAGS ${CMAKE_${_lang}_FLAGS})
			string(REGEX "/MDd" "/MD" CMAKE_${_lang}_FLAGS ${CMAKE_${_lang}_FLAGS})
			string(REGEX "/MTd" "/MT" CMAKE_${_lang}_FLAGS_DEBUG ${CMAKE_${_lang}_FLAGS_DEBUG})
			string(REGEX "/MDd" "/MD" CMAKE_${_lang}_FLAGS_DEBUG ${CMAKE_${_lang}_FLAGS_DEBUG})
		endforeach()		
	endif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
endmacro(CompillerSetupParams)
endif(NOT CompillerSetupParams)



