Skip to content

Commit aed5937

Browse files
committed
Steps toward fully cmake build
1 parent 8abf61b commit aed5937

File tree

9 files changed

+190
-56
lines changed

9 files changed

+190
-56
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ lib/ffmpeg-6.0/
1212
lib/aom
1313
lib/build
1414
install
15-
test*.sh
15+
test*.sh
16+
17+
lib/ffmpeg/build
18+
lib/ffmpeg/src
19+
20+
lib/ncurses/build
21+
lib/ncurses/src

CMakeLists.txt

Lines changed: 63 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,73 @@
11
cmake_minimum_required(VERSION 3.10)
2-
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
2+
3+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
34
set(CMAKE_CXX_STANDARD 17)
45
set(CMAKE_CXX_STANDARD_REQUIRED ON)
56
set(CMAKE_CXX_EXTENSIONS OFF)
67

8+
set(ASCII_VIDEO_VERSION_STRING "0.4.0")
9+
set(ASCII_VIDEO_VERSION_MAJOR 0)
10+
set(ASCII_VIDEO_VERSION_MINOR 4)
11+
set(ASCII_VIDEO_VERSION_PATCH 0)
12+
13+
set(ASCII_VIDEO_SUPPORTED_LANGUAGES CXX C)
14+
if (APPLE)
15+
list (APPEND ASCII_VIDEO_SUPPORTED_LANGUAGES OBJC OBJCXX)
16+
endif()
17+
718
if(NOT CMAKE_BUILD_TYPE)
819
set(CMAKE_BUILD_TYPE Release)
920
message("No Build Type Given, setting build type to Release")
1021
endif()
11-
message("Building Build Type \"${CMAKE_BUILD_TYPE}\"")
22+
message("Building Build Type: " ${CMAKE_BUILD_TYPE})
1223

1324
if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
1425
message(FATAL_ERROR "Building in-source is not supported! Create a build dir and run cmake from there")
1526
endif()
1627

28+
project(ascii_video
29+
VERSION 0.4.0
30+
LANGUAGES ${ASCII_VIDEO_SUPPORTED_LANGUAGES}
31+
DESCRIPTION "Terminal video media player")
32+
1733
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)
1841

1942
if (ASCII_VIDEO_BUILD_TESTS)
2043
message("Configured to build testing executable")
2144
else()
2245
message("Configured to NOT build testing executable")
2346
endif()
2447

25-
if(MSVC)
26-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /W4")
27-
endif(MSVC)
28-
29-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
30-
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wextra")
31-
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
32-
33-
project(ascii_video
34-
VERSION 0.4.0
35-
LANGUAGES CXX C
36-
DESCRIPTION "Terminal video media player")
37-
38-
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR})
39-
set(LOCAL_NCURSES_LIBRARIES_PATH ${CMAKE_SOURCE_DIR}/lib/build/ncurses-6.4/lib)
40-
set(LOCAL_NCURSES_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/lib/build/ncurses-6.4/include)
41-
42-
if(EXISTS ${LOCAL_NCURSES_LIBRARIES_PATH})
43-
message("FOUND LOCAL NCURSES MODULE")
44-
set(CURSES_LIBRARIES ${LOCAL_NCURSES_LIBRARIES_PATH}/libncurses.a)
45-
set(CURSES_INCLUDE_DIR ${LOCAL_NCURSES_INCLUDE_PATH} ${LOCAL_NCURSES_INCLUDE_PATH}/ncurses)
48+
if(NOT USE_SHARED_ALL)
49+
add_subdirectory(${CMAKE_SOURCE_DIR}/lib)
4650
else()
4751
find_package(Curses REQUIRED)
52+
find_package(PkgConfig REQUIRED)
53+
pkg_check_modules(
54+
LIBAV REQUIRED IMPORTED_TARGET
55+
libavformat
56+
libavcodec
57+
libswresample
58+
libswscale
59+
libavutil
60+
)
4861
endif()
4962

50-
find_package(PkgConfig REQUIRED)
51-
52-
set(LOCAL_FFMPEG ${CMAKE_SOURCE_DIR}/lib/build/ffmpeg-6.0)
53-
set(LOCAL_FFMPEG_LIB ${LOCAL_FFMPEG}/lib)
54-
set(LOCAL_FFMPEG_INCLUDE ${LOCAL_FFMPEG}/include)
55-
set(LOCAL_FFMPEG_PKG_CONFIG ${LOCAL_FFMPEG_LIB}/pkgconfig)
56-
57-
if(EXISTS ${LOCAL_FFMPEG_PKG_CONFIG})
58-
message("FOUND LOCAL FFMPEG PKG CONFIG")
59-
set(ENV{PKG_CONFIG_PATH} ${LOCAL_FFMPEG_PKG_CONFIG})
60-
endif()
61-
62-
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET
63-
libavformat
64-
libavcodec
65-
libswresample
66-
libswscale
67-
libavutil
68-
)
69-
70-
if (ASCII_VIDEO_BUILD_TESTS)
63+
if(ASCII_VIDEO_BUILD_TESTS)
7164
add_subdirectory(./lib/Catch2)
7265
endif()
7366

74-
include_directories( ${CURSES_INCLUDE_DIR} ./include ./lib/miniaudio ./lib/argparse )
75-
67+
add_library(miniaudio STATIC ./lib/miniaudio/miniaudio.c)
68+
target_include_directories(miniaudio PRIVATE ./lib/miniaudio)
69+
7670
set(COMMON_SOURCE_FILES
77-
./lib/miniaudio/miniaudio.c
7871
./src/audioresampler.cpp
7972
./src/videoconverter.cpp
8073
./src/streamdata.cpp
@@ -100,6 +93,20 @@ set(COMMON_SOURCE_FILES
10093
./src/termcolor.cpp
10194
)
10295

96+
message("Curses Libraries found at " ${CURSES_LIBRARIES})
97+
98+
add_executable(ascii_video ${COMMON_SOURCE_FILES} ./src/main.cpp)
99+
target_compile_features(ascii_video PRIVATE cxx_std_17)
100+
target_include_directories(ascii_video PRIVATE ${CURSES_INCLUDE_DIR} ./include ./lib/miniaudio ./lib/argparse )
101+
target_link_libraries(ascii_video PRIVATE PkgConfig::LIBAV ${CURSES_LIBRARIES} miniaudio)
102+
add_dependencies(ascii_video PkgConfig::LIBAV)
103+
104+
if(MSVC)
105+
target_compile_options(ascii_video PRIVATE /std:c++17 /W4 /WX)
106+
else()
107+
target_compile_options(ascii_video PRIVATE -Wall -Wextra -Wpedantic) # Consider adding -Werror back
108+
endif()
109+
103110
set(TEST_SOURCE_FILES
104111
./src/tests/test_audiobuffer.cpp
105112
./src/tests/test_playback.cpp
@@ -110,12 +117,14 @@ set(TEST_SOURCE_FILES
110117
./src/tests/test_formatting.cpp
111118
)
112119

113-
add_executable(ascii_video ${COMMON_SOURCE_FILES} ./src/main.cpp)
114-
target_compile_features(ascii_video PRIVATE cxx_std_17)
115-
target_link_libraries(ascii_video PkgConfig::LIBAV ${CURSES_LIBRARIES})
116-
117120
if (ASCII_VIDEO_BUILD_TESTS)
118-
add_executable(tests ${COMMON_SOURCE_FILES} ${TEST_SOURCE_FILES})
119-
target_compile_features(tests PRIVATE cxx_std_17)
120-
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain ${CURSES_LIBRARIES} PkgConfig::LIBAV)
121+
add_executable(ascii_tests ${COMMON_SOURCE_FILES} ${TEST_SOURCE_FILES})
122+
if(MSVC)
123+
target_compile_options(ascii_tests PRIVATE /std:c++17 /W4 /WX)
124+
else()
125+
target_compile_options(ascii_tests PRIVATE -Wall -Wextra -Wpedantic)# Consider adding -Werror back
126+
endif()
127+
target_include_directories(ascii_tests PRIVATE ${CURSES_INCLUDE_DIR} ./include ./lib/miniaudio ./lib/argparse )
128+
target_compile_features(ascii_tests PRIVATE cxx_std_17)
129+
target_link_libraries(ascii_tests PRIVATE Catch2::Catch2WithMain ${CURSES_LIBRARIES} PkgConfig::LIBAV miniaudio)
121130
endif()

lib/CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
if (NOT SUBMAKE_JOBS)
3+
include(ProcessorCount)
4+
ProcessorCount(NUM_CORES)
5+
if (NOT NUM_CORES EQUAL 0)
6+
if (NUM_CORES GREATER 2)
7+
# be nice...
8+
MATH( EXPR NUM_CORES "${NUM_CORES} - 2" )
9+
endif()
10+
set(SUBMAKE_JOBS ${NUM_CORES})
11+
else()
12+
set(SUBMAKE_JOBS 1)
13+
endif()
14+
endif()
15+
16+
MESSAGE("SUBMAKE_JOBS: " ${SUBMAKE_JOBS})
17+
18+
set(LOCAL_NCURSES_LIB ${CMAKE_SOURCE_DIR}/lib/ncurses)
19+
set(LOCAL_FFMPEG_LIB ${CMAKE_SOURCE_DIR}/lib/ffmpeg)
20+
21+
if(NOT USE_SHARED_NCURSES)
22+
add_subdirectory(${LOCAL_NCURSES_LIB})
23+
else()
24+
find_package(Curses)
25+
if((NOT CURSES_FOUND) AND FALLBACK_BUILD_FROM_SHARED)
26+
add_subdirectory(${LOCAL_NCURSES_LIB})
27+
endif()
28+
endif()
29+
30+
if(NOT USE_SHARED_FFMPEG)
31+
add_subdirectory(${CMAKE_SOURCE_DIR}/lib/ffmpeg)
32+
else()
33+
find_package(PkgConfig REQUIRED)
34+
pkg_check_modules(
35+
LIBAV REQUIRED IMPORTED_TARGET
36+
libavformat
37+
libavcodec
38+
libswresample
39+
libswscale
40+
libavutil
41+
)
42+
endif()

lib/ffmpeg/CMakeLists.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Responsible for building the ffmpeg libs into the lib/build directory
2+
# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/libantlr3c-3.1.3
3+
4+
# include(ExternalProject)
5+
6+
# set(FFMPEG_BUILD_OPTIONS --prefix="${LOCAL_FFMPEG_LIB}/build}"
7+
# --pkg-config-flags="--static"
8+
# --extra-cflags="-I${LOCAL_FFMPEG_LIB}/build/include"
9+
# --extra-ldflags="-L${LOCAL_FFMPEG_LIB}/build/lib"
10+
# --extra-libs="-lpthread -lm"
11+
# --ld="g++"
12+
# --disable-shared
13+
# --enable-static
14+
# --enable-libdav1d
15+
# --enable-libvorbis
16+
# --disable-network
17+
# --disable-encoders
18+
# --disable-muxers
19+
# --disable-programs
20+
# --disable-doc
21+
# --disable-filters
22+
# --disable-postproc
23+
# --disable-avfilter
24+
# --disable-avdevice
25+
# --disable-protocols
26+
# --enable-protocol=file,pipe
27+
# --disable-devices)
28+
29+
# ExternalProject_Add(
30+
# ffmpeg
31+
# SOURCE_DIR "${LOCAL_FFMPEG_LIB}"
32+
# URL "${LOCAL_FFMPEG_LIB}/ffmpeg-6.0.tar.xz"
33+
# CONFIGURE_COMMAND "${LOCAL_FFMPEG_LIB}/ffmpeg-6.0/configure ${FFMPEG_BUILD_OPTIONS}"
34+
# PREFIX "${LOCAL_FFMPEG_LIB}/build"
35+
# BUILD_COMMAND "make -j${SUBMAKE_JOBS}"
36+
# BUILD_IN_SOURCE OFF
37+
# INSTALL_COMMAND "make install"
38+
# )
39+
40+
find_package(PkgConfig REQUIRED)
41+
# set(PKG_CONFIG_PATH_SAVE $ENV{PKG_CONFIG_PATH})
42+
# set(ENV{PKG_CONFIG_PATH} ${LOCAL_FFMPEG_LIB}/build/pkgconfig)
43+
44+
pkg_check_modules(
45+
LIBAV REQUIRED IMPORTED_TARGET
46+
libavformat
47+
libavcodec
48+
libswresample
49+
libswscale
50+
libavutil
51+
)
52+
53+
message(PkgConfig::LIBAV)
54+
if(NOT TARGET PkgConfig::LIBAV)
55+
message("No target named PkgConfig::LIBAV could be found in the subdirectory")
56+
else()
57+
message("Target named PkgConfig::LIBAV could be found in the subdirectory")
58+
endif()
59+
60+
# set(ENV{PKG_CONFIG_PATH} ${PKG_CONFIG_PATH_SAVE})

lib/libva-2.18.0.tar.bz2

-496 KB
Binary file not shown.

lib/ncurses/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Responsible for building the ncurses libs into the lib/build directory
2+
3+
# LOCAL_NCURSES_LIB defined at lib/CMakeLists.txt
4+
5+
set(NCURSES_BUILD_DIR ${LOCAL_NCURSES_LIB}/build)
6+
include(ExternalProject)
7+
8+
ExternalProject_Add(
9+
ncurses6
10+
SOURCE_DIR ${LOCAL_NCURSES_LIB}
11+
BINARY_DIR ${NCURSES_BUILD_DIR}
12+
CONFIGURE_COMMAND ${LOCAL_NCURSES_LIB}/ncurses-6.4/configure --prefix=${NCURSES_BUILD_DIR} --datadir=${NCURSES_BUILD_DIR}/data --without-tests --without-manpages --without-progs
13+
BUILD_COMMAND "make -j${SUBMAKE_JOBS}"
14+
INSTALL_COMMAND make install
15+
BUILD_IN_SOURCE OFF
16+
URL ${LOCAL_NCURSES_LIB}/ncurses-6.4.tar.gz
17+
)

src/ascii.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern "C" {
1313
}
1414

1515
std::string AsciiImage::ASCII_STANDARD_CHAR_MAP = "@%#*+=-:_.";
16-
std::string AsciiImage::ASCII_EXTENDED_CHAR_MAP = "@MBHENR#KWXDFPQASUZbdehx*8Gm&04LOVYkpq5Tagns69owz$CIu23Jcfry\%1v7l+it[]{}?j|()=~!-/<>\"^_';,:`.";
16+
std::string AsciiImage::ASCII_EXTENDED_CHAR_MAP = "@MBHENR#KWXDFPQASUZbdehx*8Gm&04LOVYkpq5Tagns69owz$CIu23Jcfry%%1v7l+it[]{}?j|()=~!-/<>\"^_';,:`.";
1717
std::string AsciiImage::UNICODE_BOX_CHAR_MAP = "█▉▊▋▌▍▎▏";
1818
std::string AsciiImage::UNICODE_STIPPLE_CHAR_MAP = "░▒▓";
1919

0 commit comments

Comments
 (0)