1 | cmake_minimum_required(VERSION 2.8.12)
|
---|
2 | project(libogg)
|
---|
3 |
|
---|
4 | # Required modules
|
---|
5 | include(GNUInstallDirs)
|
---|
6 | include(CheckIncludeFiles)
|
---|
7 | include(CMakePackageConfigHelpers)
|
---|
8 | include(CTest)
|
---|
9 |
|
---|
10 | # Build options
|
---|
11 | option(BUILD_SHARED_LIBS "Build shared library" OFF)
|
---|
12 | if(APPLE)
|
---|
13 | option(BUILD_FRAMEWORK "Build Framework bundle for OSX" OFF)
|
---|
14 | endif()
|
---|
15 |
|
---|
16 | # Install options
|
---|
17 | option(INSTALL_DOCS "Install documentation" ON)
|
---|
18 | option(INSTALL_PKG_CONFIG_MODULE "Install ogg.pc file" ON)
|
---|
19 | option(INSTALL_CMAKE_PACKAGE_MODULE "Install CMake package configuration module" ON)
|
---|
20 |
|
---|
21 | # Extract project version from configure.ac
|
---|
22 | file(READ configure.ac CONFIGURE_AC_CONTENTS)
|
---|
23 | string(REGEX MATCH "AC_INIT\\(\\[libogg\\],\\[([0-9]*).([0-9]*).([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
|
---|
24 | set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
|
---|
25 | set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2})
|
---|
26 | set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3})
|
---|
27 | set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
|
---|
28 |
|
---|
29 | # Extract library version from configure.ac
|
---|
30 | string(REGEX MATCH "LIB_CURRENT=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
|
---|
31 | set(LIB_CURRENT ${CMAKE_MATCH_1})
|
---|
32 |
|
---|
33 | string(REGEX MATCH "LIB_AGE=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
|
---|
34 | set(LIB_AGE ${CMAKE_MATCH_1})
|
---|
35 |
|
---|
36 | string(REGEX MATCH "LIB_REVISION=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
|
---|
37 | set(LIB_REVISION ${CMAKE_MATCH_1})
|
---|
38 |
|
---|
39 | math(EXPR LIB_SOVERSION "${LIB_CURRENT} - ${LIB_AGE}")
|
---|
40 | set(LIB_VERSION "${LIB_SOVERSION}.${LIB_AGE}.${LIB_REVISION}")
|
---|
41 |
|
---|
42 |
|
---|
43 | # Helper function to configure pkg-config files
|
---|
44 | function(configure_pkg_config_file pkg_config_file_in)
|
---|
45 | set(prefix ${CMAKE_INSTALL_PREFIX})
|
---|
46 | set(exec_prefix ${CMAKE_INSTALL_FULL_BINDIR})
|
---|
47 | set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
|
---|
48 | set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
|
---|
49 | set(VERSION ${PROJECT_VERSION})
|
---|
50 | string(REPLACE ".in" "" pkg_config_file ${pkg_config_file_in})
|
---|
51 | configure_file(${pkg_config_file_in} ${pkg_config_file} @ONLY)
|
---|
52 | endfunction()
|
---|
53 |
|
---|
54 | message(STATUS "Configuring ${PROJECT_NAME} ${PROJECT_VERSION}")
|
---|
55 |
|
---|
56 | # Configure config_type.h
|
---|
57 | check_include_files(inttypes.h INCLUDE_INTTYPES_H)
|
---|
58 | check_include_files(stdint.h INCLUDE_STDINT_H)
|
---|
59 | check_include_files(sys/types.h INCLUDE_SYS_TYPES_H)
|
---|
60 |
|
---|
61 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
---|
62 | set(SIZE16 int16_t)
|
---|
63 | set(USIZE16 uint16_t)
|
---|
64 | set(SIZE32 int32_t)
|
---|
65 | set(USIZE32 uint32_t)
|
---|
66 | set(SIZE64 int64_t)
|
---|
67 | set(USIZE64 uint64_t)
|
---|
68 |
|
---|
69 | include(CheckSizes)
|
---|
70 |
|
---|
71 | configure_file(include/ogg/config_types.h.in include/ogg/config_types.h @ONLY)
|
---|
72 |
|
---|
73 | set(OGG_HEADERS
|
---|
74 | ${CMAKE_CURRENT_BINARY_DIR}/include/ogg/config_types.h
|
---|
75 | include/ogg/ogg.h
|
---|
76 | include/ogg/os_types.h
|
---|
77 | )
|
---|
78 |
|
---|
79 | set(OGG_SOURCES
|
---|
80 | src/bitwise.c
|
---|
81 | src/framing.c
|
---|
82 | src/crctable.h
|
---|
83 | )
|
---|
84 |
|
---|
85 | if(WIN32 AND BUILD_SHARED_LIBS)
|
---|
86 | list(APPEND OGG_SOURCES win32/ogg.def)
|
---|
87 | endif()
|
---|
88 |
|
---|
89 | if(BUILD_FRAMEWORK)
|
---|
90 | set(BUILD_SHARED_LIBS TRUE)
|
---|
91 | endif()
|
---|
92 |
|
---|
93 | add_library(ogg ${OGG_HEADERS} ${OGG_SOURCES})
|
---|
94 | add_library(Ogg::ogg ALIAS ogg)
|
---|
95 | target_include_directories(ogg PUBLIC
|
---|
96 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
---|
97 | $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
|
---|
98 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
---|
99 | )
|
---|
100 |
|
---|
101 | set_target_properties(
|
---|
102 | ogg PROPERTIES
|
---|
103 | SOVERSION ${LIB_SOVERSION}
|
---|
104 | VERSION ${LIB_VERSION}
|
---|
105 | PUBLIC_HEADER "${OGG_HEADERS}"
|
---|
106 | )
|
---|
107 |
|
---|
108 | if(BUILD_FRAMEWORK)
|
---|
109 | set_target_properties(ogg PROPERTIES
|
---|
110 | FRAMEWORK TRUE
|
---|
111 | FRAMEWORK_VERSION ${PROJECT_VERSION}
|
---|
112 | MACOSX_FRAMEWORK_IDENTIFIER org.xiph.ogg
|
---|
113 | MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PROJECT_VERSION}
|
---|
114 | MACOSX_FRAMEWORK_BUNDLE_VERSION ${PROJECT_VERSION}
|
---|
115 | XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
|
---|
116 | OUTPUT_NAME Ogg
|
---|
117 | )
|
---|
118 | endif()
|
---|
119 |
|
---|
120 | configure_pkg_config_file(ogg.pc.in)
|
---|
121 |
|
---|
122 | install(TARGETS ogg
|
---|
123 | EXPORT OggTargets
|
---|
124 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
---|
125 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
126 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
127 | FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
|
---|
128 | PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ogg
|
---|
129 | )
|
---|
130 |
|
---|
131 | export(EXPORT OggTargets NAMESPACE Ogg:: FILE OggTargets.cmake)
|
---|
132 |
|
---|
133 | if(INSTALL_CMAKE_PACKAGE_MODULE)
|
---|
134 | set(CMAKE_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Ogg)
|
---|
135 | install(EXPORT OggTargets
|
---|
136 | DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
|
---|
137 | NAMESPACE Ogg::
|
---|
138 | )
|
---|
139 |
|
---|
140 | include(CMakePackageConfigHelpers)
|
---|
141 |
|
---|
142 | configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/OggConfig.cmake.in ${PROJECT_BINARY_DIR}/OggConfig.cmake
|
---|
143 | INSTALL_DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
|
---|
144 | PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR
|
---|
145 | )
|
---|
146 |
|
---|
147 | write_basic_package_version_file(${PROJECT_BINARY_DIR}/OggConfigVersion.cmake
|
---|
148 | VERSION ${PROJECT_VERSION}
|
---|
149 | COMPATIBILITY SameMajorVersion
|
---|
150 | )
|
---|
151 |
|
---|
152 | install(FILES ${PROJECT_BINARY_DIR}/OggConfig.cmake ${PROJECT_BINARY_DIR}/OggConfigVersion.cmake
|
---|
153 | DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
|
---|
154 | )
|
---|
155 | endif()
|
---|
156 |
|
---|
157 | if(INSTALL_PKG_CONFIG_MODULE)
|
---|
158 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ogg.pc
|
---|
159 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
---|
160 | )
|
---|
161 | endif()
|
---|
162 |
|
---|
163 | if(INSTALL_DOCS)
|
---|
164 | set(OGG_DOCS
|
---|
165 | doc/framing.html
|
---|
166 | doc/index.html
|
---|
167 | doc/oggstream.html
|
---|
168 | doc/ogg-multiplex.html
|
---|
169 | doc/fish_xiph_org.png
|
---|
170 | doc/multiplex1.png
|
---|
171 | doc/packets.png
|
---|
172 | doc/pages.png
|
---|
173 | doc/stream.png
|
---|
174 | doc/vorbisword2.png
|
---|
175 | doc/white-ogg.png
|
---|
176 | doc/white-xifish.png
|
---|
177 | doc/rfc3533.txt
|
---|
178 | doc/rfc5334.txt
|
---|
179 | doc/skeleton.html
|
---|
180 | )
|
---|
181 | install(FILES ${OGG_DOCS} DESTINATION ${CMAKE_INSTALL_DOCDIR}/html)
|
---|
182 | install(DIRECTORY doc/libogg DESTINATION ${CMAKE_INSTALL_DOCDIR}/html)
|
---|
183 | endif()
|
---|
184 |
|
---|
185 | if(BUILD_TESTING)
|
---|
186 | add_executable(test_bitwise src/bitwise.c ${OGG_HEADERS})
|
---|
187 | target_compile_definitions(test_bitwise PRIVATE _V_SELFTEST)
|
---|
188 | target_include_directories(test_bitwise PRIVATE
|
---|
189 | include
|
---|
190 | ${CMAKE_CURRENT_BINARY_DIR}/include
|
---|
191 | )
|
---|
192 | add_test(NAME test_bitwise COMMAND $<TARGET_FILE:test_bitwise>)
|
---|
193 |
|
---|
194 | add_executable(test_framing src/framing.c ${OGG_HEADERS})
|
---|
195 | target_compile_definitions(test_framing PRIVATE _V_SELFTEST)
|
---|
196 | target_include_directories(test_framing PRIVATE
|
---|
197 | include
|
---|
198 | ${CMAKE_CURRENT_BINARY_DIR}/include
|
---|
199 | )
|
---|
200 | add_test(NAME test_framing COMMAND $<TARGET_FILE:test_framing>)
|
---|
201 | endif()
|
---|
202 |
|
---|
203 | set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
|
---|
204 | include(CPack)
|
---|