Hello,
I have written find modules for SDL2, SDL2_image and SDL2_net (see attachment).
I have tested them on Linux and Windows/MinGW with self-compiled SDL2
libraries. I did neither test with Visual Studio nor on OS X. Feel free to use
them if they are helpful for you (they are licensed under the standard license
of CMake find modules).
My question: Is it good to create new find modules for SDL2, or should the
existing SDL find modules be updated to search for SDL2?
If existing modules should be used: How to handle the case when both SDL and
SDL2 are found?
If new modules should be created: Shall I create a topic branch for the new
modules and create the missing ones (e.g., SDL2_mixer)?
Kind regards
Benjamin
# - Find SDL2 library and headers
#
# Find module for SDL 2.0 (http://www.libsdl.org/).
# It defines the following variables:
# SDL2_INCLUDE_DIRS - The location of the headers, e.g., SDL.h.
# SDL2_LIBRARIES - The libraries to link against to use SDL2.
# SDL2_FOUND - If false, do not try to use SDL2.
# SDL2_VERSION_STRING - Human-readable string containing the version of SDL2.
#
# This module responds to the the flag:
# SDL2_BUILDING_LIBRARY
# If this is defined, then no SDL2_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 SDL2_LIBRARIES variable.
#
# Also defined, but not for general use are:
# SDL2_INCLUDE_DIR - The directory that contains SDL.h.
# SDL2_LIBRARY - The location of the SDL2 library.
# SDL2MAIN_LIBRARY - The location of the SDL2main library.
#
#=============================================================================
# Copyright 2013 Benjamin Eikel
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
find_package(PkgConfig QUIET)
pkg_check_modules(PC_SDL2 QUIET sdl2)
find_path(SDL2_INCLUDE_DIR
NAMES SDL.h
HINTS
${PC_SDL2_INCLUDEDIR}
${PC_SDL2_INCLUDE_DIRS}
PATH_SUFFIXES SDL2
)
find_library(SDL2_LIBRARY
NAMES SDL2
HINTS
${PC_SDL2_LIBDIR}
${PC_SDL2_LIBRARY_DIRS}
PATH_SUFFIXES x64 x86
)
if(NOT SDL2_BUILDING_LIBRARY)
find_library(SDL2MAIN_LIBRARY
NAMES SDL2main
HINTS
${PC_SDL2_LIBDIR}
${PC_SDL2_LIBRARY_DIRS}
PATH_SUFFIXES x64 x86
)
endif()
if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h")
file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}")
set(SDL2_VERSION_STRING ${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH})
unset(SDL2_VERSION_MAJOR_LINE)
unset(SDL2_VERSION_MINOR_LINE)
unset(SDL2_VERSION_PATCH_LINE)
unset(SDL2_VERSION_MAJOR)
unset(SDL2_VERSION_MINOR)
unset(SDL2_VERSION_PATCH)
endif()
set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
set(SDL2_LIBRARIES ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SDL2
REQUIRED_VARS SDL2_INCLUDE_DIR SDL2_LIBRARY
VERSION_VAR SDL2_VERSION_STRING)
mark_as_advanced(SDL2_INCLUDE_DIR SDL2_LIBRARY)
# - Find SDL2_image library and headers
#
# Find module for SDL_image 2.0 (http://www.libsdl.org/projects/SDL_image/).
# It defines the following variables:
# SDL2_IMAGE_INCLUDE_DIRS - The location of the headers, e.g., SDL_image.h.
# SDL2_IMAGE_LIBRARIES - The libraries to link against to use SDL2_image.
# SDL2_IMAGE_FOUND - If false, do not try to use SDL2_image.
# SDL2_IMAGE_VERSION_STRING
# Human-readable string containing the version of SDL2_image.
#
# Also defined, but not for general use are:
# SDL2_IMAGE_INCLUDE_DIR - The directory that contains SDL_image.h.
# SDL2_IMAGE_LIBRARY - The location of the SDL2_image library.
#
#=============================================================================
# Copyright 2013 Benjamin Eikel
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
find_package(PkgConfig QUIET)
pkg_check_modules(PC_SDL2_IMAGE QUIET SDL2_image)
find_path(SDL2_IMAGE_INCLUDE_DIR
NAMES SDL_image.h
HINTS
${PC_SDL2_IMAGE_INCLUDEDIR}
${PC_SDL2_IMAGE_INCLUDE_DIRS}
PATH_SUFFIXES SDL2
)
find_library(SDL2_IMAGE_LIBRARY
NAMES SDL2_image
HINTS
${PC_SDL2_IMAGE_LIBDIR}
${PC_SDL2_IMAGE_LIBRARY_DIRS}
PATH_SUFFIXES x64 x86
)
if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h")
file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}")
set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH})
unset(SDL2_IMAGE_VERSION_MAJOR_LINE)
unset(SDL2_IMAGE_VERSION_MINOR_LINE)
unset(SDL2_IMAGE_VERSION_PATCH_LINE)
unset(SDL2_IMAGE_VERSION_MAJOR)
unset(SDL2_IMAGE_VERSION_MINOR)
unset(SDL2_IMAGE_VERSION_PATCH)
endif()
set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR})
set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SDL2_image
REQUIRED_VARS SDL2_IMAGE_INCLUDE_DIRS SDL2_IMAGE_LIBRARIES
VERSION_VAR SDL2_IMAGE_VERSION_STRING)
mark_as_advanced(SDL2_IMAGE_INCLUDE_DIR SDL2_IMAGE_LIBRARY)
# - Find SDL2_net library and headers
#
# Find module for SDL_net 2.0 (http://www.libsdl.org/projects/SDL_net/).
# It defines the following variables:
# SDL2_NET_INCLUDE_DIRS - The location of the headers, e.g., SDL_net.h.
# SDL2_NET_LIBRARIES - The libraries to link against to use SDL2_net.
# SDL2_NET_FOUND - If false, do not try to use SDL2_net.
# SDL2_NET_VERSION_STRING
# Human-readable string containing the version of SDL2_net.
#
# Also defined, but not for general use are:
# SDL2_NET_INCLUDE_DIR - The directory that contains SDL_net.h.
# SDL2_NET_LIBRARY - The location of the SDL2_net library.
#
#=============================================================================
# Copyright 2013 Benjamin Eikel
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
find_package(PkgConfig QUIET)
pkg_check_modules(PC_SDL2_NET QUIET SDL2_net)
find_path(SDL2_NET_INCLUDE_DIR
NAMES SDL_net.h
HINTS
${PC_SDL2_NET_INCLUDEDIR}
${PC_SDL2_NET_INCLUDE_DIRS}
PATH_SUFFIXES SDL2
)
find_library(SDL2_NET_LIBRARY
NAMES SDL2_net
HINTS
${PC_SDL2_NET_LIBDIR}
${PC_SDL2_NET_LIBRARY_DIRS}
PATH_SUFFIXES x64 x86
)
if(SDL2_NET_INCLUDE_DIR AND EXISTS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h")
file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_MAJOR "${SDL2_NET_VERSION_MAJOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_MINOR "${SDL2_NET_VERSION_MINOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_PATCH "${SDL2_NET_VERSION_PATCH_LINE}")
set(SDL2_NET_VERSION_STRING ${SDL2_NET_VERSION_MAJOR}.${SDL2_NET_VERSION_MINOR}.${SDL2_NET_VERSION_PATCH})
unset(SDL2_NET_VERSION_MAJOR_LINE)
unset(SDL2_NET_VERSION_MINOR_LINE)
unset(SDL2_NET_VERSION_PATCH_LINE)
unset(SDL2_NET_VERSION_MAJOR)
unset(SDL2_NET_VERSION_MINOR)
unset(SDL2_NET_VERSION_PATCH)
endif()
set(SDL2_NET_INCLUDE_DIRS ${SDL2_NET_INCLUDE_DIR})
set(SDL2_NET_LIBRARIES ${SDL2_NET_LIBRARY})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SDL2_net
REQUIRED_VARS SDL2_NET_INCLUDE_DIRS SDL2_NET_LIBRARIES
VERSION_VAR SDL2_NET_VERSION_STRING)
mark_as_advanced(SDL2_NET_INCLUDE_DIR SDL2_NET_LIBRARY)
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake