forked from barry-ran/QtScrcpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ported to CMake, rename i18n files, and other minor adjustments
- Loading branch information
Showing
35 changed files
with
731 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
cmake_minimum_required(VERSION 3.19 FATAL_ERROR) | ||
|
||
# Read version numbers from file | ||
file (STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/QtScrcpy/version STRING_VERSION) | ||
message(STATUS "QtScrcpy Version ${STRING_VERSION}") | ||
project(QtScrcpy | ||
VERSION ${STRING_VERSION} | ||
LANGUAGES C CXX | ||
) | ||
|
||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | ||
enable_language(OBJCXX) | ||
endif() | ||
|
||
# Split version numbers | ||
string(REPLACE "." ";" VERSION_LIST ${STRING_VERSION}) | ||
list(GET VERSION_LIST 0 VERSION_MAJOR) | ||
list(GET VERSION_LIST 1 VERSION_MINOR) | ||
list(GET VERSION_LIST 2 VERSION_PATCH) | ||
|
||
add_subdirectory(QtScrcpy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
set(CMAKE_AUTOUIC ON) | ||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
# *********************************************************** | ||
# Qt Package finding | ||
# *********************************************************** | ||
|
||
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets Network LinguistTools REQUIRED) | ||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Network LinguistTools REQUIRED) | ||
|
||
# *********************************************************** | ||
# Cross-platform settings | ||
# *********************************************************** | ||
|
||
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") | ||
|
||
# ffmpeg cannot be compiled natively by MSVC version < 12.0 (2013) | ||
if(MSVC_VERSION LESS 1800) | ||
message(FATAL_ERROR "[QtScrCpy] FATAL ERROR: MSVC version is older than 12.0 (2013).") | ||
endif() | ||
|
||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8") | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") | ||
|
||
endif() | ||
|
||
# ******************** Microsoft Windows ******************** | ||
if(WIN32) | ||
message(STATUS "[QtScrCpy] Make for Microsoft Windows.") | ||
# 通过rc的方式的话,VERSION变量rc中获取不到,定义为宏方便rc中使用 | ||
# Define macros for .rc file | ||
add_compile_definitions( | ||
VERSION_MAJOR=${VERSION_MAJOR} | ||
VERSION_MINOR=${VERSION_MINOR} | ||
VERSION_PATCH=${VERSION_PATCH} | ||
VERSION_RC_STR=\\\"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}\\\" | ||
) | ||
|
||
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # Compiler is 64-bit | ||
message(STATUS "[QtScrCpy] 64-bit compiler detected.") | ||
set(QS_DLL_PATH "${PROJECT_SOURCE_DIR}/third_party/ffmpeg/lib/x64") | ||
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) # Compiler is 32-bit | ||
message(STATUS "[QtScrCpy] 32-bit compiler detected.") | ||
set(QS_DLL_PATH "${PROJECT_SOURCE_DIR}/third_party/ffmpeg/lib/x86") | ||
endif() | ||
|
||
link_directories(${QS_DLL_PATH}) | ||
|
||
# 构建完成后复制DLL依赖库 | ||
# Copy DLL dependencies after building | ||
file(GLOB QS_DLL_FILES "${QS_DLL_PATH}/*.dll") | ||
foreach(QS_DLL_FILE ${QS_DLL_FILES}) | ||
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND | ||
${CMAKE_COMMAND} -E copy_if_different | ||
"${QS_DLL_FILE}" "${PROJECT_BINARY_DIR}" | ||
) | ||
endforeach() | ||
|
||
set(QS_EXTERNAL_LIBS_FFMPEG | ||
avformat | ||
avcodec | ||
avutil | ||
swscale | ||
) | ||
|
||
set(RC_FILE "${CMAKE_CURRENT_SOURCE_DIR}/res/QtScrCpy.rc") | ||
|
||
# ******************** Unix-like OSs ******************** | ||
elseif(UNIX) | ||
set(QS_LIB_PATH "${PROJECT_SOURCE_DIR}/third_party/ffmpeg/lib") | ||
link_directories(${QS_LIB_PATH}) | ||
|
||
# ==================== macOS ==================== | ||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | ||
message(STATUS "[QtScrCpy] Make for macOS.") | ||
|
||
# QS_MAC_RESOURCES: esource file list stored in Contents/MacOS | ||
file(GLOB QS_MAC_RESOURCES "${PROJECT_SOURCE_DIR}/third_party/ffmpeg/lib/*.dylib)") | ||
list(APPEND QS_MAC_RESOURCES | ||
"${PROJECT_SOURCE_DIR}/third_party/scrcpy-server" | ||
"${PROJECT_SOURCE_DIR}/adb/mac/adb" | ||
) | ||
|
||
# QS_MAC_CONFIG: Config file stored in Contents/MacOS/config | ||
set(QS_MAC_CONFIG "${PROJECT_SOURCE_DIR}/config/config.ini") | ||
|
||
# Icon file stored in Contents/Resources | ||
set(QS_MAC_ICON_NAME "QtScrCpy.icns") | ||
set(QS_MAC_ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/res/${QS_MAC_ICON_NAME}") | ||
|
||
set_source_files_properties(${QS_MAC_RESOURCES} PROPERTIES | ||
MACOSX_PACKAGE_LOCATION "MacOS" | ||
) | ||
set_source_files_properties(${QS_MAC_CONFIG} PROPERTIES | ||
MACOSX_PACKAGE_LOCATION "MacOS/config" | ||
) | ||
|
||
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES | ||
# The base plist template file | ||
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/res/Info_Mac.plist" | ||
# The elements to be overwritten | ||
MACOSX_BUNDLE_ICON_FILE "${QS_MAC_ICON_NAME}" | ||
MACOSX_BUNDLE_BUNDLE_VERSION "${STRING_VERSION}" | ||
MACOSX_BUNDLE_SHORT_VERSION_STRING "${STRING_VERSION}" | ||
MACOSX_BUNDLE_LONG_VERSION_STRING "${STRING_VERSION}" | ||
|
||
# Copy file(s) to Contents/Resources | ||
RESOURCE "${QS_MAC_ICON_PATH}" | ||
) | ||
|
||
set(QS_EXTERNAL_LIBS_FFMPEG | ||
avformat.58 | ||
avcodec.58 | ||
avutil.56 | ||
swscale.5 | ||
) | ||
|
||
# ========== Non-Mac Unix-like OS (Linux, BSD, etc.) ========== | ||
else() | ||
find_package(Threads REQUIRED) | ||
|
||
message(STATUS "[QtScrCpy] Make for non-Apple Unix-like OS.") | ||
set(INSTALLED_FFMPEG_FOUND false) | ||
|
||
find_package(PkgConfig) | ||
if(PkgConfig_FOUND) | ||
pkg_check_modules(FFmpeg ffmpeg>=4) | ||
if(FFmpeg_FOUND) | ||
set(INSTALLED_FFMPEG_FOUND true) | ||
message(STATUS "[QtScrCpy] Development files of FFmpeg ${FFmpeg_VERSION} were detected in your OS and will be used.") | ||
target_link_options(${CMAKE_PROJECT_NAME} "${FFmpeg_LIBRARIES}") | ||
target_compile_options(${CMAKE_PROJECT_NAME} "${FFmpeg_CFLAGS}") | ||
endif() | ||
endif() | ||
|
||
if(NOT INSTALLED_FFMPEG_FOUND) | ||
message(STATUS "[QtScrCpy] Development files of FFmpeg were not detected in your OS. Files within third_party/ffmpeg/ will be used.") | ||
set(QS_EXTERNAL_LIBS_FFMPEG | ||
avformat | ||
avcodec | ||
avutil | ||
swscale | ||
Threads::Threads | ||
) | ||
endif() | ||
endif() | ||
endif() | ||
|
||
set(QS_SUBDIRECTORIES_MAIN | ||
adb | ||
common | ||
device | ||
devicemanage | ||
fontawesome | ||
uibase | ||
util | ||
) | ||
|
||
set(QS_TS_FILES | ||
${CMAKE_CURRENT_SOURCE_DIR}/res/i18n/zh_CN.ts | ||
${CMAKE_CURRENT_SOURCE_DIR}/res/i18n/en_US.ts | ||
) | ||
|
||
set(QS_SOURCES_MAIN | ||
dialog.cpp | ||
dialog.h | ||
dialog.ui | ||
${QS_TS_FILES} | ||
) | ||
|
||
set(QS_QRC_MAIN "${CMAKE_CURRENT_SOURCE_DIR}/res/res.qrc") | ||
|
||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) | ||
if(WIN32) | ||
qt_add_executable(${CMAKE_PROJECT_NAME} WIN32 MANUAL_FINALIZATION | ||
main.cpp | ||
${QS_SOURCES_MAIN} | ||
${QS_QRC_MAIN} | ||
) | ||
elseif(UNIX) | ||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | ||
qt_add_executable(${CMAKE_PROJECT_NAME} MACOSX_BUNDLE MANUAL_FINALIZATION | ||
main.cpp | ||
${QS_SOURCES_MAIN} | ||
${QS_MAC_RESOURCES} | ||
${QS_MAC_CONFIG} | ||
${QS_QRC_MAIN} | ||
) | ||
else() | ||
qt_add_executable(${CMAKE_PROJECT_NAME} MANUAL_FINALIZATION | ||
main.cpp | ||
${QS_SOURCES_MAIN} | ||
${QS_QRC_MAIN} | ||
) | ||
endif() | ||
endif() | ||
|
||
qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${QS_TS_FILES}) | ||
|
||
else() | ||
if(WIN32) | ||
add_executable(${CMAKE_PROJECT_NAME} WIN32 | ||
main.cpp | ||
${QS_SOURCES_MAIN} | ||
${QS_QRC_MAIN} | ||
) | ||
elseif(UNIX) | ||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | ||
add_executable(${CMAKE_PROJECT_NAME} MACOSX_BUNDLE | ||
main.cpp | ||
${QS_SOURCES_MAIN} | ||
${QS_MAC_RESOURCES} | ||
${QS_MAC_CONFIG} | ||
${QS_QRC_MAIN} | ||
) | ||
else() | ||
add_executable(${CMAKE_PROJECT_NAME} | ||
main.cpp | ||
${QS_SOURCES_MAIN} | ||
${QS_QRC_MAIN} | ||
) | ||
endif() | ||
endif() | ||
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${QS_TS_FILES}) | ||
|
||
endif() | ||
|
||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
foreach(QS_SUBDIRECTORY_MAIN ${QS_SUBDIRECTORIES_MAIN}) | ||
add_subdirectory(${QS_SUBDIRECTORY_MAIN}) | ||
endforeach() | ||
|
||
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC | ||
adb | ||
devicemanage | ||
) | ||
|
||
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE | ||
Qt${QT_VERSION_MAJOR}::Widgets | ||
Qt${QT_VERSION_MAJOR}::Network | ||
device | ||
stream | ||
ui | ||
util | ||
) | ||
|
||
|
||
if(QT_VERSION_MAJOR EQUAL 6) | ||
qt_finalize_executable(${CMAKE_PROJECT_NAME}) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
set(QS_SOURCES_ADB | ||
adbprocess.h | ||
adbprocess.cpp | ||
) | ||
|
||
add_library(adb ${QS_SOURCES_ADB}) | ||
target_include_directories(adb PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
target_link_libraries(adb PRIVATE | ||
Qt${QT_VERSION_MAJOR}::Widgets | ||
util | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
set(QS_SOURCES_COMMON | ||
qscrcpyevent.h | ||
) | ||
|
||
add_library(common INTERFACE ${QS_SOURCES_COMMON}) | ||
target_include_directories(common INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
set(QS_SUBDIRECTORIES_DEVICE | ||
android | ||
controller | ||
decoder | ||
filehandler | ||
recorder | ||
render | ||
server | ||
stream | ||
ui | ||
) | ||
|
||
set(QS_SOURCES_DEVICE | ||
device.h | ||
device.cpp | ||
) | ||
|
||
add_library(device ${QS_SOURCES_DEVICE}) | ||
|
||
target_include_directories(device PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
foreach(QS_SUBDIRECTORY_DEVICE ${QS_SUBDIRECTORIES_DEVICE}) | ||
add_subdirectory (${QS_SUBDIRECTORY_DEVICE}) | ||
endforeach() | ||
|
||
target_link_libraries(device INTERFACE inputconvert) | ||
target_link_libraries(device PRIVATE | ||
Qt${QT_VERSION_MAJOR}::Widgets | ||
# device (self) | ||
controller | ||
decoder | ||
filehandler | ||
recorder | ||
server | ||
stream | ||
ui | ||
util | ||
mousetap | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
set(QS_SOURCES_DEVICE_ANDROID | ||
input.h | ||
keycodes.h | ||
) | ||
|
||
add_library(android INTERFACE ${QS_SOURCES_DEVICE_ANDROID}) | ||
target_include_directories(android INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
SET(QS_SUBDIRECTORIES_DEVICE_CONTROLLER | ||
inputconvert | ||
receiver | ||
) | ||
|
||
SET(QS_SOURCES_DEVICE_CONTROLLER | ||
controller.h | ||
controller.cpp | ||
) | ||
|
||
add_library(controller ${QS_SOURCES_DEVICE_CONTROLLER}) | ||
|
||
target_include_directories(controller PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
foreach(QS_SUBDIRECTORY_DEVICE_CONTROLLER ${QS_SUBDIRECTORIES_DEVICE_CONTROLLER}) | ||
add_subdirectory (${QS_SUBDIRECTORY_DEVICE_CONTROLLER}) | ||
endforeach() | ||
|
||
target_link_libraries(controller PUBLIC | ||
inputconvert | ||
) | ||
target_link_libraries(controller PRIVATE | ||
Qt${QT_VERSION_MAJOR}::Widgets | ||
receiver | ||
server | ||
) |
Oops, something went wrong.