From 64c1af8626942a5d5542e5a6a0d52d55ee4e2766 Mon Sep 17 00:00:00 2001 From: Evan Date: Sun, 17 Nov 2024 07:07:25 +0800 Subject: [PATCH] Include ffmpeg in CMake build (#3683) --- CMakeLists.txt | 4 ++-- deps/CMakeLists.txt | 29 +++++++++++++++++++++++++++++ src/bflib_fmvids.cpp | 1 + src/globals.h | 13 ++----------- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a6f9b2e93..d0fd072a43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,10 +62,10 @@ message(STATUS "We are using ${CMAKE_CXX_COMPILER_ID}") set_property(TARGET keeperfx PROPERTY LINKER_TYPE LLD) set_property(TARGET keeperfx_hvlog PROPERTY LINKER_TYPE LLD) -set(WARNFLAGS -Wall -W -Wshadow -Wno-sign-compare -Wno-unused-parameter -Wno-strict-aliasing -Wno-unknown-pragmas) +set(WARNFLAGS -Wall -W -Wshadow -Wno-sign-compare -Wno-unused-parameter -Wno-strict-aliasing -Wno-unknown-pragmas -Werror) set(GNU_COMPILER_FLAG -march=x86-64 -fno-omit-frame-pointer -fmessage-length=0) set(GNU_LINK_FLAG -mwindows -Wl,--enable-auto-import) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=implicit") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wimplicit") target_compile_options(keeperfx PRIVATE ${WARNFLAGS} ${GNU_COMPILER_FLAG}) target_compile_options(keeperfx_hvlog PRIVATE ${WARNFLAGS} ${GNU_COMPILER_FLAG}) target_link_options(keeperfx PRIVATE ${GNU_LINK_FLAG} -Wl,-Map,keeperfx.map) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 8a3ed7e148..4f6f3d7fc9 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -46,6 +46,15 @@ if( NOT EXISTS ${CMAKE_SOURCE_DIR}/deps/centijson ) execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${CMAKE_SOURCE_DIR}/deps/centijson-mingw32.tar.gz WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/deps/centijson) endif() +if(NOT EXISTS ${CMAKE_SOURCE_DIR}/deps/ffmpeg) + file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/deps/ffmpeg) + if(NOT EXISTS ${CMAKE_SOURCE_DIR}/deps/ffmpeg-mingw32.tar.gz) + file(DOWNLOAD https://github.com/dkfans/kfx-deps/releases/download/initial/ffmpeg-mingw32.tar.gz ${CMAKE_SOURCE_DIR}/deps/ffmpeg-mingw32.tar.gz SHOW_PROGRESS) + endif() + + execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${CMAKE_SOURCE_DIR}/deps/ffmpeg-mingw32.tar.gz WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/deps/ffmpeg) +endif() + ## enet add_library(enet_static STATIC IMPORTED) set_target_properties(enet_static PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/enet/libenet.a) @@ -96,3 +105,23 @@ target_link_libraries(centitoml PUBLIC centijson_static) target_include_directories(centitoml INTERFACE "centitoml") target_link_libraries(keeperfx PUBLIC centitoml) target_link_libraries(keeperfx_hvlog PUBLIC centitoml) + +## ffmpeg +add_library(libavcodec_static STATIC IMPORTED) +set_target_properties(libavcodec_static PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg/libavcodec/libavcodec.a) +set_target_properties(libavcodec_static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg) + +add_library(libavformat_static STATIC IMPORTED) +set_target_properties(libavformat_static PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg/libavformat/libavformat.a) +set_target_properties(libavformat_static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg) + +add_library(libavutil_static STATIC IMPORTED) +set_target_properties(libavutil_static PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg/libavutil/libavutil.a) +set_target_properties(libavutil_static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg) + +add_library(libswresample_static STATIC IMPORTED) +set_target_properties(libswresample_static PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg/libswresample/libswresample.a) +set_target_properties(libswresample_static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg) + +target_link_libraries(keeperfx PUBLIC bcrypt libavcodec_static libavformat_static libavutil_static libswresample_static) +target_link_libraries(keeperfx_hvlog PUBLIC bcrypt libavcodec_static libavformat_static libavutil_static libswresample_static) diff --git a/src/bflib_fmvids.cpp b/src/bflib_fmvids.cpp index cddc8548c1..03950bdc4b 100644 --- a/src/bflib_fmvids.cpp +++ b/src/bflib_fmvids.cpp @@ -13,6 +13,7 @@ extern "C" { #include #include #include + #pragma GCC diagnostic warning "-Wdeprecated-declarations" } #include diff --git a/src/globals.h b/src/globals.h index f7ba28be33..ceecb77bf4 100644 --- a/src/globals.h +++ b/src/globals.h @@ -19,9 +19,10 @@ #ifndef KEEPFX_GLOBALS_H #define KEEPFX_GLOBALS_H +#include // Introduced in C99. Provides true/false. #include #include -#include +#include // Provides NULL. #include #include #include @@ -72,16 +73,6 @@ extern "C" { #define SEPARATOR "\\" #endif -#ifndef false -#define false 0 -#endif -#ifndef true -#define true 1 -#endif -#ifndef NULL -#define NULL 0 -#endif - #ifndef __cplusplus #ifndef max #define max(a,b) ((a)>(b)?(a):(b))