cmake_modules/platform.cmake
author koda
Fri, 06 Dec 2013 00:45:32 +0100
branchsdl2transition
changeset 9707 c433e74da79b
parent 9705 322fe1736347
child 11342 ed5a6478e710
permissions -rw-r--r--
use clang on mavericks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     1
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     2
if(APPLE)
9517
217eacb69395 fail early when an incompatible cmake version is found
koda
parents: 9339
diff changeset
     3
    if(${CMAKE_VERSION} VERSION_GREATER "2.8.10.2" AND
217eacb69395 fail early when an incompatible cmake version is found
koda
parents: 9339
diff changeset
     4
       ${CMAKE_VERSION} VERSION_LESS "2.8.12.1")
217eacb69395 fail early when an incompatible cmake version is found
koda
parents: 9339
diff changeset
     5
        message(FATAL_ERROR "This version of CMake is known *not* to work, please update or use a lower version")
217eacb69395 fail early when an incompatible cmake version is found
koda
parents: 9339
diff changeset
     6
    endif()
217eacb69395 fail early when an incompatible cmake version is found
koda
parents: 9339
diff changeset
     7
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     8
    set(CMAKE_FIND_FRAMEWORK "FIRST")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     9
9268
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
    10
    #what system are we building for
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    11
    set(minimum_macosx_version $ENV{MACOSX_DEPLOYMENT_TARGET})
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    12
9268
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
    13
    #detect on which system we are: if sw_vers cannot be found for any reason (re)use minimum_macosx_version
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    14
    find_program(sw_vers sw_vers)
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    15
    if(sw_vers)
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    16
        execute_process(COMMAND ${sw_vers} "-productVersion"
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    17
                        OUTPUT_VARIABLE current_macosx_version
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    18
                        OUTPUT_STRIP_TRAILING_WHITESPACE)
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    19
        string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" current_macosx_version ${current_macosx_version})
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    20
    else()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    21
        if(NOT minimum_macosx_version)
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    22
            message(FATAL_ERROR "sw_vers not found! Need explicit MACOSX_DEPLOYMENT_TARGET variable set")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    23
        else()
9151
1d2df388fcc6 simplify cmake message syntax a little bit
koda
parents: 9150
diff changeset
    24
            message("*** sw_vers not found! Fallback to MACOSX_DEPLOYMENT_TARGET variable ***")
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    25
            set(current_macosx_version ${minimum_macosx_version})
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    26
        endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    27
    endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    28
9268
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
    29
    #if nothing is set, we deploy only for the current system
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    30
    if(NOT minimum_macosx_version)
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    31
        set(minimum_macosx_version ${current_macosx_version})
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    32
    endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    33
9268
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
    34
    #lower systems don't have enough processing power anyway
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    35
    if (minimum_macosx_version VERSION_LESS "10.4")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    36
        message(FATAL_ERROR "Hedgewars is not supported on Mac OS X pre-10.4")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    37
    endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    38
9707
c433e74da79b use clang on mavericks
koda
parents: 9705
diff changeset
    39
    #gcc is EOL on these systems
c433e74da79b use clang on mavericks
koda
parents: 9705
diff changeset
    40
    if (current_macosx_version VERSION_GREATER "10.8")
c433e74da79b use clang on mavericks
koda
parents: 9705
diff changeset
    41
        set(CMAKE_C_COMPILER clang)
c433e74da79b use clang on mavericks
koda
parents: 9705
diff changeset
    42
        set(CMAKE_CXX_COMPILER clang++)
c433e74da79b use clang on mavericks
koda
parents: 9705
diff changeset
    43
    endif()
c433e74da79b use clang on mavericks
koda
parents: 9705
diff changeset
    44
9268
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
    45
    #workaround for http://playcontrol.net/ewing/jibberjabber/big_behind-the-scenes_chang.html#SDL_mixer (Update 2)
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    46
    if(current_macosx_version VERSION_EQUAL "10.4")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    47
        find_package(SDL_mixer REQUIRED)
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    48
        set(DYLIB_SMPEG "-dylib_file @loader_path/Frameworks/smpeg.framework/Versions/A/smpeg:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/smpeg.framework/Versions/A/smpeg")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    49
        set(DYLIB_MIKMOD "-dylib_file @loader_path/Frameworks/mikmod.framework/Versions/A/mikmod:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/mikmod.framework/Versions/A/mikmod")
9268
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
    50
        add_flag_append(CMAKE_C_FLAGS "${DYLIB_SMPEG} ${DYLIB_MIKMOD}")
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
    51
        add_flag_append(CMAKE_CXX_FLAGS "${DYLIB_SMPEG} ${DYLIB_MIKMOD}")
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
    52
        add_flag_append(CMAKE_Pascal_FLAGS "-k${DYLIB_SMPEG} -k${DYLIB_MIKMOD}")
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    53
    endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    54
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    55
    if(NOT CMAKE_OSX_ARCHITECTURES)
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    56
        if(current_macosx_version VERSION_LESS "10.6")
9268
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
    57
            #SDL is only 32 bit on lower OS
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    58
            if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc*")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    59
                set(CMAKE_OSX_ARCHITECTURES "ppc7400")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    60
            else()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    61
                set(CMAKE_OSX_ARCHITECTURES "i386")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    62
            endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    63
        endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    64
    endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    65
9271
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    66
    #parse this system variable and adjust only the powerpc syntax to be compatible with -P
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    67
    if(CMAKE_OSX_ARCHITECTURES)
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    68
        string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}")
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    69
        string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}")
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    70
        string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}")
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    71
        if(x86_64_build)
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    72
            add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64)
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    73
        elseif(i386_build)
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    74
            add_flag_prepend(CMAKE_Pascal_FLAGS -Pi386)
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    75
        elseif(powerpc_build)
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    76
            add_flag_prepend(CMAKE_Pascal_FLAGS -Ppowerpc)
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    77
        else()
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    78
            message(FATAL_ERROR "Unknown architecture present in CMAKE_OSX_ARCHITECTURES (${CMAKE_OSX_ARCHITECTURES})")
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    79
        endif()
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    80
        list(LENGTH CMAKE_OSX_ARCHITECTURES num_of_archs)
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    81
        if(num_of_archs GREATER 1)
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    82
            message(${WARNING} "Only one architecture in CMAKE_OSX_ARCHITECTURES is currently supported, picking the first one")
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    83
        endif()
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    84
    elseif(CMAKE_SIZEOF_VOID_P MATCHES "8")
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    85
        #if that variable is not set check if we are on x86_64 and if so force it, else use default
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    86
        add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64)
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    87
    endif()
118cc5c1f677 move some osx only configuration code
koda
parents: 9268
diff changeset
    88
9268
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
    89
    #CMAKE_OSX_SYSROOT is set at the system version we are supposed to build on
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
    90
    #we need to provide the correct one when host and target differ
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    91
    if(NOT ${minimum_macosx_version} VERSION_EQUAL ${current_macosx_version})
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    92
        if(minimum_macosx_version VERSION_EQUAL "10.4")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    93
            set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    94
            set(CMAKE_C_COMPILER "/Developer/usr/bin/gcc-4.0")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    95
            set(CMAKE_CXX_COMPILER "/Developer/usr/bin/g++-4.0")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    96
        else()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    97
            string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" sdk_version ${minimum_macosx_version})
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    98
            set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX${sdk_version}.sdk/")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    99
        endif()
9268
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
   100
        add_flag_append(CMAKE_Pascal_FLAGS "-XR${CMAKE_OSX_SYSROOT}")
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
   101
        add_flag_append(CMAKE_Pascal_FLAGS "-k-macosx_version_min -k${minimum_macosx_version}")
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
   102
    endif()
9339
14f5f3a1e2f7 some work on cmake_pascal files to better support flags we use, make engine compile as library again
koda
parents: 9297
diff changeset
   103
14f5f3a1e2f7 some work on cmake_pascal files to better support flags we use, make engine compile as library again
koda
parents: 9297
diff changeset
   104
    #add user framework directory
14f5f3a1e2f7 some work on cmake_pascal files to better support flags we use, make engine compile as library again
koda
parents: 9297
diff changeset
   105
    add_flag_append(CMAKE_Pascal_FLAGS "-Ff~/Library/Frameworks")
9705
322fe1736347 fix linking on osx by hardcoding the default library output path
koda
parents: 9673
diff changeset
   106
322fe1736347 fix linking on osx by hardcoding the default library output path
koda
parents: 9673
diff changeset
   107
    #workaround most of the -Fl settings getting lost
322fe1736347 fix linking on osx by hardcoding the default library output path
koda
parents: 9673
diff changeset
   108
    add_flag_append(CMAKE_Pascal_FLAGS "-k-L${LIBRARY_OUTPUT_PATH}")
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
   109
endif(APPLE)
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
   110
9210
31fedd5ef878 freepascal on windows only supports shared libraries
koda
parents: 9151
diff changeset
   111
if(MINGW)
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
   112
    #this flags prevents a few dll hell problems
9268
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
   113
    add_flag_append(CMAKE_C_FLAGS "-static-libgcc")
8a9075ed0aab use add_flag_append more, correctly set a few flags
koda
parents: 9219
diff changeset
   114
    add_flag_append(CMAKE_CXX_FLAGS "-static-libgcc")
9210
31fedd5ef878 freepascal on windows only supports shared libraries
koda
parents: 9151
diff changeset
   115
endif(MINGW)
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
   116
9210
31fedd5ef878 freepascal on windows only supports shared libraries
koda
parents: 9151
diff changeset
   117
if(WIN32)
9218
673bf356ad8c another code typo
koda
parents: 9211
diff changeset
   118
    if(NOT ${BUILD_SHARED_LIB})
9210
31fedd5ef878 freepascal on windows only supports shared libraries
koda
parents: 9151
diff changeset
   119
        message(FATAL_ERROR "Static linking is not supported on Windows")
31fedd5ef878 freepascal on windows only supports shared libraries
koda
parents: 9151
diff changeset
   120
    endif()
31fedd5ef878 freepascal on windows only supports shared libraries
koda
parents: 9151
diff changeset
   121
endif(WIN32)
9673
5be4de0eb4b0 enable -fPIC on UNIX only
koda
parents: 9517
diff changeset
   122
5be4de0eb4b0 enable -fPIC on UNIX only
koda
parents: 9517
diff changeset
   123
if(UNIX)
5be4de0eb4b0 enable -fPIC on UNIX only
koda
parents: 9517
diff changeset
   124
    add_flag_append(CMAKE_C_FLAGS "-fPIC")
5be4de0eb4b0 enable -fPIC on UNIX only
koda
parents: 9517
diff changeset
   125
    add_flag_append(CMAKE_CXX_FLAGS "-fPIC")
5be4de0eb4b0 enable -fPIC on UNIX only
koda
parents: 9517
diff changeset
   126
    add_flag_append(CMAKE_Pascal_FLAGS "-fPIC")
5be4de0eb4b0 enable -fPIC on UNIX only
koda
parents: 9517
diff changeset
   127
endif(UNIX)