[evolution-data-server/wip/cmake] Compiler flags to build flags module



commit 4f6f809df704a74d0b72a4294aef1a7eaa7c672c
Author: Milan Crha <mcrha redhat com>
Date:   Tue Sep 20 13:55:48 2016 +0200

    Compiler flags to build flags module

 CMakeLists.txt                                     |    6 ++--
 cmake/modules/CodeCoverageGCOV.cmake               |   10 +++++-
 ...lerWarningFlags.cmake => SetupBuildFlags.cmake} |   34 ++++++++++++-------
 3 files changed, 32 insertions(+), 18 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4fcb172..4d2f876 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -129,7 +129,7 @@ add_printable_variable_path(SYSCONF_INSTALL_DIR "Install directory for system co
 include(CodeCoverageGCOV)
 include(DistTarget)
 include(PkgConfigEx)
-include(SetupCompilerWarningFlags)
+include(SetupBuildFlags)
 include(UninstallTarget)
 
 include(FindKRB5)
@@ -137,8 +137,8 @@ include(FindSMIME)
 
 add_printable_option(ENABLE_MAINTAINER_MODE "Enable maintainer mode" OFF)
 
-# Compiler warning flags
-setup_compiler_warning_flags(${ENABLE_MAINTAINER_MODE})
+# Setup compiler/linker flags
+setup_build_flags(${ENABLE_MAINTAINER_MODE})
 
 check_c_compiler_flag(-fno-strict-aliasing _flag_supported)
 if(_flag_supported)
diff --git a/cmake/modules/CodeCoverageGCOV.cmake b/cmake/modules/CodeCoverageGCOV.cmake
index 1c7801f..aa33677 100644
--- a/cmake/modules/CodeCoverageGCOV.cmake
+++ b/cmake/modules/CodeCoverageGCOV.cmake
@@ -20,10 +20,16 @@ if(ENABLE_CODE_COVERAGE)
        if("${CMAKE_C_COMPILER_ID}" STREQUAL "gcc")
                CHECK_LIBRARY_EXISTS("gcov" "gcov_exit" "" HAVE_GCOV_LIBRARY)
                if(HAVE_GCOV_LIBRARY)
-                       set(CODE_COVERAGE_DEFINES "-DNDEBUG")
                        set(CODE_COVERAGE_CFLAGS "-O0 -g -fprofile-arcs -ftest-coverage")
-                       set(CODE_COVERAGE_CXXFLAGS "-O0 -g -fprofile-arcs -ftest-coverage")
                        set(CODE_COVERAGE_LDFLAGS "-lgcov")
+
+                       add_definitions(-DNDEBUG)
+                       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CODE_COVERAGE_CFLAGS}")
+                       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CODE_COVERAGE_CFLAGS}")
+                       set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CODE_COVERAGE_LDFLAGS}")
+                       set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${CODE_COVERAGE_LDFLAGS}")
+                       set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CODE_COVERAGE_LDFLAGS}")
+                       set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${CODE_COVERAGE_LDFLAGS}")
                else(HAVE_GCOV_LIBRARY)
                        message(FATAL_ERROR "Cannot fing gcov library, use -DENABLE_CODE_COVERAGE=OFF disable 
it")
                endif(HAVE_GCOV_LIBRARY)
diff --git a/cmake/modules/SetupCompilerWarningFlags.cmake b/cmake/modules/SetupBuildFlags.cmake
similarity index 52%
rename from cmake/modules/SetupCompilerWarningFlags.cmake
rename to cmake/modules/SetupBuildFlags.cmake
index 6cd2e37..ac88ff5 100644
--- a/cmake/modules/SetupCompilerWarningFlags.cmake
+++ b/cmake/modules/SetupBuildFlags.cmake
@@ -1,12 +1,12 @@
-# SetupCompilerWarningFlags.cmake
+# SetupBuildFlags.cmake
 #
-# Setups compiler warning flags, skipping those which are not supported.
+# Setups compiler/linker flags, skipping those which are not supported.
 
 include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
 
-function(setup_compiler_warning_flags _maintainer_mode)
-       list(APPEND proposed_warning_flags
+function(setup_build_flags _maintainer_mode)
+       list(APPEND proposed_flags
                -Werror-implicit-function-declaration
                -Wformat
                -Wformat-security
@@ -18,20 +18,21 @@ function(setup_compiler_warning_flags _maintainer_mode)
                -Wredundant-decls
                -Wundef
                -Wwrite-strings
+               -no-undefined
        )
 
        if(_maintainer_mode)
-               list(APPEND proposed_warning_flags
+               list(APPEND proposed_flags
                        -Wall
                        -Wextra
                        -Wdeprecated-declarations
                )
        else(_maintainer_mode)
-               list(APPEND proposed_warning_flags -Wno-deprecated-declarations)
+               list(APPEND proposed_flags -Wno-deprecated-declarations)
        endif(_maintainer_mode)
 
-       list(APPEND proposed_c_warning_flags
-               ${proposed_warning_flags}
+       list(APPEND proposed_c_flags
+               ${proposed_flags}
                -Wdeclaration-after-statement
                -Wno-missing-field-initializers
                -Wno-sign-compare
@@ -40,19 +41,19 @@ function(setup_compiler_warning_flags _maintainer_mode)
        )
 
        if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
-               list(APPEND proposed_c_warning_flags
+               list(APPEND proposed_c_flags
                        -Wno-parentheses-equality
                        -Wno-format-nonliteral
                )
        endif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
 
-       list(APPEND proposed_cxx_warning_flags
-               ${proposed_warning_flags}
+       list(APPEND proposed_cxx_flags
+               ${proposed_flags}
                -Wabi
                -Wnoexcept
        )
 
-       foreach(flag IN LISTS proposed_c_warning_flags)
+       foreach(flag IN LISTS proposed_c_flags)
                check_c_compiler_flag(${flag} _flag_supported)
                if(_flag_supported)
                        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
@@ -60,11 +61,18 @@ function(setup_compiler_warning_flags _maintainer_mode)
                unset(_flag_supported)
        endforeach()
 
-       foreach(flag IN LISTS proposed_cxx_warning_flags)
+       foreach(flag IN LISTS proposed_cxx_flags)
                check_cxx_compiler_flag(${flag} _flag_supported)
                if(_flag_supported)
                        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
                endif(_flag_supported)
                unset(_flag_supported)
        endforeach()
+
+       if(("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "gcc"))
+               set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
+               set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
+               set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
+               set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -Wl,--no-undefined")
+       endif(("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "gcc"))
 endfunction()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]