rewritten FindOggVorbis.cmake
authorkoda
Wed, 06 Mar 2013 02:52:17 +0100
changeset 8660 6370e545fd5f
parent 8659 e49056d3aba1
child 8661 ac8dba27a3f1
rewritten FindOggVorbis.cmake
cmake_modules/FindOggVorbis.cmake
tools/CMakeLists.txt
--- a/cmake_modules/FindOggVorbis.cmake	Wed Mar 06 01:28:21 2013 +0100
+++ b/cmake_modules/FindOggVorbis.cmake	Wed Mar 06 02:52:17 2013 +0100
@@ -1,61 +1,68 @@
-### SuperTux - Removed unused vorbisenc library
-
 # - Try to find the OggVorbis libraries
 # Once done this will define
 #
-#  OGGVORBIS_FOUND - system has OggVorbis
-#  OGGVORBIS_VERSION - set either to 1 or 2
+#  OGGVORBIS_FOUND       - system has both Ogg and Vorbis
+#  OGGVORBIS_VERSION     - set either to 1 or 2
 #  OGGVORBIS_INCLUDE_DIR - the OggVorbis include directory
-#  OGGVORBIS_LIBRARIES - The libraries needed to use OggVorbis
-#  OGG_LIBRARY         - The Ogg library
-#  VORBIS_LIBRARY      - The Vorbis library
-#  VORBISFILE_LIBRARY  - The VorbisFile library
+#  OGGVORBIS_LIBRARIES   - The libraries needed to use OggVorbis
+#
+#  OGG_LIBRARY           - The Ogg library
+#  OGG_INCLUDE_DIR       - The Ogg include directory
+#  VORBIS_LIBRARY        - The Vorbis library
+#  VORBIS_INCLUDE_DIR    - The Vorbis include directory
+#  VORBISFILE_LIBRARY    - The VorbisFile library
+#
 # Copyright (c) 2006, Richard Laerkaeng, <richard@goteborg.utfors.se>
+# Copyright (c) 2013, Vittorio Giovara, <vittorio.giovara@gmail.com>
 #
 # Redistribution and use is allowed according to the terms of the BSD license.
 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
 
+### sommer [SuperTux]
+##  - Removed unused vorbisenc library
+##  - reversed order of libraries, so that cmake 2.4.5 for Windows generates an MSYS Makefile that will link correctly
+
+### koda [Hedgewars]
+##  - split ogg and vorbis lookup
+##  - special case for framework handling
+##  - standard variables handling
+
 
 include (CheckLibraryExists)
-find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h)
+include (FindPackageHandleStandardArgs)
+
+find_path(OGG_INCLUDE_DIR ogg.h PATH_SUFFIXES ogg)
+find_path(VORBIS_INCLUDE_DIR vorbisfile.h PATH_SUFFIXES vorbis)
+
+find_library(OGG_LIBRARY NAMES Ogg ogg)
+find_library(VORBIS_LIBRARY NAMES Vorbis vorbis)
+find_library(VORBISFILE_LIBRARY NAMES vorbisfile)
 
-find_library(OGG_LIBRARY NAMES ogg)
-find_library(VORBIS_LIBRARY NAMES vorbis)
-find_library(VORBISFILE_LIBRARY NAMES vorbisfile)
-if(APPLE AND NOT VORBISFILE_LIBRARY)
-#  [koda] (for Hedgewars) frameworks don't come with libvorbisfile
-   set(VORBISFILE_LIBRARY "${VORBIS_LIBRARY}")
+set(_CMAKE_REQUIRED_LIBRARIES_TMP ${CMAKE_REQUIRED_LIBRARIES})
+set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${OGGVORBIS_LIBRARIES})
+check_library_exists(${VORBIS_LIBRARY} vorbis_bitrate_addblock "" HAVE_LIBVORBISENC2)
+set(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_TMP})
+
+if(HAVE_LIBVORBISENC2)
+    set(OGGVORBIS_VERSION 2)
+else(HAVE_LIBVORBISENC2)
+    set(OGGVORBIS_VERSION 1)
+endif(HAVE_LIBVORBISENC2)
+
+if(${OGG_LIBRARY} MATCHES ".framework" AND ${VORBIS_LIBRARY} MATCHES ".framework")
+    set(VORBISFILE_LIBRARY "") #vorbisfile will appear as NOTFOUND and discarded
+    set(fphsa_vorbis_list VORBIS_LIBRARY)
+else()
+    set(fphsa_vorbis_list VORBISFILE_LIBRARY VORBIS_LIBRARY)
 endif()
 
-if (OGG_LIBRARY AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY)
-   set(OGGVORBIS_FOUND TRUE)
-#  [sommer] (for SuperTux) reversed order of libraries, so that cmake 2.4.5 for Windows generates an MSYS Makefile that will link correctly
-#  set(OGGVORBIS_LIBRARIES ${OGG_LIBRARY} ${VORBIS_LIBRARY} ${VORBISFILE_LIBRARY})
-   set(OGGVORBIS_LIBRARIES ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY})
-   set(_CMAKE_REQUIRED_LIBRARIES_TMP ${CMAKE_REQUIRED_LIBRARIES})
-   set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${OGGVORBIS_LIBRARIES})
-   check_library_exists(vorbis vorbis_bitrate_addblock "" HAVE_LIBVORBISENC2)
-   set(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_TMP})
-   if (HAVE_LIBVORBISENC2)
-      set (OGGVORBIS_VERSION 2)
-   else (HAVE_LIBVORBISENC2)
-      set (OGGVORBIS_VERSION 1)
-   endif (HAVE_LIBVORBISENC2)
-else ()
-   set(OGGVORBIS_VERSION)
-   set(OGGVORBIS_FOUND FALSE)
-endif ()
-if (OGGVORBIS_FOUND)
-   if (NOT OggVorbis_FIND_QUIETLY)
-      message(STATUS "Found OggVorbis: ${OGGVORBIS_LIBRARIES}")
-   endif (NOT OggVorbis_FIND_QUIETLY)
-else (OGGVORBIS_FOUND)
-   if (OggVorbis_FIND_REQUIRED)
-      message(FATAL_ERROR "Could NOT find OggVorbis libraries")
-   else (OggVorbis_FIND_REQUIRED)
-      if (NOT OggVorbis_FIND_QUIETLY)
-         message(STATUS "Could NOT find OggVorbis libraries")
-      endif (NOT OggVorbis_FIND_QUIETLY)
-   endif(OggVorbis_FIND_REQUIRED)
-endif (OGGVORBIS_FOUND)
+find_package_handle_standard_args(OggVorbis DEFAULT_MSG ${fphsa_vorbis_list} OGG_LIBRARY
+                                                        OGG_INCLUDE_DIR VORBIS_INCLUDE_DIR)
+unset(fphsa_vorbis_list)
 
+set(OGGVORBIS_LIBRARIES ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY})
+set(OGGVORBIS_INCLUDE_DIR ${VORBIS_INCLUDE_DIR} ${OGG_INCLUDE_DIR})
+
+mark_as_advanced(OGGVORBIS_VERSION OGGVORBIS_INCLUDE_DIR OGGVORBIS_LIBRARIES
+                 OGG_LIBRARY OGG_INCLUDE_DIR VORBIS_LIBRARY VORBIS_INCLUDE_DIR VORBISFILE_LIBRARY)
+
--- a/tools/CMakeLists.txt	Wed Mar 06 01:28:21 2013 +0100
+++ b/tools/CMakeLists.txt	Wed Mar 06 02:52:17 2013 +0100
@@ -13,7 +13,7 @@
     find_package(SDL_net REQUIRED)
     find_package(SDL_ttf REQUIRED)
     find_package(SDL_mixer REQUIRED)
-    find_package(OGGVORBIS REQUIRED)
+    find_package(OggVorbis REQUIRED)
     if(NOT NOAUTOUPDATE)
         find_package(Sparkle) #needed for SPARKLE_FOUND variable
         #needed because the 'if' clause in the script prints silly policy warnings