File: DefineCompilerFlags.cmake

package info (click to toggle)
qmapshack 1.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 50,532 kB
  • sloc: cpp: 379,209; python: 1,046; sh: 621; xml: 210; awk: 21; makefile: 10; ansic: 1
file content (42 lines) | stat: -rw-r--r-- 1,391 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# define system dependent compiler flags

include(CheckCXXCompilerFlag)

# with -fPIC
if(UNIX AND NOT WIN32)
  if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
    check_cxx_compiler_flag("-fPIC" WITH_FPIC)
    if(WITH_FPIC)
      ADD_DEFINITIONS(-fPIC)
    endif(WITH_FPIC)
  endif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
endif(UNIX AND NOT WIN32)

# function to test for compile flags
function(cxx_add_flag_if_supported flag)
    check_cxx_compiler_flag(${flag} Flag:${flag})
    if(Flag:${flag})
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
    endif(Flag:${flag})
endfunction(cxx_add_flag_if_supported)


function(cxx_local_system_optimization)
    set(flag "-march=native")
    check_cxx_compiler_flag(${flag} Flag:${flag})
    if(Flag:${flag})
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
        message(STATUS [=[
 BUILDING FOR LOCAL SYSTEM ONLY
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Specifying -DBUILD_FOR_LOCAL_SYSTEM=ON will pass -march=native to the compiler.
 The generated binary will exhibit higher performance,
 but will not be portable (e.g., might not work on other CPUs)]=])
    else(Flag:${flag})
        message(STATUS [=[
 Your compiler does not support -march=native.
 Ignoring -DBUILD_FOR_LOCAL_SYSTEM=ON!]=])
    endif(Flag:${flag})
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")

endfunction(cxx_local_system_optimization)