From 7f043ebb52be3d02e262d1f8b294313eef943379 Mon Sep 17 00:00:00 2001 From: jackyzy823 Date: Wed, 6 Jan 2021 19:54:36 +0800 Subject: [PATCH] x11: update cmake file to build with fuse2/fuse3 or without fuse --- .github/workflows/codeql-analysis.yml | 2 +- client/X11/CMakeLists.txt | 15 ++++- client/X11/xf_cliprdr.c | 58 ++++++++++++++---- cmake/FindFUSE.cmake | 88 +++++++++++++++++++++------ 4 files changed, 130 insertions(+), 33 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 06ba1f7b8..faf2056ef 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -61,7 +61,7 @@ jobs: - run: | sudo apt update - sudo apt install libxrandr-dev libxinerama-dev libusb-1.0-0-dev xserver-xorg-dev libswscale-dev libswresample-dev libavutil-dev libavcodec-dev libcups2-dev libpulse-dev libasound2-dev libpcsclite-dev xsltproc libxcb-cursor-dev libxcursor-dev libcairo2-dev libfaac-dev libfaad-dev libjpeg-dev libgsm1-dev ninja-build libxfixes-dev libxkbcommon-dev libwayland-dev libpam0g-dev libxdamage-dev libxcb-damage0-dev ccache libxtst-dev + sudo apt install libxrandr-dev libxinerama-dev libusb-1.0-0-dev xserver-xorg-dev libswscale-dev libswresample-dev libavutil-dev libavcodec-dev libcups2-dev libpulse-dev libasound2-dev libpcsclite-dev xsltproc libxcb-cursor-dev libxcursor-dev libcairo2-dev libfaac-dev libfaad-dev libjpeg-dev libgsm1-dev ninja-build libxfixes-dev libxkbcommon-dev libwayland-dev libpam0g-dev libxdamage-dev libxcb-damage0-dev ccache libxtst-dev libfuse-dev cmake -GNinja -DWITH_SERVER=ON -DWITH_SAMPLE=ON -DBUILD_TESTING=ON . cmake --build . diff --git a/client/X11/CMakeLists.txt b/client/X11/CMakeLists.txt index afcf8a640..5ede39a51 100644 --- a/client/X11/CMakeLists.txt +++ b/client/X11/CMakeLists.txt @@ -168,6 +168,11 @@ set(XFIXES_FEATURE_TYPE "RECOMMENDED") set(XFIXES_FEATURE_PURPOSE "X11 xfixes extension") set(XFIXES_FEATURE_DESCRIPTION "Useful additions to the X11 core protocol") +set(FUSE_FEATURE_TYPE "RECOMMENDED") +set(FUSE_FEATURE_PURPOSE "Remote to local file copy") +set(FUSE_FEATURE_DESCRIPTION "use -DWITH_FUSE2 or -DWITH_FUSE3 to specify fuse version") + + find_feature(XShm ${XSHM_FEATURE_TYPE} ${XSHM_FEATURE_PURPOSE} ${XSHM_FEATURE_DESCRIPTION}) find_feature(Xinerama ${XINERAMA_FEATURE_TYPE} ${XINERAMA_FEATURE_PURPOSE} ${XINERAMA_FEATURE_DESCRIPTION}) find_feature(Xext ${XEXT_FEATURE_TYPE} ${XEXT_FEATURE_PURPOSE} ${XEXT_FEATURE_DESCRIPTION}) @@ -177,6 +182,7 @@ find_feature(Xi ${XI_FEATURE_TYPE} ${XI_FEATURE_PURPOSE} ${XI_FEATURE_DESCRIPTIO find_feature(Xrender ${XRENDER_FEATURE_TYPE} ${XRENDER_FEATURE_PURPOSE} ${XRENDER_FEATURE_DESCRIPTION}) find_feature(XRandR ${XRANDR_FEATURE_TYPE} ${XRANDR_FEATURE_PURPOSE} ${XRANDR_FEATURE_DESCRIPTION}) find_feature(Xfixes ${XFIXES_FEATURE_TYPE} ${XFIXES_FEATURE_PURPOSE} ${XFIXES_FEATURE_DESCRIPTION}) +find_feature(FUSE ${FUSE_FEATURE_TYPE} ${FUSE_FEATURE_PURPOSE} ${FUSE_FEATURE_DESCRIPTION} ) if(WITH_XINERAMA) add_definitions(-DWITH_XINERAMA) @@ -226,9 +232,12 @@ if(WITH_XFIXES) set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XFIXES_LIBRARIES}) endif() -find_package(FUSE REQUIRED) -include_directories(${FUSE_INCLUDE_DIR}) -set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${FUSE_LIBRARIES}) +if(WITH_FUSE) + add_definitions(-DWITH_FUSE) + add_definitions(-DFUSE_API_VERSION=${FUSE_API_VERSION}) + include_directories(${FUSE_INCLUDE_DIR}) + set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${FUSE_LIBRARIES}) +endif() include_directories(${CMAKE_SOURCE_DIR}/resources) diff --git a/client/X11/xf_cliprdr.c b/client/X11/xf_cliprdr.c index 2e6ba210b..e8e2b0b3f 100644 --- a/client/X11/xf_cliprdr.c +++ b/client/X11/xf_cliprdr.c @@ -31,13 +31,19 @@ #include #endif -#define FUSE_USE_VERSION 26 +#ifdef WITH_FUSE +#define FUSE_USE_VERSION FUSE_API_VERSION +#if FUSE_USE_VERSION >= 30 +#include +#else #include +#endif #include #include #include #include #define WIN32_FILETIME_TO_UNIX_EPOCH_USEC UINT64_C(116444736000000000) +#endif #include #include @@ -64,6 +70,7 @@ struct xf_cliprdr_format }; typedef struct xf_cliprdr_format xfCliprdrFormat; +#ifdef WITH_FUSE struct xf_cliprdr_fuse_stream { UINT32 stream_id; @@ -103,6 +110,7 @@ void xf_cliprdr_fuse_inode_free(void* obj) free(inode); inode = NULL; } +#endif struct xf_clipboard { @@ -160,7 +168,7 @@ struct xf_clipboard /* File clipping */ BOOL streams_supported; BOOL file_formats_registered; - +#ifdef WITH_FUSE /* FUSE related**/ HANDLE fuse_thread; struct fuse_session* fuse_sess; @@ -169,6 +177,7 @@ struct xf_clipboard wArrayList* stream_list; UINT32 current_stream_id; wArrayList* ino_list; +#endif }; static UINT xf_cliprdr_send_client_format_list(xfClipboard* clipboard); @@ -882,7 +891,7 @@ static void xf_cliprdr_clear_cached_data(xfClipboard* clipboard) } clipboard->data_raw_length = 0; - +#ifdef WITH_FUSE if (clipboard->stream_list) { size_t index; @@ -905,6 +914,7 @@ static void xf_cliprdr_clear_cached_data(xfClipboard* clipboard) { ArrayList_Clear(clipboard->ino_list); } +#endif } static BOOL xf_cliprdr_process_selection_request(xfClipboard* clipboard, @@ -1239,6 +1249,7 @@ static UINT xf_cliprdr_send_client_format_list_response(xfClipboard* clipboard, return clipboard->context->ClientFormatListResponse(clipboard->context, &formatListResponse); } +#ifdef WITH_FUSE /** * Function description * @@ -1353,6 +1364,7 @@ xf_cliprdr_server_file_contents_response(CliprdrClientContext* context, ArrayList_Unlock(clipboard->stream_list); return CHANNEL_RC_OK; } +#endif /** * Function description @@ -1585,6 +1597,7 @@ xf_cliprdr_server_format_data_request(CliprdrClientContext* context, return CHANNEL_RC_OK; } +#ifdef WITH_FUSE static char* xf_cliprdr_fuse_split_basename(char* name, int len) { int s = len - 1; @@ -1838,6 +1851,7 @@ error: Stream_Free(s, FALSE); return FALSE; } +#endif /** * Function description @@ -1886,12 +1900,14 @@ xf_cliprdr_server_format_data_response(CliprdrClientContext* context, if (strcmp(clipboard->data_format_name, "FileGroupDescriptorW") == 0) { +#ifdef WITH_FUSE /* Build inode table for FILEDESCRIPTORW*/ if (xf_cliprdr_fuse_generate_list(clipboard, data, size) == FALSE) { /* just continue */ WLog_WARN(TAG, "fail to generate list for FILEDESCRIPTOR"); } +#endif srcFormatId = ClipboardGetFormatId(clipboard->system, "FileGroupDescriptorW"); dstTargetFormat = @@ -2148,6 +2164,7 @@ static UINT xf_cliprdr_clipboard_file_range_failure(wClipboardDelegate* delegate return clipboard->context->ClientFileContentsResponse(clipboard->context, &response); } +#ifdef WITH_FUSE /* For better understanding the relationship between ino and index of arraylist*/ static inline xfCliprdrFuseInode* xf_cliprdr_get_inode(wArrayList* ino_list, fuse_ino_t ino) { @@ -2515,8 +2532,21 @@ static DWORD WINAPI xf_cliprdr_fuse_thread(LPVOID arg) } clipboard->delegate->basePath = basePath; - struct fuse_chan* ch; struct fuse_args args = FUSE_ARGS_INIT(0, NULL); +#if FUSE_USE_VERSION >= 30 + fuse_opt_add_arg(&args, clipboard->delegate->basePath); + if ((clipboard->fuse_sess = fuse_session_new( + &args, &xf_cliprdr_fuse_oper, sizeof(xf_cliprdr_fuse_oper), (void*)clipboard)) != NULL) + { + if (0 == fuse_session_mount(clipboard->fuse_sess, clipboard->delegate->basePath)) + { + fuse_session_loop(clipboard->fuse_sess); + fuse_session_unmount(clipboard->fuse_sess); + } + fuse_session_destroy(clipboard->fuse_sess); + } +#else + struct fuse_chan* ch; int err; if ((ch = fuse_mount(clipboard->delegate->basePath, &args)) != NULL) @@ -2525,17 +2555,14 @@ static DWORD WINAPI xf_cliprdr_fuse_thread(LPVOID arg) sizeof(xf_cliprdr_fuse_oper), (void*)clipboard); if (clipboard->fuse_sess != NULL) { - if (fuse_set_signal_handlers(clipboard->fuse_sess) != -1) - { - fuse_session_add_chan(clipboard->fuse_sess, ch); - err = fuse_session_loop(clipboard->fuse_sess); - fuse_remove_signal_handlers(clipboard->fuse_sess); - fuse_session_remove_chan(ch); - } + fuse_session_add_chan(clipboard->fuse_sess, ch); + err = fuse_session_loop(clipboard->fuse_sess); + fuse_session_remove_chan(ch); fuse_session_destroy(clipboard->fuse_sess); } fuse_unmount(clipboard->delegate->basePath, ch); } +#endif fuse_opt_free_args(&args); RemoveDirectoryA(clipboard->delegate->basePath); @@ -2543,6 +2570,7 @@ static DWORD WINAPI xf_cliprdr_fuse_thread(LPVOID arg) ExitThread(0); return 0; } +#endif xfClipboard* xf_clipboard_new(xfContext* xfc) { @@ -2697,6 +2725,7 @@ xfClipboard* xf_clipboard_new(xfContext* xfc) clipboard->delegate = ClipboardGetDelegate(clipboard->system); clipboard->delegate->custom = clipboard; +#ifdef WITH_FUSE clipboard->current_stream_id = 0; clipboard->stream_list = ArrayList_New(TRUE); if (!clipboard->stream_list) @@ -2721,6 +2750,7 @@ xfClipboard* xf_clipboard_new(xfContext* xfc) { goto error3; } +#endif clipboard->delegate->ClipboardFileSizeSuccess = xf_cliprdr_clipboard_file_size_success; clipboard->delegate->ClipboardFileSizeFailure = xf_cliprdr_clipboard_file_size_failure; @@ -2728,12 +2758,14 @@ xfClipboard* xf_clipboard_new(xfContext* xfc) clipboard->delegate->ClipboardFileRangeFailure = xf_cliprdr_clipboard_file_range_failure; return clipboard; +#ifdef WITH_FUSE error3: ArrayList_Free(clipboard->ino_list); error2: ArrayList_Free(clipboard->stream_list); +#endif error: for (i = 0; i < n; i++) @@ -2766,6 +2798,7 @@ void xf_clipboard_free(xfClipboard* clipboard) free(clipboard->clientFormats[i].formatName); } +#ifdef WITH_FUSE if (clipboard->fuse_thread) { if (clipboard->fuse_sess) @@ -2786,6 +2819,7 @@ void xf_clipboard_free(xfClipboard* clipboard) // fuse related ArrayList_Free(clipboard->stream_list); ArrayList_Free(clipboard->ino_list); +#endif ClipboardDestroy(clipboard->system); free(clipboard->data); @@ -2807,7 +2841,9 @@ void xf_cliprdr_init(xfContext* xfc, CliprdrClientContext* cliprdr) cliprdr->ServerFormatDataRequest = xf_cliprdr_server_format_data_request; cliprdr->ServerFormatDataResponse = xf_cliprdr_server_format_data_response; cliprdr->ServerFileContentsRequest = xf_cliprdr_server_file_contents_request; +#ifdef WITH_FUSE cliprdr->ServerFileContentsResponse = xf_cliprdr_server_file_contents_response; +#endif } void xf_cliprdr_uninit(xfContext* xfc, CliprdrClientContext* cliprdr) diff --git a/cmake/FindFUSE.cmake b/cmake/FindFUSE.cmake index bd178e26a..41da814ff 100644 --- a/cmake/FindFUSE.cmake +++ b/cmake/FindFUSE.cmake @@ -9,26 +9,78 @@ IF (FUSE_INCLUDE_DIR) SET (FUSE_FIND_QUIETLY TRUE) ENDIF (FUSE_INCLUDE_DIR) -# find includes -FIND_PATH (FUSE_INCLUDE_DIR fuse.h - /usr/local/include/osxfuse - /usr/local/include - /usr/include - ) +include(FindPackageHandleStandardArgs) -# find lib -if (APPLE) - SET(FUSE_NAMES libosxfuse.dylib fuse) -else (APPLE) - SET(FUSE_NAMES fuse) -endif (APPLE) -FIND_LIBRARY(FUSE_LIBRARIES - NAMES ${FUSE_NAMES} - PATHS /lib64 /lib /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib /usr/lib/x86_64-linux-gnu - ) +macro(find_fuse2) + find_path(FUSE_INCLUDE_DIR fuse/fuse_lowlevel.h + /usr/local/include/osxfuse + /usr/local/include + /usr/include + ) + if (APPLE) + SET(FUSE_NAMES libosxfuse.dylib fuse) + else () + SET(FUSE_NAMES fuse) + endif () + FIND_LIBRARY(FUSE_LIBRARIES + NAMES ${FUSE_NAMES} + PATHS /lib64 /lib /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib /usr/lib/x86_64-linux-gnu + ) + + if(FUSE_INCLUDE_DIR) + file(READ "${FUSE_INCLUDE_DIR}/fuse/fuse_common.h" _FUSE_COMMON_H_CONTENTS) + string(REGEX REPLACE "^(.*\n)?#define[ \t]+FUSE_MINOR_VERSION[ \t]+([0-9]+).*" + "\\2" FUSE_MINOR_VERSION ${_FUSE_COMMON_H_CONTENTS}) + if( FUSE_MINOR_VERSION GREATER_EQUAL 6) + set(FUSE_API_VERSION 26) + else() + set(FUSE_API_VERSION 21) + endif() + endif() + +endmacro() + +macro(find_fuse3) + find_path(FUSE_INCLUDE_DIR fuse3/fuse_lowlevel.h + /usr/local/include/osxfuse + /usr/local/include + /usr/include + ) + if (APPLE) + SET(FUSE_NAMES libosxfuse.dylib fuse3) + else () + SET(FUSE_NAMES fuse3) + endif () + FIND_LIBRARY(FUSE_LIBRARIES + NAMES ${FUSE_NAMES} + PATHS /lib64 /lib /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib /usr/lib/x86_64-linux-gnu + ) + + if(FUSE_INCLUDE_DIR) + file(READ "${FUSE_INCLUDE_DIR}/fuse3/fuse_common.h" _FUSE_COMMON_H_CONTENTS) + string(REGEX REPLACE "^(.*\n)?#define[ \t]+FUSE_MINOR_VERSION[ \t]+([0-9]+).*" + "\\2" FUSE_MINOR_VERSION ${_FUSE_COMMON_H_CONTENTS}) + if( FUSE_MINOR_VERSION GREATER_EQUAL 5) + set(FUSE_API_VERSION 35) + else() + set(FUSE_API_VERSION 30) + endif() + endif() +endmacro() + +if(WITH_FUSE3) + find_fuse3() +elseif(WITH_FUSE2) + find_fuse2() +else() + find_fuse3() + if (NOT FUSE_INCLUDE_DIR) + find_fuse2() + endif() +endif() -include ("FindPackageHandleStandardArgs") find_package_handle_standard_args ("FUSE" DEFAULT_MSG - FUSE_INCLUDE_DIR FUSE_LIBRARIES) + FUSE_LIBRARIES FUSE_INCLUDE_DIR FUSE_API_VERSION) + mark_as_advanced (FUSE_INCLUDE_DIR FUSE_LIBRARIES) \ No newline at end of file