summaryrefslogtreecommitdiffstats
path: root/Modules/FindSDL.cmake
diff options
context:
space:
mode:
authorEric Wing <ewing2121@yahoo.com>2007-12-21 01:59:44 (GMT)
committerEric Wing <ewing2121@yahoo.com>2007-12-21 01:59:44 (GMT)
commita5b3ab4eee1f11287c69da39b5e742353fdbd372 (patch)
tree4aaf6549ec4f360eb44a05ca3b6568b8783452ff /Modules/FindSDL.cmake
parent355b1f23afd6809edb9ed1924c0112d02d4c8f85 (diff)
downloadCMake-a5b3ab4eee1f11287c69da39b5e742353fdbd372.zip
CMake-a5b3ab4eee1f11287c69da39b5e742353fdbd372.tar.gz
CMake-a5b3ab4eee1f11287c69da39b5e742353fdbd372.tar.bz2
BUG: Fixed modules to set FOO_FOUND when both headers and libraries are found.
BUG: FindSDL now has flag it responds to so it will not find/link against SDLmain. This is required to build libraries instead of applications since they don't have main(). ENH: All modules have a predictable search order, where environmental variables are searched before system paths. This is designed to make automation easier for those that need to automatically build projects without intervention but may be using alternative install locations for isolated testing. ENH: New modules for OpenSceneGraph, Freetype, GDAL, Lua, QuickTime, GIFLIB, Producer, OpenThreads. STYLE: Added documentation explaining peculuar SDL_LIBRARY_TEMP variable in SDL module when library find is incomplete.
Diffstat (limited to 'Modules/FindSDL.cmake')
-rw-r--r--Modules/FindSDL.cmake202
1 files changed, 133 insertions, 69 deletions
diff --git a/Modules/FindSDL.cmake b/Modules/FindSDL.cmake
index 9f2bf33..c25e13c 100644
--- a/Modules/FindSDL.cmake
+++ b/Modules/FindSDL.cmake
@@ -1,19 +1,40 @@
-# - Locate the SDL library
+# Locate SDL library
# This module defines
-# SDL_LIBRARY, the library to link against
-# SDL_FOUND, if false, do not try to link to SDL
-# SDL_INCLUDE_DIR, where to find SDL.h
+# SDL_LIBRARY, the name of the library to link against
+# SDL_FOUND, if false, do not try to link to SDL
+# SDL_INCLUDE_DIR, where to find SDL.h
+#
+# This module responds to the the flag:
+# SDL_BUILDING_LIBRARY
+# If this is defined, then no SDL_main will be linked in because
+# only applications need main().
+# Otherwise, it is assumed you are building an application and this
+# module will attempt to locate and set the the proper link flags
+# as part of the returned SDL_LIBRARY variable.
#
# Don't forget to include SDLmain.h and SDLmain.m your project for the
# OS X framework based version. (Other versions link to -lSDLmain which
# this module will try to find on your behalf.) Also for OS X, this
# module will automatically add the -framework Cocoa on your behalf.
+#
+#
+# Additional Note: If you see an empty SDL_LIBRARY_TEMP in your configuration
+# and no SDL_LIBRARY, it means CMake did not find your SDL library
+# (SDL.dll, libsdl.so, SDL.framework, etc).
+# Set SDL_LIBRARY_TEMP to point to your SDL library, and configure again.
+# Similarly, if you see an empty SDLMAIN_LIBRARY, you should set this value
+# as appropriate. These values are used to generate the final SDL_LIBRARY
+# variable, but when these values are unset, SDL_LIBRARY does not get created.
+#
+#
# $SDLDIR is an environment variable that would
# correspond to the ./configure --prefix=$SDLDIR
# used in building SDL.
# l.e.galup 9-20-02
#
# Modified by Eric Wing.
+# Added code to assist with automated building by using environmental variables
+# and providing a more controlled/consistent search behavior.
# Added new modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
# Also corrected the header search path to follow "proper" SDL guidelines.
@@ -23,69 +44,109 @@
#
# On OSX, this will prefer the Framework version (if found) over others.
# People will have to manually change the cache values of
-# SDL_LIBRARY to override this selection.
+# SDL_LIBRARY to override this selection or set the CMake environment
+# CMAKE_INCLUDE_PATH to modify the search paths.
#
# Note that the header path has changed from SDL/SDL.h to just SDL.h
# This needed to change because "proper" SDL convention
# is #include "SDL.h", not <SDL/SDL.h>. This is done for portability
# reasons because not all systems place things in SDL/ (see FreeBSD).
-FIND_PATH(SDL_INCLUDE_DIR NAMES SDL.h
- PATH_SUFFIXES SDL SDL12 SDL11
+FIND_PATH(SDL_INCLUDE_DIR SDL.h
+ PATHS
+ $ENV{SDLDIR}
+ NO_DEFAULT_PATH
+ PATH_SUFFIXES include
+)
+FIND_PATH(SDL_INCLUDE_DIR SDL.h
+ PATHS ${CMAKE_PREFIX_PATH} # Unofficial: We are proposing this.
+ NO_DEFAULT_PATH
+ PATH_SUFFIXES include
+)
+FIND_PATH(SDL_INCLUDE_DIR SDL.h
+ PATHS
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /usr/local/include/SDL
+ /usr/include/SDL
+ /usr/local/include/SDL12
+ /usr/local/include/SDL11 # FreeBSD ports
+ /usr/include/SDL12
+ /usr/include/SDL11
+ /usr/local/include
+ /usr/include
+ /sw/include/SDL # Fink
+ /sw/include
+ /opt/local/include/SDL # DarwinPorts
+ /opt/local/include
+ /opt/csw/include/SDL # Blastwave
+ /opt/csw/include
+ /opt/include/SDL
+ /opt/include
+)
+#MESSAGE("SDL_INCLUDE_DIR is ${SDL_INCLUDE_DIR}")
+
+# SDL-1.1 is the name used by FreeBSD ports...
+# don't confuse it for the version number.
+FIND_LIBRARY(SDL_LIBRARY_TEMP
+ NAMES SDL SDL-1.1
+ PATHS
+ $ENV{SDLDIR}
+ NO_DEFAULT_PATH
+ PATH_SUFFIXES lib64 lib
+)
+FIND_LIBRARY(SDL_LIBRARY_TEMP
+ NAMES SDL SDL-1.1
+ PATHS ${CMAKE_PREFIX_PATH} # Unofficial: We are proposing this.
+ NO_DEFAULT_PATH
+ PATH_SUFFIXES lib64 lib
+)
+FIND_LIBRARY(SDL_LIBRARY_TEMP
+ NAMES SDL SDL-1.1
PATHS
- $ENV{SDLDIR}/include
- ~/Library/Frameworks/SDL.framework/Headers
- /Library/Frameworks/SDL.framework/Headers
- )
+ /usr/local
+ /usr
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ PATH_SUFFIXES lib64 lib
+)
-# I'm not sure if I should do a special casing for Apple. It is
-# unlikely that other Unix systems will find the framework path.
-# But if they do ([Next|Open|GNU]Step?),
-# do they want the -framework option also?
-IF(${SDL_INCLUDE_DIR} MATCHES ".framework")
- # The Cocoa framework must be linked into SDL because SDL is Cocoa based.
- # Remember that the OS X framework version expects you to drop in
- # SDLmain.h and SDLmain.m directly into your project.
- # (Cocoa link moved to bottom of this script.)
- # SET (SDL_LIBRARY "-framework SDL -framework Cocoa" CACHE STRING "SDL framework for OSX")
- # SET(SDL_LIBRARY "-framework SDL" CACHE STRING "SDL framework for OSX")
- # Extract the path the framework resides in so we can use it for the -F flag
- STRING(REGEX REPLACE "(.*)/.*\\.framework/.*" "\\1" SDL_FRAMEWORK_PATH_TEMP ${SDL_INCLUDE_DIR})
- IF("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks"
- OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks"
- )
- # String is in default search path, don't need to use -F
- SET(SDL_LIBRARY_TEMP "-framework SDL")
- ELSE("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks"
- OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks"
- )
- # String is not /Library/Frameworks, need to use -F
- SET(SDL_LIBRARY_TEMP "-F${SDL_FRAMEWORK_PATH_TEMP} -framework SDL")
- ENDIF("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks"
- OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks"
- )
- # Clear the temp variable so nobody can see it
- SET(SDL_FRAMEWORK_PATH_TEMP "" CACHE INTERNAL "")
+#MESSAGE("SDL_LIBRARY_TEMP is ${SDL_LIBRARY_TEMP}")
-ELSE(${SDL_INCLUDE_DIR} MATCHES ".framework")
- # SDL-1.1 is the name used by FreeBSD ports...
- # don't confuse it for the version number.
- FIND_LIBRARY(SDL_LIBRARY_TEMP
- NAMES SDL SDL-1.1
- PATHS
- $ENV{SDLDIR}/lib
+IF(NOT SDL_BUILDING_LIBRARY)
+ IF(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework")
+ # Non-OS X framework versions expect you to also dynamically link to
+ # SDLmain. This is mainly for Windows and OS X. Other (Unix) platforms
+ # seem to provide SDLmain for compatibility even though they don't
+ # necessarily need it.
+ FIND_LIBRARY(SDLMAIN_LIBRARY
+ NAMES SDLmain SDLmain-1.1
+ PATHS
+ $ENV{SDLDIR}
+ NO_DEFAULT_PATH
+ PATH_SUFFIXES lib64 lib
)
-
- # Non-OS X framework versions expect you to also dynamically link to
- # SDLmain. This is mainly for Windows and OS X. Other platforms
- # seem to provide SDLmain for compatibility even though they don't
- # necessarily need it.
- FIND_LIBRARY(SDLMAIN_LIBRARY
- NAMES SDLmain SDLmain-1.1
- PATHS
- $ENV{SDLDIR}/lib
+ FIND_LIBRARY(SDLMAIN_LIBRARY
+ NAMES SDLmain SDLmain-1.1
+ PATHS ${CMAKE_PREFIX_PATH} # Unofficial: We are proposing this.
+ NO_DEFAULT_PATH
+ PATH_SUFFIXES lib64 lib
+ )
+ FIND_LIBRARY(SDLMAIN_LIBRARY
+ NAMES SDLmain SDLmain-1.1
+ PATHS
+ /usr/local
+ /usr
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ PATH_SUFFIXES lib64 lib
)
-ENDIF(${SDL_INCLUDE_DIR} MATCHES ".framework")
+ ENDIF(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework")
+ENDIF(NOT SDL_BUILDING_LIBRARY)
# SDL may require threads on your system.
# The Apple build may not need an explicit flag because one of the
@@ -102,23 +163,27 @@ IF(MINGW)
SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
ENDIF(MINGW)
+SET(SDL_FOUND "NO")
IF(SDL_LIBRARY_TEMP)
# For SDLmain
- IF(SDLMAIN_LIBRARY)
- SET(SDL_LIBRARY_TEMP ${SDLMAIN_LIBRARY} ${SDL_LIBRARY_TEMP})
- ENDIF(SDLMAIN_LIBRARY)
+ IF(NOT SDL_BUILDING_LIBRARY)
+ IF(SDLMAIN_LIBRARY)
+ SET(SDL_LIBRARY_TEMP ${SDLMAIN_LIBRARY} ${SDL_LIBRARY_TEMP})
+ ENDIF(SDLMAIN_LIBRARY)
+ ENDIF(NOT SDL_BUILDING_LIBRARY)
# For OS X, SDL uses Cocoa as a backend so it must link to Cocoa.
# CMake doesn't display the -framework Cocoa string in the UI even
- # though it actually is there. I think it has something to do
- # with the CACHE STRING. Maybe somebody else knows how to fix this.
- # The problem is mainly cosmetic, and not a functional issue.
+ # though it actually is there if I modify a pre-used variable.
+ # I think it has something to do with the CACHE STRING.
+ # So I use a temporary variable until the end so I can set the
+ # "real" variable in one-shot.
IF(APPLE)
SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "-framework Cocoa")
ENDIF(APPLE)
-
+
# For threads, as mentioned Apple doesn't need this.
- # In fact, there seems to be a problem if Find the threads package
+ # In fact, there seems to be a problem if I used the Threads package
# and try using this line, so I'm just skipping it entirely for OS X.
IF(NOT APPLE)
SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
@@ -131,12 +196,11 @@ IF(SDL_LIBRARY_TEMP)
# Set the final string here so the GUI reflects the final state.
SET(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found")
+ # Set the temp variable to INTERNAL so it is not seen in the CMake GUI
+ SET(SDL_LIBRARY_TEMP "" CACHE INTERNAL "")
+ SET(SDL_FOUND "YES")
ENDIF(SDL_LIBRARY_TEMP)
-# handle the QUIETLY and REQUIRED arguments and set SDL_FOUND to TRUE if
-# all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL DEFAULT_MSG SDL_LIBRARY_TEMP)
+#MESSAGE("SDL_LIBRARY is ${SDL_LIBRARY}")
-MARK_AS_ADVANCED(SDL_LIBRARY_TEMP)