1 cmake_minimum_required(VERSION 2.8.7)
5 include(GNUInstallDirs)
6 include(CheckIncludeFiles)
9 option(BUILD_SHARED_LIBS "Build shared library" OFF)
11 option(BUILD_FRAMEWORK "Build Framework bundle for OSX" OFF)
15 set(BUILD_SHARED_LIBS TRUE)
18 # Extract project version from configure.ac
19 file(READ configure.ac CONFIGURE_AC_CONTENTS)
20 string(REGEX MATCH "AC_INIT\\(\\[libvorbis\\],\\[([0-9]*).([0-9]*).([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
21 set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
22 set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2})
23 set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3})
24 set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
26 # Helper function to get version-info
27 function(get_version_info result current_var_name age_var_name revision_var_name)
28 string(REGEX MATCH "${current_var_name}=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
29 set(VERSION_INFO_CURRENT ${CMAKE_MATCH_1})
31 string(REGEX MATCH "${age_var_name}=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
32 set(VERSION_INFO_AGE ${CMAKE_MATCH_1})
34 string(REGEX MATCH "${revision_var_name}=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
35 set(VERSION_INFO_REVISION ${CMAKE_MATCH_1})
37 math(EXPR VERSION_INFO_CURRENT_MINUS_AGE "${VERSION_INFO_CURRENT} - ${VERSION_INFO_AGE}")
39 set(${result} "${VERSION_INFO_CURRENT_MINUS_AGE}.${VERSION_INFO_AGE}.${VERSION_INFO_REVISION}" PARENT_SCOPE)
42 # Helper function to configure pkg-config files
43 function(configure_pkg_config_file pkg_config_file_in)
44 set(prefix ${CMAKE_INSTALL_PREFIX})
45 set(exec_prefix ${CMAKE_INSTALL_FULL_BINDIR})
46 set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
47 set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
48 set(VERSION ${PROJECT_VERSION})
49 string(REPLACE ".in" "" pkg_config_file ${pkg_config_file_in})
50 configure_file(${pkg_config_file_in} ${pkg_config_file} @ONLY)
53 message(STATUS "Configuring ${PROJECT_NAME} ${PROJECT_VERSION}")
56 find_package(PkgConfig QUIET)
57 pkg_check_modules(PC_OGG QUIET ogg)
58 find_path(OGG_INCLUDE_DIRS NAMES ogg/ogg.h HINTS ${PC_OGG_INCLUDE_DIRS} PATH_SUFFIXES ogg)
59 find_library(OGG_LIBRARIES NAMES ogg HINTS ${PC_OGG_LIBRARY_DIRS})
60 include(FindPackageHandleStandardArgs)
61 find_package_handle_standard_args(OGG DEFAULT_MSG OGG_INCLUDE_DIRS OGG_LIBRARIES)
65 configure_pkg_config_file(vorbis.pc.in)
66 configure_pkg_config_file(vorbisenc.pc.in)
67 configure_pkg_config_file(vorbisfile.pc.in)
69 install(FILES vorbis.pc vorbisenc.pc vorbisfile.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)