diff --git a/kde-modules/KDECMakeSettings.cmake b/kde-modules/KDECMakeSettings.cmake index 2dd54ed..3f7f5a8 100644 --- a/kde-modules/KDECMakeSettings.cmake +++ b/kde-modules/KDECMakeSettings.cmake @@ -1,373 +1,373 @@ #.rst: # KDECMakeSettings # ---------------- # # Changes various CMake settings to what the KDE community views as more # sensible defaults. # # It is recommended to include this module with the NO_POLICY_SCOPE flag, # otherwise you may get spurious warnings with some versions of CMake. # # It is split into three parts, which can be independently disabled if desired. # # Runtime Paths # ~~~~~~~~~~~~~ # # The default runtime path (used on Unix systems to search for # dynamically-linked libraries) is set to include the location that libraries # will be installed to (as set in LIB_INSTALL_DIR or, if the former is not set, # KDE_INSTALL_LIBDIR), and also the linker search path. # # Note that ``LIB_INSTALL_DIR`` or alternatively ``KDE_INSTALL_LIBDIR`` needs # to be set before including this module. # Typically, this is done by including the :kde-module:`KDEInstallDirs` module. # # This section can be disabled by setting ``KDE_SKIP_RPATH_SETTINGS`` to TRUE # before including this module. # # # Testing # ~~~~~~~ # # Testing is enabled by default, and an option (BUILD_TESTING) is provided for # users to control this. See the CTest module documentation in the CMake manual # for more details. # # This section can be disabled by setting ``KDE_SKIP_TEST_SETTINGS`` to TRUE # before including this module. # # # Build Settings # ~~~~~~~~~~~~~~ # # Various CMake build defaults are altered, such as searching source and build # directories for includes first, enabling automoc by default. # # When find_package(ECM 5.38) or higher is called, this also selects # a layout for the build dir that helps running executables without installing: # all executables are built into a toplevel "bin" dir, making it possible to find # helper binaries, and to find uninstalled plugins (provided that you use # kcoreaddons_add_plugin or set LIBRARY_OUTPUT_DIRECTORY as documented on # https://community.kde.org/Guidelines_and_HOWTOs/Making_apps_run_uninstalled). # # This section can be disabled by setting ``KDE_SKIP_BUILD_SETTINGS`` to TRUE # before including this module. # # This section also provides an "uninstall" target that can be individually # disabled by setting ``KDE_SKIP_UNINSTALL_TARGET`` to TRUE before including # this module. # # By default on OS X, X11 and XCB related detections are disabled. However if # the need would arise to use these technologies, the detection can be enabled # by setting ``APPLE_FORCE_X11`` to ``ON``. # # A warning is printed for the developer to know that the detection is disabled on OS X. # This message can be turned off by setting ``APPLE_SUPPRESS_X11_WARNING`` to ``ON``. # # Since pre-1.0.0. # # ``ENABLE_CLAZY`` option is added (OFF by default) when clang is being used. # Turning this option on will force clang to load the clazy plugins for richer # warnings on Qt-related code. # # If clang is not being used, this won't have an effect. # See https://commits.kde.org/clazy?path=README.md # # Since 5.17.0 # # - Uninstall target functionality since 1.7.0. # - ``APPLE_FORCE_X11`` option since 5.14.0 (detecting X11 was previously the default behavior) # - ``APPLE_SUPPRESS_X11_WARNING`` option since 5.14.0 # # Translations # ~~~~~~~~~~~~ # A fetch-translations target will be set up that will download translations # for projects using l10n.kde.org. # # ``KDE_L10N_BRANCH`` will be responsible for choosing which l10n branch to use # for the translations. # # ``KDE_L10N_AUTO_TRANSLATIONS`` (OFF by default) will indicate whether translations # should be downloaded when building the project. # # Since 5.34.0 # # ``KDE_L10N_SYNC_TRANSLATIONS`` (OFF by default) will download the translations at configuration # time instead of build time. # # Since 5.50.0 # # #============================================================================= # Copyright 2014 Alex Merry # Copyright 2013 Aleix Pol # Copyright 2012-2013 Stephen Kelly # Copyright 2007 Matthias Kretz # Copyright 2006-2007 Laurent Montel # Copyright 2006-2013 Alex Neundorf # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ################# RPATH handling ################################## if(NOT KDE_SKIP_RPATH_SETTINGS) # Set the default RPATH to point to useful locations, namely where the # libraries will be installed and the linker search path # First look for the old LIB_INSTALL_DIR, then fallback to newer KDE_INSTALL_LIBDIR if(NOT LIB_INSTALL_DIR) if(NOT KDE_INSTALL_LIBDIR) message(FATAL_ERROR "Neither KDE_INSTALL_LIBDIR nor LIB_INSTALL_DIR is set. Setting one is necessary for using the RPATH settings.") else() set(_abs_LIB_INSTALL_DIR "${KDE_INSTALL_LIBDIR}") endif() else() set(_abs_LIB_INSTALL_DIR "${LIB_INSTALL_DIR}") endif() if (NOT IS_ABSOLUTE "${_abs_LIB_INSTALL_DIR}") set(_abs_LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}") endif() if (UNIX) # for mac os: add install name dir in addition # check: is the rpath stuff below really required on mac os? at least it seems so to use a stock qt from qt.io if (APPLE) set(CMAKE_INSTALL_NAME_DIR ${_abs_LIB_INSTALL_DIR}) endif () # add our LIB_INSTALL_DIR to the RPATH (but only when it is not one of # the standard system link directories - such as /usr/lib on UNIX) list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${_abs_LIB_INSTALL_DIR}" _isSystemLibDir) list(FIND CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "${_abs_LIB_INSTALL_DIR}" _isSystemCxxLibDir) list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${_abs_LIB_INSTALL_DIR}" _isSystemCLibDir) if("${_isSystemLibDir}" STREQUAL "-1" AND "${_isSystemCxxLibDir}" STREQUAL "-1" AND "${_isSystemCLibDir}" STREQUAL "-1") set(CMAKE_INSTALL_RPATH "${_abs_LIB_INSTALL_DIR}") endif() # Append directories in the linker search path (but outside the project) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) endif (UNIX) endif() ################ Testing setup #################################### find_program(APPSTREAMCLI appstreamcli) function(appstreamtest) if(APPSTREAMCLI AND NOT appstreamtest_added) set(appstreamtest_added TRUE PARENT_SCOPE) add_test(NAME appstreamtest COMMAND ${CMAKE_COMMAND} -DAPPSTREAMCLI=${APPSTREAMCLI} -DINSTALL_FILES=${CMAKE_BINARY_DIR}/install_manifest.txt -P ${CMAKE_CURRENT_LIST_DIR}/appstreamtest.cmake) else() message(STATUS "Could not set up the appstream test. appstreamcli is missing.") endif() endfunction() if(NOT KDE_SKIP_TEST_SETTINGS) # If there is a CTestConfig.cmake, include CTest. # Otherwise, there will not be any useful settings, so just # fake the functionality we care about from CTest. if (EXISTS ${CMAKE_SOURCE_DIR}/CTestConfig.cmake) include(CTest) else() option(BUILD_TESTING "Build the testing tree." ON) if(BUILD_TESTING) enable_testing() appstreamtest() endif () endif () endif() ################ Build-related settings ########################### if(NOT KDE_SKIP_BUILD_SETTINGS) # Always include srcdir and builddir in include path # This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} in about every subdir # since cmake 2.4.0 set(CMAKE_INCLUDE_CURRENT_DIR ON) # put the include dirs which are in the source or build tree # before all other include dirs, so the headers in the sources # are preferred over the already installed ones # since cmake 2.4.1 set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) # Add the src and build dir to the BUILD_INTERFACE include directories # of all targets. Similar to CMAKE_INCLUDE_CURRENT_DIR, but transitive. # Since CMake 2.8.11 set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) # When a shared library changes, but its includes do not, don't relink # all dependencies. It is not needed. # Since CMake 2.8.11 set(CMAKE_LINK_DEPENDS_NO_SHARED ON) # Default to shared libs for KDE, if no type is explicitly given to add_library(): set(BUILD_SHARED_LIBS TRUE CACHE BOOL "If enabled, shared libs will be built by default, otherwise static libs") # Enable automoc in cmake # Since CMake 2.8.6 set(CMAKE_AUTOMOC ON) # By default, create 'GUI' executables. This can be reverted on a per-target basis # using ECMMarkNonGuiExecutable # Since CMake 2.8.8 set(CMAKE_WIN32_EXECUTABLE ON) set(CMAKE_MACOSX_BUNDLE ON) # By default, don't put a prefix on MODULE targets. add_library(MODULE) is basically for plugin targets, # and in KDE plugins don't have a prefix. set(CMAKE_SHARED_MODULE_PREFIX "") unset(EXECUTABLE_OUTPUT_PATH) unset(LIBRARY_OUTPUT_PATH) unset(CMAKE_ARCHIVE_OUTPUT_DIRECTORY) unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY) unset(CMAKE_RUNTIME_OUTPUT_DIRECTORY) # under Windows, output all executables and dlls into # one common directory, and all static|import libraries and plugins # into another one. This way test executables can find their dlls # even without installation. # We do the same under Unix to make it possible to run tests and apps without installing if (WIN32 OR NOT ("${ECM_GLOBAL_FIND_VERSION}" VERSION_LESS "5.38.0")) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") endif() if (APPLE) # Disable detection of X11 and related package on OS X because when using # brew or macports, X11 can be installed and thus is detected. option(APPLE_FORCE_X11 "Force enable X11 related detection on OS X" OFF) option(APPLE_SUPPRESS_X11_WARNING "Suppress X11 and related technologies search disabling warning on OS X" OFF) if(NOT APPLE_FORCE_X11) if (NOT APPLE_SUPPRESS_X11_WARNING) message(WARNING "Searching for X11 and related technologies is disabled on Apple systems. Set APPLE_FORCE_X11 to ON to change this behaviour. Set APPLE_SUPPRESS_X11_WARNING to ON to hide this warning.") endif() set(CMAKE_DISABLE_FIND_PACKAGE_X11 true) set(CMAKE_DISABLE_FIND_PACKAGE_XCB true) set(CMAKE_DISABLE_FIND_PACKAGE_Qt5X11Extras true) endif() endif() option(KDE_SKIP_UNINSTALL_TARGET "Prevent an \"uninstall\" target from being generated." OFF) if(NOT KDE_SKIP_UNINSTALL_TARGET) include("${ECM_MODULE_DIR}/ECMUninstallTarget.cmake") endif() endif() -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") option(ENABLE_CLAZY "Enable Clazy warnings" OFF) if(ENABLE_CLAZY) set(CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT} -Xclang -load -Xclang ClangLazy${CMAKE_SHARED_LIBRARY_SUFFIX} -Xclang -add-plugin -Xclang clang-lazy") endif() endif() ################################################################### # Download translations function(_repository_name reponame dir) execute_process(COMMAND git config --get remote.origin.url OUTPUT_VARIABLE giturl RESULT_VARIABLE exitCode WORKING_DIRECTORY "${dir}") if(exitCode EQUAL 0) string(REGEX MATCHALL ".+[:\\/]([-A-Za-z0-9]+)(.git)?\\s*" "" ${giturl}) set(${reponame} ${CMAKE_MATCH_1}) endif() if(NOT ${reponame}) set(${reponame} ${CMAKE_PROJECT_NAME}) endif() set(${reponame} ${${reponame}} PARENT_SCOPE) endfunction() if(NOT EXISTS ${CMAKE_SOURCE_DIR}/po AND NOT TARGET fetch-translations) option(KDE_L10N_AUTO_TRANSLATIONS "Automatically 'make fetch-translations`" OFF) option(KDE_L10N_SYNC_TRANSLATIONS "Fetch translations when KDECMakeSettings.cmake is processed." OFF) set(KDE_L10N_BRANCH "trunk" CACHE STRING "Branch from l10n.kde.org to fetch from: trunk | stable | lts | trunk_kde4 | stable_kde4") if(KDE_L10N_AUTO_TRANSLATIONS AND NOT KDE_L10N_SYNC_TRANSLATIONS) set(_EXTRA_ARGS "ALL") else() set(_EXTRA_ARGS) endif() set(_reponame "") _repository_name(_reponame "${CMAKE_SOURCE_DIR}") set(releaseme_clone_commands COMMAND git clone --depth 1 https://anongit.kde.org/releaseme.git ) add_custom_command( OUTPUT "${CMAKE_BINARY_DIR}/releaseme" ${releaseme_clone_commands} COMMENT "Fetching releaseme scripts to download translations..." ) set(_l10n_po_dir "${CMAKE_BINARY_DIR}/po") set(_l10n_poqm_dir "${CMAKE_BINARY_DIR}/poqm") if(CMAKE_VERSION VERSION_GREATER 3.2) set(extra BYPRODUCTS ${_l10n_po_dir} ${_l10n_poqm_dir}) endif() set(fetch_commands COMMAND ruby "${CMAKE_BINARY_DIR}/releaseme/fetchpo.rb" --origin ${KDE_L10N_BRANCH} --project "${_reponame}" --output-dir "${_l10n_po_dir}" --output-poqm-dir "${_l10n_poqm_dir}" "${CMAKE_CURRENT_SOURCE_DIR}" ) add_custom_target(fetch-translations ${_EXTRA_ARGS} COMMENT "Downloading translations for ${_reponame} branch ${KDE_L10N_BRANCH}..." COMMAND git -C "${CMAKE_BINARY_DIR}/releaseme" pull COMMAND cmake -E remove_directory ${_l10n_po_dir} COMMAND cmake -E remove_directory ${_l10n_poqm_dir} ${fetch_commands} ${extra} DEPENDS "${CMAKE_BINARY_DIR}/releaseme" ) if (KDE_L10N_SYNC_TRANSLATIONS AND (NOT EXISTS ${_l10n_po_dir} OR NOT EXISTS ${_l10n_poqm_dir})) execute_process(${releaseme_clone_commands}) execute_process(${fetch_commands}) endif() endif() diff --git a/kde-modules/KDECompilerSettings.cmake b/kde-modules/KDECompilerSettings.cmake index 44358fb..c713cc2 100644 --- a/kde-modules/KDECompilerSettings.cmake +++ b/kde-modules/KDECompilerSettings.cmake @@ -1,498 +1,498 @@ #.rst: # KDECompilerSettings # ------------------- # # Set useful compile and link flags for C++ (and C) code. # # Enables many more warnings than the default, and sets stricter modes # for some compiler features. By default, exceptions are disabled; # kde_target_enable_exceptions() can be used to re-enable them for a # specific target. # # NB: it is recommended to include this module with the NO_POLICY_SCOPE # flag, otherwise you may get spurious warnings with some versions of CMake. # # This module provides the following functions:: # # kde_source_files_enable_exceptions([file1 [file2 [...]]]) # # Enables exceptions for specific source files. This should not be # used on source files in a language other than C++. # # :: # # kde_target_enable_exceptions(target ) # # Enables exceptions for a specific target. This should not be used # on a target that has source files in a language other than C++. # # :: # # kde_enable_exceptions() # # Enables exceptions for C++ source files compiled for the # CMakeLists.txt file in the current directory and all subdirectories. # # Since pre-1.0.0. #============================================================================= # Copyright 2014 Alex Merry # Copyright 2013 Stephen Kelly # Copyright 2012-2013 Raphael Kubo da Costa # Copyright 2007 Matthias Kretz # Copyright 2006-2007 Laurent Montel # Copyright 2006-2013 Alex Neundorf # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ############################################################ # Toolchain minimal requirements # # Note that only compilers officially supported by Qt are # supported by this file; workarounds for older compilers # will generally not be included. See # https://qt-project.org/doc/qt-5/supported-platforms.html # and # https://community.kde.org/Frameworks/Policies#Frameworks_compiler_requirements_and_C.2B.2B11 # for more details. ############################################################ macro(_kde_compiler_min_version min_version) if ("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "${min_version}") message(WARNING "Version ${CMAKE_CXX_COMPILER_VERSION} of the ${CMAKE_CXX_COMPILER_ID} C++ compiler is not supported. Please use version ${min_version} or later.") endif() endmacro() if (MSVC) # MSVC_VERSION 1600 = VS 10.0 = Windows SDK 7 # See: cmake --help-variable MSVC_VERSION # and https://developer.mozilla.org/en-US/docs/Windows_SDK_versions if (${MSVC_VERSION} LESS 1600) message(WARNING "Your MSVC version (${MSVC_VERSION}) is not supported. Please use the Windows SDK version 7 or later (or Microsoft Visual Studio 2010 or later).") endif() elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if (WIN32) _kde_compiler_min_version("4.7") elseif (APPLE) # FIXME: Apple heavily modifies GCC, so checking the # GCC version on OS/X is not very useful. else() _kde_compiler_min_version("4.5") endif() elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") _kde_compiler_min_version("3.1") else() message(WARNING "${CMAKE_CXX_COMPILER_ID} is not a supported C++ compiler.") endif() ############################################################ # System API features ############################################################ # This macro is for adding definitions that affect the underlying # platform API. It makes sure that configure checks will also have # the same defines, so that the checks match compiled code. macro (_KDE_ADD_PLATFORM_DEFINITIONS) add_definitions(${ARGV}) set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} ${ARGV}) endmacro() include(CheckSymbolExists) check_symbol_exists("__GLIBC__" "stdlib.h" LIBC_IS_GLIBC) if (LIBC_IS_GLIBC) # Enable everything in GNU libc. Any code using non-portable features # needs to perform feature tests, but this ensures that any such features # will be found if they exist. # # NB: we do NOT define _BSD_SOURCE, as with GNU libc that requires linking # against the -lbsd-compat library (it changes the behaviour of some # functions). This, however, means that strlcat and strlcpy are not # provided by glibc. _kde_add_platform_definitions(-D_GNU_SOURCE) endif () if (UNIX) # Enable extra API for using 64-bit file offsets on 32-bit systems. # FIXME: this is included in _GNU_SOURCE in glibc; do other libc # implementation recognize it? _kde_add_platform_definitions(-D_LARGEFILE64_SOURCE) include(CheckCXXSourceCompiles) # By default (in glibc, at least), on 32bit platforms off_t is 32 bits, # which causes a SIGXFSZ when trying to manipulate files larger than 2Gb # using libc calls (note that this issue does not occur when using QFile). check_cxx_source_compiles(" #include /* Check that off_t can represent 2**63 - 1 correctly. We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int main() { return 0; } " _OFFT_IS_64BIT) if (NOT _OFFT_IS_64BIT) _kde_add_platform_definitions(-D_FILE_OFFSET_BITS=64) endif () endif() if (WIN32) # Speeds up compile times by not including everything with windows.h # See http://msdn.microsoft.com/en-us/library/windows/desktop/aa383745%28v=vs.85%29.aspx _kde_add_platform_definitions(-DWIN32_LEAN_AND_MEAN) # Target Windows Vista # This enables various bits of new API # See http://msdn.microsoft.com/en-us/library/windows/desktop/aa383745%28v=vs.85%29.aspx _kde_add_platform_definitions(-D_WIN32_WINNT=0x0600 -DWINVER=0x0600 -D_WIN32_IE=0x0600) # Use the Unicode versions of Windows API by default # See http://msdn.microsoft.com/en-us/library/windows/desktop/dd317766%28v=vs.85%29.aspx _kde_add_platform_definitions(-DUNICODE -D_UNICODE) # As stated in http://msdn.microsoft.com/en-us/library/4hwaceh6.aspx M_PI only gets defined # if _USE_MATH_DEFINES is defined, with mingw this has a similar effect as -D_GNU_SOURCE on math.h _kde_add_platform_definitions(-D_USE_MATH_DEFINES) endif() ############################################################ # Language and toolchain features ############################################################ # Pick sensible versions of the C and C++ standards. # Note that MSVC does not have equivalent flags; the features are either # supported or they are not. if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") # We use the C89 standard because that is what is common to all our # compilers (in particular, MSVC 2010 does not support C99) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=iso9899:1990") endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") endif() # Do not merge uninitialized global variables. # This is mostly a "principle of least surprise" thing, but also # has performance benefits. # See https://www.ibm.com/developerworks/community/blogs/zTPF/entry/benefits_of_the_fnocommon_compile_option_peter_lemieszewski?lang=en # Note that this only applies to C code; C++ already behaves like this. if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-common") endif() # Do not treat the operator name keywords and, bitand, bitor, compl, not, or and xor as synonyms as keywords. # They're not supported under Visual Studio out of the box thus using them limits the portability of code if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-operator-names") endif() # Default to hidden visibility for symbols set(CMAKE_C_VISIBILITY_PRESET hidden) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) if (POLICY CMP0063) # No sane project should be affected by CMP0063, so suppress the warnings # generated by the above visibility settings in CMake >= 3.3 cmake_policy(SET CMP0063 NEW) endif() if (UNIX AND NOT APPLE AND NOT CYGWIN) # Enable adding DT_RUNPATH, which means that LD_LIBRARY_PATH takes precedence # over the built-in rPath set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-new-dtags ${CMAKE_SHARED_LINKER_FLAGS}") set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--enable-new-dtags ${CMAKE_MODULE_LINKER_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags ${CMAKE_EXE_LINKER_FLAGS}") endif() if (CMAKE_SYSTEM_NAME STREQUAL GNU) # Enable multithreading with the pthread library # FIXME: Is this actually necessary to have here? # Can CMakeLists.txt files that require it use FindThreads.cmake # instead? set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pthread") endif() ############################################################ # Turn off exceptions by default # # This involves enough code to be separate from the # previous section. ############################################################ # TODO: Deal with QT_NO_EXCEPTIONS for non-gnu compilers? # This should be defined if and only if exceptions are disabled. # qglobal.h has some magic to set it when exceptions are disabled # with gcc, but other compilers are unaccounted for. # Turn off exceptions by default if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") #elseif (MSVC OR (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Intel")) # Exceptions appear to be disabled by default for MSVC # http://msdn.microsoft.com/en-us/library/1deeycx5.aspx # FIXME: are exceptions disabled by default for Intel? endif() macro(_kdecompilersettings_append_exception_flag VAR) if (MSVC) set(${VAR} "${${VAR}} -EHsc") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") if (WIN32) set(${VAR} "${${VAR}} -EHsc") else() set(${VAR} "${${VAR}} -fexceptions") endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(${VAR} "${${VAR}} -fexceptions") elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(${VAR} "${${VAR}} -fexceptions") endif() string(STRIP "${${VAR}}" ${VAR}) endmacro() function(KDE_SOURCE_FILES_ENABLE_EXCEPTIONS) foreach(source_file ${ARGV}) get_source_file_property(flags ${source_file} COMPILE_FLAGS) if(NOT flags) # If COMPILE_FLAGS is not set, get_source_file_property() sets it to # NOTFOUND, which breaks build if we concatenate anything to # the "NOTFOUND" string. # Note that NOTFOUND evaluates to False, so we do enter the if. set(flags "") endif() _kdecompilersettings_append_exception_flag(flags) set_source_files_properties(${source_file} COMPILE_FLAGS "${flags}") endforeach() endfunction() function(KDE_TARGET_ENABLE_EXCEPTIONS target mode) target_compile_options(${target} ${mode} "$<$:-EHsc>") if (WIN32) target_compile_options(${target} ${mode} "$<$:-EHsc>") else() target_compile_options(${target} ${mode} "$<$:-fexceptions>") endif() target_compile_options(${target} ${mode} "$<$,$,$>:-fexceptions>") endfunction() function(KDE_ENABLE_EXCEPTIONS) # We set CMAKE_CXX_FLAGS, rather than add_compile_options(), because # we only want to affect the compilation of C++ source files. # strip any occurrences of -DQT_NO_EXCEPTIONS; this should only be defined # if exceptions are disabled # the extra spaces mean we will not accentially mangle any other options string(REPLACE " -DQT_NO_EXCEPTIONS " " " CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} ") # this option is common to several compilers, so just always remove it string(REPLACE " -fno-exceptions " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # strip undoes the extra spaces we put in above string(STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS) _kdecompilersettings_append_exception_flag(CMAKE_CXX_FLAGS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE) endfunction() ############################################################ # Better diagnostics (warnings, errors) ############################################################ if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT APPLE) OR - (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE) OR + (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT APPLE) OR (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)) # Linker warnings should be treated as errors set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--fatal-warnings ${CMAKE_SHARED_LINKER_FLAGS}") set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--fatal-warnings ${CMAKE_MODULE_LINKER_FLAGS}") # Do not allow undefined symbols, even in non-symbolic shared libraries set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined ${CMAKE_SHARED_LINKER_FLAGS}") set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined ${CMAKE_MODULE_LINKER_FLAGS}") endif() set(_KDE_GCC_COMMON_WARNING_FLAGS "-Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wpointer-arith -Wundef") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # -Wgnu-zero-variadic-macro-arguments (part of -pedantic) is triggered by every qCDebug() call and therefore results # in a lot of noise. This warning is only notifying us that clang is emulating the GCC behaviour # instead of the exact standard wording so we can safely ignore it set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-zero-variadic-macro-arguments") endif() if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_KDE_GCC_COMMON_WARNING_FLAGS} -Wmissing-format-attribute -Wwrite-strings") # Make some warnings errors set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=implicit-function-declaration") endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_KDE_GCC_COMMON_WARNING_FLAGS} -Wnon-virtual-dtor -Woverloaded-virtual") # Make some warnings errors set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type") endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)) # -Wvla: use of variable-length arrays (an extension to C++) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla") endif() if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)) include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-Wdate-time HAVE_DATE_TIME) if (HAVE_DATE_TIME) # -Wdate-time: warn if we use __DATE__ or __TIME__ (we want to be able to reproduce the exact same binary) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdate-time") endif() endif() # -w1 turns on warnings and errors # FIXME: someone needs to have a closer look at the Intel compiler options if (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -w1 -Wpointer-arith") endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -w1 -Wpointer-arith") endif() if (MSVC) # FIXME: do we not want to set the warning level up to level 3? (/W3) # Disable warnings: # C4250: 'class1' : inherits 'class2::member' via dominance set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4250") # C4251: 'identifier' : class 'type' needs to have dll-interface to be # used by clients of class 'type2' set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251") # C4396: 'identifier' : 'function' the inline specifier cannot be used # when a friend declaration refers to a specialization of a # function template set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4396") # C4661: 'identifier' : no suitable definition provided for explicit # template instantiation request set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4661") endif() if (WIN32) # Disable deprecation warnings for some API # FIXME: do we really want this? add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS ) endif() if (APPLE) #full Single Unix Standard v3 (SUSv3) conformance (the Unix API) _kde_add_platform_definitions(-D_DARWIN_C_SOURCE) #Cocoa is unconditional since we only support OS X 10.6 and above _kde_add_platform_definitions(-DQT_MAC_USE_COCOA) endif() ############################################################ # Hacks # # Anything in this section should be thoroughly documented, # including what problems it is supposed to fix and in what # circumstances those problems occur. Include links to any # relevant bug reports. ############################################################ if (APPLE) # FIXME: why are these needed? The commit log is unhelpful # (it was introduced in svn path=/trunk/KDE/kdelibs/; revision=503025 - # kdelibs git commit 4e4cb9cb9a2216b63d3eabf88b8fe94ee3c898cf - # with the message "mac os x fixes for the cmake build") set (CMAKE_SHARED_LINKER_FLAGS "-single_module -multiply_defined suppress ${CMAKE_SHARED_LINKER_FLAGS}") set (CMAKE_MODULE_LINKER_FLAGS "-multiply_defined suppress ${CMAKE_MODULE_LINKER_FLAGS}") endif() if (WIN32) if (MSVC OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel") # MSVC has four incompatible C runtime libraries: static (libcmt), # static debug (libcmtd), shared (msvcrt) and shared debug (msvcrtd): # see http://support.microsoft.com/kb/154753 # # By default, when you create static libraries, they are automatically # linked against either libcmt or libcmtd, and when you create shared # libraries, they are automatically linked against either msvcrt or # msvcrtd. Trying to link to both a library that links to libcmt and # library that links to mscvrt, for example, will produce a warning as # described at # http://msdn.microsoft.com/en-us/library/aa267384%28VS.60%29.aspx # and can produce link errors like # "__thiscall type_info::type_info(class type_info const &)" # (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj) # # It is actually the options passed to the compiler, rather than the # linker, which control what will be linked (/MT, /MTd, /MD or /MDd), # but we can override this by telling the linker to ignore any "libcmt" # or "libcmtd" link suggestion embedded in the object files, and instead # link against the shared versions. That way, everything will link # against the same runtime library. set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt ${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}") set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/NODEFAULTLIB:libcmtd /DEFAULTLIB:msvcrtd ${CMAKE_EXE_LINKER_FLAGS_DEBUG}") endif() endif() if (MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # This was copied from the Phonon build settings, where it had the comment # "otherwise undefined symbol in phononcore.dll errors occurs", with the commit # message "set linker flag --export-all-symbols for all targets, otherwise # some depending targets could not be build" # FIXME: do our export macros not deal with this properly? set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols") set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--export-all-symbols") endif() if (CMAKE_GENERATOR STREQUAL "Ninja" AND ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR - (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5))) + (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5))) # Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support. # Rationale in https://github.com/ninja-build/ninja/issues/814 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") endif() include("${ECM_MODULE_DIR}/ECMEnableSanitizers.cmake") include("${ECM_MODULE_DIR}/ECMCoverageOption.cmake") diff --git a/kde-modules/KDEFrameworkCompilerSettings.cmake b/kde-modules/KDEFrameworkCompilerSettings.cmake index 1d3e1f7..b191e55 100644 --- a/kde-modules/KDEFrameworkCompilerSettings.cmake +++ b/kde-modules/KDEFrameworkCompilerSettings.cmake @@ -1,78 +1,78 @@ #.rst: # KDEFrameworkCompilerSettings # ---------------------------- # # Set stricter compile and link flags for KDE Frameworks modules. # # The KDECompilerSettings module is included and, in addition, various # defines that affect the Qt libraries are set to enforce certain # conventions. # # For example, constructions like QString("foo") are prohibited, instead # forcing the use of QLatin1String or QStringLiteral, and some # Qt-defined keywords like signals and slots will not be defined. # # NB: it is recommended to include this module with the NO_POLICY_SCOPE # flag, otherwise you may get spurious warnings with some versions of CMake. # # Since pre-1.0.0. #============================================================================= # Copyright 2013 Albert Astals Cid # Copyright 2007 Matthias Kretz # Copyright 2006-2007 Laurent Montel # Copyright 2006-2013 Alex Neundorf # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. include(KDECompilerSettings NO_POLICY_SCOPE) add_definitions(-DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_URL_CAST_FROM_STRING -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_SIGNALS_SLOTS_KEYWORDS -DQT_USE_QSTRINGBUILDER -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT ) if (CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions(-DQT_STRICT_ITERATORS) endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override -Wlogical-op -Wzero-as-null-pointer-constant" ) endif() endif() -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant" ) endif() endif() diff --git a/modules/ECMEnableSanitizers.cmake b/modules/ECMEnableSanitizers.cmake index 9a77c6f..10b058c 100644 --- a/modules/ECMEnableSanitizers.cmake +++ b/modules/ECMEnableSanitizers.cmake @@ -1,177 +1,177 @@ #.rst: # ECMEnableSanitizers # ------------------- # # Enable compiler sanitizer flags. # # The following sanitizers are supported: # # - Address Sanitizer # - Memory Sanitizer # - Thread Sanitizer # - Leak Sanitizer # - Undefined Behaviour Sanitizer # # All of them are implemented in Clang, depending on your version, and # there is an work in progress in GCC, where some of them are currently # implemented. # # This module will check your current compiler version to see if it # supports the sanitizers that you want to enable # # Usage # ===== # # Simply add:: # # include(ECMEnableSanitizers) # # to your ``CMakeLists.txt``. Note that this module is included in # KDECompilerSettings, so projects using that module do not need to also # include this one. # # The sanitizers are not enabled by default. Instead, you must set # ``ECM_ENABLE_SANITIZERS`` (either in your ``CMakeLists.txt`` or on the # command line) to a semicolon-separated list of sanitizers you wish to enable. # The options are: # # - address # - memory # - thread # - leak # - undefined # - fuzzer # # The sanitizers "address", "memory" and "thread" are mutually exclusive. You # cannot enable two of them in the same build. # # "leak" requires the "address" sanitizer. # # .. note:: # # To reduce the overhead induced by the instrumentation of the sanitizers, it # is advised to enable compiler optimizations (``-O1`` or higher). # # Example # ======= # # This is an example of usage:: # # mkdir build # cd build # cmake -DECM_ENABLE_SANITIZERS='address;leak;undefined' .. # # .. note:: # # Most of the sanitizers will require Clang. To enable it, use:: # # -DCMAKE_CXX_COMPILER=clang++ # # Since 1.3.0. #============================================================================= # Copyright 2014 Mathieu Tarral # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # MACRO check_compiler_version #----------------------------- macro (check_compiler_version gcc_required_version clang_required_version) if ( ( CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${gcc_required_version} ) OR ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${clang_required_version} ) ) # error ! message(FATAL_ERROR "You ask to enable the sanitizer ${CUR_SANITIZER}, but your compiler ${CMAKE_CXX_COMPILER_ID} version ${CMAKE_CXX_COMPILER_VERSION} does not support it ! You should use at least GCC ${gcc_required_version} or Clang ${clang_required_version} (99.99 means not implemented yet)") endif () endmacro () # MACRO check_compiler_support #------------------------------ macro (enable_sanitizer_flags sanitize_option) if (${sanitize_option} MATCHES "address") check_compiler_version("4.8" "3.1") set(XSAN_COMPILE_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") set(XSAN_LINKER_FLAGS "asan") elseif (${sanitize_option} MATCHES "thread") check_compiler_version("4.8" "3.1") set(XSAN_COMPILE_FLAGS "-fsanitize=thread") set(XSAN_LINKER_FLAGS "tsan") elseif (${sanitize_option} MATCHES "memory") check_compiler_version("99.99" "3.1") set(XSAN_COMPILE_FLAGS "-fsanitize=memory") elseif (${sanitize_option} MATCHES "leak") check_compiler_version("4.9" "3.4") set(XSAN_COMPILE_FLAGS "-fsanitize=leak") set(XSAN_LINKER_FLAGS "lsan") elseif (${sanitize_option} MATCHES "undefined") check_compiler_version("4.9" "3.1") set(XSAN_COMPILE_FLAGS "-fsanitize=undefined -fno-omit-frame-pointer -fno-optimize-sibling-calls") elseif (${sanitize_option} MATCHES "fuzzer") check_compiler_version("99.99" "6.0") set(XSAN_COMPILE_FLAGS "-fsanitize=fuzzer") else () message(FATAL_ERROR "Compiler sanitizer option \"${sanitize_option}\" not supported.") endif () endmacro () if (ECM_ENABLE_SANITIZERS) if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") # for each element of the ECM_ENABLE_SANITIZERS list foreach ( CUR_SANITIZER ${ECM_ENABLE_SANITIZERS} ) # lowercase filter string(TOLOWER ${CUR_SANITIZER} CUR_SANITIZER) # check option and enable appropriate flags enable_sanitizer_flags ( ${CUR_SANITIZER} ) # TODO: GCC will not link pthread library if enabled ASan if(CMAKE_C_COMPILER_ID MATCHES "Clang") set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XSAN_COMPILE_FLAGS}" ) endif() set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${XSAN_COMPILE_FLAGS}" ) if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") link_libraries(${XSAN_LINKER_FLAGS}) endif() - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") string(REPLACE "-Wl,--no-undefined" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") string(REPLACE "-Wl,--no-undefined" "" CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}") endif () endforeach() else() message(STATUS "Tried to enable sanitizers (-DECM_ENABLE_SANITIZERS=${ECM_ENABLE_SANITIZERS}), \ but compiler (${CMAKE_CXX_COMPILER_ID}) does not have sanitizer support") endif() endif()