forked from ffAudio/FFmpegBuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
211 lines (149 loc) · 6.66 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
include_guard (GLOBAL)
cmake_minimum_required (VERSION 3.22 FATAL_ERROR)
project (
FFmpeg
VERSION 4.4.1
DESCRIPTION "CMake build of FFmpeg"
HOMEPAGE_URL "https://www.ffmpeg.org/"
LANGUAGES NONE) # FFmpeg is built using make shell commands, so within CMake we don't need to enable any languages
enable_testing ()
if (APPLE)
if (CMAKE_OSX_ARCHITECTURES)
if (arm64 IN_LIST CMAKE_OSX_ARCHITECTURES AND x86_64 IN_LIST CMAKE_OSX_ARCHITECTURES)
set (univ_bin_default ON)
else ()
set (univ_bin_default OFF)
endif ()
else ()
if (IOS)
set (univ_bin_default OFF)
else ()
set (univ_bin_default ON)
endif ()
endif ()
option (FFMPEG_MAC_UNIVERSAL_BINARY "Build a Mac universal binary" "${univ_bin_default}")
else()
set (FFMPEG_MAC_UNIVERSAL_BINARY OFF)
endif ()
if (PROJECT_IS_TOP_LEVEL)
set_property (
GLOBAL PROPERTY
USE_FOLDERS YES
PREDEFINED_TARGETS_FOLDER Targets
REPORT_UNDEFINED_PROPERTIES "${CMAKE_BINARY_DIR}/undefined_properties.log")
set (CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
set (CMAKE_INSTALL_MESSAGE LAZY)
set (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION ON)
# Need to enable at least one language for GNUInstallDirs
enable_language (C)
endif ()
include (GNUInstallDirs)
include (FeatureSummary)
set (FFMPEG_INSTALL_DEST "${CMAKE_INSTALL_LIBDIR}/cmake/FFmpeg"
CACHE STRING
"Directory below INSTALL_PREFIX where FFmpeg CMake package files will be installed to")
find_program (FFMPEG_MAKE_EXECUTABLE
NAMES make gmake nmake
DOC "Path to the make executable used for building FFmpeg"
REQUIRED)
set (FFMPEG_VERSION 4.4.1 CACHE STRING "FFmpeg version")
set (FFMPEG_NAME "ffmpeg-${FFMPEG_VERSION}")
set (cache_dir "${CMAKE_CURRENT_LIST_DIR}/Cache")
set (FFMPEG_SOURCE_DIR "${cache_dir}/${FFMPEG_NAME}" CACHE PATH "Path to FFmpeg source code")
mark_as_advanced (FORCE FFMPEG_VERSION FFMPEG_SOURCE_DIR FFMPEG_MAKE_EXECUTABLE FFMPEG_INSTALL_DEST)
#
if (NOT EXISTS "${FFMPEG_SOURCE_DIR}")
set (FFMPEG_URL "https://ffmpeg.org/releases/${FFMPEG_NAME}.tar.bz2")
get_filename_component (FFMPEG_ARCHIVE_NAME "${FFMPEG_URL}" NAME)
set (ffmpeg_tarball "${cache_dir}/${FFMPEG_ARCHIVE_NAME}")
if(NOT EXISTS "${ffmpeg_tarball}")
message (STATUS "Downloading FFmpeg sources from ${FFMPEG_URL} to ${FFMPEG_SOURCE_DIR}...")
file (DOWNLOAD "${FFMPEG_URL}" "${ffmpeg_tarball}")
endif()
message (VERBOSE "Unpacking ffmpeg tarball...")
execute_process (COMMAND "${CMAKE_COMMAND}" -E tar xzf "${ffmpeg_tarball}"
WORKING_DIRECTORY "${cache_dir}")
endif ()
#
string (REPLACE " -Wl,--fatal-warnings" "" FFMPEG_LD_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
set (FFMPEG_LD_FLAGS "${FFMPEG_C_FLAGS} ${FFMPEG_LD_FLAGS} ${FFMPEG_EXTRA_LD_FLAGS}")
#
include ("${CMAKE_CURRENT_LIST_DIR}/cmake/ConfigureFFmpegBuild.cmake")
add_library (ffmpeg INTERFACE)
set (ffmpeg_output_dir "${CMAKE_CURRENT_BINARY_DIR}/ffmpeg")
message (DEBUG "ffmpeg output dir: ${ffmpeg_output_dir}")
if (FFMPEG_MAC_UNIVERSAL_BINARY)
include ("${CMAKE_CURRENT_LIST_DIR}/cmake/FFmpegMacBuild.cmake")
else ()
message (STATUS "Configuring FFmpeg build...")
if (PROJECT_IS_TOP_LEVEL)
set (all_flag ALL)
else ()
unset (all_flag)
endif ()
preconfigure_ffmpeg_build (SOURCE_DIR "${FFMPEG_SOURCE_DIR}"
OUTPUT_DIR "${ffmpeg_output_dir}")
create_ffmpeg_build_target (SOURCE_DIR "${FFMPEG_SOURCE_DIR}"
OUTPUT_DIR "${ffmpeg_output_dir}"
BUILD_TARGET ffmpeg_build
${all_flag})
# avconfig.h is generated by the configure script, need to manually copy it to the output directory...
file (MAKE_DIRECTORY "${ffmpeg_output_dir}/include/libavutil")
file (COPY_FILE
"${FFMPEG_SOURCE_DIR}/libavutil/avconfig.h"
"${ffmpeg_output_dir}/include/libavutil/avconfig.h")
endif ()
# Need to manually copy headers...
file (GLOB lib_headers ${FFMPEG_SOURCE_DIR}/lib*)
file (COPY ${lib_headers} "${FFMPEG_SOURCE_DIR}/compat"
DESTINATION "${ffmpeg_output_dir}/include" FILES_MATCHING PATTERN *.h)
add_feature_info ("FFmpeg universal binary"
"${FFMPEG_MAC_UNIVERSAL_BINARY}"
"Mac universal binary build of ffmpeg")
target_include_directories (
ffmpeg
INTERFACE "$<BUILD_INTERFACE:${ffmpeg_output_dir}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/ffmpeg>")
get_property (debug_configs GLOBAL PROPERTY DEBUG_CONFIGURATIONS)
if (NOT debug_configs)
set (debug_configs Debug)
endif ()
set (config_is_debug "$<IN_LIST:$<CONFIG>,${debug_configs}>")
set (compiler_msvc "$<C_COMPILER_ID:MSVC>")
# see https://www.ffmpeg.org/platform.html#toc-Linking-to-FFmpeg-with-Microsoft-Visual-C_002b_002b
set_target_properties (ffmpeg PROPERTIES
$<${compiler_msvc}:MSVC_RUNTIME_LIBRARY MultiThreaded$<${config_is_debug}:Debug>>)
target_compile_options (ffmpeg INTERFACE "$<${compiler_msvc}:/MT>")
add_library (ffmpeg::ffmpeg ALIAS ffmpeg)
install (
DIRECTORY "${ffmpeg_output_dir}/include"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ffmpeg"
COMPONENT ffmpeg_base
FILES_MATCHING PATTERN *.h)
include (CPackComponent)
cpack_add_component (ffmpeg_base HIDDEN)
cpack_add_component_group (ffmpeg DISPLAY_NAME "All FFmpeg libraries" BOLD_TITLE)
install (
TARGETS ffmpeg
EXPORT FFmpegTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT ffmpeg_base
NAMELINK_COMPONENT ffmpeg_base
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT ffmpeg_base
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ffmpeg_base
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ffmpeg")
install (EXPORT FFmpegTargets NAMESPACE ffmpeg::
DESTINATION "${FFMPEG_INSTALL_DEST}"
COMPONENT ffmpeg_base)
#
include (CMakePackageConfigHelpers)
write_basic_package_version_file (ffmpeg-config-version.cmake
VERSION "${PROJECT_VERSION}"
COMPATIBILITY SameMajorVersion)
configure_package_config_file (cmake/ffmpeg-config.cmake ffmpeg-config.cmake
INSTALL_DESTINATION "${FFMPEG_INSTALL_DEST}"
NO_SET_AND_CHECK_MACRO)
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/ffmpeg-config-version.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/ffmpeg-config.cmake"
DESTINATION "${FFMPEG_INSTALL_DEST}"
COMPONENT ffmpeg_base)
export (PACKAGE FFmpeg)