Merge pull request #225 from rolk/225_cxxflags
Let the user set compilation flags
This commit is contained in:
commit
f5b5cee768
@ -46,14 +46,8 @@ set (${project}_DEPS
|
||||
"dune-istl"
|
||||
)
|
||||
|
||||
# C++ project
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
project (${${project}_NAME})
|
||||
enable_language (C)
|
||||
enable_language (CXX)
|
||||
|
||||
# additional search modules
|
||||
set (${project}_MODULE_DIR "${PROJECT_SOURCE_DIR}/cmake/Modules")
|
||||
set (${project}_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
|
||||
list (APPEND CMAKE_MODULE_PATH ${${project}_MODULE_DIR})
|
||||
|
||||
# include special
|
||||
@ -67,6 +61,16 @@ if (CMAKE_VERSION VERSION_LESS "2.8.7")
|
||||
list (APPEND CMAKE_MODULE_PATH "${${project}_MODULE_DIR}/compat-2.8.7")
|
||||
endif (CMAKE_VERSION VERSION_LESS "2.8.7")
|
||||
|
||||
# don't write default flags into the cache, preserve that for user set values
|
||||
include (AddOptions)
|
||||
no_default_options ()
|
||||
|
||||
# C++ project
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
project (${${project}_NAME})
|
||||
enable_language (C)
|
||||
enable_language (CXX)
|
||||
|
||||
# print system information to better pinpoint issues from log alone
|
||||
include (UseSystemInfo)
|
||||
system_info ()
|
||||
|
@ -59,3 +59,24 @@ function (add_options langs builds)
|
||||
endforeach (build)
|
||||
endforeach (lang)
|
||||
endfunction (add_options lang build)
|
||||
|
||||
# set varname to flag unless user has specified something that matches regex
|
||||
function (set_default_option varname flag regex)
|
||||
if (NOT "$ENV{CXXFLAGS}" MATCHES "${regex}"
|
||||
AND NOT "${CMAKE_CXX_FLAGS}" MATCHES "${regex}"
|
||||
AND NOT "${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}" MATCHES "${regex}")
|
||||
set (${varname} ${flag} PARENT_SCOPE)
|
||||
else (NOT "$ENV{CXXFLAGS}" MATCHES "${regex}"
|
||||
AND NOT "${CMAKE_CXX_FLAGS}" MATCHES "${regex}"
|
||||
AND NOT "${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}" MATCHES "${regex}")
|
||||
set (${varname} PARENT_SCOPE)
|
||||
endif (NOT "$ENV{CXXFLAGS}" MATCHES "${regex}"
|
||||
AND NOT "${CMAKE_CXX_FLAGS}" MATCHES "${regex}"
|
||||
AND NOT "${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}" MATCHES "${regex}")
|
||||
endfunction (set_default_option)
|
||||
|
||||
# note: this must be called before project()
|
||||
macro (no_default_options)
|
||||
# prevent the platform probe to set options
|
||||
set (CMAKE_NOT_USING_CONFIG_FLAGS TRUE)
|
||||
endmacro (no_default_options)
|
||||
|
@ -13,11 +13,16 @@ include (AddOptions)
|
||||
|
||||
# only debugging using the GNU toolchain is supported for now
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
# default debug level, if not specified by the user
|
||||
set_default_option (_dbg_flag "-ggdb3" "(^|\ )-g")
|
||||
|
||||
# add debug symbols to *all* targets, regardless. there WILL come a
|
||||
# time when you need to find a bug which only manifests itself in a
|
||||
# release target on a production system!
|
||||
message (STATUS "Generating debug symbols: -ggdb3")
|
||||
add_options (ALL_LANGUAGES ALL_BUILDS "-ggdb3")
|
||||
if (_dbg_flag)
|
||||
message (STATUS "Generating debug symbols: ${_dbg_flag}")
|
||||
add_options (ALL_LANGUAGES ALL_BUILDS "${_dbg_flag}")
|
||||
endif (_dbg_flag)
|
||||
|
||||
# extracting the debug info is done by a separate utility in the GNU
|
||||
# toolchain. check that this is actually installed.
|
||||
|
@ -3,25 +3,26 @@
|
||||
include(TestCXXAcceptsFlag)
|
||||
include (AddOptions)
|
||||
|
||||
# mapping from profile name (in CMAKE_BUILD_TYPE) to variable part
|
||||
set (_prof_DEBUG "Debug")
|
||||
set (_prof_RELEASE "Release;RelWithDebInfo;MinSizeRel")
|
||||
|
||||
# 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"
|
||||
)
|
||||
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
# 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)
|
||||
option (WHOLE_PROG_OPTIM "Whole program optimization (lto)" ON)
|
||||
if (WHOLE_PROG_OPTIM)
|
||||
check_cxx_accepts_flag ("-flto" HAVE_LINK_OPTS)
|
||||
if (HAVE_LINK_OPTS)
|
||||
list (APPEND _opt_flags "-flto")
|
||||
endif (HAVE_LINK_OPTS)
|
||||
endif (WHOLE_PROG_OPTIM)
|
||||
|
||||
# native instruction set tuning
|
||||
option (WITH_NATIVE "Use native instruction set" ON)
|
||||
@ -32,10 +33,29 @@ if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
endif (HAVE_MTUNE)
|
||||
endif (WITH_NATIVE)
|
||||
|
||||
# default optimization flags, if not set by user
|
||||
set_default_option (_opt_dbg "-O0" "(^|\ )-O")
|
||||
set_default_option (_opt_rel "-O3" "(^|\ )-O")
|
||||
|
||||
# use these options for debug builds - no optimizations
|
||||
add_options (ALL_LANGUAGES "${_prof_DEBUG}" ${_opt_dbg} "-DDEBUG")
|
||||
|
||||
# use these options for release builds - full optimization
|
||||
add_options (
|
||||
ALL_LANGUAGES
|
||||
"Release;RelWithDebInfo;MinSizeRel"
|
||||
"-O3" "-DNDEBUG" ${_opt_flags}
|
||||
)
|
||||
add_options (ALL_LANGUAGES "${_prof_RELEASE}" ${_opt_rel} "-DNDEBUG" ${_opt_flags})
|
||||
|
||||
else (CMAKE_COMPILER_IS_GNUCXX)
|
||||
# default information from system
|
||||
foreach (lang IN ITEMS C CXX Fortran)
|
||||
if (lang STREQUAL "Fortran")
|
||||
set (_lang F)
|
||||
else (lang STREQUAL "Fortran")
|
||||
set (_lang ${lang})
|
||||
endif (lang STREQUAL "Fortran")
|
||||
foreach (profile IN ITEMS DEBUG RELEASE)
|
||||
if (NOT CMAKE_${lang}_FLAGS_${profile})
|
||||
add_options (${lang} "${_prof_${profile}}"
|
||||
"$ENV{${_lang}FLAGS} ${CMAKE_${lang}_FLAGS_${profile}_INIT}")
|
||||
endif (NOT CMAKE_${lang}_FLAGS_${profile})
|
||||
endforeach (profile)
|
||||
endforeach (lang)
|
||||
endif (CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
@ -2,6 +2,10 @@
|
||||
|
||||
include (AddOptions)
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
message (STATUS "All warnings enabled: -Wall")
|
||||
add_options (ALL_LANGUAGES ALL_BUILDS "-Wall")
|
||||
# default warnings flags, if not set by user
|
||||
set_default_option (_warn_flag "-Wall" "(^|\ )-W")
|
||||
if (_warn_flag)
|
||||
message (STATUS "All warnings enabled: ${_warn_flag}")
|
||||
add_options (ALL_LANGUAGES ALL_BUILDS "${_warn_flag}")
|
||||
endif (_warn_flag)
|
||||
endif (CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
10
configure
vendored
10
configure
vendored
@ -18,6 +18,7 @@ Optional Features:
|
||||
--enable-static build a static library [default=no]. Note: only one
|
||||
of the options shared and static may be built.
|
||||
--disable-debug build a release version of the library [default=no]
|
||||
--disable-lto do not use whole program optimization [default=yes]
|
||||
--disable-pch do not use precompiled headers (if buggy compiler)
|
||||
--disable-silent-rules print every compilation statement as executed
|
||||
--enable-system-debug put .debug files in global GDB debug dir
|
||||
@ -101,6 +102,8 @@ use_mpi=
|
||||
silent_rules=
|
||||
#debug_loc=" -DSYSTEM_DEBUG=OFF"
|
||||
debug_loc=
|
||||
#use_lto=" -DWHOLE_PROG_OPTIM=ON"
|
||||
use_lto=
|
||||
|
||||
# default is to warn for unknown options, but this can be disabled
|
||||
option_check=yes
|
||||
@ -232,6 +235,11 @@ for OPT in "$@"; do
|
||||
debug_loc=" -DSYSTEM_DEBUG=OFF"
|
||||
pkgname=""
|
||||
;;
|
||||
wpo |\
|
||||
lto )
|
||||
use_lto=" -DWHOLE_PROG_OPTIM=OFF"
|
||||
pkgname=""
|
||||
;;
|
||||
openmp)
|
||||
use_openmp=" -DUSE_OPENMP=OFF"
|
||||
pkgname=""
|
||||
@ -333,7 +341,7 @@ for a in "${VARS[@]}"; do
|
||||
done
|
||||
|
||||
# pass everything on to CMake
|
||||
CMDLINE="env ${ENVVARS} ${CMAKE_COMMAND} \"${srcdir}\" \"-DCMAKE_INSTALL_PREFIX=$prefix\" -DCMAKE_BUILD_TYPE=${buildtype}${pch_use}${silent_rules}${debug_loc}${use_openmp}${use_mpi} ${FEATURES}"
|
||||
CMDLINE="env ${ENVVARS} ${CMAKE_COMMAND} \"${srcdir}\" \"-DCMAKE_INSTALL_PREFIX=$prefix\" -DCMAKE_BUILD_TYPE=${buildtype}${pch_use}${silent_rules}${debug_loc}${use_openmp}${use_mpi}${use_lto} ${FEATURES}"
|
||||
echo --- calling CMake ---
|
||||
echo ${CMDLINE}
|
||||
eval exec ${CMDLINE}
|
||||
|
Loading…
Reference in New Issue
Block a user