Skip to content

Commit

Permalink
Update scripts and libs, improve OpenSSL detection
Browse files Browse the repository at this point in the history
  • Loading branch information
cfnptr committed Oct 15, 2024
1 parent c6f40d2 commit 1374053
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 302 deletions.
2 changes: 1 addition & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Or
## 2. Install required packages

1. Run ```sudo apt-get update``` command using **Terminal** app
2. And ```sudo apt-get install git gcc g++ cmake libssl-dev```
2. And ```sudo apt-get install git cmake gcc g++ libssl-dev```


# macOS (14/15)
Expand Down
52 changes: 4 additions & 48 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,7 @@ if(TARGET nets-static)
return()
endif()

if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
if(NOT DEFINED VCPKG_ROOT)
cmake_path(SET VCPKG_ROOT $ENV{VCPKG_ROOT})
message(STATUS "VCPKG_ROOT: " ${VCPKG_ROOT})
endif()
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
if (NOT EXISTS ${CMAKE_TOOLCHAIN_FILE})
message(FATAL_ERROR "vcpkg is not installed or added to the System Environment Variables.")
endif()
endif()

if(NOT DEFINED VCPKG_ARCH)
if($ENV{PROCESSOR_ARCHITECTURE} MATCHES "64")
set(VCPKG_ARCH "x64")
elseif($ENV{PROCESSOR_ARCHITECTURE} MATCHES "86")
set(VCPKG_ARCH "x86")
else()
message(FATAL_ERROR "Failed to determine target architecture")
endif()
endif()

if(NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "${VCPKG_ARCH}-windows-static")
message(STATUS "VCPKG_TARGET_TRIPLET: " ${VCPKG_TARGET_TRIPLET})
endif()
endif()
include(cmake/package-managers.cmake)

project(nets VERSION 2.0.3 LANGUAGES C
DESCRIPTION "Secure multi-platform networking library \
Expand All @@ -64,18 +38,6 @@ option(NETS_USE_OPENSSL "Use OpenSSL for secure communication" ON)
option(NETS_ALLOW_DEPRECATED_SSL "Allow deprecated OpenSSL functions" OFF)

if(NETS_USE_OPENSSL)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if(EXISTS /opt/homebrew/opt/openssl@3)
set(OPENSSL_ROOT_DIR /opt/homebrew/opt/openssl@3 CACHE FILEPATH "" FORCE)
elseif(EXISTS /usr/local/opt/openssl@3) # support of old intel based macs
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl@3 CACHE FILEPATH "" FORCE)
endif()
if(DEFINED OPENSSL_ROOT_DIR)
set(OPENSSL_SSL_LIBRARY ${OPENSSL_ROOT_DIR}/lib/libssl.a CACHE FILEPATH "" FORCE)
set(OPENSSL_CRYPTO_LIBRARY ${OPENSSL_ROOT_DIR}/lib/libcrypto.a CACHE FILEPATH "" FORCE)
endif()
endif()

find_package(OpenSSL)

if(OpenSSL_FOUND)
Expand Down Expand Up @@ -125,17 +87,11 @@ endif()
configure_file(cmake/defines.h.in include/nets/defines.h)

if(NETS_USE_OPENSSL AND OpenSSL_FOUND)
list(APPEND NETS_LINK_LIBRARIES
OpenSSL::SSL OpenSSL::Crypto)
list(APPEND NETS_LINK_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
endif()

set(NETS_SOURCES
source/datagram_client.c
source/datagram_server.c
source/http_client.c
source/socket.c
source/stream_client.c
source/stream_server.c)
set(NETS_SOURCES source/datagram_client.c source/datagram_server.c source/http_client.c
source/socket.c source/stream_client.c source/stream_server.c)

add_library(nets-static STATIC ${NETS_SOURCES})
target_link_libraries(nets-static PUBLIC ${NETS_LINK_LIBRARIES} zlibstatic)
Expand Down
29 changes: 0 additions & 29 deletions build.bat

This file was deleted.

33 changes: 0 additions & 33 deletions build.sh

This file was deleted.

55 changes: 55 additions & 0 deletions cmake/package-managers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2022-2023 Nikita Fediuchin. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set(OPENSSL_USE_STATIC_LIBS ON CACHE BOOL "" FORCE)

if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(OPENSSL_MSVC_STATIC_RT ON CACHE BOOL "" FORCE)

if(NOT DEFINED VCPKG_ROOT)
cmake_path(SET VCPKG_ROOT $ENV{VCPKG_ROOT})
message(STATUS "VCPKG_ROOT: " ${VCPKG_ROOT})
endif()
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
if (NOT EXISTS ${CMAKE_TOOLCHAIN_FILE})
message(FATAL_ERROR "vcpkg is not installed or added to the System Environment Variables.")
endif()
endif()

if(NOT DEFINED VCPKG_ARCH)
if($ENV{PROCESSOR_ARCHITECTURE} MATCHES "64")
set(VCPKG_ARCH "x64")
elseif($ENV{PROCESSOR_ARCHITECTURE} MATCHES "86")
set(VCPKG_ARCH "x86")
else()
message(FATAL_ERROR "Failed to determine target architecture")
endif()
endif()

if(NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "${VCPKG_ARCH}-windows-static")
message(STATUS "VCPKG_TARGET_TRIPLET: " ${VCPKG_TARGET_TRIPLET})
endif()
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
if(NOT DEFINED HOMEBREW_PREFIX)
set(HOMEBREW_PREFIX $ENV{HOMEBREW_PREFIX})
if (NOT EXISTS ${HOMEBREW_PREFIX})
message(FATAL_ERROR "Homebrew is not installed or added to the System Environment Variables.")
endif()
endif()
if(NOT DEFINED CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH ${HOMEBREW_PREFIX}${HOMEBREW_PREFIX}/opt/openssl@3)
endif()
endif()
30 changes: 0 additions & 30 deletions scripts/build-debug-clang.bat

This file was deleted.

53 changes: 0 additions & 53 deletions scripts/build-debug-clang.sh

This file was deleted.

30 changes: 0 additions & 30 deletions scripts/build-release-clang.bat

This file was deleted.

53 changes: 0 additions & 53 deletions scripts/build-release-clang.sh

This file was deleted.

Loading

0 comments on commit 1374053

Please sign in to comment.