Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
377 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
# - Find SDL2 | ||
# Find the SDL2 headers and libraries | ||
# | ||
# SDL2::SDL2 - Imported target to use for building a library | ||
# SDL2::SDL2main - Imported target to use if you want SDL and SDLmain. | ||
# SDL2_FOUND - True if SDL2 was found. | ||
# | ||
# Original Author: | ||
# 2015 Ryan Pavlik <ryan.pavlik@gmail.com> <abiryan@ryand.net> | ||
# | ||
# Copyright Sensics, Inc. 2015. | ||
# Distributed under the Boost Software License, Version 1.0. | ||
# (See accompanying file LICENSE_1_0.txt or copy at | ||
# http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
# Set up architectures (for windows) and prefixes (for mingw builds) | ||
if(WIN32) | ||
if(CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
set(SDL2_LIB_PATH_SUFFIX lib/x64) | ||
if(NOT MSVC) | ||
set(SDL2_PREFIX x86_64-w64-mingw32) | ||
endif() | ||
else() | ||
set(SDL2_LIB_PATH_SUFFIX lib/x86) | ||
if(NOT MSVC) | ||
set(SDL2_PREFIX i686-w64-mingw32) | ||
endif() | ||
endif() | ||
endif() | ||
if(SDL2_PREFIX) | ||
set(SDL2_ORIGPREFIXPATH ${CMAKE_PREFIX_PATH}) | ||
if(SDL2_ROOT_DIR) | ||
list(APPEND CMAKE_PREFIX_PATH "${SDL2_ROOT_DIR}") | ||
endif() | ||
if(CMAKE_PREFIX_PATH) | ||
foreach(_prefix ${CMAKE_PREFIX_PATH}) | ||
list(APPEND CMAKE_PREFIX_PATH "${_prefix}/${SDL2_PREFIX}") | ||
endforeach() | ||
endif() | ||
endif() | ||
|
||
# Invoke pkgconfig for hints | ||
find_package(PkgConfig QUIET) | ||
set(SDL2_INCLUDE_HINTS) | ||
set(SDL2_LIB_HINTS) | ||
if(PKG_CONFIG_FOUND) | ||
pkg_search_module(SDL2PC QUIET sdl2) | ||
if(SDL2PC_INCLUDE_DIRS) | ||
set(SDL2_INCLUDE_HINTS ${SDL2PC_INCLUDE_DIRS}) | ||
endif() | ||
if(SDL2PC_LIBRARY_DIRS) | ||
set(SDL2_LIB_HINTS ${SDL2PC_LIBRARY_DIRS}) | ||
endif() | ||
endif() | ||
|
||
include(FindPackageHandleStandardArgs) | ||
|
||
find_path(SDL2_INCLUDE_DIR | ||
NAMES | ||
SDL_haptic.h # this file was introduced with SDL2 | ||
HINTS | ||
${SDL2_INCLUDE_HINTS} | ||
PATHS | ||
${SDL2_ROOT_DIR} | ||
ENV SDL2DIR | ||
PATH_SUFFIXES include include/sdl2) | ||
find_library(SDL2_LIBRARY | ||
NAMES | ||
SDL2 | ||
HINTS | ||
${SDL2_LIB_HINTS} | ||
PATHS | ||
${SDL2_ROOT_DIR} | ||
ENV SDL2DIR | ||
PATH_SUFFIXES lib ${SDL2_LIB_PATH_SUFFIX}) | ||
if(WIN32 AND SDL2_LIBRARY) | ||
find_file(SDL2_RUNTIME_LIBRARY | ||
NAMES | ||
SDL2.dll | ||
libSDL2.dll | ||
HINTS | ||
${SDL2_LIB_HINTS} | ||
PATHS | ||
${SDL2_ROOT_DIR} | ||
ENV SDL2DIR | ||
PATH_SUFFIXES bin lib ${SDL2_LIB_PATH_SUFFIX}) | ||
endif() | ||
|
||
if(WIN32 OR ANDROID OR IOS) | ||
set(SDL2_EXTRA_REQUIRED SDL2_SDLMAIN_LIBRARY) | ||
find_library(SDL2_SDLMAIN_LIBRARY | ||
NAMES | ||
SDL2main | ||
PATHS | ||
${SDL2_ROOT_DIR} | ||
ENV SDL2DIR | ||
PATH_SUFFIXES lib ${SDL2_LIB_PATH_SUFFIX}) | ||
endif() | ||
|
||
if(SDL2_PREFIX) | ||
# Restore things the way they used to be. | ||
set(CMAKE_PREFIX_PATH ${SDL2_ORIGPREFIXPATH}) | ||
endif() | ||
|
||
# handle the QUIETLY and REQUIRED arguments and set QUATLIB_FOUND to TRUE if | ||
# all listed variables are TRUE | ||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(SDL2 | ||
DEFAULT_MSG | ||
SDL2_LIBRARY | ||
SDL2_INCLUDE_DIR | ||
${SDL2_EXTRA_REQUIRED}) | ||
|
||
if(SDL2_FOUND) | ||
if(WIN32 AND SDL2_RUNTIME_LIBRARY) | ||
add_library(SDL2::SDL2 SHARED IMPORTED) | ||
set_target_properties(SDL2::SDL2 | ||
PROPERTIES | ||
IMPORTED_IMPLIB "${SDL2_LIBRARY}" | ||
IMPORTED_LOCATION "${SDL2_RUNTIME_LIBRARY}" | ||
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" | ||
) | ||
else() | ||
add_library(SDL2::SDL2 STATIC IMPORTED) | ||
set_target_properties(SDL2::SDL2 | ||
PROPERTIES | ||
IMPORTED_LOCATION "${SDL2_LIBRARY}" | ||
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" | ||
) | ||
endif() | ||
add_library(SDL2::SDL2main STATIC IMPORTED) | ||
set(SDL2MAIN_LIBRARIES SDL2::SDL2) | ||
if(SDL2_SDLMAIN_LIBRARY) | ||
set_target_properties(SDL2::SDL2main | ||
PROPERTIES | ||
IMPORTED_LOCATION "${SDL2_SDLMAIN_LIBRARY}") | ||
endif() | ||
if(MINGW) | ||
list(APPEND SDL2MAIN_LIBRARIES mingw32 mwindows) | ||
set_target_properties(SDL2::SDL2main | ||
PROPERTIES | ||
INTERFACE_COMPILE_DEFINITIONS "main=SDL_main") | ||
endif() | ||
set_target_properties(SDL2::SDL2main | ||
PROPERTIES | ||
INTERFACE_LINK_LIBRARIES "${SDL2MAIN_LIBRARIES}") | ||
mark_as_advanced(SDL2_ROOT_DIR) | ||
endif() | ||
|
||
mark_as_advanced(SDL2_LIBRARY SDL2_RUNTIME_LIBRARY SDL2_INCLUDE_DIR SDL2_SDLMAIN_LIBRARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#.rst: | ||
# GetMSVCVersion | ||
# -------------- | ||
# | ||
# | ||
# | ||
# get_msvc_major_version(<var>) | ||
# get_msvc_minor_version(<var>) | ||
# get_msvc_combined_major_minor_version(<var>) | ||
# get_msvc_major_minor_version(<major_var> <minor_var>) | ||
# get_msvc_unique_decimal_version(<var>) | ||
# | ||
# This family of functions is designed to be used to convert | ||
# MSVC_VERSION from the compiler version number to the Visual Studio | ||
# decimal version number (2012 is 11.0, 2015 is 14.0). All take a name | ||
# of a variable in <var> to return their results in. | ||
# | ||
# Consider Visual Studio 2013, which reports 1800 in MSVC_VERSION (and | ||
# the _MSC_VER preprocessor macro). It is also known as VS 12 or 12.0. | ||
# (Minor versions are rarely used, except in the case of 7.1 aka | ||
# VS.NET 2003) The functions would return this output for 2013: | ||
# | ||
# get_msvc_major_version: 12 | ||
# get_msvc_minor_version: 0 | ||
# get_msvc_combined_major_minor_version: 120 | ||
# get_msvc_major_minor_version: 12 in <major_var>, 0 in <minor_var> | ||
# get_msvc_unique_decimal_version: 12 (this returns with a decimal and | ||
# minor when needed to be precise, e.g. 7.1) | ||
# | ||
# The variable is not modified if not building with MSVC. | ||
|
||
#============================================================================= | ||
# Copyright 2015 Ryan Pavlik <ryan.pavlik@gmail.com> | ||
# | ||
# Distributed under the OSI-approved BSD License (the "License"); | ||
# see below. | ||
# | ||
# 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. | ||
#============================================================================= | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# | ||
# * Neither the names of Kitware, Inc., the Insight Software Consortium, | ||
# nor the names of their contributors may be used to endorse or promote | ||
# products derived from this software without specific prior written | ||
# permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
#============================================================================= | ||
|
||
# This function serves as the main implementation, with the others just | ||
# tweaking the result. | ||
function(get_msvc_combined_major_minor_version _var) | ||
if(NOT MSVC) | ||
return() | ||
endif() | ||
math(EXPR _vs_ver "${MSVC_VERSION} / 10 - 60") | ||
|
||
# VS 2015 changed the pattern because they skipped VS 13 | ||
if(_vs_ver GREATER 120) | ||
math(EXPR _vs_ver "${_vs_ver} + 10") | ||
endif() | ||
set(${_var} ${_vs_ver} PARENT_SCOPE) | ||
endfunction() | ||
|
||
# This function is also used as backend to some implementation, though | ||
# its contents are simpler, no real business logic to speak of. | ||
function(get_msvc_major_minor_version _major_var _minor_var) | ||
if(NOT MSVC) | ||
return() | ||
endif() | ||
get_msvc_combined_major_minor_version(_vs_ver) | ||
|
||
math(EXPR _vs_minor "${_vs_ver} % 10") | ||
math(EXPR _vs_major "(${_vs_ver} - ${_vs_minor}) / 10") | ||
set(${_major_var} ${_vs_major} PARENT_SCOPE) | ||
set(${_minor_var} ${_vs_minor} PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(get_msvc_major_version _var) | ||
if(NOT MSVC) | ||
return() | ||
endif() | ||
get_msvc_major_minor_version(_vs_ver _dummy) | ||
set(${_var} ${_vs_ver} PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(get_msvc_minor_version _var) | ||
if(NOT MSVC) | ||
return() | ||
endif() | ||
get_msvc_major_minor_version(_dummy _vs_ver) | ||
set(${_var} ${_vs_ver} PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(get_msvc_unique_decimal_version _var) | ||
if(NOT MSVC) | ||
return() | ||
endif() | ||
get_msvc_major_minor_version(_vs_major _vs_minor) | ||
set(_vs_ver ${_vs_major}) | ||
if(_vs_minor GREATER 0) | ||
set(_vs_ver "${_vs_ver}.${_vs_minor}") | ||
endif() | ||
set(${_var} ${_vs_ver} PARENT_SCOPE) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Sets CMAKE_MAP_IMPORTED_CONFIG_* so that if there isn't a perfect match between | ||
# the current project's build type and the imported build, but they're both some | ||
# kind of "Release" variant, things will just work. | ||
# | ||
# Original Author: | ||
# 2015 Ryan Pavlik <ryan@sensics.com> <abiryan@ryand.net> | ||
# http://academic.cleardefinition.com | ||
# | ||
# Copyright Sensics, Inc. 2015. | ||
# Distributed under the Boost Software License, Version 1.0. | ||
# (See accompanying file LICENSE_1_0.txt or copy at | ||
# http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
# RelWithDebInfo falls back to Release, then MinSizeRel | ||
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO RelWithDebInfo Release MinSizeRel NoConfig) | ||
|
||
# MinSizeRel falls back to Release, then RelWithDebInfo | ||
set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL MinSizeRel Release RelWithDebInfo NoConfig) | ||
|
||
# Release falls back to RelWithDebInfo, then MinSizeRel | ||
set(CMAKE_MAP_IMPORTED_CONFIG_RELEASE Release RelWithDebInfo MinSizeRel NoConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Defines a series of preprocessor variables based on the current platform. | ||
# | ||
# Usage: define_platform_macros(PREFIX) | ||
# | ||
# where PREFIX is the macro prefix (i.e., if PREFIX is XYZZY then the macros | ||
# will be named XYZZY_LINUX, XYZZY_WINDOWS, etc.). | ||
# | ||
# Author: | ||
# Kevin M. Godby <kevin@godby.org> | ||
# | ||
# Distributed under the Boost Software License, Version 1.0. | ||
# (See accompanying file LICENSE_1_0.txt or copy at | ||
# http://www.boost.org/LICENSE_1_0.txt) | ||
# | ||
|
||
function(_define_platform_macros_impl prefix platform_string variable_name) | ||
if (${CMAKE_SYSTEM_NAME} MATCHES "${platform_string}") | ||
string(TOUPPER "${prefix}_${variable_name}" _varname) | ||
set(${_varname} TRUE PARENT_SCOPE) | ||
endif() | ||
endfunction() | ||
|
||
macro(define_platform_macros _prefix) | ||
_define_platform_macros_impl(${_prefix} "AIX" AIX) | ||
_define_platform_macros_impl(${_prefix} "Android" ANDROID) | ||
_define_platform_macros_impl(${_prefix} "BS/DOS" BSDOS) | ||
_define_platform_macros_impl(${_prefix} "FreeBSD" FREEBSD) | ||
_define_platform_macros_impl(${_prefix} "HP-UX" HPUX) | ||
_define_platform_macros_impl(${_prefix} "IRIX" IRIX) | ||
_define_platform_macros_impl(${_prefix} "Linux" LINUX) | ||
_define_platform_macros_impl(${_prefix} "GNU/kFreeBSD" KFREEBSD) | ||
_define_platform_macros_impl(${_prefix} "NetBSD" NETBSD) | ||
_define_platform_macros_impl(${_prefix} "OpenBSD" OPENBSD) | ||
_define_platform_macros_impl(${_prefix} "OFS1" OFS1) | ||
_define_platform_macros_impl(${_prefix} "SCO_SV" SCO_SV) | ||
_define_platform_macros_impl(${_prefix} "UnixWare" UNIXWARE) | ||
_define_platform_macros_impl(${_prefix} "Xenix" XENIX) | ||
_define_platform_macros_impl(${_prefix} "SunOS" SUNOS) | ||
_define_platform_macros_impl(${_prefix} "Tru64" TRU64) | ||
_define_platform_macros_impl(${_prefix} "ULTRIX" ULTRIX) | ||
_define_platform_macros_impl(${_prefix} "CYGWIN" CYGWIN) | ||
_define_platform_macros_impl(${_prefix} "Darwin" MACOSX) | ||
_define_platform_macros_impl(${_prefix} "Windows" WINDOWS) | ||
endmacro() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# - Contains a function to sensibly and easily enable the "USE_FOLDERS" global property | ||
# without burning people using old MSVC Express Editions. | ||
# | ||
# use_folders([option_name]) - Creates an option (default name if you don't pass | ||
# one: BUILD_WITH_PROJECT_FOLDERS) that controls the USE_FOLDERS global property. | ||
# It has intelligently-set defaults that err on the side of caution (disabling) | ||
# on old MSVC versions, since solutions generated with USE_FOLDERS set to ON | ||
# cannot be used in some older MSVC Express Editions, so it's explicit opt-in there. | ||
# | ||
# Original Author: | ||
# 2015 Ryan Pavlik <ryan@sensics.com> <abiryan@ryand.net> | ||
# http://academic.cleardefinition.com | ||
# | ||
# Copyright Sensics, Inc. 2015. | ||
# Distributed under the Boost Software License, Version 1.0. | ||
# (See accompanying file LICENSE_1_0.txt or copy at | ||
# http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
function(use_folders) | ||
set(_option_name BUILD_WITH_PROJECT_FOLDERS) | ||
if(ARGV0) | ||
set(_option_name ${ARGV0}) | ||
endif() | ||
# Nitpicky TODO: This unnecessarily defaults to project folders off when using | ||
# an older toolset in a newer IDE... | ||
if(MSVC_IDE AND MSVC_VERSION LESS 1600) | ||
# VS 2012 Express and newer has folder support... | ||
option(${_option_name} "Enable project folders in the IDE. May only work in non-Express Editions!" OFF) | ||
else() | ||
option(${_option_name} "Enable project folders in the IDE." ON) | ||
endif() | ||
set_property(GLOBAL PROPERTY | ||
USE_FOLDERS ${${_option_name}}) | ||
endfunction() |