~ubuntu-branches/ubuntu/precise/libssh/precise

« back to all changes in this revision

Viewing changes to cmake/Modules/DefineCompilerFlags.cmake

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-06-15 15:48:07 UTC
  • mfrom: (1.1.10 upstream) (4.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20110615154807-3muklcqfftr1vtch
Tags: 0.5.0-2
* debian/patches/0002-Check-for-NULL-pointers-in-string-c.patch:
  Consolidate patch (Should fix previous REJECT)
* Support multiarch spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# define system dependent compiler flags
2
2
 
3
3
include(CheckCCompilerFlag)
 
4
include(MacroCheckCCompilerFlagSSP)
4
5
 
5
6
if (UNIX AND NOT WIN32)
6
 
  if (${CMAKE_C_COMPILER_ID} MATCHES GNU)
7
 
    # add -Wconversion ?
8
 
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -Wall -Wextra -Wshadow -Wmissing-prototypes -Wdeclaration-after-statement -Wunused -Wfloat-equal -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute")
9
 
 
10
 
    # with -fPIC
11
 
    check_c_compiler_flag("-fPIC" WITH_FPIC)
12
 
    if (WITH_FPIC)
13
 
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
14
 
    endif (WITH_FPIC)
15
 
 
16
 
    check_c_compiler_flag("-fstack-protector" WITH_STACK_PROTECTOR)
17
 
    if (WITH_STACK_PROTECTOR)
18
 
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
19
 
    endif (WITH_STACK_PROTECTOR)
20
 
 
21
 
    check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
22
 
    if (WITH_FORTIFY_SOURCE)
23
 
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2")
24
 
    endif (WITH_FORTIFY_SOURCE)
25
 
 
26
 
  endif (${CMAKE_C_COMPILER_ID} MATCHES GNU)
27
 
 
28
 
  if (CMAKE_SIZEOF_VOID_P MATCHES "8")
29
 
   # with large file support
30
 
   execute_process(
31
 
     COMMAND
32
 
       getconf LFS64_CFLAGS
33
 
     OUTPUT_VARIABLE
34
 
       _lfs_CFLAGS
35
 
     ERROR_QUIET
36
 
     OUTPUT_STRIP_TRAILING_WHITESPACE
37
 
   )
38
 
 else (CMAKE_SIZEOF_VOID_P MATCHES "8")
39
 
   # with large file support
40
 
   execute_process(
41
 
     COMMAND
42
 
       getconf LFS_CFLAGS
43
 
     OUTPUT_VARIABLE
44
 
       _lfs_CFLAGS
45
 
     ERROR_QUIET
46
 
     OUTPUT_STRIP_TRAILING_WHITESPACE
47
 
   )
48
 
 endif (CMAKE_SIZEOF_VOID_P MATCHES "8")
49
 
 if (_lfs_CFLAGS)
50
 
   string(REGEX REPLACE "[\r\n]" " " "${_lfs_CFLAGS}" "${${_lfs_CFLAGS}}")
51
 
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_lfs_CFLAGS}")
52
 
 endif (_lfs_CFLAGS)
 
7
    #
 
8
    # Define GNUCC compiler flags
 
9
    #
 
10
    if (${CMAKE_C_COMPILER_ID} MATCHES GNU)
 
11
        # add -Wconversion ?
 
12
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -pedantic-errors")
 
13
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wshadow -Wmissing-prototypes -Wdeclaration-after-statement")
 
14
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused -Wfloat-equal -Wpointer-arith -Wwrite-strings -Wformat-security")
 
15
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-format-attribute")
 
16
 
 
17
        # with -fPIC
 
18
        check_c_compiler_flag("-fPIC" WITH_FPIC)
 
19
        if (WITH_FPIC)
 
20
            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
 
21
        endif (WITH_FPIC)
 
22
 
 
23
        check_c_compiler_flag_ssp("-fstack-protector" WITH_STACK_PROTECTOR)
 
24
        if (WITH_STACK_PROTECTOR)
 
25
            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
 
26
        endif (WITH_STACK_PROTECTOR)
 
27
 
 
28
        check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
 
29
        if (WITH_FORTIFY_SOURCE)
 
30
            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2")
 
31
        endif (WITH_FORTIFY_SOURCE)
 
32
    endif (${CMAKE_C_COMPILER_ID} MATCHES GNU)
 
33
 
 
34
    #
 
35
    # Check for large filesystem support
 
36
    #
 
37
    if (CMAKE_SIZEOF_VOID_P MATCHES "8")
 
38
        # with large file support
 
39
        execute_process(
 
40
            COMMAND
 
41
                getconf LFS64_CFLAGS
 
42
            OUTPUT_VARIABLE
 
43
                _lfs_CFLAGS
 
44
            ERROR_QUIET
 
45
            OUTPUT_STRIP_TRAILING_WHITESPACE
 
46
        )
 
47
    else (CMAKE_SIZEOF_VOID_P MATCHES "8")
 
48
        # with large file support
 
49
        execute_process(
 
50
            COMMAND
 
51
                getconf LFS_CFLAGS
 
52
            OUTPUT_VARIABLE
 
53
                _lfs_CFLAGS
 
54
            ERROR_QUIET
 
55
            OUTPUT_STRIP_TRAILING_WHITESPACE
 
56
        )
 
57
    endif (CMAKE_SIZEOF_VOID_P MATCHES "8")
 
58
    if (_lfs_CFLAGS)
 
59
        string(REGEX REPLACE "[\r\n]" " " "${_lfs_CFLAGS}" "${${_lfs_CFLAGS}}")
 
60
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_lfs_CFLAGS}")
 
61
    endif (_lfs_CFLAGS)
53
62
 
54
63
endif (UNIX AND NOT WIN32)
55
64
 
56
 
# suppress warning about "deprecated" functions
57
65
if (MSVC)
58
 
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
 
66
    # Use secure functions by defaualt and suppress warnings about
 
67
    #"deprecated" functions
 
68
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1")
 
69
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1")
 
70
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_NONSTDC_NO_WARNINGS=1 /D _CRT_SECURE_NO_WARNINGS=1")
59
71
endif (MSVC)