Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor find vorbis file cmake #6671

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ later, or a version of Clang with equivalent support.
You'll need to have these libraries and their development headers installed in
order to build Wesnoth:

* Boost libraries >= 1.65.0
* Boost libraries >= 1.66.0
Most headers plus the following binary libs:
* Filesystem
* Locale
Expand Down Expand Up @@ -56,7 +56,7 @@ The following build systems are fully supported for compiling Wesnoth on Linux,
*BSD, and other Unix-like platforms:

* SCons >= 0.98.3
* CMake >= 2.8.5
* CMake >= 3.14

You will also need to have a working installation of GNU gettext to build the
translations.
Expand Down
143 changes: 84 additions & 59 deletions cmake/FindVorbisFile.cmake
Original file line number Diff line number Diff line change
@@ -1,96 +1,121 @@
# Locate VorbisFile
# This module defines XXX_FOUND, XXX_INCLUDE_DIRS and XXX_LIBRARIES standard variables
#
# $VORBISDIR is an environment variable that would
# correspond to the ./configure --prefix=$VORBISDIR
# used in building Vorbis.
#[=======================================================================[.rst:
FindVorbisFile
--------------

# Copied from
# http://code.google.com/p/osgaudio/source/browse/trunk/CMakeModules/FindVorbisFile.cmake
Find the VorbisFile includes and library.

SET(VORBISFILE_SEARCH_PATHS
Environment
^^^^^^^^^^^

$ENV{VORBISDIR} is an environment variable that would correspond to
the `./configure --prefix=$VORBISDIR` used in building Vorbis.


IMPORTED Targets
^^^^^^^^^^^^^^^^

This module defines the `IMPORTED` target ``VorbisFile::VorbisFile``, if
VorbisFile has been found.

Result Variables
^^^^^^^^^^^^^^^^

This module defines the following variables:

VORBISFILE_FOUND - True if VorbisFile found.
VORBISFILE_INCLUDE_DIR - Where to find vorbis/vorbisfile.h.
VORBISFILE_LIBRARIES - Libraries when using VorbisFile.

Inspiration
^^^^^^^^^^^

http://code.google.com/p/osgaudio/source/browse/trunk/CMakeModules/FindVorbisFile.cmake

#]=======================================================================]

set(VORBISFILE_SEARCH_PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr/local
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces -> tabs

/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)

SET(MSVC_YEAR_NAME)
IF (MSVC_VERSION GREATER 1599) # >= 1600
SET(MSVC_YEAR_NAME VS2010)
ELSEIF(MSVC_VERSION GREATER 1499) # >= 1500
SET(MSVC_YEAR_NAME VS2008)
ELSEIF(MSVC_VERSION GREATER 1399) # >= 1400
SET(MSVC_YEAR_NAME VS2005)
ELSEIF(MSVC_VERSION GREATER 1299) # >= 1300
SET(MSVC_YEAR_NAME VS2003)
ELSEIF(MSVC_VERSION GREATER 1199) # >= 1200
SET(MSVC_YEAR_NAME VS6)
ENDIF()

FIND_PATH(VORBISFILE_INCLUDE_DIR
find_path(VORBISFILE_INCLUDE_DIR
NAMES vorbis/vorbisfile.h
HINTS
$ENV{VORBISFILEDIR}
$ENV{VORBISFILE_PATH}
$ENV{VORBISDIR}
$ENV{VORBIS_PATH}
$ENV{VORBISFILEDIR}
$ENV{VORBISFILE_PATH}
$ENV{VORBISDIR}
$ENV{VORBIS_PATH}
PATH_SUFFIXES include
PATHS ${VORBISFILE_SEARCH_PATHS}
)

FIND_LIBRARY(VORBISFILE_LIBRARY
find_library(VORBISFILE_LIBRARY
NAMES vorbisfile libvorbisfile
HINTS
$ENV{VORBISFILEDIR}
$ENV{VORBISFILE_PATH}
$ENV{VORBISDIR}
$ENV{VORBIS_PATH}
PATH_SUFFIXES lib lib64 win32/VorbisFile_Dynamic_Release "Win32/${MSVC_YEAR_NAME}/x64/Release" "Win32/${MSVC_YEAR_NAME}/Win32/Release"
$ENV{VORBISFILEDIR}
$ENV{VORBISFILE_PATH}
$ENV{VORBISDIR}
$ENV{VORBIS_PATH}
PATH_SUFFIXES
lib
lib64
PATHS ${VORBISFILE_SEARCH_PATHS}
)

# First search for d-suffixed libs
FIND_LIBRARY(VORBISFILE_LIBRARY_DEBUG
find_library(VORBISFILE_LIBRARY_DEBUG
NAMES vorbisfiled vorbisfile_d libvorbisfiled libvorbisfile_d
HINTS
$ENV{VORBISFILEDIR}
$ENV{VORBISFILE_PATH}
$ENV{VORBISDIR}
$ENV{VORBIS_PATH}
PATH_SUFFIXES lib lib64 win32/VorbisFile_Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug"
$ENV{VORBISFILEDIR}
$ENV{VORBISFILE_PATH}
$ENV{VORBISDIR}
$ENV{VORBIS_PATH}
PATH_SUFFIXES
lib
lib64
PATHS ${VORBISFILE_SEARCH_PATHS}
)

IF(NOT VORBISFILE_LIBRARY_DEBUG)
if(NOT VORBISFILE_LIBRARY_DEBUG)
# Then search for non suffixed libs if necessary, but only in debug dirs
FIND_LIBRARY(VORBISFILE_LIBRARY_DEBUG
find_library(VORBISFILE_LIBRARY_DEBUG
NAMES vorbisfile libvorbisfile
HINTS
$ENV{VORBISFILEDIR}
$ENV{VORBISFILE_PATH}
$ENV{VORBISDIR}
$ENV{VORBIS_PATH}
PATH_SUFFIXES win32/VorbisFile_Dynamic_Debug "Win32/${MSVC_YEAR_NAME}/x64/Debug" "Win32/${MSVC_YEAR_NAME}/Win32/Debug"
$ENV{VORBISFILEDIR}
$ENV{VORBISFILE_PATH}
$ENV{VORBISDIR}
$ENV{VORBIS_PATH}
PATHS ${VORBISFILE_SEARCH_PATHS}
)
ENDIF()

endif()

IF(VORBISFILE_LIBRARY)
IF(VORBISFILE_LIBRARY_DEBUG)
SET(VORBISFILE_LIBRARIES optimized "${VORBISFILE_LIBRARY}" debug "${VORBISFILE_LIBRARY_DEBUG}")
ELSE()
SET(VORBISFILE_LIBRARIES "${VORBISFILE_LIBRARY}") # Could add "general" keyword, but it is optional
ENDIF()
ENDIF()
if(VORBISFILE_LIBRARY)
if(VORBISFILE_LIBRARY_DEBUG)
set(VORBISFILE_LIBRARIES optimized "${VORBISFILE_LIBRARY}" debug "${VORBISFILE_LIBRARY_DEBUG}")
else()
set(VORBISFILE_LIBRARIES "${VORBISFILE_LIBRARY}") # Could add "general" keyword, but it is optional
endif()
endif()

# handle the QUIETLY and REQUIRED arguments and set XXX_FOUND to TRUE if all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(VorbisFile DEFAULT_MSG VORBISFILE_LIBRARIES VORBISFILE_INCLUDE_DIR)
# handle the QUIETLY and REQUIRED arguments and set VORBISFILE_FOUND to TRUE if all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(VorbisFile DEFAULT_MSG VORBISFILE_LIBRARIES VORBISFILE_INCLUDE_DIR)

mark_as_advanced(VORBISFILE_INCLUDE_DIR VORBISFILE_LIBRARIES VORBISFILE_LIBRARY VORBISFILE_LIBRARY_DEBUG)

if(VORBISFILE_FOUND AND (NOT TARGET VorbisFile::VorbisFile))
add_library(VorbisFile::VorbisFile UNKNOWN IMPORTED)
set_target_properties(VorbisFile::VorbisFile PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${VORBISFILE_INCLUDE_DIR}")
if(VORBISFILE_LIBRARY_DEBUG)
set_target_properties(VorbisFile::VorbisFile PROPERTIES IMPORTED_LOCATION_DEBUG "${VORBISFILE_LIBRARY_DEBUG}")
set_target_properties(VorbisFile::VorbisFile PROPERTIES IMPORTED_LOCATION_RELEASE "${VORBISFILE_LIBRARY}")
else()
set_target_properties(VorbisFile::VorbisFile PROPERTIES IMPORTED_LOCATION "${VORBISFILE_LIBRARY}")
endif()
endif()
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ endif()
include_directories(SYSTEM ${PANGOCAIRO_INCLUDE_DIRS})
include_directories(SYSTEM ${GETTEXT_INCLUDE_DIR})
include_directories(SYSTEM ${LIBDBUS_INCLUDE_DIRS})
include_directories(SYSTEM ${VORBISFILE_INCLUDE_DIR})
if(NOT MSVC)
include_directories(SYSTEM ${SDL2_INCLUDE_DIRS})
include_directories(SYSTEM ${SDL2IMAGE_INCLUDE_DIRS})
Expand Down Expand Up @@ -54,7 +53,7 @@ set(game-external-libs
${common-external-libs}
${PANGOCAIRO_LIBRARIES}
${LIBDBUS_LIBRARIES}
${VORBISFILE_LIBRARIES}
VorbisFile::VorbisFile
)

if(NOT MSVC)
Expand Down