cmake_modules/FindSDL2.cmake
author unc0rr
Mon, 18 Nov 2013 00:44:30 +0400
changeset 9702 27006953d901
parent 9649 2d30721b1a11
child 11662 ae6706411b24
permissions -rw-r--r--
- Column for script in rooms list - Get rid of scheme and weapons filters
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9649
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
     1
# Locate SDL2 library
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
     2
# This module defines
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
     3
# SDL2_LIBRARY, the name of the library to link against
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
     4
# SDL2_FOUND, if false, do not try to link to SDL2
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
     5
# SDL2_INCLUDE_DIR, where to find SDL.h
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
     6
#
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
     7
# This module responds to the the flag:
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
     8
# SDL2_BUILDING_LIBRARY
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
     9
# If this is defined, then no SDL2main will be linked in because
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    10
# only applications need main().
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    11
# Otherwise, it is assumed you are building an application and this
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    12
# module will attempt to locate and set the the proper link flags
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    13
# as part of the returned SDL2_LIBRARY variable.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    14
#
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    15
# Don't forget to include SDLmain.h and SDLmain.m your project for the
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    16
# OS X framework based version. (Other versions link to -lSDL2main which
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    17
# this module will try to find on your behalf.) Also for OS X, this
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    18
# module will automatically add the -framework Cocoa on your behalf.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    19
#
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    20
#
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    21
# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    22
# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    23
# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    24
# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    25
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    26
# as appropriate. These values are used to generate the final SDL2_LIBRARY
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    27
# variable, but when these values are unset, SDL2_LIBRARY does not get created.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    28
#
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    29
#
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    30
# $SDL2DIR is an environment variable that would
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    31
# correspond to the ./configure --prefix=$SDL2DIR
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    32
# used in building SDL2.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    33
# l.e.galup  9-20-02
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    34
#
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    35
# Modified by Eric Wing.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    36
# Added code to assist with automated building by using environmental variables
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    37
# and providing a more controlled/consistent search behavior.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    38
# Added new modifications to recognize OS X frameworks and
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    39
# additional Unix paths (FreeBSD, etc).
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    40
# Also corrected the header search path to follow "proper" SDL guidelines.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    41
# Added a search for SDL2main which is needed by some platforms.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    42
# Added a search for threads which is needed by some platforms.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    43
# Added needed compile switches for MinGW.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    44
#
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    45
# On OSX, this will prefer the Framework version (if found) over others.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    46
# People will have to manually change the cache values of
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    47
# SDL2_LIBRARY to override this selection or set the CMake environment
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    48
# CMAKE_INCLUDE_PATH to modify the search paths.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    49
#
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    50
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    51
# This needed to change because "proper" SDL convention
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    52
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    53
# reasons because not all systems place things in SDL2/ (see FreeBSD).
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    54
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    55
#=============================================================================
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    56
# Copyright 2003-2009 Kitware, Inc.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    57
#
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    58
# Distributed under the OSI-approved BSD License (the "License");
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    59
# see accompanying file Copyright.txt for details.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    60
#
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    61
# This software is distributed WITHOUT ANY WARRANTY; without even the
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    62
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    63
# See the License for more information.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    64
#=============================================================================
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    65
# (To distribute this file outside of CMake, substitute the full
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    66
#  License text for the above reference.)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    67
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    68
SET(SDL2_SEARCH_PATHS
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    69
    ~/Library/Frameworks
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    70
    /Library/Frameworks
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    71
    /usr/local
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    72
    /usr
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    73
    /sw # Fink
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    74
    /opt/local # DarwinPorts
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    75
    /opt/csw # Blastwave
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    76
    /opt
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    77
)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    78
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    79
FIND_PATH(SDL2_INCLUDE_DIR SDL.h
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    80
    HINTS
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    81
    $ENV{SDL2DIR}
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    82
    PATH_SUFFIXES include/SDL2 include
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    83
    PATHS ${SDL2_SEARCH_PATHS}
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    84
)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    85
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    86
FIND_LIBRARY(SDL2_LIBRARY_TEMP
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    87
    NAMES SDL2
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    88
    HINTS
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    89
    $ENV{SDL2DIR}
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    90
    PATH_SUFFIXES lib64 lib
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    91
    PATHS ${SDL2_SEARCH_PATHS}
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    92
)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    93
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    94
IF(NOT SDL2_BUILDING_LIBRARY)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    95
    IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    96
        # Non-OS X framework versions expect you to also dynamically link to
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    97
        # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    98
        # seem to provide SDL2main for compatibility even though they don't
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
    99
        # necessarily need it.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   100
        FIND_LIBRARY(SDL2MAIN_LIBRARY
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   101
            NAMES SDL2main
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   102
            HINTS
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   103
            $ENV{SDL2DIR}
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   104
            PATH_SUFFIXES lib64 lib
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   105
            PATHS ${SDL2_SEARCH_PATHS}
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   106
        )
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   107
    ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   108
ENDIF(NOT SDL2_BUILDING_LIBRARY)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   109
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   110
# SDL2 may require threads on your system.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   111
# The Apple build may not need an explicit flag because one of the
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   112
# frameworks may already provide it.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   113
# But for non-OSX systems, I will use the CMake Threads package.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   114
IF(NOT APPLE)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   115
    FIND_PACKAGE(Threads)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   116
ENDIF(NOT APPLE)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   117
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   118
# MinGW needs an additional library, mwindows
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   119
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   120
# (Actually on second look, I think it only needs one of the m* libraries.)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   121
IF(MINGW)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   122
    SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   123
ENDIF(MINGW)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   124
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   125
IF(SDL2_LIBRARY_TEMP)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   126
    # For SDL2main
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   127
    IF(NOT SDL2_BUILDING_LIBRARY)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   128
        IF(SDL2MAIN_LIBRARY)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   129
            SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   130
        ENDIF(SDL2MAIN_LIBRARY)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   131
    ENDIF(NOT SDL2_BUILDING_LIBRARY)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   132
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   133
    # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   134
    # CMake doesn't display the -framework Cocoa string in the UI even
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   135
    # though it actually is there if I modify a pre-used variable.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   136
    # I think it has something to do with the CACHE STRING.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   137
    # So I use a temporary variable until the end so I can set the
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   138
    # "real" variable in one-shot.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   139
    IF(APPLE)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   140
        SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   141
    ENDIF(APPLE)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   142
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   143
    # For threads, as mentioned Apple doesn't need this.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   144
    # In fact, there seems to be a problem if I used the Threads package
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   145
    # and try using this line, so I'm just skipping it entirely for OS X.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   146
    IF(NOT APPLE)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   147
        SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   148
    ENDIF(NOT APPLE)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   149
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   150
    # For MinGW library
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   151
    IF(MINGW)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   152
        SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   153
    ENDIF(MINGW)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   154
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   155
    # Set the final string here so the GUI reflects the final state.
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   156
    SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   157
    # Set the temp variable to INTERNAL so it is not seen in the CMake GUI
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   158
    SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   159
ENDIF(SDL2_LIBRARY_TEMP)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   160
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   161
INCLUDE(FindPackageHandleStandardArgs)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   162
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   163
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)
2d30721b1a11 add FindSDL2 module from dhewm repo
koda
parents:
diff changeset
   164