qtscrcpy: init at 2.2.1

This commit is contained in:
Daru 2024-09-10 18:53:19 +02:00 committed by aleksana
parent c701c72b71
commit 1112eb8f1a
3 changed files with 255 additions and 0 deletions

View File

@ -0,0 +1,132 @@
{
lib,
stdenv,
fetchFromGitHub,
cmake,
pkg-config,
libsForQt5,
scrcpy,
android-tools,
ffmpeg_4,
makeDesktopItem,
copyDesktopItems,
}:
stdenv.mkDerivation rec {
pname = "qtscrcpy";
version = "2.2.1";
src =
(fetchFromGitHub {
owner = "barry-ran";
repo = "QtScrcpy";
rev = "refs/tags/v${version}";
hash = "sha256-PL/UvRNqvLaFuvSHbkJsaJ2nqRp5+ERM+rmlKVtbShk=";
fetchSubmodules = true;
}).overrideAttrs
(_: {
GIT_CONFIG_COUNT = 1;
GIT_CONFIG_KEY_0 = "url.https://github.com/.insteadOf";
GIT_CONFIG_VALUE_0 = "git@github.com:";
});
patches = [
# remove vendored ffmpeg, adb and scrcpy-server
./remove_vendors.patch
# remove predefined adb and scrcpy-server path
# we later set them in wrapper
./remove_predefined_paths.patch
];
postPatch = ''
substituteInPlace QtScrcpy/QtScrcpyCore/{include/QtScrcpyCoreDef.h,src/device/server/server.h} \
--replace-fail 'serverVersion = "2.1.1"' 'serverVersion = "${scrcpy.version}"'
substituteInPlace QtScrcpy/util/config.cpp \
--replace-fail 'COMMON_SERVER_VERSION_DEF "2.1.1"' 'COMMON_SERVER_VERSION_DEF "${scrcpy.version}"'
substituteInPlace QtScrcpy/audio/audiooutput.cpp \
--replace-fail 'sndcpy.sh' "$out/share/qtscrcpy/sndcpy.sh"
substituteInPlace QtScrcpy/sndcpy/sndcpy.sh \
--replace-fail 'ADB=./adb' "ADB=${lib.getExe' android-tools "adb"}" \
--replace-fail 'SNDCPY_APK=sndcpy.apk' "SNDCPY_APK=$out/share/qtscrcpy/sndcpy.apk"
'';
nativeBuildInputs = [
cmake
pkg-config
libsForQt5.wrapQtAppsHook
copyDesktopItems
];
buildInputs =
[
scrcpy
ffmpeg_4
]
++ (with libsForQt5; [
qtbase
qtmultimedia
qtx11extras
]);
env.NIX_CFLAGS_COMPILE = toString [
"-Wno-error=sign-compare"
];
# Doesn't contain rule to install
installPhase = ''
runHook preInstall
pushd ../output/x64/Release
install -Dm755 QtScrcpy -t $out/bin
install -Dm755 sndcpy.sh -t $out/share/qtscrcpy
install -Dm644 sndcpy.apk -t $out/share/qtscrcpy
popd
install -Dm644 ../QtScrcpy/res/image/tray/logo.png $out/share/pixmaps/qtscrcpy.png
runHook postInstall
'';
desktopItems = [
(makeDesktopItem {
name = "QtScrcpy";
exec = "QtScrcpy %U";
icon = "qtscrcpy";
desktopName = "QtScrcpy";
genericName = "Android Display Control";
categories = [
"Utility"
"RemoteAccess"
];
})
];
preFixup = ''
qtWrapperArgs+=(
--set QTSCRCPY_ADB_PATH ${lib.getExe' android-tools "adb"}
--set QTSCRCPY_SERVER_PATH ${scrcpy}/share/scrcpy/scrcpy-server
)
'';
meta = {
description = "Android real-time display control software";
homepage = "https://github.com/barry-ran/QtScrcpy";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [
daru-san
aleksana
];
mainProgram = "QtScrcpy";
platforms = with lib.platforms; linux ++ darwin ++ windows;
# needs some special handling on darwin as it generates .app bundle directly
badPlatforms = lib.platforms.darwin;
sourceProvenance = with lib.sourceTypes; [
fromSource
# Still includes sndcpy.apk vendored in the same repo
# which will run on controlled Android device
# https://github.com/barry-ran/QtScrcpy/blob/master/QtScrcpy/sndcpy/sndcpy.apk
binaryBytecode
];
};
}

View File

@ -0,0 +1,27 @@
diff --git a/QtScrcpy/main.cpp b/QtScrcpy/main.cpp
index a24ba60..51e3d76 100644
--- a/QtScrcpy/main.cpp
+++ b/QtScrcpy/main.cpp
@@ -22,22 +22,16 @@ int main(int argc, char *argv[])
{
// set env
#ifdef Q_OS_WIN32
- qputenv("QTSCRCPY_ADB_PATH", "../../../QtScrcpy/QtScrcpyCore/src/third_party/adb/win/adb.exe");
- qputenv("QTSCRCPY_SERVER_PATH", "../../../QtScrcpy/QtScrcpyCore/src/third_party/scrcpy-server");
qputenv("QTSCRCPY_KEYMAP_PATH", "../../../keymap");
qputenv("QTSCRCPY_CONFIG_PATH", "../../../config");
#endif
#ifdef Q_OS_OSX
- qputenv("QTSCRCPY_ADB_PATH", "../../../../../../QtScrcpy/QtScrcpyCore/src/third_party/adb/mac/adb");
- qputenv("QTSCRCPY_SERVER_PATH", "../../../../../../QtScrcpy/QtScrcpyCore/src/third_party/scrcpy-server");
qputenv("QTSCRCPY_KEYMAP_PATH", "../../../../../../keymap");
qputenv("QTSCRCPY_CONFIG_PATH", "../../../../../../config");
#endif
#ifdef Q_OS_LINUX
- qputenv("QTSCRCPY_ADB_PATH", "../../../QtScrcpy/QtScrcpyCore/src/third_party/adb/linux/adb");
- qputenv("QTSCRCPY_SERVER_PATH", "../../../QtScrcpy/QtScrcpyCore/src/third_party/scrcpy-server");
qputenv("QTSCRCPY_KEYMAP_PATH", "../../../keymap");
qputenv("QTSCRCPY_CONFIG_PATH", "../../../config");
#endif

View File

@ -0,0 +1,96 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 85c733e..02fea2c 100644
--- a/QtScrcpy/QtScrcpyCore/CMakeLists.txt
+++ b/QtScrcpy/QtScrcpyCore/CMakeLists.txt
@@ -139,87 +139,10 @@ target_include_directories(${QSC_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DI
target_include_directories(${QSC_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/device/recorder)
target_include_directories(${QSC_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/devicemanage)
-#
-# plantform deps
-#
-# windows
-if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
- # ffmpeg
- # include
- target_include_directories(${QSC_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/ffmpeg/include)
- # link
- set(FFMPEG_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/ffmpeg/lib/${QSC_CPU_ARCH}")
- target_link_directories(${QSC_PROJECT_NAME} PUBLIC ${FFMPEG_LIB_PATH})
- target_link_libraries(${QSC_PROJECT_NAME} PRIVATE
- avformat
- avcodec
- avutil
- swscale
- )
- # copy
- set(THIRD_PARTY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party")
- set(FFMPEG_BIN_PATH "${THIRD_PARTY_PATH}/ffmpeg/bin/${QSC_CPU_ARCH}")
- add_custom_command(TARGET ${QSC_PROJECT_NAME} POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${FFMPEG_BIN_PATH}/avcodec-58.dll" "${QSC_DEPLOY_PATH}"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${FFMPEG_BIN_PATH}/avformat-58.dll" "${QSC_DEPLOY_PATH}"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${FFMPEG_BIN_PATH}/avutil-56.dll" "${QSC_DEPLOY_PATH}"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${FFMPEG_BIN_PATH}/swscale-5.dll" "${QSC_DEPLOY_PATH}"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${FFMPEG_BIN_PATH}/swresample-3.dll" "${QSC_DEPLOY_PATH}"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${THIRD_PARTY_PATH}/adb/win/adb.exe" "${QSC_DEPLOY_PATH}"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${THIRD_PARTY_PATH}/adb/win/AdbWinApi.dll" "${QSC_DEPLOY_PATH}"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${THIRD_PARTY_PATH}/adb/win/AdbWinUsbApi.dll" "${QSC_DEPLOY_PATH}"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${THIRD_PARTY_PATH}/scrcpy-server" "${QSC_DEPLOY_PATH}"
- )
-endif()
-# MacOS
-if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
- # ffmpeg
- # include
- target_include_directories(${QSC_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/ffmpeg/include)
- # link
- set(FFMPEG_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/ffmpeg/lib")
- target_link_directories(${QSC_PROJECT_NAME} PUBLIC ${FFMPEG_LIB_PATH})
- target_link_libraries(${QSC_PROJECT_NAME} PRIVATE
- avformat.58
- avcodec.58
- avutil.56
- swscale.5
- )
-
- # copy bundle file
- add_custom_command(TARGET ${QSC_PROJECT_NAME} POST_BUILD
- # dylib,scrcpy-server,adb copy to Contents/MacOS
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/ffmpeg/lib/libavcodec.58.dylib" "${QSC_DEPLOY_PATH}/MacOS"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/ffmpeg/lib/libavformat.58.dylib" "${QSC_DEPLOY_PATH}/MacOS"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/ffmpeg/lib/libavutil.56.dylib" "${QSC_DEPLOY_PATH}/MacOS"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/ffmpeg/lib/libswscale.5.dylib" "${QSC_DEPLOY_PATH}/MacOS"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/ffmpeg/lib/libswresample.3.dylib" "${QSC_DEPLOY_PATH}/MacOS"
-
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/scrcpy-server" "${QSC_DEPLOY_PATH}/MacOS"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/adb/mac/adb" "${QSC_DEPLOY_PATH}/MacOS"
- )
-endif()
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(FFMPEG REQUIRED libavcodec libavformat libavutil libswscale)
-# Linux
-if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
- # include
- target_include_directories(${QSC_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/ffmpeg/include)
- # link
- set(FFMPEG_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/ffmpeg/lib")
- target_link_directories(${QSC_PROJECT_NAME} PUBLIC ${FFMPEG_LIB_PATH})
- target_link_libraries(${QSC_PROJECT_NAME} PRIVATE
- # ffmpeg
- avformat
- avcodec
- avutil
- swscale
- z
- )
-
- add_custom_command(TARGET ${QSC_PROJECT_NAME} POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/adb/linux/adb" "${QSC_DEPLOY_PATH}"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/scrcpy-server" "${QSC_DEPLOY_PATH}"
- )
-endif()
+target_link_libraries(${QSC_PROJECT_NAME} PRIVATE ${FFMPEG_LIBRARIES})
+target_include_directories(${QSC_PROJECT_NAME} PRIVATE ${FFMPEG_INCLUDE_DIRS})