CMakeLists.txt 5.98 KB
Newer Older
1
cmake_minimum_required(VERSION 2.8.12)
stopiccot's avatar
stopiccot committed
2 3 4 5 6
project(libogg)

# Required modules
include(GNUInstallDirs)
include(CheckIncludeFiles)
7 8
include(CMakePackageConfigHelpers)
include(CTest)
stopiccot's avatar
stopiccot committed
9 10 11 12 13 14 15

# Build options
option(BUILD_SHARED_LIBS "Build shared library" OFF)
if(APPLE)
    option(BUILD_FRAMEWORK "Build Framework bundle for OSX" OFF)
endif()

16 17 18 19 20
# Install options
option(INSTALL_DOCS "Install documentation" ON)
option(INSTALL_PKG_CONFIG_MODULE "Install ogg.pc file" ON)
option(INSTALL_CMAKE_PACKAGE_MODULE "Install CMake package configiguration module" ON)

stopiccot's avatar
stopiccot committed
21 22 23 24 25 26 27 28
# Extract project version from configure.ac
file(READ configure.ac CONFIGURE_AC_CONTENTS)
string(REGEX MATCH "AC_INIT\\(\\[libogg\\],\\[([0-9]*).([0-9]*).([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2})
set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3})
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})

29 30 31
# Extract library version from configure.ac
string(REGEX MATCH "LIB_CURRENT=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
set(LIB_CURRENT ${CMAKE_MATCH_1})
Ralph Giles's avatar
Ralph Giles committed
32

33 34
string(REGEX MATCH "LIB_AGE=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
set(LIB_AGE ${CMAKE_MATCH_1})
35

36 37
string(REGEX MATCH "LIB_REVISION=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
set(LIB_REVISION ${CMAKE_MATCH_1})
38

39 40
math(EXPR LIB_SOVERSION "${LIB_CURRENT} - ${LIB_AGE}")
set(LIB_VERSION "${LIB_SOVERSION}.${LIB_AGE}.${LIB_REVISION}")
41 42 43 44 45 46 47 48 49 50


# Helper function to configure pkg-config files
function(configure_pkg_config_file pkg_config_file_in)
    set(prefix ${CMAKE_INSTALL_PREFIX})
    set(exec_prefix ${CMAKE_INSTALL_FULL_BINDIR})
    set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
    set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
    set(VERSION ${PROJECT_VERSION})
    string(REPLACE ".in" "" pkg_config_file ${pkg_config_file_in})
Tomas Maly's avatar
Tomas Maly committed
51
    configure_file(${pkg_config_file_in} ${CMAKE_CURRENT_BINARY_DIR}/${pkg_config_file} @ONLY)
52
endfunction()
stopiccot's avatar
stopiccot committed
53 54 55 56 57 58 59 60

message(STATUS "Configuring ${PROJECT_NAME} ${PROJECT_VERSION}")

# Configure config_type.h
check_include_files(inttypes.h INCLUDE_INTTYPES_H)
check_include_files(stdint.h INCLUDE_STDINT_H)
check_include_files(sys/types.h INCLUDE_SYS_TYPES_H)

61 62 63
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(CheckSizes)
stopiccot's avatar
stopiccot committed
64

Tomas Maly's avatar
Tomas Maly committed
65
configure_file(include/ogg/config_types.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/ogg/config_types.h @ONLY)
stopiccot's avatar
stopiccot committed
66 67

set(OGG_HEADERS
Ralph Giles's avatar
Ralph Giles committed
68
    ${CMAKE_CURRENT_BINARY_DIR}/include/ogg/config_types.h
stopiccot's avatar
stopiccot committed
69 70 71 72 73 74 75
    include/ogg/ogg.h
    include/ogg/os_types.h
)

set(OGG_SOURCES
    src/bitwise.c
    src/framing.c
76
    src/crctable.h
stopiccot's avatar
stopiccot committed
77 78
)

79
if(WIN32 AND BUILD_SHARED_LIBS)
stopiccot's avatar
stopiccot committed
80 81 82 83 84 85 86 87
    list(APPEND OGG_SOURCES win32/ogg.def)
endif()

if(BUILD_FRAMEWORK)
    set(BUILD_SHARED_LIBS TRUE)
endif()

add_library(ogg ${OGG_HEADERS} ${OGG_SOURCES})
88 89 90 91 92
target_include_directories(ogg PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
93

94 95
set_target_properties(
    ogg PROPERTIES
96 97
    SOVERSION ${LIB_SOVERSION}
    VERSION ${LIB_VERSION}
98 99
    PUBLIC_HEADER "${OGG_HEADERS}"
)
stopiccot's avatar
stopiccot committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

if(BUILD_FRAMEWORK)
    set_target_properties(ogg PROPERTIES
        FRAMEWORK TRUE
        FRAMEWORK_VERSION ${PROJECT_VERSION}
        MACOSX_FRAMEWORK_IDENTIFIER org.xiph.ogg
        MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PROJECT_VERSION}
        MACOSX_FRAMEWORK_BUNDLE_VERSION ${PROJECT_VERSION}
        XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
        OUTPUT_NAME Ogg
    )
endif()

configure_pkg_config_file(ogg.pc.in)

115
install(TARGETS ogg
116
    EXPORT OggTargets
117 118 119
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
120
    FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
121 122
    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ogg
)
123 124

if(INSTALL_CMAKE_PACKAGE_MODULE)
125 126
    set(CMAKE_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Ogg)
    install(EXPORT OggTargets
127 128 129
        DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
        NAMESPACE Ogg::
    )
130 131 132 133 134 135 136 137 138 139 140 141 142 143

    include(CMakePackageConfigHelpers)

    configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/OggConfig.cmake.in ${PROJECT_BINARY_DIR}/OggConfig.cmake
        INSTALL_DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
        PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR
    )

    write_basic_package_version_file(${PROJECT_BINARY_DIR}/OggConfigVersion.cmake
        VERSION ${PROJECT_VERSION}
        COMPATIBILITY SameMajorVersion
    )

    install(FILES ${PROJECT_BINARY_DIR}/OggConfig.cmake ${PROJECT_BINARY_DIR}/OggConfigVersion.cmake
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
        DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
    )
endif()

if(INSTALL_PKG_CONFIG_MODULE)
    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ogg.pc
        DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
    )
endif()

if(INSTALL_DOCS)
    set(OGG_DOCS
        doc/framing.html
        doc/index.html
        doc/oggstream.html
        doc/ogg-multiplex.html
        doc/fish_xiph_org.png
        doc/multiplex1.png
        doc/packets.png
        doc/pages.png
        doc/stream.png
        doc/vorbisword2.png
        doc/white-ogg.png
        doc/white-xifish.png
        doc/rfc3533.txt
        doc/rfc5334.txt
        doc/skeleton.html
    )
    install(FILES ${OGG_DOCS} DESTINATION ${CMAKE_INSTALL_DOCDIR}/html)
    install(DIRECTORY doc/libogg DESTINATION ${CMAKE_INSTALL_DOCDIR}/html)
endif()

if(BUILD_TESTING)
    add_executable(test_bitwise src/bitwise.c ${OGG_HEADERS})
    target_compile_definitions(test_bitwise PRIVATE _V_SELFTEST)
    target_include_directories(test_bitwise PRIVATE
        include
        ${CMAKE_CURRENT_BINARY_DIR}/include
    )
    add_test(NAME test_bitwise COMMAND $<TARGET_FILE:test_bitwise>)

    add_executable(test_framing src/framing.c ${OGG_HEADERS})
    target_compile_definitions(test_framing PRIVATE _V_SELFTEST)
    target_include_directories(test_framing PRIVATE
        include
        ${CMAKE_CURRENT_BINARY_DIR}/include
    )
    add_test(NAME test_framing COMMAND $<TARGET_FILE:test_framing>)
endif()

set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
include(CPack)