#Setup general compiler options
IF (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
	set(COMMON_FLAGS ${COMMON_FLAGS} "-fsyntax-only")  #-Wall -Wextra -pedantic -Wstrict-prototypes -Wunreachable-code  -Wwrite-strings -Wpointer-arith -Wbad-function-cast -Wcast-align -Wcast-qual
	set(CXX_ONLY_FLAGS ${CXX_ONLY_FLAGS} " -std=c++11")

	SET(CXX_ONLY_FLAGS "${CXX_ONLY_FLAGS} -fno-rtti") # Somehow required to make it link!

	IF (ENABLE_SSE)
		set(COMMON_FLAGS "${COMMON_FLAGS} -msse4")
		message("Enabling SSE4.")
	ENDIF (ENABLE_SSE)

	IF (ENABLE_NATIVE)
		set(COMMON_FLAGS "${COMMON_FLAGS} -march=native")
		message("Enabling native modus.")
	ENDIF (ENABLE_NATIVE)

	# Release build
	set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
	# Release build with debug symbols
	set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3 -DNDEBUG")
	# Debug Build
	set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")

	set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} ${CXX_ONLY_FLAGS} ${CMAKE_CXX_FLAGS}")
ENDIF (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)

# set default build type
IF (NOT CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE Debug)
ENDIF (NOT CMAKE_BUILD_TYPE)

string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
IF (CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
	set(EXE_SUFFIX "Debug")
ELSEIF (CMAKE_BUILD_TYPE_UPPER STREQUAL "RELEASE")
	set(EXE_SUFFIX "")
ELSEIF (CMAKE_BUILD_TYPE_UPPER STREQUAL "RELWITHDEBINFO")
	set(EXE_SUFFIX "RelWithDebInfo")
ELSE (CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
	set(EXE_SUFFIX "Unknown")
ENDIF (CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")

IF (CMAKE_BUILD_TYPE_UPPER MATCHES "RELWITHDEBINFO")
	set(ALL_CXX_FLAGS ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
ENDIF (CMAKE_BUILD_TYPE_UPPER MATCHES "RELWITHDEBINFO")
IF (CMAKE_BUILD_TYPE_UPPER MATCHES "DEBUG")
	set(ALL_CXX_FLAGS ${CMAKE_CXX_FLAGS_DEBUG})
ENDIF (CMAKE_BUILD_TYPE_UPPER MATCHES "DEBUG")
IF (CMAKE_BUILD_TYPE_UPPER MATCHES "RELEASE")
	set(ALL_CXX_FLAGS ${CMAKE_CXX_FLAGS_RELEASE})
ENDIF (CMAKE_BUILD_TYPE_UPPER MATCHES "RELEASE")

message(STATUS "Build Type: " ${CMAKE_BUILD_TYPE})
message(STATUS "Compiler Flags (Modus): " ${ALL_CXX_FLAGS})
message(STATUS "Compiler Flags (cmake): " ${CMAKE_CXX_FLAGS})
