Annotation of hatari/cmake/FindSDL2.cmake, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.