Skip to content

Commit 8a6768c

Browse files
committed
ascii_video now builds ffmpeg and ncurses completely from CMake with ExternalProject
1 parent ac85c64 commit 8a6768c

File tree

10 files changed

+183
-168
lines changed

10 files changed

+183
-168
lines changed

.gitignore

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ blueprints/
77
COMMITLOGGING.md
88
devscripts/
99

10-
lib/ncurses-6.4/
11-
lib/ffmpeg-6.0/
1210
lib/aom
1311
lib/build
1412
install
1513
test*.sh
1614

17-
lib/ffmpeg/build
18-
lib/ffmpeg/src
15+
lib/ffmpeg/build/
16+
lib/ffmpeg/src/
1917

20-
lib/ncurses/build
21-
lib/ncurses/src
18+
lib/ncurses/build/
19+
lib/ncurses/src/
20+
21+
ignore/

CMakeLists.txt

Lines changed: 132 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ set(ASCII_VIDEO_VERSION_MINOR 4)
1010
set(ASCII_VIDEO_VERSION_PATCH 0)
1111
set(ASCII_VIDEO_VERSION "${ASCII_VIDEO_VERSION_MAJOR}.${ASCII_VIDEO_VERSION_MINOR}.${ASCII_VIDEO_VERSION_PATCH}")
1212

13+
set(LOCAL_NCURSES_LIB ${CMAKE_SOURCE_DIR}/lib/ncurses)
14+
set(LOCAL_FFMPEG_LIB ${CMAKE_SOURCE_DIR}/lib/ffmpeg)
15+
1316
set(ASCII_VIDEO_SUPPORTED_LANGUAGES CXX C)
1417
if (APPLE)
1518
list (APPEND ASCII_VIDEO_SUPPORTED_LANGUAGES OBJC OBJCXX)
@@ -31,36 +34,133 @@ LANGUAGES ${ASCII_VIDEO_SUPPORTED_LANGUAGES}
3134
DESCRIPTION "Terminal video media player")
3235

3336
option(ASCII_VIDEO_BUILD_TESTS "Build Testing Executable for ascii_video" OFF)
34-
option(FALLBACK_BUILD_FROM_SHARED "Will build dependencies if the shared version is requested but is not found" ON)
35-
option(USE_SHARED_NCURSES "Use globally detected NCurses build" OFF)
36-
option(USE_SHARED_FFMPEG "Use globally detected FFmpeg" OFF)
37-
option(USE_SHARED_ALL "Use All Globally detected libraries" OFF)
38-
39-
option(BUILD_FFMPEG_AS_SHARED "Build FFmpeg Library as a shared library. " OFF)
40-
option(BUILD_NCURSES_AS_SHARED "Build NCurses as a shared library." OFF)
4137

4238
if (ASCII_VIDEO_BUILD_TESTS)
4339
message("Configured to build testing executable")
4440
else()
4541
message("Configured to NOT build testing executable")
4642
endif()
4743

44+
set(NCURSES_CONFIGURE_OPTIONS --prefix=${CMAKE_BINARY_DIR}
45+
--datadir=${CMAKE_BINARY_DIR}/data
46+
--without-tests
47+
--without-manpages
48+
--without-progs
49+
--with-shared
50+
--without-normal
51+
--without-debug
52+
)
4853

49-
if(NOT USE_SHARED_ALL)
50-
add_subdirectory(${CMAKE_SOURCE_DIR}/lib)
51-
else()
52-
find_package(Curses REQUIRED)
53-
find_package(PkgConfig REQUIRED)
54-
pkg_check_modules(
55-
LIBAV REQUIRED IMPORTED_TARGET
56-
libavformat
57-
libavcodec
58-
libswresample
59-
libswscale
60-
libavutil
61-
)
54+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
55+
list(APPEND NCURSES_CONFIGURE_OPTIONS --with-build-cflags=-g)
6256
endif()
6357

58+
include(ExternalProject)
59+
ExternalProject_Add(
60+
ncurses6
61+
SOURCE_DIR ${LOCAL_NCURSES_LIB}/src
62+
BINARY_DIR ${LOCAL_NCURSES_LIB}/build
63+
PREFIX ${CMAKE_BINARY_DIR}
64+
INSTALL_DIR ${CMAKE_BINARY_DIR}
65+
CONFIGURE_COMMAND ${LOCAL_NCURSES_LIB}/src/configure ${NCURSES_CONFIGURE_OPTIONS}
66+
BUILD_COMMAND make
67+
INSTALL_COMMAND make install
68+
BUILD_IN_SOURCE OFF
69+
URL https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.4.tar.gz
70+
TLS_VERIFY ON
71+
)
72+
73+
set(CURSES_LIBRARIES ${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}ncurses${CMAKE_SHARED_LIBRARY_SUFFIX}
74+
${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}form${CMAKE_SHARED_LIBRARY_SUFFIX})
75+
76+
set(CURSES_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include/ncurses)
77+
78+
set(FFMPEG_BUILD_OPTIONS --prefix=${CMAKE_BINARY_DIR}
79+
--pkg-config-flags=--static
80+
--extra-cflags=-I${CMAKE_BINARY_DIR}/include
81+
--extra-ldflags=-L${CMAKE_BINARY_DIR}/lib
82+
--extra-libs=-lpthread
83+
--extra-libs=-lm
84+
--enable-rpath
85+
--enable-shared
86+
--disable-static
87+
--disable-network
88+
--disable-encoders
89+
--disable-muxers
90+
--disable-programs
91+
--disable-doc
92+
--disable-filters
93+
--disable-postproc
94+
--disable-avfilter
95+
--disable-avdevice
96+
--disable-protocols
97+
--disable-devices
98+
--enable-protocol=file,pipe)
99+
100+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
101+
list(APPEND FFMPEG_BUILD_OPTIONS --extra-cflags=-g)
102+
endif()
103+
# --enable-libdav1d
104+
# --enable-libvorbis
105+
# --ld="g++"
106+
# --disable-shared
107+
# --enable-static
108+
109+
ExternalProject_Add(
110+
ffmpeg
111+
SOURCE_DIR ${LOCAL_FFMPEG_LIB}/src
112+
BINARY_DIR ${LOCAL_FFMPEG_LIB}/build
113+
GIT_REPOSITORY https://git.ffmpeg.org/ffmpeg.git
114+
GIT_SHALLOW ON
115+
UPDATE_DISCONNECTED ON
116+
STEP_TARGETS update
117+
CONFIGURE_COMMAND ${LOCAL_FFMPEG_LIB}/src/configure ${FFMPEG_BUILD_OPTIONS}
118+
PREFIX ${CMAKE_BINARY_DIR}
119+
INSTALL_DIR ${CMAKE_BINARY_DIR}
120+
BUILD_COMMAND make
121+
BUILD_IN_SOURCE OFF
122+
INSTALL_COMMAND make install
123+
)
124+
125+
set(PKG_CONFIG_PATH_SEPARATOR :)
126+
if (WIN32)
127+
set(PKG_CONFIG_PATH_SEPARATOR ;)
128+
endif()
129+
130+
# set(ENV{PKG_CONFIG_PATH} ${CMAKE_BINARY_DIR}/lib/pkgconfig${PKG_CONFIG_PATH_SEPARATOR}$ENV{PKG_CONFIG_PATH})
131+
set(FFMPEG_LIBS ${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}avcodec${CMAKE_SHARED_LIBRARY_SUFFIX}
132+
${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}avformat${CMAKE_SHARED_LIBRARY_SUFFIX}
133+
${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}avutil${CMAKE_SHARED_LIBRARY_SUFFIX}
134+
${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}swresample${CMAKE_SHARED_LIBRARY_SUFFIX}
135+
${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}swscale${CMAKE_SHARED_LIBRARY_SUFFIX})
136+
set(FFMPEG_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include)
137+
# set(ENV{PKG_CONFIG_PATH} ${CMAKE_BINARY_DIR}/lib/pkgconfig)
138+
# find_package(PkgConfig REQUIRED)
139+
# pkg_check_modules(
140+
# LIBAV REQUIRED IMPORTED_TARGET
141+
# libavformat
142+
# libavcodec
143+
# libswresample
144+
# libswscale
145+
# libavutil
146+
# )
147+
148+
# if(NOT USE_SHARED_ALL)
149+
# message("Experimental Library Building Enabled")
150+
# # add_subdirectory(${CMAKE_SOURCE_DIR}/lib)
151+
# else()
152+
# find_package(Curses REQUIRED)
153+
# find_package(PkgConfig REQUIRED)
154+
# pkg_check_modules(
155+
# LIBAV REQUIRED IMPORTED_TARGET
156+
# libavformat
157+
# libavcodec
158+
# libswresample
159+
# libswscale
160+
# libavutil
161+
# )
162+
# endif()
163+
64164
if(ASCII_VIDEO_BUILD_TESTS)
65165
add_subdirectory(./lib/Catch2)
66166
endif()
@@ -103,9 +203,12 @@ message("Curses Libraries found at " ${CURSES_LIBRARIES})
103203

104204
add_executable(ascii_video ${COMMON_SOURCE_FILES} ./src/main.cpp)
105205
target_compile_features(ascii_video PRIVATE cxx_std_17)
106-
target_include_directories(ascii_video PRIVATE ${CURSES_INCLUDE_DIR} ./include ./lib/miniaudio ${CMAKE_CURRENT_BINARY_DIR}/include )
107-
target_link_libraries(ascii_video PRIVATE PkgConfig::LIBAV ${CURSES_LIBRARIES} $<TARGET_OBJECTS:miniaudio> argparse ${CMAKE_DL_LIBS})
108-
add_dependencies(ascii_video PkgConfig::LIBAV)
206+
target_include_directories(ascii_video PRIVATE ${FFMPEG_INCLUDE_DIR} ${CURSES_INCLUDE_DIR} ./include ./lib/miniaudio ${CMAKE_CURRENT_BINARY_DIR}/include )
207+
target_link_libraries(ascii_video PRIVATE ${FFMPEG_LIBS} ${CURSES_LIBRARIES} $<TARGET_OBJECTS:miniaudio> argparse ${CMAKE_DL_LIBS})
208+
add_dependencies(ascii_video ffmpeg ncurses6)
209+
set_target_properties(ascii_video PROPERTIES INSTALL_RPATH ${CMAKE_BINARY_DIR}/lib)
210+
set_target_properties(ascii_video PROPERTIES BUILD_WITH_INSTALL_RPATH ON)
211+
target_compile_options(ascii_video PRIVATE -Wl,-rpath,'$ORIGIN'/lib)
109212

110213
if(MSVC)
111214
target_compile_options(ascii_video PRIVATE /std:c++17 /W4 /WX)
@@ -130,7 +233,10 @@ if (ASCII_VIDEO_BUILD_TESTS)
130233
else()
131234
target_compile_options(ascii_tests PRIVATE -Wall -Wextra -Wpedantic)# Consider adding -Werror back
132235
endif()
133-
target_include_directories(ascii_tests PRIVATE ${CURSES_INCLUDE_DIR} ./include ./lib/miniaudio)
236+
add_dependencies(tests ffmpeg ncurses6)
237+
target_include_directories(ascii_tests PRIVATE ${FFMPEG_INCLUDE_DIR} ${CURSES_INCLUDE_DIR} ./include ./lib/miniaudio)
134238
target_compile_features(ascii_tests PRIVATE cxx_std_17)
135-
target_link_libraries(ascii_tests PRIVATE Catch2::Catch2WithMain ${CURSES_LIBRARIES} PkgConfig::LIBAV $<TARGET_OBJECTS:miniaudio> ${CMAKE_DL_LIBS})
136-
endif()
239+
target_link_libraries(ascii_tests PRIVATE Catch2::Catch2WithMain ${FFMPEG_LIBS} ${CURSES_LIBRARIES} PkgConfig::LIBAV $<TARGET_OBJECTS:miniaudio> ${CMAKE_DL_LIBS})
240+
set_target_properties(ascii_tests PROPERTIES INSTALL_RPATH ${CMAKE_BINARY_DIR}/lib)
241+
set_target_properties(ascii_tests PROPERTIES BUILD_WITH_INSTALL_RPATH ON)
242+
endif()

lib/CMakeLists.txt

Lines changed: 0 additions & 42 deletions
This file was deleted.

lib/ffmpeg/CMakeLists.txt

Lines changed: 0 additions & 60 deletions
This file was deleted.

lib/ffmpeg/ffmpeg-6.0.tar.xz

-9.76 MB
Binary file not shown.

lib/ncurses/CMakeLists.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/ncurses/ncurses-6.4.tar.gz

-3.45 MB
Binary file not shown.

src/boiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ AVFormatContext* open_format_context(std::string file_path) {
2828
if (format_context != nullptr) {
2929
avformat_free_context(format_context);
3030
}
31-
throw std::runtime_error("Failed to find stream info for " + file_path);
31+
throw ascii::ffmpeg_error("Failed to find stream info for " + file_path, result);
3232
}
3333

3434
if (format_context != nullptr) {

0 commit comments

Comments
 (0)