Support Sf2 Player, Mallets, PortAudio, and Lame with MSVC (#6507)
This commit is contained in:
73
cmake/modules/FindFluidSynth.cmake
Normal file
73
cmake/modules/FindFluidSynth.cmake
Normal file
@@ -0,0 +1,73 @@
|
||||
# Copyright (c) 2022 Dominic Clark
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the New BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
# Return if we already have FluidSynth
|
||||
if(TARGET fluidsynth)
|
||||
set(FluidSynth_FOUND 1)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Attempt to find FluidSynth using PkgConfig
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(FLUIDSYNTH_PKG fluidsynth)
|
||||
endif()
|
||||
|
||||
# Find the library and headers using the results from PkgConfig as a guide
|
||||
find_path(FluidSynth_INCLUDE_DIR
|
||||
NAMES "fluidsynth.h"
|
||||
HINTS ${FLUIDSYNTH_PKG_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
find_library(FluidSynth_LIBRARY
|
||||
NAMES "fluidsynth"
|
||||
HINTS ${FLUIDSYNTH_PKG_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
if(FluidSynth_INCLUDE_DIR AND FluidSynth_LIBRARY)
|
||||
add_library(fluidsynth UNKNOWN IMPORTED)
|
||||
set_target_properties(fluidsynth PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${FluidSynth_INCLUDE_DIR}"
|
||||
)
|
||||
|
||||
if(VCPKG_INSTALLED_DIR)
|
||||
include(ImportedTargetHelpers)
|
||||
_get_vcpkg_library_configs(FluidSynth_IMPLIB_RELEASE FluidSynth_IMPLIB_DEBUG "${FluidSynth_LIBRARY}")
|
||||
else()
|
||||
set(FluidSynth_IMPLIB_RELEASE "${FluidSynth_LIBRARY}")
|
||||
endif()
|
||||
|
||||
if(FluidSynth_IMPLIB_DEBUG)
|
||||
set_target_properties(fluidsynth PROPERTIES
|
||||
IMPORTED_LOCATION_RELEASE "${FluidSynth_IMPLIB_RELEASE}"
|
||||
IMPORTED_LOCATION_DEBUG "${FluidSynth_IMPLIB_DEBUG}"
|
||||
)
|
||||
else()
|
||||
set_target_properties(fluidsynth PROPERTIES
|
||||
IMPORTED_LOCATION "${FluidSynth_IMPLIB_RELEASE}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(EXISTS "${FluidSynth_INCLUDE_DIR}/fluidsynth/version.h")
|
||||
file(STRINGS
|
||||
"${FluidSynth_INCLUDE_DIR}/fluidsynth/version.h"
|
||||
_version_string
|
||||
REGEX "^#[\t ]*define[\t ]+FLUIDSYNTH_VERSION[\t ]+\".*\""
|
||||
)
|
||||
string(REGEX REPLACE
|
||||
"^.*FLUIDSYNTH_VERSION[\t ]+\"([^\"]*)\".*$"
|
||||
"\\1"
|
||||
FluidSynth_VERSION_STRING
|
||||
"${_version_string}"
|
||||
)
|
||||
unset(_version_string)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(FluidSynth
|
||||
REQUIRED_VARS FluidSynth_LIBRARY FluidSynth_INCLUDE_DIR
|
||||
VERSION_VAR FluidSynth_VERSION_STRING
|
||||
)
|
||||
@@ -1,16 +1,37 @@
|
||||
# - Try to find LAME
|
||||
# Once done this will define
|
||||
#
|
||||
# LAME_FOUND - system has liblame
|
||||
# LAME_INCLUDE_DIRS - the liblame include directory
|
||||
# LAME_LIBRARIES - The liblame libraries
|
||||
# Lame_FOUND - system has liblame
|
||||
# Lame_INCLUDE_DIRS - the liblame include directory
|
||||
# Lame_LIBRARIES - The liblame libraries
|
||||
# mp3lame::mp3lame - an imported target providing lame
|
||||
|
||||
find_path(LAME_INCLUDE_DIRS lame/lame.h)
|
||||
find_library(LAME_LIBRARIES mp3lame)
|
||||
find_package(mp3lame CONFIG QUIET)
|
||||
|
||||
if(TARGET mp3lame::mp3lame)
|
||||
# Extract details for find_package_handle_standard_args
|
||||
get_target_property(Lame_LIBRARIES mp3lame::mp3lame LOCATION)
|
||||
get_target_property(Lame_INCLUDE_DIRS mp3lame::mp3lame INTERFACE_INCLUDE_DIRECTORIES)
|
||||
else()
|
||||
find_path(Lame_INCLUDE_DIRS lame/lame.h)
|
||||
find_library(Lame_LIBRARIES mp3lame)
|
||||
|
||||
list(APPEND Lame_DEFINITIONS HAVE_LIBMP3LAME=1)
|
||||
|
||||
mark_as_advanced(Lame_INCLUDE_DIRS Lame_LIBRARIES Lame_DEFINITIONS)
|
||||
|
||||
if(Lame_LIBRARIES AND Lame_INCLUDE_DIRS)
|
||||
add_library(mp3lame::mp3lame UNKNOWN IMPORTED)
|
||||
|
||||
set_target_properties(mp3lame::mp3lame PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${Lame_INCLUDE_DIRS}"
|
||||
INTERFACE_COMPILE_DEFINITIONS "${Lame_DEFINITIONS}"
|
||||
IMPORTED_LOCATION "${Lame_LIBRARIES}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Lame DEFAULT_MSG LAME_INCLUDE_DIRS LAME_LIBRARIES)
|
||||
|
||||
list(APPEND LAME_DEFINITIONS -DHAVE_LIBMP3LAME=1)
|
||||
|
||||
mark_as_advanced(LAME_INCLUDE_DIRS LAME_LIBRARIES LAME_DEFINITIONS)
|
||||
find_package_handle_standard_args(Lame
|
||||
REQUIRED_VARS Lame_LIBRARIES Lame_INCLUDE_DIRS
|
||||
)
|
||||
|
||||
@@ -1,36 +1,44 @@
|
||||
# - Try to find Portaudio
|
||||
# Once done this will define
|
||||
#
|
||||
# PORTAUDIO_FOUND - system has Portaudio
|
||||
# PORTAUDIO_INCLUDE_DIRS - the Portaudio include directory
|
||||
# PORTAUDIO_LIBRARIES - Link these to use Portaudio
|
||||
# PORTAUDIO_DEFINITIONS - Compiler switches required for using Portaudio
|
||||
#
|
||||
# Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
|
||||
# Copyright (c) 2022 Dominic Clark
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the New BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
#
|
||||
|
||||
# Try config mode if possible
|
||||
find_package(portaudio CONFIG QUIET)
|
||||
|
||||
if (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS)
|
||||
# in cache already
|
||||
set(PORTAUDIO_FOUND TRUE)
|
||||
else (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS)
|
||||
include(FindPkgConfig)
|
||||
pkg_check_modules(PORTAUDIO portaudio-2.0)
|
||||
if (PORTAUDIO_FOUND)
|
||||
if (NOT Portaudio_FIND_QUIETLY)
|
||||
message(STATUS "Found Portaudio: ${PORTAUDIO_LIBRARIES}")
|
||||
endif (NOT Portaudio_FIND_QUIETLY)
|
||||
else (PORTAUDIO_FOUND)
|
||||
if (Portaudio_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Could not find Portaudio")
|
||||
endif (Portaudio_FIND_REQUIRED)
|
||||
endif (PORTAUDIO_FOUND)
|
||||
if(TARGET portaudio)
|
||||
# Extract details for find_package_handle_standard_args
|
||||
get_target_property(Portaudio_LIBRARY portaudio LOCATION)
|
||||
get_target_property(Portaudio_INCLUDE_DIR portaudio INTERFACE_INCLUDE_DIRECTORIES)
|
||||
else()
|
||||
# Attempt to find PortAudio using PkgConfig, if we have it
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(PORTAUDIO_PKG portaudio-2.0)
|
||||
endif()
|
||||
|
||||
# show the PORTAUDIO_INCLUDE_DIRS and PORTAUDIO_LIBRARIES variables only in the advanced view
|
||||
mark_as_advanced(PORTAUDIO_INCLUDE_DIRS PORTAUDIO_LIBRARIES)
|
||||
# Find the library and headers using the results from PkgConfig as a guide
|
||||
find_library(Portaudio_LIBRARY
|
||||
NAMES "portaudio"
|
||||
HINTS ${PORTAUDIO_PKG_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
endif (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS)
|
||||
find_path(Portaudio_INCLUDE_DIR
|
||||
NAMES "portaudio.h"
|
||||
HINTS ${PORTAUDIO_PKG_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# Create an imported target for PortAudio if we succeeded in finding it.
|
||||
if(Portaudio_LIBRARY AND Portaudio_INCLUDE_DIR)
|
||||
add_library(portaudio UNKNOWN IMPORTED)
|
||||
set_target_properties(portaudio PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${Portaudio_INCLUDE_DIR}"
|
||||
IMPORTED_LOCATION "${Portaudio_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Portaudio
|
||||
REQUIRED_VARS Portaudio_LIBRARY Portaudio_INCLUDE_DIR
|
||||
)
|
||||
|
||||
@@ -1,60 +1,20 @@
|
||||
# This module defines
|
||||
# SDL2::SDL2, a target providing SDL2 itself
|
||||
# SDL2::SDL2main, a target providing an entry point for applications
|
||||
# SDL2_LIBRARY, the name of the library to link against
|
||||
# SDL2_FOUND, if false, do not try to link to SDL2
|
||||
# SDL2_INCLUDE_DIR, where to find SDL.h
|
||||
#
|
||||
# This module responds to the the flag:
|
||||
# SDL2_BUILDING_LIBRARY
|
||||
# If this is defined, then no SDL2::SDL2main target will be created 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 SDL2::SDL2main target.
|
||||
#
|
||||
# Don't forget to include SDLmain.h and SDLmain.m your project for the
|
||||
# OS X framework based version. (Other versions link to -lSDL2main 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 SDL2_LIBRARY in your configuration, it
|
||||
# means CMake did not find your SDL2 library (SDL2.dll, libsdl2.so,
|
||||
# SDL2.framework, etc).
|
||||
# Set SDL2_LIBRARY to point to your SDL2 library, and configure again.
|
||||
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
|
||||
# as appropriate.
|
||||
#
|
||||
#
|
||||
# Modified by Dominic Clark.
|
||||
# Added modern CMake targets to match those SDL2 itself uses.
|
||||
#
|
||||
# $SDL2DIR is an environment variable that would
|
||||
# correspond to the ./configure --prefix=$SDL2DIR
|
||||
# used in building SDL2.
|
||||
# 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.
|
||||
# Added a search for SDL2main which is needed by some platforms.
|
||||
# Added a search for threads which is needed by some platforms.
|
||||
# Added needed compile switches for MinGW.
|
||||
#
|
||||
# On OSX, this will prefer the Framework version (if found) over others.
|
||||
# People will have to manually change the cache values of
|
||||
# SDL2_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 SDL2/SDL.h to just SDL.h
|
||||
# This needed to change because "proper" SDL convention
|
||||
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
|
||||
# reasons because not all systems place things in SDL2/ (see FreeBSD).
|
||||
|
||||
# $SDL2DIR is an environment variable that would
|
||||
# correspond to the ./configure --prefix=$SDL2DIR
|
||||
# used in building SDL2.
|
||||
#
|
||||
# Modified by Eric Wing, l.e.galup, and Dominic Clark
|
||||
#
|
||||
#=============================================================================
|
||||
# Copyright 2003-2009 Kitware, Inc.
|
||||
#
|
||||
@@ -68,110 +28,91 @@
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
# message("<FindSDL2.cmake>")
|
||||
# Try config mode first - anything SDL2 itself provides is likely to be more
|
||||
# reliable than our guesses.
|
||||
find_package(SDL2 CONFIG QUIET)
|
||||
|
||||
SET(SDL2_SEARCH_PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
${SDL2_PATH}
|
||||
)
|
||||
|
||||
FIND_PATH(SDL2_INCLUDE_DIR SDL.h
|
||||
HINTS
|
||||
$ENV{SDL2DIR}
|
||||
PATH_SUFFIXES SDL2 include/SDL2 include
|
||||
PATHS ${SDL2_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(PATH_SUFFIXES lib64 lib/x64 lib)
|
||||
else()
|
||||
set(PATH_SUFFIXES lib/x86 lib)
|
||||
endif()
|
||||
|
||||
FIND_LIBRARY(SDL2_LIBRARY
|
||||
NAMES SDL2
|
||||
HINTS
|
||||
$ENV{SDL2DIR}
|
||||
PATH_SUFFIXES ${PATH_SUFFIXES}
|
||||
PATHS ${SDL2_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
IF(NOT SDL2_BUILDING_LIBRARY)
|
||||
IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
|
||||
# Non-OS X framework versions expect you to also dynamically link to
|
||||
# SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
|
||||
# seem to provide SDL2main for compatibility even though they don't
|
||||
# necessarily need it.
|
||||
FIND_LIBRARY(SDL2MAIN_LIBRARY
|
||||
NAMES SDL2main
|
||||
HINTS
|
||||
$ENV{SDL2DIR}
|
||||
PATH_SUFFIXES ${PATH_SUFFIXES}
|
||||
PATHS ${SDL2_SEARCH_PATHS}
|
||||
)
|
||||
ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
|
||||
ENDIF(NOT SDL2_BUILDING_LIBRARY)
|
||||
|
||||
# SDL2 may require threads on your system.
|
||||
# The Apple build may not need an explicit flag because one of the
|
||||
# frameworks may already provide it.
|
||||
# But for non-OSX systems, I will use the CMake Threads package.
|
||||
IF(NOT APPLE)
|
||||
FIND_PACKAGE(Threads)
|
||||
ENDIF(NOT APPLE)
|
||||
|
||||
# MinGW needs an additional link flag, -mwindows
|
||||
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows
|
||||
IF(MINGW)
|
||||
SET(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "mwindows for MinGW")
|
||||
ENDIF(MINGW)
|
||||
|
||||
IF(SDL2_LIBRARY)
|
||||
ADD_LIBRARY(SDL2::SDL2 UNKNOWN IMPORTED)
|
||||
SET_TARGET_PROPERTIES(SDL2::SDL2 PROPERTIES
|
||||
IMPORTED_LOCATION "${SDL2_LIBRARY}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
|
||||
if(TARGET SDL2::SDL2)
|
||||
# Extract details for find_package_handle_standard_args
|
||||
get_target_property(SDL2_LIBRARY SDL2::SDL2 LOCATION)
|
||||
get_target_property(SDL2_INCLUDE_DIR SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES)
|
||||
else()
|
||||
set(SDL2_SEARCH_PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
${SDL2_PATH}
|
||||
)
|
||||
|
||||
# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
|
||||
IF(APPLE)
|
||||
SET_PROPERTY(TARGET SDL2::SDL2 APPEND PROPERTY
|
||||
INTERFACE_LINK_OPTIONS "-framework Cocoa"
|
||||
)
|
||||
ENDIF(APPLE)
|
||||
|
||||
# For threads, as mentioned Apple doesn't need this.
|
||||
# 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 AND Threads_FOUND)
|
||||
SET_PROPERTY(TARGET SDL2::SDL2 APPEND PROPERTY
|
||||
INTERFACE_LINK_LIBRARIES "Threads::Threads"
|
||||
)
|
||||
ENDIF(NOT APPLE AND Threads_FOUND)
|
||||
ENDIF(SDL2_LIBRARY)
|
||||
|
||||
IF(NOT SDL2_BUILDING_LIBRARY AND SDL2MAIN_LIBRARY)
|
||||
ADD_LIBRARY(SDL2::SDL2main STATIC IMPORTED)
|
||||
SET_TARGET_PROPERTIES(SDL2::SDL2main PROPERTIES
|
||||
IMPORTED_LOCATION "${SDL2MAIN_LIBRARY}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
|
||||
find_path(SDL2_INCLUDE_DIR
|
||||
NAMES SDL.h
|
||||
HINTS $ENV{SDL2DIR} ${SDL2_INCLUDE_DIRS}
|
||||
PATH_SUFFIXES SDL2 include/SDL2 include
|
||||
PATHS ${SDL2_SEARCH_PATHS}
|
||||
)
|
||||
IF(MINGW)
|
||||
SET_PROPERTY(TARGET SDL2::SDL2main APPEND PROPERTY
|
||||
INTERFACE_LINK_OPTIONS "${MINGW32_LIBRARY}"
|
||||
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(PATH_SUFFIXES lib64 lib/x64 lib)
|
||||
else()
|
||||
set(PATH_SUFFIXES lib/x86 lib)
|
||||
endif()
|
||||
|
||||
find_library(SDL2_LIBRARY
|
||||
NAMES SDL2
|
||||
HINTS $ENV{SDL2DIR} ${SDL2_LIBDIR}
|
||||
PATH_SUFFIXES ${PATH_SUFFIXES}
|
||||
PATHS ${SDL2_SEARCH_PATHS}
|
||||
)
|
||||
|
||||
# SDL2 may require threads on your system.
|
||||
# The Apple build may not need an explicit flag because one of the
|
||||
# frameworks may already provide it.
|
||||
# But for non-OSX systems, I will use the CMake Threads package.
|
||||
if(NOT APPLE)
|
||||
find_package(Threads)
|
||||
endif()
|
||||
|
||||
if(SDL2_LIBRARY AND SDL2_INCLUDE_DIR)
|
||||
add_library(SDL2::SDL2 UNKNOWN IMPORTED)
|
||||
set_target_properties(SDL2::SDL2 PROPERTIES
|
||||
IMPORTED_LOCATION "${SDL2_LIBRARY}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
|
||||
)
|
||||
ENDIF(MINGW)
|
||||
ENDIF(NOT SDL2_BUILDING_LIBRARY AND SDL2MAIN_LIBRARY)
|
||||
|
||||
# message("</FindSDL2.cmake>")
|
||||
# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
|
||||
if(APPLE)
|
||||
set_property(TARGET SDL2::SDL2 APPEND PROPERTY
|
||||
INTERFACE_LINK_OPTIONS "-framework Cocoa"
|
||||
)
|
||||
endif()
|
||||
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
# For threads, as mentioned Apple doesn't need this.
|
||||
# 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 AND Threads_FOUND)
|
||||
set_property(TARGET SDL2::SDL2 APPEND PROPERTY
|
||||
INTERFACE_LINK_LIBRARIES "Threads::Threads"
|
||||
)
|
||||
endif()
|
||||
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)
|
||||
if(EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h")
|
||||
file(READ "${SDL2_INCLUDE_DIR}/SDL_version.h" _sdl_version_h)
|
||||
string(REGEX REPLACE ".*#[\t ]*define[\t ]+SDL_MAJOR_VERSION[\t ]+([0-9]+).*" "\\1" SDL2_VERSION_MAJOR "${_sdl_version_h}")
|
||||
string(REGEX REPLACE ".*#[\t ]*define[\t ]+SDL_MINOR_VERSION[\t ]+([0-9]+).*" "\\1" SDL2_VERSION_MINOR "${_sdl_version_h}")
|
||||
string(REGEX REPLACE ".*#[\t ]*define[\t ]+SDL_PATCHLEVEL[\t ]+([0-9]+).*" "\\1" SDL2_VERSION_PATCH "${_sdl_version_h}")
|
||||
set(SDL2_VERSION "${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH}")
|
||||
unset(_sdl_version_h)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(SDL2
|
||||
REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR
|
||||
VERSION_VAR SDL2_VERSION
|
||||
)
|
||||
|
||||
@@ -1,20 +1,32 @@
|
||||
FIND_PATH(STK_INCLUDE_DIR Stk.h /usr/include/stk /usr/local/include/stk ${CMAKE_INSTALL_PREFIX}/include/stk ${CMAKE_FIND_ROOT_PATH}/include/stk)
|
||||
# Try config mode first
|
||||
find_package(unofficial-libstk CONFIG QUIET)
|
||||
|
||||
FIND_LIBRARY(STK_LIBRARY NAMES stk PATH /usr/lib /usr/local/lib ${CMAKE_INSTALL_PREFIX}/lib ${CMAKE_FIND_ROOT_PATH}/lib)
|
||||
if(TARGET unofficial::libstk::libstk)
|
||||
# Extract details for find_package_handle_standard_args
|
||||
get_target_property(STK_LIBRARY unofficial::libstk::libstk LOCATION)
|
||||
get_target_property(STK_INCLUDE_DIR unofficial::libstk::libstk INTERFACE_INCLUDE_DIRECTORIES)
|
||||
else()
|
||||
find_path(STK_INCLUDE_DIR
|
||||
NAMES stk/Stk.h
|
||||
PATH /usr/include /usr/local/include "${CMAKE_INSTALL_PREFIX}/include" "${CMAKE_FIND_ROOT_PATH}/include"
|
||||
)
|
||||
|
||||
IF (STK_INCLUDE_DIR AND STK_LIBRARY)
|
||||
SET(STK_FOUND TRUE)
|
||||
ENDIF (STK_INCLUDE_DIR AND STK_LIBRARY)
|
||||
find_library(STK_LIBRARY
|
||||
NAMES stk
|
||||
PATH /usr/lib /usr/local/lib "${CMAKE_INSTALL_PREFIX}/lib" "${CMAKE_FIND_ROOT_PATH}/lib"
|
||||
)
|
||||
|
||||
if(STK_INCLUDE_DIR AND STK_LIBRARY)
|
||||
# Yes, this target name is hideous, but it matches that provided by vcpkg
|
||||
add_library(unofficial::libstk::libstk UNKNOWN IMPORTED)
|
||||
set_target_properties(unofficial::libstk::libstk PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${STK_INCLUDE_DIR}"
|
||||
IMPORTED_LOCATION "${STK_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
IF (STK_FOUND)
|
||||
IF (NOT STK_FIND_QUIETLY)
|
||||
MESSAGE(STATUS "Found STK: ${STK_LIBRARY}")
|
||||
SET(HAVE_STK TRUE)
|
||||
ENDIF (NOT STK_FIND_QUIETLY)
|
||||
ELSE (STK_FOUND)
|
||||
IF (STK_FIND_REQUIRED)
|
||||
MESSAGE(FATAL_ERROR "Could not find STK")
|
||||
ENDIF (STK_FIND_REQUIRED)
|
||||
ENDIF (STK_FOUND)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(STK
|
||||
REQUIRED_VARS STK_LIBRARY STK_INCLUDE_DIR
|
||||
)
|
||||
|
||||
57
cmake/modules/ImportedTargetHelpers.cmake
Normal file
57
cmake/modules/ImportedTargetHelpers.cmake
Normal file
@@ -0,0 +1,57 @@
|
||||
# Given a library in vcpkg, find appropriate debug and release versions. If only
|
||||
# one version exists, it is used as the release version, and the debug version
|
||||
# is not set.
|
||||
function(_get_vcpkg_library_configs _release_out _debug_out _library)
|
||||
# We want to do all operations within the vcpkg directory
|
||||
file(RELATIVE_PATH _lib_relative "${VCPKG_INSTALLED_DIR}" "${_library}")
|
||||
|
||||
# Return early if we're not using vcpkg
|
||||
if(IS_ABSOLUTE _lib_relative OR _lib_relative MATCHES "^\\.\\./")
|
||||
set("${_release_out}" "${_library}" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
string(REPLACE "/" ";" _path_bits "${_lib_relative}")
|
||||
|
||||
# Determine whether we were given the debug or release version
|
||||
list(FIND _path_bits "debug" _debug_index)
|
||||
if(_debug_index EQUAL -1)
|
||||
# We have the release version, so use it
|
||||
set(_release_lib "${_library}")
|
||||
|
||||
# Try to find a debug version too
|
||||
list(FIND _path_bits "lib" _lib_index)
|
||||
if(_lib_index GREATER_EQUAL 0)
|
||||
list(INSERT _path_bits "${_lib_index}" "debug")
|
||||
list(INSERT _path_bits 0 "${VCPKG_INSTALLED_DIR}")
|
||||
string(REPLACE ";" "/" _debug_lib "${_path_bits}")
|
||||
|
||||
if(NOT EXISTS "${_debug_lib}")
|
||||
# Debug version does not exist - only use given version
|
||||
unset(_debug_lib)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
# We have the debug version, so try to find a release version too
|
||||
list(REMOVE_AT _path_bits "${_debug_index}")
|
||||
list(INSERT _path_bits 0 "${VCPKG_INSTALLED_DIR}")
|
||||
string(REPLACE ";" "/" _release_lib "${_path_bits}")
|
||||
|
||||
if(NOT EXISTS "${_release_lib}")
|
||||
# Release version does not exist - only use given version
|
||||
set(_release_lib "${_library}")
|
||||
else()
|
||||
# Release version exists, so use given version as debug
|
||||
set(_debug_lib "${_library}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Set output variables appropriately
|
||||
if(_debug_lib)
|
||||
set("${_release_out}" "${_release_lib}" PARENT_SCOPE)
|
||||
set("${_debug_out}" "${_debug_lib}" PARENT_SCOPE)
|
||||
else()
|
||||
set("${_release_out}" "${_release_lib}" PARENT_SCOPE)
|
||||
unset("${_debug_out}" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
Reference in New Issue
Block a user