CMakeLists.txt 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. cmake_minimum_required(VERSION 2.8.7)
  2. project(vorbis)
  3. # Required modules
  4. include(GNUInstallDirs)
  5. include(CheckIncludeFiles)
  6. # Build options
  7. option(BUILD_SHARED_LIBS "Build shared library" OFF)
  8. if(APPLE)
  9. option(BUILD_FRAMEWORK "Build Framework bundle for OSX" OFF)
  10. endif()
  11. if(BUILD_FRAMEWORK)
  12. set(BUILD_SHARED_LIBS TRUE)
  13. endif()
  14. # Extract project version from configure.ac
  15. file(READ configure.ac CONFIGURE_AC_CONTENTS)
  16. string(REGEX MATCH "AC_INIT\\(\\[libvorbis\\],\\[([0-9]*).([0-9]*).([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
  17. set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
  18. set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2})
  19. set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3})
  20. set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
  21. # Helper function to get version-info
  22. function(get_version_info result current_var_name age_var_name revision_var_name)
  23. string(REGEX MATCH "${current_var_name}=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
  24. set(VERSION_INFO_CURRENT ${CMAKE_MATCH_1})
  25. string(REGEX MATCH "${age_var_name}=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
  26. set(VERSION_INFO_AGE ${CMAKE_MATCH_1})
  27. string(REGEX MATCH "${revision_var_name}=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
  28. set(VERSION_INFO_REVISION ${CMAKE_MATCH_1})
  29. math(EXPR VERSION_INFO_CURRENT_MINUS_AGE "${VERSION_INFO_CURRENT} - ${VERSION_INFO_AGE}")
  30. set(${result} "${VERSION_INFO_CURRENT_MINUS_AGE}.${VERSION_INFO_AGE}.${VERSION_INFO_REVISION}" PARENT_SCOPE)
  31. endfunction()
  32. # Helper function to configure pkg-config files
  33. function(configure_pkg_config_file pkg_config_file_in)
  34. set(prefix ${CMAKE_INSTALL_PREFIX})
  35. set(exec_prefix ${CMAKE_INSTALL_FULL_BINDIR})
  36. set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
  37. set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
  38. set(VERSION ${PROJECT_VERSION})
  39. string(REPLACE ".in" "" pkg_config_file ${pkg_config_file_in})
  40. configure_file(${pkg_config_file_in} ${pkg_config_file} @ONLY)
  41. endfunction()
  42. message(STATUS "Configuring ${PROJECT_NAME} ${PROJECT_VERSION}")
  43. # Find ogg dependency
  44. if(NOT OGG_ROOT)
  45. find_package(PkgConfig QUIET)
  46. pkg_check_modules(PC_OGG QUIET ogg)
  47. find_path(OGG_INCLUDE_DIRS NAMES ogg/ogg.h HINTS ${PC_OGG_INCLUDE_DIRS} PATH_SUFFIXES ogg)
  48. find_library(OGG_LIBRARIES NAMES ogg HINTS ${PC_OGG_LIBRARY_DIRS})
  49. else()
  50. find_path(OGG_INCLUDE_DIRS NAMES ogg/ogg.h HINTS ${OGG_ROOT}/include PATH_SUFFIXES ogg)
  51. find_library(OGG_LIBRARIES NAMES ogg HINTS ${OGG_ROOT}/lib ${OGG_ROOT}/lib64)
  52. endif()
  53. include(FindPackageHandleStandardArgs)
  54. find_package_handle_standard_args(OGG DEFAULT_MSG OGG_INCLUDE_DIRS OGG_LIBRARIES)
  55. add_subdirectory(lib)
  56. configure_pkg_config_file(vorbis.pc.in)
  57. configure_pkg_config_file(vorbisenc.pc.in)
  58. configure_pkg_config_file(vorbisfile.pc.in)
  59. install(
  60. FILES
  61. ${CMAKE_CURRENT_BINARY_DIR}/vorbis.pc
  62. ${CMAKE_CURRENT_BINARY_DIR}/vorbisenc.pc
  63. ${CMAKE_CURRENT_BINARY_DIR}/vorbisfile.pc
  64. DESTINATION
  65. ${CMAKE_INSTALL_LIBDIR}/pkgconfig
  66. )