Files
opm-core/cmake/Modules/UseOptimization.cmake
Roland Kaufmann 7976b95983 Use native instruction set on build system
CMake files are in general not portable between systems anyway, so we
may as well take full advantage of the native instruction set.

There must be a companion option to switch this off in case anyone
wants to build a package for distribution.
2013-02-11 22:37:55 +01:00

42 lines
1.1 KiB
CMake

# - Turn on optimizations based on build type
include(TestCXXAcceptsFlag)
include (AddOptions)
# if we are building a debug target, then disable all optimizations
# otherwise, turn them on. indicate to the code what we have done
# so it can turn on assertions etc.
if (CMAKE_COMPILER_IS_GNUCXX)
# use these options for debug builds - no optimizations
add_options (
ALL_LANGUAGES
"Debug"
"-O0" "-DDEBUG"
)
# extra flags passed for optimization
set (_opt_flags "")
# link-time (a.k.a. global) optimizations
check_cxx_accepts_flag ("-flto" HAVE_LINK_OPTS)
if (HAVE_LINK_OPTS)
list (APPEND _opt_flags "-flto")
endif (HAVE_LINK_OPTS)
# native instruction set tuning
option (WITH_NATIVE "Use native instruction set" ON)
if (WITH_NATIVE)
check_cxx_accepts_flag ("-mtune=native" HAVE_MTUNE)
if (HAVE_MTUNE)
list (APPEND _opt_flags "-mtune=native")
endif (HAVE_MTUNE)
endif (WITH_NATIVE)
# use these options for release builds - full optimization
add_options (
ALL_LANGUAGES
"Release;RelWithDebInfo;MinSizeRel"
"-O3" "-DNDEBUG" ${_opt_flags}
)
endif (CMAKE_COMPILER_IS_GNUCXX)