1 | cmake_minimum_required(VERSION 2.8.12)
|
---|
2 | project(vorbis)
|
---|
3 |
|
---|
4 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
---|
5 |
|
---|
6 | # Required modules
|
---|
7 | include(GNUInstallDirs)
|
---|
8 | include(CheckIncludeFiles)
|
---|
9 | include(CheckLibraryExists)
|
---|
10 |
|
---|
11 | # Build options
|
---|
12 | option(BUILD_SHARED_LIBS "Build shared library" OFF)
|
---|
13 | if(APPLE)
|
---|
14 | option(BUILD_FRAMEWORK "Build Framework bundle for OSX" OFF)
|
---|
15 | endif()
|
---|
16 |
|
---|
17 | if(BUILD_FRAMEWORK)
|
---|
18 | set(BUILD_SHARED_LIBS TRUE)
|
---|
19 | endif()
|
---|
20 |
|
---|
21 | option(INSTALL_CMAKE_PACKAGE_MODULE "Install CMake package configiguration module" ON)
|
---|
22 |
|
---|
23 | # Extract project version from configure.ac
|
---|
24 | file(READ configure.ac CONFIGURE_AC_CONTENTS)
|
---|
25 | string(REGEX MATCH "AC_INIT\\(\\[libvorbis\\],\\[([0-9]*).([0-9]*).([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
|
---|
26 | set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
|
---|
27 | set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2})
|
---|
28 | set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3})
|
---|
29 | set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
|
---|
30 |
|
---|
31 | # Helper function to get version-info
|
---|
32 | function(get_version_info result current_var_name age_var_name revision_var_name)
|
---|
33 | string(REGEX MATCH "${current_var_name}=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
|
---|
34 | set(VERSION_INFO_CURRENT ${CMAKE_MATCH_1})
|
---|
35 |
|
---|
36 | string(REGEX MATCH "${age_var_name}=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
|
---|
37 | set(VERSION_INFO_AGE ${CMAKE_MATCH_1})
|
---|
38 |
|
---|
39 | string(REGEX MATCH "${revision_var_name}=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
|
---|
40 | set(VERSION_INFO_REVISION ${CMAKE_MATCH_1})
|
---|
41 |
|
---|
42 | math(EXPR VERSION_INFO_CURRENT_MINUS_AGE "${VERSION_INFO_CURRENT} - ${VERSION_INFO_AGE}")
|
---|
43 |
|
---|
44 | set(${result} "${VERSION_INFO_CURRENT_MINUS_AGE}.${VERSION_INFO_AGE}.${VERSION_INFO_REVISION}" PARENT_SCOPE)
|
---|
45 | endfunction()
|
---|
46 |
|
---|
47 | # Helper function to configure pkg-config files
|
---|
48 | function(configure_pkg_config_file pkg_config_file_in)
|
---|
49 | set(prefix ${CMAKE_INSTALL_PREFIX})
|
---|
50 | set(exec_prefix ${CMAKE_INSTALL_FULL_BINDIR})
|
---|
51 | set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
|
---|
52 | set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
|
---|
53 | set(VERSION ${PROJECT_VERSION})
|
---|
54 | string(REPLACE ".in" "" pkg_config_file ${pkg_config_file_in})
|
---|
55 | configure_file(${pkg_config_file_in} ${pkg_config_file} @ONLY)
|
---|
56 | endfunction()
|
---|
57 |
|
---|
58 | message(STATUS "Configuring ${PROJECT_NAME} ${PROJECT_VERSION}")
|
---|
59 |
|
---|
60 | # Find math library
|
---|
61 |
|
---|
62 | check_library_exists(m floor "" HAVE_LIBM)
|
---|
63 |
|
---|
64 | # Find ogg dependency
|
---|
65 | find_package(Ogg REQUIRED)
|
---|
66 |
|
---|
67 | add_subdirectory(lib)
|
---|
68 |
|
---|
69 | configure_pkg_config_file(vorbis.pc.in)
|
---|
70 | configure_pkg_config_file(vorbisenc.pc.in)
|
---|
71 | configure_pkg_config_file(vorbisfile.pc.in)
|
---|
72 |
|
---|
73 | install(
|
---|
74 | FILES
|
---|
75 | ${CMAKE_CURRENT_BINARY_DIR}/vorbis.pc
|
---|
76 | ${CMAKE_CURRENT_BINARY_DIR}/vorbisenc.pc
|
---|
77 | ${CMAKE_CURRENT_BINARY_DIR}/vorbisfile.pc
|
---|
78 | DESTINATION
|
---|
79 | ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
---|
80 | )
|
---|