################################################################################# # Setup compiler flags to enable or disable optimization # By default: Release with -O3, Debug -O0 ################################################################################# # make sure a build type is set, default to release if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif () message("-- Using Build Type: " ${CMAKE_BUILD_TYPE}) # Enable optimizations in release builds if (CMAKE_BUILD_TYPE STREQUAL "Release") # Link time optimization set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") # -O2 is often seen as 'the most speed', # but inlining functions and SIMD/Vectorization is # only enabled by -O3, thus it's way faster in some # array calculations. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native") set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) else () set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") endif ()