cmake_modules/platform.cmake
branchsdl2transition
changeset 11362 ed5a6478e710
parent 9707 c433e74da79b
parent 9941 d33d4727b39e
child 15312 5b2dec63f4cf
equal deleted inserted replaced
11361:31570b766315 11362:ed5a6478e710
    29     #if nothing is set, we deploy only for the current system
    29     #if nothing is set, we deploy only for the current system
    30     if(NOT minimum_macosx_version)
    30     if(NOT minimum_macosx_version)
    31         set(minimum_macosx_version ${current_macosx_version})
    31         set(minimum_macosx_version ${current_macosx_version})
    32     endif()
    32     endif()
    33 
    33 
    34     #lower systems don't have enough processing power anyway
    34     #10.3 systems don't have enough processing power anyway
    35     if (minimum_macosx_version VERSION_LESS "10.4")
    35     #10.4 does not have @rpath support (which SDL uses)
    36         message(FATAL_ERROR "Hedgewars is not supported on Mac OS X pre-10.4")
    36     if(minimum_macosx_version VERSION_LESS "10.5")
    37     endif()
    37         message(FATAL_ERROR "Hedgewars is not supported on your version of Mac OS X")
    38 
       
    39     #gcc is EOL on these systems
       
    40     if (current_macosx_version VERSION_GREATER "10.8")
       
    41         set(CMAKE_C_COMPILER clang)
       
    42         set(CMAKE_CXX_COMPILER clang++)
       
    43     endif()
       
    44 
       
    45     #workaround for http://playcontrol.net/ewing/jibberjabber/big_behind-the-scenes_chang.html#SDL_mixer (Update 2)
       
    46     if(current_macosx_version VERSION_EQUAL "10.4")
       
    47         find_package(SDL_mixer REQUIRED)
       
    48         set(DYLIB_SMPEG "-dylib_file @loader_path/Frameworks/smpeg.framework/Versions/A/smpeg:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/smpeg.framework/Versions/A/smpeg")
       
    49         set(DYLIB_MIKMOD "-dylib_file @loader_path/Frameworks/mikmod.framework/Versions/A/mikmod:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/mikmod.framework/Versions/A/mikmod")
       
    50         add_flag_append(CMAKE_C_FLAGS "${DYLIB_SMPEG} ${DYLIB_MIKMOD}")
       
    51         add_flag_append(CMAKE_CXX_FLAGS "${DYLIB_SMPEG} ${DYLIB_MIKMOD}")
       
    52         add_flag_append(CMAKE_Pascal_FLAGS "-k${DYLIB_SMPEG} -k${DYLIB_MIKMOD}")
       
    53     endif()
    38     endif()
    54 
    39 
    55     if(NOT CMAKE_OSX_ARCHITECTURES)
    40     if(NOT CMAKE_OSX_ARCHITECTURES)
    56         if(current_macosx_version VERSION_LESS "10.6")
    41         if(current_macosx_version VERSION_LESS "10.6")
    57             #SDL is only 32 bit on lower OS
    42             #SDL is only 32 bit on older OS version
    58             if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc*")
    43             if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc*")
    59                 set(CMAKE_OSX_ARCHITECTURES "ppc7400")
    44                 set(CMAKE_OSX_ARCHITECTURES "ppc7400")
    60             else()
    45             else()
    61                 set(CMAKE_OSX_ARCHITECTURES "i386")
    46                 set(CMAKE_OSX_ARCHITECTURES "i386")
    62             endif()
    47             endif()
    77         else()
    62         else()
    78             message(FATAL_ERROR "Unknown architecture present in CMAKE_OSX_ARCHITECTURES (${CMAKE_OSX_ARCHITECTURES})")
    63             message(FATAL_ERROR "Unknown architecture present in CMAKE_OSX_ARCHITECTURES (${CMAKE_OSX_ARCHITECTURES})")
    79         endif()
    64         endif()
    80         list(LENGTH CMAKE_OSX_ARCHITECTURES num_of_archs)
    65         list(LENGTH CMAKE_OSX_ARCHITECTURES num_of_archs)
    81         if(num_of_archs GREATER 1)
    66         if(num_of_archs GREATER 1)
    82             message(${WARNING} "Only one architecture in CMAKE_OSX_ARCHITECTURES is currently supported, picking the first one")
    67             message("*** Only one architecture in CMAKE_OSX_ARCHITECTURES is supported, picking the first one ***")
    83         endif()
    68         endif()
    84     elseif(CMAKE_SIZEOF_VOID_P MATCHES "8")
    69     elseif(CMAKE_SIZEOF_VOID_P MATCHES "8")
    85         #if that variable is not set check if we are on x86_64 and if so force it, else use default
    70         #if that variable is not set check if we are on x86_64 and if so force it, else use default
    86         add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64)
    71         add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64)
    87     endif()
    72     endif()
    88 
    73 
    89     #CMAKE_OSX_SYSROOT is set at the system version we are supposed to build on
    74     #CMAKE_OSX_SYSROOT is set at the system version we are supposed to build on
    90     #we need to provide the correct one when host and target differ
    75     #we need to provide the correct one when host and target differ
    91     if(NOT ${minimum_macosx_version} VERSION_EQUAL ${current_macosx_version})
    76     if(NOT CMAKE_OSX_SYSROOT AND
    92         if(minimum_macosx_version VERSION_EQUAL "10.4")
    77        NOT ${minimum_macosx_version} VERSION_EQUAL ${current_macosx_version})
    93             set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
    78         find_program(xcrun xcrun)
    94             set(CMAKE_C_COMPILER "/Developer/usr/bin/gcc-4.0")
    79         if(xcrun)
    95             set(CMAKE_CXX_COMPILER "/Developer/usr/bin/g++-4.0")
    80             execute_process(COMMAND ${xcrun} "--show-sdk-path"
       
    81                             OUTPUT_VARIABLE current_sdk_path
       
    82                             OUTPUT_STRIP_TRAILING_WHITESPACE)
       
    83             string(REPLACE "${current_macosx_version}"
       
    84                            "${minimum_macosx_version}"
       
    85                            CMAKE_OSX_SYSROOT
       
    86                            "${current_sdk_path}")
    96         else()
    87         else()
    97             string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" sdk_version ${minimum_macosx_version})
    88             message("*** xcrun not found! Build will work on ${current_macosx_version} only ***")
    98             set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX${sdk_version}.sdk/")
       
    99         endif()
    89         endif()
       
    90     endif()
       
    91     if(CMAKE_OSX_SYSROOT)
   100         add_flag_append(CMAKE_Pascal_FLAGS "-XR${CMAKE_OSX_SYSROOT}")
    92         add_flag_append(CMAKE_Pascal_FLAGS "-XR${CMAKE_OSX_SYSROOT}")
   101         add_flag_append(CMAKE_Pascal_FLAGS "-k-macosx_version_min -k${minimum_macosx_version}")
    93         add_flag_append(CMAKE_Pascal_FLAGS "-k-macosx_version_min -k${minimum_macosx_version}")
       
    94         add_flag_append(CMAKE_Pascal_FLAGS "-k-L${LIBRARY_OUTPUT_PATH} -Fl${LIBRARY_OUTPUT_PATH}")
   102     endif()
    95     endif()
   103 
    96 
   104     #add user framework directory
    97     #add user framework directory
   105     add_flag_append(CMAKE_Pascal_FLAGS "-Ff~/Library/Frameworks")
    98     add_flag_append(CMAKE_Pascal_FLAGS "-Ff~/Library/Frameworks")
   106 
    99 
   107     #workaround most of the -Fl settings getting lost
   100     #workaround older cmake versions
   108     add_flag_append(CMAKE_Pascal_FLAGS "-k-L${LIBRARY_OUTPUT_PATH}")
   101     if(${CMAKE_VERSION} VERSION_LESS "2.8.12")
       
   102         add_flag_append(CMAKE_C_LINK_FLAGS "-Wl,-rpath -Wl,${CMAKE_INSTALL_RPATH}")
       
   103         add_flag_append(CMAKE_CXX_LINK_FLAGS "-Wl,-rpath -Wl,${CMAKE_INSTALL_RPATH}")
       
   104         add_flag_append(CMAKE_Pascal_LINK_FLAGS "-k-rpath -k${CMAKE_INSTALL_RPATH}")
       
   105     endif()
   109 endif(APPLE)
   106 endif(APPLE)
   110 
   107 
   111 if(MINGW)
   108 if(MINGW)
   112     #this flags prevents a few dll hell problems
   109     #this flags prevents a few dll hell problems
   113     add_flag_append(CMAKE_C_FLAGS "-static-libgcc")
   110     add_flag_append(CMAKE_C_FLAGS "-static-libgcc")
   121 endif(WIN32)
   118 endif(WIN32)
   122 
   119 
   123 if(UNIX)
   120 if(UNIX)
   124     add_flag_append(CMAKE_C_FLAGS "-fPIC")
   121     add_flag_append(CMAKE_C_FLAGS "-fPIC")
   125     add_flag_append(CMAKE_CXX_FLAGS "-fPIC")
   122     add_flag_append(CMAKE_CXX_FLAGS "-fPIC")
   126     add_flag_append(CMAKE_Pascal_FLAGS "-fPIC")
       
   127 endif(UNIX)
   123 endif(UNIX)