1# define system dependent compiler flags
2
3include(CheckCXXCompilerFlag)
4
5# with -fPIC
6if(UNIX AND NOT WIN32)
7  if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
8    check_cxx_compiler_flag("-fPIC" WITH_FPIC)
9    if(WITH_FPIC)
10      ADD_DEFINITIONS(-fPIC)
11    endif(WITH_FPIC)
12  endif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
13endif(UNIX AND NOT WIN32)
14
15# function to test for compile flags
16function(cxx_add_flag_if_supported flag)
17    check_cxx_compiler_flag(${flag} Flag:${flag})
18    if(Flag:${flag})
19        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
20    endif(Flag:${flag})
21endfunction(cxx_add_flag_if_supported)
22
23
24function(cxx_local_system_optimization)
25    set(flag "-march=native")
26    check_cxx_compiler_flag(${flag} Flag:${flag})
27    if(Flag:${flag})
28        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
29        message(STATUS [=[
30 BUILDING FOR LOCAL SYSTEM ONLY
31 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32 Specifying -DBUILD_FOR_LOCAL_SYSTEM=ON will pass -march=native to the compiler.
33 The generated binary will exhibit higher performance,
34 but will not be portable (e.g., might not work on other CPUs)]=])
35    else(Flag:${flag})
36        message(STATUS [=[
37 Your compiler does not support -march=native.
38 Ignoring -DBUILD_FOR_LOCAL_SYSTEM=ON!]=])
39    endif(Flag:${flag})
40   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
41
42endfunction(cxx_local_system_optimization)
43