cmake_modules/TargetArch.cmake
author Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
Sat, 04 Jan 2014 02:18:57 +0100
branch0.9.20
changeset 9899 5b8bde62a8ef
permissions -rw-r--r--
Fixed fPIC link failure with arm and sparc architectures, fixing issue #757 Added TargetArch.cmake, from https://github.com/petroules/solar-cmake/blob/master/TargetArch.cmake
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9899
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
     1
# Original file location https://github.com/petroules/solar-cmake/blob/master/TargetArch.cmake
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
     2
#Copyright (c) 2012 Petroules Corporation. All rights reserved.
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
     3
#Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
     4
#
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
     5
# 1    Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
     6
# 2    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
     7
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
     8
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
     9
# Based on the Qt 5 processor detection code, so should be very accurate
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    10
# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    11
# Currently handles arm (v5, v6, v7), x86 (32/64), ia64, and ppc (32/64)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    12
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    13
# Regarding POWER/PowerPC, just as is noted in the Qt source,
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    14
# "There are many more known variants/revisions that we do not handle/detect."
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    15
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    16
set(archdetect_c_code "
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    17
#if defined(__arm__) || defined(__TARGET_ARCH_ARM)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    18
    #if defined(__ARM_ARCH_7__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    19
        || defined(__ARM_ARCH_7A__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    20
        || defined(__ARM_ARCH_7R__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    21
        || defined(__ARM_ARCH_7M__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    22
        || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    23
        #error cmake_ARCH armv7
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    24
    #elif defined(__ARM_ARCH_6__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    25
        || defined(__ARM_ARCH_6J__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    26
        || defined(__ARM_ARCH_6T2__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    27
        || defined(__ARM_ARCH_6Z__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    28
        || defined(__ARM_ARCH_6K__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    29
        || defined(__ARM_ARCH_6ZK__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    30
        || defined(__ARM_ARCH_6M__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    31
        || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    32
        #error cmake_ARCH armv6
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    33
    #elif defined(__ARM_ARCH_5TEJ__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    34
        || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    35
        #error cmake_ARCH armv5
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    36
    #else
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    37
        #error cmake_ARCH arm
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    38
    #endif
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    39
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    40
    #error cmake_ARCH i386
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    41
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    42
    #error cmake_ARCH x86_64
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    43
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    44
    #error cmake_ARCH ia64
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    45
#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    46
      || defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC)  \\
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    47
      || defined(_M_MPPC) || defined(_M_PPC)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    48
    #if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    49
        #error cmake_ARCH ppc64
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    50
    #else
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    51
        #error cmake_ARCH ppc
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    52
    #endif
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    53
#endif
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    54
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    55
#error cmake_ARCH unknown
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    56
")
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    57
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    58
# Set ppc_support to TRUE before including this file or ppc and ppc64
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    59
# will be treated as invalid architectures since they are no longer supported by Apple
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    60
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    61
function(target_architecture output_var)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    62
    if(APPLE AND CMAKE_OSX_ARCHITECTURES)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    63
        # On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    64
        # First let's normalize the order of the values
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    65
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    66
        # Note that it's not possible to compile PowerPC applications if you are using
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    67
        # the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    68
        # disable it by default
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    69
        # See this page for more information:
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    70
        # http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    71
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    72
        # Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime.
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    73
        # On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise.
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    74
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    75
        foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    76
            if("${osx_arch}" STREQUAL "ppc" AND ppc_support)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    77
                set(osx_arch_ppc TRUE)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    78
            elseif("${osx_arch}" STREQUAL "i386")
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    79
                set(osx_arch_i386 TRUE)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    80
            elseif("${osx_arch}" STREQUAL "x86_64")
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    81
                set(osx_arch_x86_64 TRUE)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    82
            elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    83
                set(osx_arch_ppc64 TRUE)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    84
            else()
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    85
                message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    86
            endif()
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    87
        endforeach()
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    88
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    89
        # Now add all the architectures in our normalized order
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    90
        if(osx_arch_ppc)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    91
            list(APPEND ARCH ppc)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    92
        endif()
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    93
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    94
        if(osx_arch_i386)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    95
            list(APPEND ARCH i386)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    96
        endif()
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    97
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    98
        if(osx_arch_x86_64)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
    99
            list(APPEND ARCH x86_64)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   100
        endif()
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   101
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   102
        if(osx_arch_ppc64)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   103
            list(APPEND ARCH ppc64)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   104
        endif()
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   105
    else()
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   106
        file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   107
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   108
        enable_language(C)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   109
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   110
        # Detect the architecture in a rather creative way...
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   111
        # This compiles a small C program which is a series of ifdefs that selects a
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   112
        # particular #error preprocessor directive whose message string contains the
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   113
        # target architecture. The program will always fail to compile (both because
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   114
        # file is not a valid C program, and obviously because of the presence of the
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   115
        # #error preprocessor directives... but by exploiting the preprocessor in this
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   116
        # way, we can detect the correct target architecture even when cross-compiling,
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   117
        # since the program itself never needs to be run (only the compiler/preprocessor)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   118
        try_run(
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   119
            run_result_unused
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   120
            compile_result_unused
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   121
            "${CMAKE_BINARY_DIR}"
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   122
            "${CMAKE_BINARY_DIR}/arch.c"
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   123
            COMPILE_OUTPUT_VARIABLE ARCH
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   124
            CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   125
        )
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   126
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   127
        # Parse the architecture name from the compiler output
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   128
        string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   129
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   130
        # Get rid of the value marker leaving just the architecture name
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   131
        string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   132
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   133
        # If we are compiling with an unknown architecture this variable should
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   134
        # already be set to "unknown" but in the case that it's empty (i.e. due
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   135
        # to a typo in the code), then set it to unknown
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   136
        if (NOT ARCH)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   137
            set(ARCH unknown)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   138
        endif()
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   139
    endif()
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   140
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   141
    set(${output_var} "${ARCH}" PARENT_SCOPE)
5b8bde62a8ef Fixed fPIC link failure with arm and sparc architectures, fixing issue #757
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
diff changeset
   142
endfunction()