SetupOptimizationLevel.cmake 913 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#################################################################################
# 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 "-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 "-O3")
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
    set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
endif()