SetupOptimizationLevel.cmake 979 Bytes
Newer Older
1 2 3 4 5 6
#################################################################################
# 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
7
if (NOT CMAKE_BUILD_TYPE)
8
    set(CMAKE_BUILD_TYPE Release)
9
endif ()
10 11 12 13
message("-- Using Build Type: " ${CMAKE_BUILD_TYPE})


# Enable optimizations in release builds
14
if (CMAKE_BUILD_TYPE STREQUAL "Release")
15
    # Link time optimization
16
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
17 18 19 20
    # -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.
21
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native")
22
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
23
else ()
24
    set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
25
endif ()