Bläddra i källkod

fixed Mac CMake compilation

properly find oggvorbis
Andy Li 8 år sedan
förälder
incheckning
cd93e0b20b
2 ändrade filer med 94 tillägg och 3 borttagningar
  1. 5 3
      CMakeLists.txt
  2. 89 0
      cmake/FindOggVorbis.cmake

+ 5 - 3
CMakeLists.txt

@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8.12)
 cmake_policy(SET CMP0042 NEW)
 
 include(GNUInstallDirs)
+include(FindPkgConfig)
 project(hashlink C)
 
 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
@@ -176,7 +177,7 @@ endif()
 if(WIN32)
     set(ZLIB_INCLUDE_DIRS include/zlib)
     set(PNG_INCLUDE_DIRS include/png)
-    set(Vorbis_INCLUDE_DIRS include/vorbis)
+    set(OGGVORBIS_INCLUDE_DIR include/vorbis)
 
     if(CMAKE_SIZEOF_VOID_P EQUAL 8) 
         set(TurboJPEG_INCLUDE_DIRS include/turbojpeg include/turbojpeg/x64)
@@ -292,6 +293,7 @@ else()
     find_package(ZLIB REQUIRED)
     find_package(PNG REQUIRED)
     find_package(TurboJPEG REQUIRED)
+    find_package(OggVorbis REQUIRED)
 
     add_library(fmt.hdll MODULE
         libs/fmt/fmt.c
@@ -310,14 +312,14 @@ target_include_directories(fmt.hdll
 	${ZLIB_INCLUDE_DIRS}
 	${PNG_INCLUDE_DIRS}
 	${TurboJPEG_INCLUDE_DIRS}
-	${Vorbis_INCLUDE_DIRS}
+	${OGGVORBIS_INCLUDE_DIR}
 )
 target_link_libraries(fmt.hdll
     libhl
     ${ZLIB_LIBRARIES}
     ${PNG_LIBRARIES}
     ${TurboJPEG_LIBRARIES}
-    ${Vorbis_LIBRARIES}
+    ${OGGVORBIS_LIBRARIES}
 )
 target_compile_definitions(fmt.hdll
     PRIVATE

+ 89 - 0
cmake/FindOggVorbis.cmake

@@ -0,0 +1,89 @@
+# - 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_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
+#  VORBISENC_LIBRARY   - The VorbisEnc library
+
+# Copyright (c) 2006, Richard Laerkaeng, <[email protected]>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+
+include (CheckLibraryExists)
+
+find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h)
+find_path(OGG_INCLUDE_DIR ogg/ogg.h)
+
+find_library(OGG_LIBRARY NAMES ogg)
+find_library(VORBIS_LIBRARY NAMES vorbis)
+find_library(VORBISFILE_LIBRARY NAMES vorbisfile)
+find_library(VORBISENC_LIBRARY NAMES vorbisenc)
+
+mark_as_advanced(VORBIS_INCLUDE_DIR OGG_INCLUDE_DIR
+                 OGG_LIBRARY VORBIS_LIBRARY VORBISFILE_LIBRARY VORBISENC_LIBRARY)
+
+
+if (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY AND VORBISENC_LIBRARY)
+   set(OGGVORBIS_FOUND TRUE)
+
+   set(OGGVORBIS_LIBRARIES ${OGG_LIBRARY} ${VORBIS_LIBRARY} ${VORBISFILE_LIBRARY} ${VORBISENC_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 (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY AND VORBISENC_LIBRARY)
+   set (OGGVORBIS_VERSION)
+   set(OGGVORBIS_FOUND FALSE)
+endif (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY AND VORBISENC_LIBRARY)
+
+
+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")
+   endif (OggVorbis_FIND_REQUIRED)
+   if (NOT OggVorbis_FIND_QUITELY)
+      message(STATUS "Could NOT find OggVorbis libraries")
+   endif (NOT OggVorbis_FIND_QUITELY)
+endif (OGGVORBIS_FOUND)
+
+#check_include_files(vorbis/vorbisfile.h HAVE_VORBISFILE_H)
+#check_library_exists(ogg ogg_page_version "" HAVE_LIBOGG)
+#check_library_exists(vorbis vorbis_info_init "" HAVE_LIBVORBIS)
+#check_library_exists(vorbisfile ov_open "" HAVE_LIBVORBISFILE)
+#check_library_exists(vorbisenc vorbis_info_clear "" HAVE_LIBVORBISENC)
+#check_library_exists(vorbis vorbis_bitrate_addblock "" HAVE_LIBVORBISENC2)
+
+#if (HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
+#    message(STATUS "Ogg/Vorbis found")
+#    set (VORBIS_LIBS "-lvorbis -logg")
+#    set (VORBISFILE_LIBS "-lvorbisfile")
+#    set (VORBISENC_LIBS "-lvorbisenc")
+#    set (OGGVORBIS_FOUND TRUE)
+#    if (HAVE_LIBVORBISENC2)
+#        set (HAVE_VORBIS 2)
+#    else (HAVE_LIBVORBISENC2)
+#        set (HAVE_VORBIS 1)
+#    endif (HAVE_LIBVORBISENC2)
+#else (HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
+#    message(STATUS "Ogg/Vorbis not found")
+#endif (HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
+