Skip to content

Commit

Permalink
Update to make it linux compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Black-Speedy committed Jan 13, 2024
1 parent 6bf33ae commit 4198616
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ dkms.conf
.vs/
out/
build/
buildWindows/
buildLinux/
Documentation/
54 changes: 45 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>: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")
Expand Down
43 changes: 16 additions & 27 deletions WebShare-Connect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 9 additions & 3 deletions WebShare-Connect/WebShare-Connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <ws2tcpip.h>
#include <czmq.h>
#include <OpenSSL/ssl.h>
#include "common.h"
#include "common.h"
//if on windows
#ifdef _WIN32
#include <OpenSSL/ssl.h>
//if on linux
#endif
#ifdef __linux__
#include <openssl/ssl.h>
#endif
10 changes: 9 additions & 1 deletion WebShare-Connect/sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
* @file receiver_main.c
* @brief Main sender functionality.
*/
#include <stdio.h>
#include "WebShare-Connect.h"
#include "sender.h"
#include "sha512.h"
#include "nice.h"
#include <zmq.h>


/**
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 4198616

Please sign in to comment.