Skip to content

Commit ffcd784

Browse files
evpobrrillian
authored andcommitted
Add CMake config-file package generation
Signed-off-by: Ralph Giles <[email protected]>
1 parent 30c4903 commit ffcd784

File tree

6 files changed

+202
-24
lines changed

6 files changed

+202
-24
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,19 @@ doc/Doxyfile
3838
doc/doxygen-build.stamp
3939
lib/test_sharedbook
4040
test/test
41+
42+
CMakeCache.txt
43+
CMakeFiles
44+
CMakeScripts
45+
Testing
46+
Makefile
47+
cmake_install.cmake
48+
install_manifest.txt
49+
compile_commands.json
50+
CTestTestfile.cmake
51+
CMakeSettings.json
52+
53+
*[Bb]uild*/
54+
55+
.vs/
56+
.vscode/

CMakeLists.txt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
cmake_minimum_required(VERSION 2.8.7)
1+
cmake_minimum_required(VERSION 2.8.12)
22
project(vorbis)
33

4+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
5+
46
# Required modules
57
include(GNUInstallDirs)
68
include(CheckIncludeFiles)
9+
include(CheckLibraryExists)
710

811
# Build options
912
option(BUILD_SHARED_LIBS "Build shared library" OFF)
@@ -15,6 +18,8 @@ if(BUILD_FRAMEWORK)
1518
set(BUILD_SHARED_LIBS TRUE)
1619
endif()
1720

21+
option(INSTALL_CMAKE_PACKAGE_MODULE "Install CMake package configiguration module" ON)
22+
1823
# Extract project version from configure.ac
1924
file(READ configure.ac CONFIGURE_AC_CONTENTS)
2025
string(REGEX MATCH "AC_INIT\\(\\[libvorbis\\],\\[([0-9]*).([0-9]*).([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
@@ -52,18 +57,12 @@ endfunction()
5257

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

60+
# Find math library
61+
62+
check_library_exists(m floor "" HAVE_LIBM)
63+
5564
# Find ogg dependency
56-
if(NOT OGG_ROOT)
57-
find_package(PkgConfig QUIET)
58-
pkg_check_modules(PC_OGG QUIET ogg)
59-
find_path(OGG_INCLUDE_DIRS NAMES ogg/ogg.h HINTS ${PC_OGG_INCLUDE_DIRS} PATH_SUFFIXES ogg)
60-
find_library(OGG_LIBRARIES NAMES ogg HINTS ${PC_OGG_LIBRARY_DIRS})
61-
else()
62-
find_path(OGG_INCLUDE_DIRS NAMES ogg/ogg.h HINTS ${OGG_ROOT}/include PATH_SUFFIXES ogg)
63-
find_library(OGG_LIBRARIES NAMES ogg HINTS ${OGG_ROOT}/lib ${OGG_ROOT}/lib64)
64-
endif()
65-
include(FindPackageHandleStandardArgs)
66-
find_package_handle_standard_args(OGG DEFAULT_MSG OGG_INCLUDE_DIRS OGG_LIBRARIES)
65+
find_package(Ogg REQUIRED)
6766

6867
add_subdirectory(lib)
6968

Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ EXTRA_DIST = \
2626
vorbisenc-uninstalled.pc.in \
2727
vorbisfile-uninstalled.pc.in \
2828
symbian \
29-
macosx win32 CMakeLists.txt
29+
macosx win32 CMakeLists.txt cmake/FindOgg.cmake \
30+
cmake/VorbisConfig.cmake.in
3031

3132

3233
DISTCHECK_CONFIGURE_FLAGS = --enable-docs

cmake/FindOgg.cmake

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#[=======================================================================[.rst:
2+
3+
FindOgg
4+
--------
5+
6+
Find the native Ogg includes and library.
7+
8+
IMPORTED Targets
9+
^^^^^^^^^^^^^^^^
10+
11+
This module defines :prop_tgt:`IMPORTED` target ``Ogg::ogg``, if
12+
Ogg has been found.
13+
14+
Result Variables
15+
^^^^^^^^^^^^^^^^
16+
17+
This module defines the following variables:
18+
19+
::
20+
21+
OGG_INCLUDE_DIRS - where to find ogg.h, etc.
22+
OGG_LIBRARIES - List of libraries when using ogg.
23+
OGG_FOUND - True if ogg found.
24+
25+
::
26+
27+
OGG_VERSION_STRING - The version of ogg found (x.y.z)
28+
29+
Hints
30+
^^^^^
31+
32+
A user may set ``OGG_ROOT`` to a ogg installation root to tell this
33+
module where to look.
34+
#]=======================================================================]
35+
36+
if(OGG_INCLUDE_DIR)
37+
# Already in cache, be silent
38+
set(OGG_FIND_QUIETLY TRUE)
39+
endif()
40+
41+
find_package(PkgConfig QUIET)
42+
pkg_check_modules(PC_OGG QUIET ogg)
43+
44+
set(OGG_VERSION_STRING ${PC_OGG_VERSION})
45+
46+
find_path(OGG_INCLUDE_DIR ogg/ogg.h
47+
HINTS
48+
${PC_OGG_INCLUDEDIR}
49+
${PC_OGG_INCLUDE_DIRS}
50+
${OGG_ROOT}
51+
PATH_SUFFIXES
52+
include
53+
)
54+
# MSVC built ogg may be named ogg_static.
55+
# The provided project files name the library with the lib prefix.
56+
find_library(OGG_LIBRARY
57+
NAMES
58+
ogg
59+
ogg_static
60+
libogg
61+
libogg_static
62+
HINTS
63+
${PC_OGG_LIBDIR}
64+
${PC_OGG_LIBRARY_DIRS}
65+
${OGG_ROOT}
66+
PATH_SUFFIXES
67+
lib
68+
)
69+
70+
# Handle the QUIETLY and REQUIRED arguments and set OGG_FOUND
71+
# to TRUE if all listed variables are TRUE.
72+
include(FindPackageHandleStandardArgs)
73+
find_package_handle_standard_args(Ogg
74+
REQUIRED_VARS
75+
OGG_LIBRARY
76+
OGG_INCLUDE_DIR
77+
VERSION_VAR
78+
OGG_VERSION_STRING
79+
)
80+
81+
if(OGG_FOUND)
82+
set(OGG_LIBRARIES ${OGG_LIBRARY})
83+
set(OGG_INCLUDE_DIRS ${OGG_INCLUDE_DIR})
84+
85+
if(NOT TARGET Ogg::ogg)
86+
add_library(Ogg::ogg UNKNOWN IMPORTED)
87+
set_target_properties(Ogg::ogg PROPERTIES
88+
INTERFACE_INCLUDE_DIRECTORIES "${OGG_INCLUDE_DIRS}"
89+
IMPORTED_LOCATION "${OGG_LIBRARIES}"
90+
)
91+
endif()
92+
endif()
93+
94+
mark_as_advanced(OGG_INCLUDE_DIR OGG_LIBRARY)

cmake/VorbisConfig.cmake.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@PACKAGE_INIT@
2+
3+
include(CMakeFindDependencyMacro)
4+
find_dependency(Ogg REQUIRED)
5+
6+
include(${CMAKE_CURRENT_LIST_DIR}/vorbis-targets.cmake)
7+
8+
set(Vorbis_Vorbis_FOUND 1)
9+
set(Vorbis_Enc_FOUND 0)
10+
set(Vorbis_File_FOUND 0)
11+
12+
if(TARGET Vorbis::vorbisenc)
13+
set(Vorbis_Enc_FOUND TRUE)
14+
endif()
15+
if(TARGET Vorbis::vorbisfile)
16+
set(Vorbis_File_FOUND TRUE)
17+
endif()
18+
19+
check_required_components(Vorbis)

lib/CMakeLists.txt

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ if(MSVC)
6767
list(APPEND VORBISFILE_SOURCES ../win32/vorbisfile.def)
6868
endif()
6969

70-
include_directories(../include)
71-
include_directories(.)
72-
include_directories(${OGG_INCLUDE_DIRS})
73-
7470
if (NOT BUILD_FRAMEWORK)
7571
add_library(vorbis ${VORBIS_HEADERS} ${VORBIS_SOURCES})
7672
add_library(vorbisenc ${VORBISENC_SOURCES})
@@ -83,15 +79,68 @@ if (NOT BUILD_FRAMEWORK)
8379
get_version_info(VORBISFILE_VERSION_INFO "VF_LIB_CURRENT" "VF_LIB_AGE" "VF_LIB_REVISION")
8480
set_target_properties(vorbisfile PROPERTIES SOVERSION ${VORBISFILE_VERSION_INFO})
8581

86-
target_link_libraries(vorbis ${OGG_LIBRARIES})
87-
target_link_libraries(vorbisenc ${OGG_LIBRARIES} vorbis)
88-
target_link_libraries(vorbisfile ${OGG_LIBRARIES} vorbis)
82+
target_include_directories(vorbis
83+
PUBLIC
84+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
85+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
86+
PRIVATE
87+
${CMAKE_CURRENT_SOURCE_DIR}
88+
)
89+
target_include_directories(vorbisenc
90+
PUBLIC
91+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
92+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
93+
PRIVATE
94+
${CMAKE_CURRENT_SOURCE_DIR}
95+
)
96+
target_include_directories(vorbisfile
97+
PUBLIC
98+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
99+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
100+
)
101+
102+
target_link_libraries(vorbis
103+
PUBLIC Ogg::ogg
104+
PRIVATE $<$<BOOL:${HAVE_LIBM}>:m>
105+
)
106+
target_link_libraries(vorbisenc PUBLIC vorbis)
107+
target_link_libraries(vorbisfile PUBLIC vorbis)
108+
109+
install(FILES ${VORBIS_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/Vorbis)
110+
111+
install(TARGETS vorbis vorbisenc vorbisfile
112+
EXPORT VorbisTargets
113+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
114+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
115+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
116+
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
117+
)
118+
119+
if(INSTALL_CMAKE_PACKAGE_MODULE)
120+
121+
set(CMAKE_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Vorbis)
122+
123+
install(EXPORT VorbisTargets
124+
DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
125+
NAMESPACE Vorbis::
126+
)
127+
128+
129+
include(CMakePackageConfigHelpers)
130+
131+
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/VorbisConfig.cmake.in ${PROJECT_BINARY_DIR}/VorbisConfig.cmake
132+
INSTALL_DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
133+
)
134+
135+
write_basic_package_version_file(${PROJECT_BINARY_DIR}/VorbisConfigVersion.cmake
136+
COMPATIBILITY SameMajorVersion
137+
)
89138

90-
install(FILES ${VORBIS_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/vorbis)
139+
install(FILES ${PROJECT_BINARY_DIR}/VorbisConfig.cmake ${PROJECT_BINARY_DIR}/VorbisConfigVersion.cmake
140+
DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
141+
)
91142

92-
install(TARGETS vorbis RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
93-
install(TARGETS vorbisenc RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
94-
install(TARGETS vorbisfile RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
143+
endif()
95144
else()
96145
add_library(vorbis ${VORBIS_PUBLIC_HEADERS} ${VORBIS_HEADERS} ${VORBIS_SOURCES} ${VORBISFILE_SOURCES} ${VORBISENC_SOURCES})
97146
set_target_properties(vorbis PROPERTIES

0 commit comments

Comments
 (0)