From 9ac0c06549af6afbb3027f05c3d7aab3a0df0cc9 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Sun, 5 Mar 2023 16:29:18 +0300 Subject: [PATCH 1/4] Fix minor warning GCC analyzer wrongly assumes that `if(cp == NULL || c == ':')` not guarding against `cp++`. --- src/XGetopt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/XGetopt.cpp b/src/XGetopt.cpp index bc5cf32..0adb93c 100644 --- a/src/XGetopt.cpp +++ b/src/XGetopt.cpp @@ -198,7 +198,7 @@ int getopt(int argc, char *argv[], const char *optstring) if (cp == NULL || c == ':') return '?'; - cp++; + cp++; if (*cp == ':') { if (*next != '\0') From da3a5b1e6b5c966e0cf39f0f841c3ac8e05ff6e4 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Sun, 5 Mar 2023 17:38:08 +0300 Subject: [PATCH 2/4] Statically compile binary in MinGW environment In order to achieve more portability int2ssl needs to compiled with `-static` option in MinGW environment, so all required toolchain libraries gets compiled into binary. Partially fixes #6. Now project supports cross-compiling for Windows binaries in Linux host. To do so, pass `-DCMAKE_TOOLCHAIN_FILE=/path/to/Toolchain-MinGW64.cmake` on cmake configuration phase. Also reorganized CMakeLists.txt file for more modern CMake project best practies usage: * -Os (optimized for size) is part of Cmake's MinSizeRel build type, so this option should'nt defined manually. Instead use `-DCMAKE_BUILD_TYPE=MinSizeRel`. * -s (strip binary option) is not true crossplatform option, so moved it into option STRIP_EXE enabled by default. * Minimal CMake version requirement updated to 3.13 to avoid deprecation warnings on modern cmake. --- .appveyor.yml | 2 +- CHANGELOG.md | 1 + CMakeLists.txt | 21 ++++++++++----------- cmake/Toolchain-MinGW64.cmake | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 cmake/Toolchain-MinGW64.cmake diff --git a/.appveyor.yml b/.appveyor.yml index f7cc7a7..3a80620 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,7 +2,7 @@ version: '8.4.4-{build}' environment: matrix: - - BUILD_TYPE: Release + - BUILD_TYPE: MinSizeRel COMPILER: MinGW PLATFORM: Win32 WITH_MPFR: yes diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a3b617..68d72a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ 8.4.4 under development ===== +- Statically compile binary in MinGW environment (winterheart) 8.4.3 (2018-01-03) ===== diff --git a/CMakeLists.txt b/CMakeLists.txt index e456bf6..d111f5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,16 @@ -set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build (by default Debug)") - -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.13) project(int2ssl) -aux_source_directory(src SRC_LIST) - -add_definitions (-Wall) +option(STRIP_EXE "Strip debug info from compiled files" ON) +file(GLOB_RECURSE SRC_LIST CONFIGURE_DEPENDS src/*.cpp) -set(CMAKE_CXX_FLAGS_RELEASE "-Os -s") +add_executable(${PROJECT_NAME} ${SRC_LIST}) +target_compile_options(${PROJECT_NAME} PRIVATE -Wall) -message("CMAKE_CXX_FLAGS_DEBUG is ${CMAKE_CXX_FLAGS_DEBUG}") -message("CMAKE_CXX_FLAGS_RELEASE is ${CMAKE_CXX_FLAGS_RELEASE}") +target_link_options(${PROJECT_NAME} PRIVATE + $<$:-static> + $<$:-s> +) -add_executable(${PROJECT_NAME} ${SRC_LIST}) -install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) \ No newline at end of file +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) diff --git a/cmake/Toolchain-MinGW64.cmake b/cmake/Toolchain-MinGW64.cmake new file mode 100644 index 0000000..73094da --- /dev/null +++ b/cmake/Toolchain-MinGW64.cmake @@ -0,0 +1,22 @@ +# Toolchain file to cross compile on Linux targeting Windows (x64/mingw-w64). +# Running: +# cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/Toolchain-MinGW64.cmake .... + +set(CMAKE_SYSTEM_NAME Windows) + +set(MINGW_COMPILER_PREFIX "x86_64-w64-mingw32" CACHE STRING "What compiler prefix to use for mingw (i686-w64-mingw32 or x86_64-w64-mingw32)") +set(MINGW_SYSROOT "/usr/${MINGW_COMPILER_PREFIX}" CACHE STRING "What sysroot to use for mingw") + +# Which compilers to use for C and C++ +find_program(CMAKE_C_COMPILER NAMES ${MINGW_COMPILER_PREFIX}-gcc) +find_program(CMAKE_CXX_COMPILER NAMES ${MINGW_COMPILER_PREFIX}-g++) +find_program(CMAKE_RC_COMPILER NAMES ${MINGW_COMPILER_PREFIX}-windres) + +set(CMAKE_FIND_ROOT_PATH ${MINGW_SYSROOT}) + +# Adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) From f345a459299eb1a7906cfbb933251b20055d83d9 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Sun, 5 Mar 2023 18:03:33 +0300 Subject: [PATCH 3/4] Implementing GitHub Actions --- .github/workflows/build.yml | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..68bceae --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,43 @@ +name: build + +on: + push: + branches: + - develop + pull_request: + branches: + - develop + +jobs: + build: + name: Build all + runs-on: ${{ matrix.config.os }} + strategy: + fail-fast: false + matrix: + config: + - { os: ubuntu-latest, cc: "gcc", cxx: "g++", build_type: "Release" } + - { os: ubuntu-latest, cc: "clang", cxx: "clang++", build_type: "Release" } + - { os: ubuntu-latest, cc: "x86_64-w64-mingw32-gcc", cxx: "x86_64-w64-mingw32-g++", build_type: "MinSizeRel", + toolchain: "cmake/Toolchain-MinGW64.cmake" } + steps: + - uses: actions/checkout@v3 + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install g++-mingw-w64-x86-64 ninja-build + - name: Build with ${{ matrix.config.cc }}/${{ matrix.config.cxx }} + env: + CC: ${{ matrix.config.cc }} + CXX: ${{ matrix.config.cxx }} + run: | + cmake -B build -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE=${{ matrix.config.toolchain }} \ + -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} + cmake --build build -j2 -v + - name: Store artifacts + uses: actions/upload-artifact@v3 + with: + name: executables + path: build/int2ssl.exe + From a4277d094c28539022f8368e6e54d69ad4a6ddbe Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Mon, 6 Mar 2023 12:22:56 +0300 Subject: [PATCH 4/4] Documenting changes --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 182825b..a88a820 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Building from source: Dependencies: ------------- -- CMake (>= 2.8) +- CMake (>= 3.13) Build: ------ @@ -35,6 +35,16 @@ Build: mkdir build && cd build && cmake .. && make ``` +If you want cross-compile on Linux for Windows, you'll need to install MinGW +toolchain and use special toolchain file: + +```bash +sudo apt-get install g++-mingw-w64-x86-64 +mkdir build && cd build +cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-MinGW64.cmake +make +``` + Usage: ======