Skip to content

Commit

Permalink
Use package manager zlib instead of submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Fediuchin committed Oct 17, 2024
1 parent 1374053 commit f7fbdca
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 26 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

env:
BUILD_TYPE: Release
VCPKG_CACHE: Windows-openssl_3.3.2
VCPKG_CACHE: Windows-zlib_1.3.1-openssl_3.3.2

jobs:
build:
Expand Down Expand Up @@ -33,15 +33,15 @@ jobs:

- name: Install Ubuntu packages
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install libssl-dev
run: sudo apt-get update && sudo apt-get install zlib1g-dev libssl-dev

- name: Install macOS packages
if: matrix.os == 'macos-latest'
run: brew update && brew install openssl
run: brew update && brew install zlib openssl

- name: Install Windows packages
if: ${{matrix.os == 'windows-latest' && steps.vcpkg-cache.outputs.cache-hit != 'true'}}
run: vcpkg install openssl:x64-windows-static
run: vcpkg install zlib:x64-windows-static openssl:x64-windows-static

- name: Create build environment
run: cmake -E make_directory ${{runner.workspace}}/build
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "libraries/mpmt"]
path = libraries/mpmt
url = https://github.com/cfnptr/mpmt
[submodule "libraries/zlib"]
path = libraries/zlib
url = https://github.com/madler/zlib
[submodule "libraries/mpio"]
path = libraries/mpio
url = https://github.com/cfnptr/mpio
6 changes: 3 additions & 3 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Or

## 6. Install required packages

1. Run ```vcpkg install openssl:x64-windows-static``` using **Terminal** or **CMD** app
1. Run ```vcpkg install zlib:x64-windows-static openssl:x64-windows-static``` using **Terminal** or **CMD** app


# Ubuntu (22.04/24.04)
Expand All @@ -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 cmake gcc g++ libssl-dev```
2. And ```sudo apt-get install git cmake gcc g++ zlib1g-dev libssl-dev```


# macOS (14/15)
Expand All @@ -79,7 +79,7 @@ Or

1. Install **Homebrew** package manager from [brew.sh](https://brew.sh)
2. Run ```brew update``` command using **Terminal** app
3. And ```brew install git cmake openssl```
3. And ```brew install git cmake zlib openssl```


# Build Project
Expand Down
18 changes: 7 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ option(NETS_BUILD_EXAMPLES "Build Nets usage examples" ON)
option(NETS_USE_OPENSSL "Use OpenSSL for secure communication" ON)
option(NETS_ALLOW_DEPRECATED_SSL "Allow deprecated OpenSSL functions" OFF)

find_package(ZLIB REQUIRED)

if(NETS_USE_OPENSSL)
find_package(OpenSSL)

Expand Down Expand Up @@ -65,10 +67,9 @@ else()
set(NETS_LITTLE_ENDIAN 1)
endif()

set(NETS_INCLUDE_DIRECTORIES
${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/include
${PROJECT_BINARY_DIR}/libraries/zlib ${PROJECT_SOURCE_DIR}/libraries/zlib)
set(NETS_LINK_LIBRARIES mpmt-static mpio-static)
set(NETS_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRS}
${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/include)
set(NETS_LINK_LIBRARIES mpmt-static mpio-static ZLIB::ZLIB)

set(MPMT_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(MPMT_BUILD_TESTS OFF CACHE BOOL "" FORCE)
Expand All @@ -79,11 +80,6 @@ set(MPIO_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(MPIO_BUILD_TESTS OFF CACHE BOOL "" FORCE)
add_subdirectory(libraries/mpio)

if(NOT TARGET zlibstatic)
set(ZLIB_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(libraries/zlib)
endif()

configure_file(cmake/defines.h.in include/nets/defines.h)

if(NETS_USE_OPENSSL AND OpenSSL_FOUND)
Expand All @@ -94,14 +90,14 @@ set(NETS_SOURCES source/datagram_client.c source/datagram_server.c source/http_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)
target_link_libraries(nets-static PUBLIC ${NETS_LINK_LIBRARIES})
target_include_directories(nets-static PUBLIC ${NETS_INCLUDE_DIRECTORIES})

if(NETS_BUILD_SHARED)
add_library(nets-shared SHARED ${NETS_SOURCES})
set_target_properties(nets-shared PROPERTIES
OUTPUT_NAME "nets" WINDOWS_EXPORT_ALL_SYMBOLS ON)
target_link_libraries(nets-shared PUBLIC ${NETS_LINK_LIBRARIES} zlib)
target_link_libraries(nets-shared PUBLIC ${NETS_LINK_LIBRARIES})
target_include_directories(nets-shared PUBLIC ${NETS_INCLUDE_DIRECTORIES})
endif()

Expand Down
4 changes: 3 additions & 1 deletion cmake/package-managers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
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})
Expand Down Expand Up @@ -49,7 +50,8 @@ elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
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)
set(CMAKE_PREFIX_PATH ${HOMEBREW_PREFIX}/opt/zlib ${HOMEBREW_PREFIX}/opt/openssl@3)
endif()
endif()
1 change: 0 additions & 1 deletion libraries/zlib
Submodule zlib deleted from 51b7f2
2 changes: 1 addition & 1 deletion scripts/install-packages.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ IF NOT %ERRORLEVEL% == 0 (
EXIT /B %ERRORLEVEL%
)

vcpkg install openssl:x64-windows-static
vcpkg install zlib:x64-windows-static openssl:x64-windows-static

IF NOT %ERRORLEVEL% == 0 (
ECHO vcpkg failed to install required packages.
Expand Down
4 changes: 2 additions & 2 deletions scripts/install-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
exit $status
fi

brew update && brew install git cmake openssl
brew update && brew install git cmake zlib openssl
status=$?

if [ $status -ne 0 ]; then
Expand All @@ -26,7 +26,7 @@ else
exit $status
fi

sudo apt-get update && sudo apt-get install git cmake gcc g++ libssl-dev
sudo apt-get update && sudo apt-get install git cmake gcc g++ zlib1g-dev libssl-dev
status=$?

if [ $status -ne 0 ]; then
Expand Down

0 comments on commit f7fbdca

Please sign in to comment.