Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #135 from lazyten/dev-mfh
Browse files Browse the repository at this point in the history
DRB works on C compiler flags as well
  • Loading branch information
mfherbst committed Aug 27, 2017
2 parents 44ff544 + 765b164 commit ef18011
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 34 deletions.
14 changes: 10 additions & 4 deletions cmake/IncludeKrimsCmakeModule.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## ---------------------------------------------------------------------
##
## Copyright (C) 2016 by the krims authors
## Copyright (C) 2017 by the krims authors
##
## This file is part of krims.
##
Expand Down Expand Up @@ -80,15 +80,20 @@ macro(include_krims_cmake_module MODULE)
# Determine FIRST_TRY_LOCATION, i.e the place where we first try to find
# the module
set(FIRST_TRY_LOCATION "")
if (NOT "$ENV{krims_DIR}" MATCHES "NOTFOUND"
if (NOT "$ENV{krims_DIR}" STREQUAL ""
AND NOT "$ENV{krims_DIR}" MATCHES "NOTFOUND"
AND NOT "$ENV{krims_DIR}" MATCHES "AUTOCHECKOUT")
set(FIRST_TRY_LOCATION
"$ENV{krims_DIR}/share/cmake/modules/${MODULE}.cmake")
endif()

if (NOT "${krims_DIR}" MATCHES "NOTFOUND"
# krims_DIR points to the directory containing the package config
# this is a sister directory to the modules directory containing
# the module files we are after.
if (NOT "${krims_DIR}" STREQUAL ""
AND NOT "${krims_DIR}" MATCHES "NOTFOUND"
AND NOT "${krims_DIR}" MATCHES "AUTOCHECKOUT")
set(FIRST_TRY_LOCATION "${krims_DIR}/share/cmake/modules/${MODULE}.cmake")
set(FIRST_TRY_LOCATION "${krims_DIR}/../modules/${MODULE}.cmake")
endif()

if ("${krims_DIR}" STREQUAL "krims_DIR-AUTOCHECKOUT"
Expand All @@ -101,6 +106,7 @@ macro(include_krims_cmake_module MODULE)
endif()

# Try the first try location
set(RES "NOTFOUND")
if (NOT "${FIRST_TRY_LOCATION}" STREQUAL "")
include("${FIRST_TRY_LOCATION}" OPTIONAL RESULT_VARIABLE RES)
endif()
Expand Down
9 changes: 3 additions & 6 deletions cmake/modules/DebugReleaseBuild/compiler_flags/coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ endif()
option(DRB_COVERAGE_Debug "Compile with coverage testing in the Debug build." OFF)

if(DRB_COVERAGE_Debug AND CMAKE_BUILD_TYPE MATCHES "Debug")
set(_FLAGSS "--coverage")
enable_if_compiles(_FLAGSS "--coverage")

# TODO This does only enable so-called DebugInfo-based coverage in clang.
# But clang has more to offer. See
# http://clang.llvm.org/docs/SourceBasedCodeCoverage.html
# http://clang.llvm.org/docs/SanitizerCoverage.html

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${_FLAGSS}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${_FLAGSS}")
unset(_FLAGSS)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} --coverage")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} --coverage")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --coverage")

message(STATUS "Enabled coverage analysis in the Debug build.")
endif()
Expand Down
15 changes: 9 additions & 6 deletions cmake/modules/DebugReleaseBuild/compiler_flags/sanitise.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ endif()
# Options
#

option(DRB_SANITIZE_ADDRESS_Release "Enable detection of memory errors (Out-of-bounds, use-after-free, ...) in RELEASE build.")
option(DRB_SANITIZE_THREAD_Release "Enable detection of data races introduced by multi-threading in the RELEASE build.")
option(DRB_SANITIZE_UNDEFINED_Release "Enable detection of undefined behaviour instructions in the RELEASE build.")
option(DRB_SANITIZE_ADDRESS_Release "Enable detection of memory errors (Out-of-bounds, use-after-free, ...) in RELEASE build.")
option(DRB_SANITIZE_THREAD_Release "Enable detection of data races introduced by multi-threading in the RELEASE build.")
option(DRB_SANITIZE_UNDEFINED_Release "Enable detection of undefined behaviour instructions (negative shifts, integer overflows) in the RELEASE build.")

set(DRB_SANITIZE_OPTIONS DRB_SANITIZE_THREAD_Release DRB_SANITIZE_ADDRESS_Release
DRB_SANITIZE_UNDEFINED_Release)
Expand Down Expand Up @@ -72,10 +72,11 @@ if (CMAKE_BUILD_TYPE MATCHES "Release" AND DRB_HAVE_ANY_SANITIZE)

# Set flags for sanitizer:
set(_FLAGSS "-g")
set(dummy "")

if(DRB_SANITIZE_MEMORY_Release)
set(_FLAGSS "${_FLAGSS} -fsanitize=memory")
enable_if_compiles(_FLAGSS "-fsanitize-memory-track-origin")
enable_if_all_compiles(_FLAGSS dummy "-fsanitize-memory-track-origin")
message(STATUS "Enabled memory sanitiser in Release build.")
elseif(DRB_SANITIZE_THREAD_Release)
set(_FLAGSS "${_FLAGSS} -fsanitize=thread")
Expand All @@ -89,12 +90,14 @@ if (CMAKE_BUILD_TYPE MATCHES "Release" AND DRB_HAVE_ANY_SANITIZE)
endif()

# Disable some further optimisations
enable_if_compiles(_FLAGSS "-fno-omit-frame-pointer")
enable_if_compiles(_FLAGSS "-fno-optimize-sibling-calls")
enable_if_all_compiles(_FLAGSS dummy "-fno-omit-frame-pointer")
enable_if_all_compiles(_FLAGSS dummy "-fno-optimize-sibling-calls")

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${_FLAGSS}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${_FLAGSS}")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${_FLAGSS}")
unset(_FLAGSS)
unset(dummy)
endif()

#
Expand Down
33 changes: 18 additions & 15 deletions cmake/modules/DebugReleaseBuild/compiler_flags/standard.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## ---------------------------------------------------------------------
##
## Copyright (C) 2016 by the krims authors
## Copyright (C) 2016-17 by the krims authors
##
## This file is part of krims.
##
Expand Down Expand Up @@ -36,10 +36,12 @@
# Warnings
#
# Show high confidence warning
enable_if_compiles(CMAKE_CXX_FLAGS "-Wall")
enable_if_compiles(CMAKE_CXX_FLAGS "-Wall")
enable_if_cc_compiles(CMAKE_C_FLAGS "-Wall")

# Show valuable extra warnings
enable_if_compiles(CMAKE_CXX_FLAGS "-Wextra")
enable_if_compiles(CMAKE_CXX_FLAGS "-Wextra")
enable_if_cc_compiles(CMAKE_C_FLAGS "-Wextra")

# Warn if virtual classes do not have a virtual destructor
enable_if_compiles(CMAKE_CXX_FLAGS "-Wnon-virtual-dtor")
Expand All @@ -54,22 +56,23 @@ enable_if_compiles(CMAKE_CXX_FLAGS "-Wold-style-cast")
enable_if_compiles(CMAKE_CXX_FLAGS "-Wcast-align")

# But silence some rather annoying warnings
enable_if_compiles(CMAKE_CXX_FLAGS "-Wno-unused-macros")
enable_if_compiles(CMAKE_CXX_FLAGS "-Wno-unused-parameter")
enable_if_all_compiles(CMAKE_CXX_FLAGS CMAKE_C_FLAGS "-Wno-unused-macros")
enable_if_all_compiles(CMAKE_CXX_FLAGS CMAKE_C_FLAGS "-Wno-unused-parameter")

# Turn on warnings about language extensions
enable_if_compiles(CMAKE_CXX_FLAGS "-pedantic")
enable_if_compiles(CMAKE_CXX_FLAGS "-pedantic")
enable_if_cc_compiles(CMAKE_C_FLAGS "-pedantic")

#
# Warnings as errors
#
# Make warnings errors, such that we cannot ignore them
enable_if_compiles(CMAKE_CXX_FLAGS "-Werror")
enable_if_compiles(CMAKE_CXX_FLAGS "-Werror")
enable_if_cc_compiles(CMAKE_C_FLAGS "-Werror")

# Do not make overloaded virtuals errors:
# TODO maybe do?
enable_if_compiles(CMAKE_CXX_FLAGS "-Wno-error=overloaded-virtual")
enable_if_compiles(CMAKE_CXX_FLAGS "-Wno-error=deprecated-declarations")
# Some things we rather want as warnings, not as errors:
enable_if_compiles(CMAKE_CXX_FLAGS "-Wno-error=deprecated-declarations")
enable_if_cc_compiles(CMAKE_C_FLAGS "-Wno-error=extra-semi")

#######################
#-- Bug workarounds --#
Expand All @@ -91,8 +94,8 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")
# Extra stuff for debug:
#
if (CMAKE_BUILD_TYPE MATCHES "Debug")
enable_if_compiles(CMAKE_CXX_FLAGS_DEBUG "-O0")
enable_if_compiles(CMAKE_CXX_FLAGS_DEBUG "-Og")
enable_if_all_compiles(CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG "-O0")
enable_if_all_compiles(CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG "-Og")

# Common linker flags for all of debug:
set(COMMON_LINKER_FLAGS_DEBUG "${COMMON_LINKER_FLAGS_DEBUG} -g")
Expand All @@ -114,8 +117,8 @@ endif()
option(DRB_MACHINE_SPECIFIC_OPTIM_Release "Enable machine-specific optimisations in REALEASE build. Your build might not be transferable to other machines.")
if (CMAKE_BUILD_TYPE MATCHES "Release")
if (DRB_MACHINE_SPECIFIC_OPTIM_Release)
enable_if_compiles(CMAKE_CXX_FLAGS_RELEASE "-march=native")
enable_if_compiles(CMAKE_CXX_FLAGS_RELEASE "-mtune=native")
enable_if_all_compiles(CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE "-march=native")
enable_if_all_compiles(CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE "-mtune=native")
message(STATUS "Enabled machine-specific optimisations in Release build.")
endif()
endif()
29 changes: 28 additions & 1 deletion cmake/modules/DebugReleaseBuild/drb_setup_compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
## ---------------------------------------------------------------------

include(CheckCXXCompilerFlag)
include(CheckCCompilerFlag)

macro(determine_supported_cxx_standards)
# macro to check for the highest fully supported c++ standard.
Expand Down Expand Up @@ -193,7 +194,7 @@ macro(use_cxx_standard STANDARD)
endmacro(use_cxx_standard)

macro(enable_if_compiles VARIABLE FLAG)
# Checks whether a compiler supports a flag and if yes
# Checks whether a cxx compiler supports a flag and if yes
# adds it to the variable provided.
#
string(REGEX REPLACE "[^a-zA-Z0-9]" "" FLAG_CLEAN "${FLAG}")
Expand All @@ -204,6 +205,32 @@ macro(enable_if_compiles VARIABLE FLAG)
unset(FLAG_CLEAN)
endmacro(enable_if_compiles)

macro(enable_if_cc_compiles VARIABLE FLAG)
# Checks whether a plain c compiler supports a flag and if yes
# adds it to the variable provided.
#
string(REGEX REPLACE "[^a-zA-Z0-9]" "" FLAG_CLEAN "${FLAG}")
CHECK_C_COMPILER_FLAG("-Werror ${FLAG}" DRB_CC_HAVE_FLAG_${FLAG_CLEAN})
if (DRB_CC_HAVE_FLAG_${FLAG_CLEAN})
set(${VARIABLE} "${${VARIABLE}} ${FLAG}")
endif()
unset(FLAG_CLEAN)
endmacro(enable_if_cc_compiles)

macro(enable_if_all_compiles VARIABLE1 VARIABLE2 FLAG)
# Checks whether the plain c compiler as well as the C++ compiler
# supports a flag and if yes adds it to the variable provided.
#
string(REGEX REPLACE "[^a-zA-Z0-9]" "" FLAG_CLEAN "${FLAG}")
CHECK_C_COMPILER_FLAG("-Werror ${FLAG}" DRB_CC_HAVE_FLAG_${FLAG_CLEAN})
CHECK_CXX_COMPILER_FLAG("-Werror ${FLAG}" DRB_HAVE_FLAG_${FLAG_CLEAN})
if (DRB_CC_HAVE_FLAG_${FLAG_CLEAN} AND DRB_HAVE_FLAG_${FLAG_CLEAN})
set(${VARIABLE1} "${${VARIABLE1}} ${FLAG}")
set(${VARIABLE2} "${${VARIABLE2}} ${FLAG}")
endif()
unset(FLAG_CLEAN)
endmacro()

# TODO have something similar for the linker

macro(DRB_SETUP_COMPILER_FLAGS CXX_STANDARD)
Expand Down
2 changes: 0 additions & 2 deletions cmake/modules/FindPackageAutocheckoutFallback.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ Either provide the installation prefix of the ${NAME} library in the environment
variable ${NAME}_DIR or enable autocheckout via -DAUTOCHECKOUT_MISSING_REPOS=ON.")
endif()

message(WARNING "This part of find_package_autocheckout_fallback has never been tested.")

# Setup library targets
set(${NAME}_DEBUG_TARGET "Upstream::${NAME}.g"
CACHE INTERNAL "Target name of debug version of ${NAME}")
Expand Down

0 comments on commit ef18011

Please sign in to comment.