File: SetSystemProcessor.cmake

package info (click to toggle)
libsoxr 0.1.3-4.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 840 kB
  • sloc: ansic: 8,011; sh: 284; cpp: 40; makefile: 13
file content (37 lines) | stat: -rw-r--r-- 1,422 bytes parent folder | download | duplicates (3)
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
# SoX Resampler Library       Copyright (c) 2007-16 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1                  See LICENCE for details.

# Sets CMAKE_SYSTEM_PROCESSOR for cross-compiling.

macro (set_system_processor)
  if (CMAKE_CROSSCOMPILING)
    if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "unknown")
      unset(CMAKE_SYSTEM_PROCESSOR)
    endif ()
    if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
      include (CheckCSourceCompiles)
      set (CPU_LINES
        "#if defined __x86_64__ || defined _M_X64  /*\;x86_64\;*/"
        "#if defined __i386__   || defined _M_IX86 /*\;x86_32\;*/"
        "#if defined __arm__    || defined _M_ARM  /*\;arm\;*/"
        )
      foreach (CPU_LINE ${CPU_LINES})
        string (CONCAT CPU_SOURCE "${CPU_LINE}" "
        int main() {return 0;}
        #endif
        ")
        unset (SYSTEM_PROCESSOR_DETECTED CACHE)
        check_c_source_compiles ("${CPU_SOURCE}" SYSTEM_PROCESSOR_DETECTED)
        if (SYSTEM_PROCESSOR_DETECTED)
          list (GET CPU_LINE 1 CMAKE_SYSTEM_PROCESSOR)
          message (STATUS "CMAKE_SYSTEM_PROCESSOR is ${CMAKE_SYSTEM_PROCESSOR}")
          break ()
        endif ()
      endforeach ()
    endif ()

    # N.B. Will not overwrite existing cache variable:
    set (CMAKE_SYSTEM_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}"
      CACHE STRING "Target system processor")
  endif ()
endmacro ()