Skip to content

Commit

Permalink
feat: add Windows support (#29)
Browse files Browse the repository at this point in the history
* win32: add basic things

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* win32: update CMakeLists

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* win32: add daemon code

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* misc: add editorconfig, little changes in CMakeLists

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* win32: support and compat changes

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* compat: push prebuilt libraries for windows

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* win32: init Windows Sockets at start, support Windows paths

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* win32: work as unicode app

Signed-off-by: R4SAS <r4sas@i2pmail.org>

* compat: fix typo

Signed-off-by: R4SAS <r4sas@i2pmail.org>

Signed-off-by: R4SAS <r4sas@i2pmail.org>
  • Loading branch information
r4sas committed Oct 28, 2022
1 parent 0694bea commit 567786c
Show file tree
Hide file tree
Showing 86 changed files with 6,922 additions and 158 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# editorconfig.org

root = true

[*]
# Unix style files
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{h,cpp}]
indent_style = space
indent_size = 2

[*.rc]
indent_style = space
indent_size = 4

[*.{md,markdown}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = false
42 changes: 42 additions & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build on Windows

on: [push, pull_request]

defaults:
run:
shell: msys2 {0}

jobs:
build:
name: Building using ${{ matrix.arch }} toolchain
runs-on: windows-latest
strategy:
fail-fast: true
matrix:
include: [
{ msystem: UCRT64, arch: ucrt-x86_64, arch_short: x64-ucrt },
{ msystem: MINGW64, arch: x86_64, arch_short: x64 },
]
steps:
- uses: actions/checkout@v2
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.msystem }}
install: base-devel mingw-w64-${{ matrix.arch }}-cmake mingw-w64-${{ matrix.arch }}-gcc mingw-w64-${{ matrix.arch }}-boost mingw-w64-${{ matrix.arch }}-openssl
update: true
- name: Build application
run: |
cd build
cmake -G "MSYS Makefiles" -DMIMETIC_LIBRARY=../lib/compat-win/${{ matrix.arch_short }}/lib/libmimetic.a -DMIMETIC_INCLUDE_DIR=../lib/compat-win/include -DWITH_STATIC=ON .
make -j$(nproc)
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: pboted-${{ matrix.arch_short }}
path: build/pboted.exe
- name: Upload debug symbols
uses: actions/upload-artifact@v2
with:
name: pboted-${{ matrix.arch_short }}-debug
path: build/pboted.exe.debug
74 changes: 54 additions & 20 deletions build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ project(
VERSION ${PROJECT_VERSION})

# Configuration options
option(DISABLE_SOCKET "Disable UNIX socket in control module" OFF)
option(WITH_STATIC "Static build" OFF)
option(WITH_CXX11 "Force C++11" OFF)
option(WITH_CXX17 "Force C++17" OFF)
option(CONTROL_SOCKET "Use UNIX socket in control module" ON)
option(WITH_STATIC "Static build" OFF)
option(WITH_CXX11 "Force C++11" OFF)
option(WITH_CXX17 "Force C++17" OFF)
# ToDo?
#option(WITH_CLANG "Force Clang compiler" OFF)
#if (WITH_CLANG)
Expand Down Expand Up @@ -68,17 +68,28 @@ add_library(liblzma ${LIBLZMA_SRC})
set_target_properties(liblzma PROPERTIES PREFIX "")

# pboted stuff
include_directories(${PBOTE_SRC_DIR})
include_directories(${PBOTED_SRC_DIR})
file(GLOB PBOTED_SRC ${PBOTED_SRC_DIR}/*.cpp)

if (MSYS)
set(CMAKE_RC_COMPILER_INIT windres)
ENABLE_LANGUAGE(RC)
SET(CMAKE_RC_COMPILE_OBJECT
"<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")

set(WIN32_SRC_DIR ${PBOTED_SRC_DIR}/win32)
file(GLOB WIN32_RC ${WIN32_SRC_DIR}/*.rc)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32 -DWIN32_LEAN_AND_MEAN")
endif ()
# Compiler flags customization (by vendor)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Winvalid-pch -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pedantic")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -flto -s -ffunction-sections -fdata-sections")
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "-Wl,--gc-sections") # -flto is added from above

if (DISABLE_SOCKET)
if (NOT CONTROL_SOCKET)
add_definitions("-DDISABLE_SOCKET=1")
endif ()

Expand Down Expand Up @@ -155,6 +166,8 @@ if (WITH_STATIC)
set(Boost_USE_RELEASE_LIBS ON)
set(Boost_USE_STATIC_RUNTIME OFF)

set(OPENSSL_USE_STATIC_LIBS ON)

set(ZLIB_USE_STATIC_LIBS ON)
set(ZLIB_NAMES libz zlibstatic zlibstat zlib z)
#set(ZLIB_NAMES_DEBUG zlibstaticd zlibstatd)
Expand Down Expand Up @@ -230,10 +243,10 @@ endif ()

# Load includes
set(INCLUDED_DIRS
${MIMETIC_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIR}
${ZLIB_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS})
${MIMETIC_INCLUDE_DIRS})

# After migrating to CLI11
#if (CMAKE_CXX_STANDARD LESS 17)
Expand All @@ -256,14 +269,33 @@ message(STATUS "Architecture : ${ARCHITECTURE}")
message(STATUS "Install prefix : ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Options:")
message(STATUS " STATIC BUILD : ${WITH_STATIC}")
message(STATUS " OFF UNIX SOCKET : ${DISABLE_SOCKET}")
message(STATUS " UNIX SOCKET : ${CONTROL_SOCKET}")
message(STATUS " FORCE C++11 : ${WITH_CXX11}")
message(STATUS " FORCE C++17 : ${WITH_CXX17}")
message(STATUS "----------------------------------------")

add_executable("${PROJECT_NAME}" ${PBOTED_SRC})
if(MSYS)
add_executable("${PROJECT_NAME}" ${PBOTED_SRC} ${WIN32_RC})
else()
add_executable("${PROJECT_NAME}" ${PBOTED_SRC})
endif()

if (NOT MSVC)
if (MSYS)
set(MINGW_EXTRA
"wsock32"
"ws2_32"
"iphlpapi"
)
#add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
# DEPENDS "${PROJECT_NAME}"
# COMMAND ${CMAKE_OBJCOPY}
# ARGS --only-keep-debug $<TARGET_FILE:${PROJECT_NAME}> $<TARGET_FILE:${PROJECT_NAME}>.debug)
#add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
# DEPENDS "${PROJECT_NAME}"
# COMMAND ${CMAKE_STRIP}
# ARGS $<TARGET_FILE:${PROJECT_NAME}>)
endif ()
if (WITH_STATIC)
set_target_properties("${PROJECT_NAME}" PROPERTIES LINK_FLAGS "-static")
endif ()
Expand All @@ -280,24 +312,26 @@ if (WITH_STATIC)
set(DL_LIB ${CMAKE_DL_LIBS})
endif ()

if (CMAKE_CXX_STANDARD LESS 17)
set(PBOTED_BOOST_Libs Boost::system Boost::filesystem Boost::program_options)
else ()
set(PBOTED_BOOST_Libs Boost::program_options )
endif ()

set(LINK_LIBS
libi2pd
libi2psam
liblzma
Threads::Threads
ZLIB::ZLIB
${MIMETIC_LIBRARIES}
${OPENSSL_LIBRARIES}
${PBOTED_BOOST_Libs}
OpenSSL::SSL
OpenSSL::Crypto
ZLIB::ZLIB
Threads::Threads
${MINGW_EXTRA}
${DL_LIB}
${CMAKE_REQUIRED_LIBRARIES})

if (CMAKE_CXX_STANDARD LESS 17)
list(APPEND LINK_LIBS Boost::system Boost::filesystem Boost::program_options)
else ()
list(APPEND LINK_LIBS Boost::program_options )
endif ()

# If GCC version is less than 9 we need to link filesystem manually
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0 AND CMAKE_CXX_STANDARD EQUAL 17)
Expand Down
170 changes: 170 additions & 0 deletions contrib/logo/pboted.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 567786c

Please sign in to comment.