|
| 1 | +# Copyright (c) 2014, Siemens AG. All rights reserved. |
| 2 | +# |
| 3 | +# Redistribution and use in source and binary forms, with or without |
| 4 | +# modification, are permitted provided that the following conditions are met: |
| 5 | +# |
| 6 | +# 1. Redistributions of source code must retain the above copyright notice, |
| 7 | +# this list of conditions and the following disclaimer. |
| 8 | +# |
| 9 | +# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 10 | +# this list of conditions and the following disclaimer in the documentation |
| 11 | +# and/or other materials provided with the distribution. |
| 12 | +# |
| 13 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 14 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 16 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 17 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 23 | +# POSSIBILITY OF SUCH DAMAGE. |
| 24 | + |
| 25 | +## DETERMINE COMPILER AND LINKER FLAGS |
| 26 | +# |
| 27 | +function(SetGNUCompilerFlags compiler_libs) |
| 28 | + if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) |
| 29 | + set(compiler_libs pthread rt PARENT_SCOPE) |
| 30 | + # -Wall -> All warnings |
| 31 | + # -Wextra -> Even more warnings |
| 32 | + # -Werror -> Warnings are errors |
| 33 | + set(warning_flags "-Wall -Wextra") |
| 34 | + if (WARNINGS_ARE_ERRORS STREQUAL ON) |
| 35 | + set(warning_flags "${warning_flags} -Werror") |
| 36 | + endif() |
| 37 | + if(CMAKE_COMPILER_IS_GNUCC) |
| 38 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -std=c99 ${warning_flags}" |
| 39 | + PARENT_SCOPE) |
| 40 | + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DEMBB_DEBUG" |
| 41 | + PARENT_SCOPE) |
| 42 | + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG" |
| 43 | + PARENT_SCOPE) |
| 44 | + endif() |
| 45 | + if(CMAKE_COMPILER_IS_GNUCXX) |
| 46 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++03 ${warning_flags}" |
| 47 | + PARENT_SCOPE) |
| 48 | + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DEMBB_DEBUG" |
| 49 | + PARENT_SCOPE) |
| 50 | + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG" |
| 51 | + PARENT_SCOPE) |
| 52 | + endif() |
| 53 | + endif() |
| 54 | +endfunction() |
| 55 | + |
| 56 | +function(SetVisualStudioCompilerFlags) |
| 57 | + if(MSVC) |
| 58 | + # /Wall -> All warnings |
| 59 | + # /WX -> Warnings as errors |
| 60 | + # |
| 61 | + # Globally deactivated warning numbers (by flag \wd#): |
| 62 | + # 4820 -> Deactivates warning "2/4/... bytes padding added after some type" |
| 63 | + # 4514 -> Deactivates warning "'fct': unreferenced inline function has |
| 64 | + # been removed" |
| 65 | + # 4668 -> Deactivates warning "'macro' is not defined as preprocessor macro, |
| 66 | + # replacing with '0' in #if/#elif" |
| 67 | + # 4710 -> Deactivates warning "Function not inlined" |
| 68 | + # 4350 -> Deactivates warning "Behavior change ...", which warns a |
| 69 | + # behavior change since VS C++ 2002, when using R-values as |
| 70 | + # L-value arguments. This warning occurs a lot in the VC libs. |
| 71 | + # 4571 -> Deactivates warning that when compiling with /EHs, |
| 72 | + # a catch(...) block will not catch a structured exception. |
| 73 | + # 4625 -> Deactivates warning for derived classes |
| 74 | + # when copy constructor could not be generated because |
| 75 | + # a base class copy constructor is inaccessible |
| 76 | + # 4626 -> Deactivates warning for derived classes |
| 77 | + # when assignment operator could not be generated because |
| 78 | + # a base class assignment operator is inaccessible |
| 79 | + # 4711 -> Deactivates warning for inline functions |
| 80 | + # This is only an informational warning about which functions |
| 81 | + # have been inlined by the compiler. |
| 82 | + # 4255 -> Deactivates warning "no function prototype given converting () to (void)" |
| 83 | + # |
| 84 | + # Locally suppressed warnings (should not be globally suppressed): |
| 85 | + # 4640 -> Information that local static variable initialization is not |
| 86 | + # thread-safe. |
| 87 | + set(warning_flags "/Wall /wd4820 /wd4514 /wd4668 /wd4710 /wd4350 /wd4571 /wd4625 /wd4626 /wd4711 /wd4255") |
| 88 | + if (WARNINGS_ARE_ERRORS STREQUAL ON) |
| 89 | + set(warning_flags "${warning_flags} /WX") |
| 90 | + endif() |
| 91 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${warning_flags}" PARENT_SCOPE) |
| 92 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${warning_flags}" PARENT_SCOPE) |
| 93 | + endif() |
| 94 | +endfunction() |
0 commit comments