From 419861697134348b62bbb712be7ed322de0d7933 Mon Sep 17 00:00:00 2001 From: Black-Speedy <78355795+Black-Speedy@users.noreply.github.com> Date: Sat, 13 Jan 2024 19:34:30 +0100 Subject: [PATCH] Update to make it linux compatible --- .gitignore | 2 ++ CMakeLists.txt | 54 ++++++++++++++++++++++++----- WebShare-Connect/CMakeLists.txt | 43 +++++++++-------------- WebShare-Connect/WebShare-Connect.h | 12 +++++-- WebShare-Connect/sender.c | 10 +++++- 5 files changed, 81 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 58eec89..551f6f0 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,6 @@ dkms.conf .vs/ out/ build/ +buildWindows/ +buildLinux/ Documentation/ diff --git a/CMakeLists.txt b/CMakeLists.txt index d090258..cf92e68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,24 +3,60 @@ # cmake_minimum_required (VERSION 3.8) -# Set the vcpkg toolchain file if vcpkg is being used -if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) - set(CMAKE_TOOLCHAIN_FILE "-DCMAKE_TOOLCHAIN_FILE=R:/vcpkg/scripts/buildsystems/vcpkg.cmake" - CACHE STRING "") +if(WIN32) + # Set the vcpkg toolchain file if vcpkg is being used + if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) + set(CMAKE_TOOLCHAIN_FILE "-DCMAKE_TOOLCHAIN_FILE=R:/vcpkg/scripts/buildsystems/vcpkg.cmake" + CACHE STRING "") + endif() endif() - # Enable Hot Reload for MSVC compilers if supported. if (POLICY CMP0141) cmake_policy(SET CMP0141 NEW) set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$,$>,$<$:EditAndContinue>,$<$:ProgramDatabase>>") endif() -project (WebShare-Connect C) +project(WebShare-Connect + LANGUAGES C + VERSION 0.0.1) + + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") +find_package(LibNice REQUIRED) +message("LibNice_FOUND: ${LibNice_FOUND}") +if(WIN32) + find_package(ZeroMQ CONFIG REQUIRED) + message("ZeroMQ_FOUND: ${ZeroMQ_FOUND}") + message("ZeroMQ_VERSION: ${ZeroMQ_VERSION}") + find_package(czmq CONFIG REQUIRED) + message("czmq_FOUND: ${czmq_FOUND}") +message("czmq_VERSION: ${czmq_VERSION}") +elseif(UNIX AND NOT APPLE) + + find_package(PkgConfig REQUIRED) + message(STATUS "PkgConfig found: ${PKG_CONFIG_FOUND}") + + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/local/lib/cmake/") -# Find packages -find_package(czmq CONFIG REQUIRED) -find_package(ZeroMQ REQUIRED) + set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH}"/usr/include") + pkg_check_modules(czmq REQUIRED libczmq) + message("CZMQ Dir" ${czmq_INCLUDE_DIRS}) + message("CZMQ Lib" ${czmq_LIBRARIES}) + message("czmq_FOUND: ${czmq_FOUND}") + message("czmq_VERSION: ${czmq_VERSION}") + + set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH}"/usr/include") + find_package(ZeroMQ CONFIG REQUIRED) + message("ZeroMQ Dir" ${ZeroMQ_INCLUDE_DIRS}) + message("ZeroMQ Lib" ${ZeroMQ_LIBRARIES}) + message("ZeroMQ_FOUND: ${ZeroMQ_FOUND}") + message("ZeroMQ_VERSION: ${ZeroMQ_VERSION}") +endif() find_package(OpenSSL REQUIRED) +#set(OPENSSL_INCLUDE_DIR "${OPENSSL_INCLUDE_DIR}/openssl") +message("OPENSSL_FOUND: ${OPENSSL_FOUND}") + + # Include sub-projects. add_subdirectory ("WebShare-Connect") diff --git a/WebShare-Connect/CMakeLists.txt b/WebShare-Connect/CMakeLists.txt index a25deaa..dfee30c 100644 --- a/WebShare-Connect/CMakeLists.txt +++ b/WebShare-Connect/CMakeLists.txt @@ -1,10 +1,11 @@ cmake_minimum_required(VERSION 3.12) -project(WebShare-Connect) +project(WebShare-Connect LANGUAGES C VERSION 0.0.1) + +set(CMAKE_VERBOSE_MAKEFILE 1) -set (CMAKE_VERBOSE_MAKEFILE 1) if (MSVC) # Use different flags for MSVC - set(CMAKE_C_FLAGS "/Wall /w14242 /W4 ") + set(CMAKE_C_FLAGS "/Wall /w14242 /W4") else() # Use your original flags for other compilers set(CMAKE_C_FLAGS "-Wall -Wextra -Wconversion -Wunreachable-code -Wshadow -Wundef") @@ -32,49 +33,37 @@ add_library(sender "sender.c" "sender.h") add_library(receiver "receiver.c" "receiver.h") add_library(removeQuotes "removeQuotes.c" "removeQuotes.h") -# Find packages using PkgConfig -find_package(PkgConfig REQUIRED) -message(STATUS "PkgConfig found: ${PKG_CONFIG_FOUND}\nThe path is: ${PKG_CONFIG_EXECUTABLE}") - - -set(ENV{PKG_CONFIG_PATH} "${VCPKG_INSTALLED_DIR}/x64-windows/lib/pkgconfig") -message(STATUS "PKG_CONFIG_PATH: $ENV{PKG_CONFIG_PATH}") - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") - -find_package(LibNice REQUIRED) +# Include the OpenSSL include directory +include_directories(${OPENSSL_INCLUDE_DIR}) +include_directories(${ZMQ_INCLUDE_DIRS}) +message("ZMQ_INCLUDE_DIRS: ${ZMQ_INCLUDE_DIRS}") # Link against libraries target_link_libraries(WebShare-Connect PRIVATE - czmq - libzmq - sha512 + sha512 sender receiver OpenSSL::SSL OpenSSL::Crypto removeQuotes LibNice::LibNice -) - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") + ) -find_package(LibNice REQUIRED) # Link libraries to sender and receiver targets target_link_libraries(sender PRIVATE czmq - libzmq + libzmq sha512 OpenSSL::SSL OpenSSL::Crypto - LibNice::LibNice) - - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") + LibNice::LibNice +) -find_package(LibNice REQUIRED) target_link_libraries(receiver PRIVATE czmq - LibNice::LibNice) + libzmq + LibNice::LibNice +) target_link_libraries(sha512 PRIVATE OpenSSL::SSL OpenSSL::Crypto) diff --git a/WebShare-Connect/WebShare-Connect.h b/WebShare-Connect/WebShare-Connect.h index b3a9292..0091858 100644 --- a/WebShare-Connect/WebShare-Connect.h +++ b/WebShare-Connect/WebShare-Connect.h @@ -7,7 +7,13 @@ #include #include #include -#include #include -#include -#include "common.h" \ No newline at end of file +#include "common.h" +//if on windows +#ifdef _WIN32 + #include +//if on linux +#endif +#ifdef __linux__ + #include +#endif \ No newline at end of file diff --git a/WebShare-Connect/sender.c b/WebShare-Connect/sender.c index 507a765..1011750 100644 --- a/WebShare-Connect/sender.c +++ b/WebShare-Connect/sender.c @@ -2,10 +2,12 @@ * @file receiver_main.c * @brief Main sender functionality. */ +#include #include "WebShare-Connect.h" #include "sender.h" #include "sha512.h" #include "nice.h" +#include /** @@ -64,7 +66,13 @@ void sender_send(zsock_t* serv_sock, const char* file_path) // Determine file size fseek(fp, 0L, SEEK_END); - int64_t file_size = _ftelli64(fp); + int64_t file_size; + + #ifdef WIN32 + file_size = _ftelli64(fp); + #else + file_size = ftell(fp); + #endif rewind(fp); if (file_size < 1) { printf("Error: File size error.\n");