cmake_modules/platform.cmake
branchwebgl
changeset 9521 8054d9d775fd
parent 9517 217eacb69395
child 9673 5be4de0eb4b0
equal deleted inserted replaced
9282:92af50454cf2 9521:8054d9d775fd
     1 
     1 
     2 if(APPLE)
     2 if(APPLE)
       
     3     if(${CMAKE_VERSION} VERSION_GREATER "2.8.10.2" AND
       
     4        ${CMAKE_VERSION} VERSION_LESS "2.8.12.1")
       
     5         message(FATAL_ERROR "This version of CMake is known *not* to work, please update or use a lower version")
       
     6     endif()
       
     7 
     3     set(CMAKE_FIND_FRAMEWORK "FIRST")
     8     set(CMAKE_FIND_FRAMEWORK "FIRST")
     4 
     9 
     5 #what system are we building for
    10     #what system are we building for
     6     set(minimum_macosx_version $ENV{MACOSX_DEPLOYMENT_TARGET})
    11     set(minimum_macosx_version $ENV{MACOSX_DEPLOYMENT_TARGET})
     7 
    12 
     8 #detect on which system we are: if sw_vers cannot be found for any reason (re)use minimum_macosx_version
    13     #detect on which system we are: if sw_vers cannot be found for any reason (re)use minimum_macosx_version
     9     find_program(sw_vers sw_vers)
    14     find_program(sw_vers sw_vers)
    10     if(sw_vers)
    15     if(sw_vers)
    11         execute_process(COMMAND ${sw_vers} "-productVersion"
    16         execute_process(COMMAND ${sw_vers} "-productVersion"
    12                         OUTPUT_VARIABLE current_macosx_version
    17                         OUTPUT_VARIABLE current_macosx_version
    13                         OUTPUT_STRIP_TRAILING_WHITESPACE)
    18                         OUTPUT_STRIP_TRAILING_WHITESPACE)
    19             message("*** sw_vers not found! Fallback to MACOSX_DEPLOYMENT_TARGET variable ***")
    24             message("*** sw_vers not found! Fallback to MACOSX_DEPLOYMENT_TARGET variable ***")
    20             set(current_macosx_version ${minimum_macosx_version})
    25             set(current_macosx_version ${minimum_macosx_version})
    21         endif()
    26         endif()
    22     endif()
    27     endif()
    23 
    28 
    24 #if nothing is set, we deploy only for the current system
    29     #if nothing is set, we deploy only for the current system
    25     if(NOT minimum_macosx_version)
    30     if(NOT minimum_macosx_version)
    26         set(minimum_macosx_version ${current_macosx_version})
    31         set(minimum_macosx_version ${current_macosx_version})
    27     endif()
    32     endif()
    28 
    33 
    29 #lower systems don't have enough processing power anyway
    34     #lower systems don't have enough processing power anyway
    30     if (minimum_macosx_version VERSION_LESS "10.4")
    35     if (minimum_macosx_version VERSION_LESS "10.4")
    31         message(FATAL_ERROR "Hedgewars is not supported on Mac OS X pre-10.4")
    36         message(FATAL_ERROR "Hedgewars is not supported on Mac OS X pre-10.4")
    32     endif()
    37     endif()
    33 
    38 
    34 #workaround for http://playcontrol.net/ewing/jibberjabber/big_behind-the-scenes_chang.html#SDL_mixer (Update 2)
    39     #workaround for http://playcontrol.net/ewing/jibberjabber/big_behind-the-scenes_chang.html#SDL_mixer (Update 2)
    35     if(current_macosx_version VERSION_EQUAL "10.4")
    40     if(current_macosx_version VERSION_EQUAL "10.4")
    36         find_package(SDL_mixer REQUIRED)
    41         find_package(SDL_mixer REQUIRED)
    37         set(DYLIB_SMPEG "-dylib_file @loader_path/Frameworks/smpeg.framework/Versions/A/smpeg:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/smpeg.framework/Versions/A/smpeg")
    42         set(DYLIB_SMPEG "-dylib_file @loader_path/Frameworks/smpeg.framework/Versions/A/smpeg:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/smpeg.framework/Versions/A/smpeg")
    38         set(DYLIB_MIKMOD "-dylib_file @loader_path/Frameworks/mikmod.framework/Versions/A/mikmod:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/mikmod.framework/Versions/A/mikmod")
    43         set(DYLIB_MIKMOD "-dylib_file @loader_path/Frameworks/mikmod.framework/Versions/A/mikmod:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/mikmod.framework/Versions/A/mikmod")
    39         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DYLIB_SMPEG} ${DYLIB_MIKMOD}")
    44         add_flag_append(CMAKE_C_FLAGS "${DYLIB_SMPEG} ${DYLIB_MIKMOD}")
    40         set(CMAKE_CX_FLAGS "${CMAKE_CX_FLAGS} ${DYLIB_SMPEG} ${DYLIB_MIKMOD}")
    45         add_flag_append(CMAKE_CXX_FLAGS "${DYLIB_SMPEG} ${DYLIB_MIKMOD}")
    41         list(APPEND pascal_flags "-k${DYLIB_SMPEG}" "-k${DYLIB_MIKMOD}")
    46         add_flag_append(CMAKE_Pascal_FLAGS "-k${DYLIB_SMPEG} -k${DYLIB_MIKMOD}")
    42     endif()
    47     endif()
    43 
    48 
    44 #CMAKE_OSX_ARCHITECTURES and CMAKE_OSX_SYSROOT need to be set for universal binary and correct linking
       
    45     if(NOT CMAKE_OSX_ARCHITECTURES)
    49     if(NOT CMAKE_OSX_ARCHITECTURES)
    46         if(current_macosx_version VERSION_LESS "10.6")
    50         if(current_macosx_version VERSION_LESS "10.6")
       
    51             #SDL is only 32 bit on lower OS
    47             if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc*")
    52             if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc*")
    48                 set(CMAKE_OSX_ARCHITECTURES "ppc7400")
    53                 set(CMAKE_OSX_ARCHITECTURES "ppc7400")
    49             else()
    54             else()
    50                 set(CMAKE_OSX_ARCHITECTURES "i386")
    55                 set(CMAKE_OSX_ARCHITECTURES "i386")
    51             endif()
    56             endif()
    52         else()
       
    53             set(CMAKE_OSX_ARCHITECTURES "x86_64")
       
    54         endif()
    57         endif()
    55     endif()
    58     endif()
    56 
    59 
    57 #CMAKE_OSX_SYSROOT is set at the system version we are supposed to build on
    60     #parse this system variable and adjust only the powerpc syntax to be compatible with -P
    58 #we need to provide the correct one when host and target differ
    61     if(CMAKE_OSX_ARCHITECTURES)
       
    62         string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}")
       
    63         string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}")
       
    64         string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}")
       
    65         if(x86_64_build)
       
    66             add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64)
       
    67         elseif(i386_build)
       
    68             add_flag_prepend(CMAKE_Pascal_FLAGS -Pi386)
       
    69         elseif(powerpc_build)
       
    70             add_flag_prepend(CMAKE_Pascal_FLAGS -Ppowerpc)
       
    71         else()
       
    72             message(FATAL_ERROR "Unknown architecture present in CMAKE_OSX_ARCHITECTURES (${CMAKE_OSX_ARCHITECTURES})")
       
    73         endif()
       
    74         list(LENGTH CMAKE_OSX_ARCHITECTURES num_of_archs)
       
    75         if(num_of_archs GREATER 1)
       
    76             message(${WARNING} "Only one architecture in CMAKE_OSX_ARCHITECTURES is currently supported, picking the first one")
       
    77         endif()
       
    78     elseif(CMAKE_SIZEOF_VOID_P MATCHES "8")
       
    79         #if that variable is not set check if we are on x86_64 and if so force it, else use default
       
    80         add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64)
       
    81     endif()
       
    82 
       
    83     #CMAKE_OSX_SYSROOT is set at the system version we are supposed to build on
       
    84     #we need to provide the correct one when host and target differ
    59     if(NOT ${minimum_macosx_version} VERSION_EQUAL ${current_macosx_version})
    85     if(NOT ${minimum_macosx_version} VERSION_EQUAL ${current_macosx_version})
    60         if(minimum_macosx_version VERSION_EQUAL "10.4")
    86         if(minimum_macosx_version VERSION_EQUAL "10.4")
    61             set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
    87             set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
    62             set(CMAKE_C_COMPILER "/Developer/usr/bin/gcc-4.0")
    88             set(CMAKE_C_COMPILER "/Developer/usr/bin/gcc-4.0")
    63             set(CMAKE_CXX_COMPILER "/Developer/usr/bin/g++-4.0")
    89             set(CMAKE_CXX_COMPILER "/Developer/usr/bin/g++-4.0")
    64         else()
    90         else()
    65             string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" sdk_version ${minimum_macosx_version})
    91             string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" sdk_version ${minimum_macosx_version})
    66             set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX${sdk_version}.sdk/")
    92             set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX${sdk_version}.sdk/")
    67         endif()
    93         endif()
       
    94         add_flag_append(CMAKE_Pascal_FLAGS "-XR${CMAKE_OSX_SYSROOT}")
       
    95         add_flag_append(CMAKE_Pascal_FLAGS "-k-macosx_version_min -k${minimum_macosx_version}")
    68     endif()
    96     endif()
    69 
    97 
    70 #add user framework directory, other paths can be passed via FPFLAGS
    98     #add user framework directory
    71     list(APPEND pascal_flags "-Ff~/Library/Frameworks")
    99     add_flag_append(CMAKE_Pascal_FLAGS "-Ff~/Library/Frameworks")
    72 #set deployment target
       
    73     list(APPEND pascal_flags "-k-macosx_version_min" "-k${minimum_macosx_version}" "-XR${CMAKE_OSX_SYSROOT}")
       
    74 
       
    75 endif(APPLE)
   100 endif(APPLE)
    76 
   101 
    77 if(MINGW)
   102 if(MINGW)
    78     #this flags prevents a few dll hell problems
   103     #this flags prevents a few dll hell problems
    79     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc ")
   104     add_flag_append(CMAKE_C_FLAGS "-static-libgcc")
    80     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc ")
   105     add_flag_append(CMAKE_CXX_FLAGS "-static-libgcc")
    81 endif(MINGW)
   106 endif(MINGW)
    82 
   107 
    83 if(WIN32)
   108 if(WIN32)
    84     if(NOT ${BUILD_SHARED_LIB})
   109     if(NOT ${BUILD_SHARED_LIB})
    85         message(FATAL_ERROR "Static linking is not supported on Windows")
   110         message(FATAL_ERROR "Static linking is not supported on Windows")