0
0
mirror of https://github.com/OpenVPN/openvpn.git synced 2024-09-19 11:32:28 +02:00

CMake: Add complete MinGW and MSVC build

This is based on the initial CMake patch by
Arne Schwabe, but extends that to provide
a complete replacement for existing MinGW
build (autotools based) and MSVC build
(openvpn.sln).

The following features are added while switching
these builds to CMake:
 - vcpkg support for MinGW build, allowing for
   trivial cross-compilation on Linux
 - Add unittests to MSVC build
 - Rework MSVC config header generation, removing
   need for separate headers between autotools
   and MSVC

The following advantages are reasons for switching
to CMake over the existing MSVC build:
 - Easier to maintain CMake files without IDE
   than the sln and vcxproj files
 - Able to maintain MSVC and MinGW build side-by-side

The plan is to completely remove the existing MSVC
build system but leave the existing autotools builds
in place as-is, including MinGW support.

CMake is not the intended build system for Unix-like
platforms and there are no current plans to switch
to it.

v2:
 - Reduce default warning level for MSVC to /W2. With
   /W3 the build is just much too noisy, making it
   difficult to spot new warnings.
 - Change MSVC CMake presets to have hardcoded build
   type. When using pkg_search_module MSVC Multi-Config
   builds do not work correctly at all since PkgConfig
   doesn't seem to be able to create multi-config
   libraries like find_package does.
 - Change minGW presets to be Multi-Config capable.
 - Remove OPENVPN_VERSION_MAJOR, OPENVPN_VERSION_MINOR,
   OPENVPN_VERSION_PATCH from config.h.cmake.in.
   They are not required and cause macro redefinition
   warnings in MSVC (with openvpn-plugin.h). gcc doesn't
   warn about this because the definitions are identical
   so no need to fix this in autoheader config.h.in.
v3:
 - Apply fixes by Lev Stipakov to match MSVC compile
   options better to previous build.
 - Apply change by Lev Stipakov to enable generation
   of PDB files.
 - Move /Brepro to its own commit. This is a behavior
   change that should be more visible.
 - Rebase on top of my dist fixes.

Change-Id: I237f28eca618d4fc476225b887c0be26cca362b1
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20230620135310.94455-3-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26754.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
This commit is contained in:
Frank Lichtenheld 2023-06-20 15:53:07 +02:00 committed by Gert Doering
parent 0134184012
commit e8881ec6dd
19 changed files with 1279 additions and 657 deletions

View File

@ -39,230 +39,95 @@ jobs:
strategy:
fail-fast: false
matrix:
osslver: [1.1.1q, 3.0.5]
target: [mingw64, mingw]
include:
- target: mingw64
chost: x86_64-w64-mingw32
- target: mingw
chost: i686-w64-mingw32
arch: [x86, x64]
name: "gcc-mingw - ${{matrix.target}} - OSSL ${{ matrix.osslver }}"
name: "gcc-mingw - ${{ matrix.arch }} - OSSL"
runs-on: ubuntu-22.04
env:
MAKEFLAGS: -j3
LZO_VERSION: "2.10"
PKCS11_HELPER_VERSION: "1.29.0"
OPENSSL_VERSION: "${{ matrix.osslver }}"
TAP_WINDOWS_VERSION: "9.23.3"
CMOCKA_VERSION: "1.1.5"
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
steps:
- name: Install dependencies
run: sudo apt update && sudo apt install -y mingw-w64 libtool automake autoconf man2html unzip cmake ninja-build build-essential wget
run: sudo apt update && sudo apt install -y mingw-w64 unzip cmake ninja-build build-essential wget python3-docutils man2html-base
- name: Checkout OpenVPN
uses: actions/checkout@v3
- name: Restore from cache and install vcpkg
uses: lukka/run-vcpkg@v10
with:
path: openvpn
vcpkgGitCommitId: 'd10d511f25620ca0f315cd83dcef6485efc63010'
vcpkgJsonGlob: '**/mingw/vcpkg.json'
appendedCacheKey: mingw_${{ matrix.arch }}
- name: autoconf
run: autoreconf -fvi
working-directory: openvpn
- name: Cache dependencies
id: cache
uses: actions/cache@v3
- name: Run CMake with vcpkg.json manifest
uses: lukka/run-cmake@v10
with:
path: '~/mingw/'
key: ${{ matrix.target }}-mingw-${{ matrix.osslver }}-${{ env.LZO_VERSION }}-${{ env.PKCS11_HELPER_VERSION }}-${{ env.TAP_WINDOWS_VERSION }}--${{ env.CMOCKA_VERSION }}
configurePreset: mingw-${{ matrix.arch }}
buildPreset: mingw-${{ matrix.arch }}
buildPresetAdditionalArgs: "['--config Debug']"
# Repeating if: steps.cache.outputs.cache-hit != 'true'
# on every step for building dependencies is ugly but
# I haven't found a better solution so far.
- name: Download mingw dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
wget -c -P download-cache/ "https://build.openvpn.net/downloads/releases/tap-windows-${TAP_WINDOWS_VERSION}.zip"
wget -c -P download-cache/ "https://www.oberhumer.com/opensource/lzo/download/lzo-${LZO_VERSION}.tar.gz"
wget -c -P download-cache/ "https://github.com/OpenSC/pkcs11-helper/releases/download/pkcs11-helper-${PKCS11_HELPER_VERSION}/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2"
wget -c -P download-cache/ "https://github.com/coreboot/cmocka/archive/refs/tags/cmocka-${CMOCKA_VERSION}.tar.gz"
tar jxf "download-cache/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2"
wget -c -P download-cache/ "https://www.openssl.org/source/old/1.1.1/openssl-${OPENSSL_VERSION}.tar.gz" || wget -c -P download-cache/ "https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz"
tar zxf "download-cache/openssl-${OPENSSL_VERSION}.tar.gz"
tar zxf "download-cache/lzo-${LZO_VERSION}.tar.gz"
tar zxf "download-cache/cmocka-${CMOCKA_VERSION}.tar.gz"
unzip download-cache/tap-windows-${TAP_WINDOWS_VERSION}.zip
- name: create cmocka build directory
if: steps.cache.outputs.cache-hit != 'true'
run: mkdir cmocka-build
- name: configure cmocka
if: steps.cache.outputs.cache-hit != 'true'
working-directory: "./cmocka-build"
run: cmake -GNinja -DCMAKE_C_COMPILER=${{ matrix.chost }}-gcc -DCMAKE_CXX_COMPILER=${{ matrix.chost }}-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SHARED_LINKER_FLAGS=-static-libgcc -DCMAKE_PREFIX_PATH=${HOME}/mingw/opt/lib/pkgconfig/ -DCMAKE_INCLUDE_PATH=${HOME}/mingw/opt/lib/include -DCMAKE_LIBRARY_PATH=${HOME}/mingw/opt/lib -DCMAKE_INSTALL_PREFIX=${HOME}/mingw/opt/ ../cmocka-cmocka-${{ env.CMOCKA_VERSION }}
- name: build cmocka
if: steps.cache.outputs.cache-hit != 'true'
working-directory: "./cmocka-build"
run: ninja
- name: install cmocka
if: steps.cache.outputs.cache-hit != 'true'
working-directory: "./cmocka-build"
run: ninja install
- name: Configure OpenSSL
if: steps.cache.outputs.cache-hit != 'true'
run: ./Configure --cross-compile-prefix=${{ matrix.chost }}- shared ${{ matrix.target }} no-capieng --prefix="${HOME}/mingw/opt" --openssldir="${HOME}/mingw/opt" -static-libgcc
working-directory: "./openssl-${{ env.OPENSSL_VERSION }}"
- name: Build OpenSSL
if: steps.cache.outputs.cache-hit != 'true'
run: make
working-directory: "./openssl-${{ env.OPENSSL_VERSION }}"
# OpenSSL 3.0.5 installs itself into mingw/opt/lib64 instead of
# mingw/opt/lib, so we include both dirs in the following steps
# (pkcs11-helper and OpenVPN) so the libraries will be found
- name: Install OpenSSL
if: steps.cache.outputs.cache-hit != 'true'
run: make install
working-directory: "./openssl-${{ env.OPENSSL_VERSION }}"
- name: autoreconf pkcs11-helper
if: steps.cache.outputs.cache-hit != 'true'
run: autoreconf -iv
working-directory: "./pkcs11-helper-${{ env.PKCS11_HELPER_VERSION }}"
- name: configure pkcs11-helper
if: steps.cache.outputs.cache-hit != 'true'
run: OPENSSL_LIBS="-L${HOME}/mingw/opt/lib -L${HOME}/mingw/opt/lib64 -lssl -lcrypto" OPENSSL_CFLAGS=-I$HOME/mingw/opt/include PKG_CONFIG_PATH=${HOME}/mingw/opt/lib/pkgconfig ./configure --host=${{ matrix.chost }} --program-prefix='' --libdir=${HOME}/mingw/opt/lib --prefix=${HOME}/mingw/opt --build=x86_64-pc-linux-gnu --disable-crypto-engine-gnutls --disable-crypto-engine-nss --disable-crypto-engine-polarssl --disable-crypto-engine-mbedtls
working-directory: "./pkcs11-helper-${{ env.PKCS11_HELPER_VERSION }}"
- name: build pkcs11-helper
if: steps.cache.outputs.cache-hit != 'true'
run: make all
working-directory: "./pkcs11-helper-${{ env.PKCS11_HELPER_VERSION }}"
- name: install pkcs11-helper
if: steps.cache.outputs.cache-hit != 'true'
run: make install
working-directory: "./pkcs11-helper-${{ env.PKCS11_HELPER_VERSION }}"
- name: Configure lzo
if: steps.cache.outputs.cache-hit != 'true'
run: ./configure --host=${{ matrix.chost }} --program-prefix='' --libdir=${HOME}/mingw/opt/lib --prefix=${HOME}/mingw/opt --build=x86_64-pc-linux-gnu
working-directory: "./lzo-${{ env.LZO_VERSION }}"
- name: build lzo
if: steps.cache.outputs.cache-hit != 'true'
working-directory: "./lzo-${{ env.LZO_VERSION }}"
run: make
- name: install lzo
if: steps.cache.outputs.cache-hit != 'true'
working-directory: "./lzo-${{ env.LZO_VERSION }}"
run: make install
- name: copy tap-windows.h header
if: steps.cache.outputs.cache-hit != 'true'
run: cp ./tap-windows-${TAP_WINDOWS_VERSION}/include/tap-windows.h ${HOME}/mingw/opt/include/
- name: configure OpenVPN
run: PKG_CONFIG_PATH=${HOME}/mingw/opt/lib/pkgconfig LDFLAGS=-L$HOME/mingw/opt/lib CFLAGS=-I$HOME/mingw/opt/include OPENSSL_LIBS="-L${HOME}/opt/lib -L$HOME/mingw/opt/lib64 -lssl -lcrypto" OPENSSL_CFLAGS=-I$HOME/mingw/opt/include PREFIX=$HOME/mingw/opt LZO_CFLAGS=-I$HOME/mingw/opt/include LZO_LIBS="-L${HOME}/mingw/opt/lib -llzo2" ./configure --host=${{ matrix.chost }} --disable-lz4
working-directory: openvpn
- name: build OpenVPN
run: make -j3
working-directory: openvpn
- name: build OpenVPN unittests
run: make -j3 check
working-directory: openvpn
# We use multiple upload-artifact here, so it becomes a flat folder
# structure since we need the dlls on the same level as the binaries
- name: Archive cmocka/openssl/lzo dlls
uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v3
with:
retention-days: 1
name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-dlls
path: '~/mingw/opt/bin/*.dll'
name: openvpn-mingw-${{ matrix.arch }}
path: |
${{ github.workspace }}/out/build/mingw/${{ matrix.arch }}/Debug/*.exe
${{ github.workspace }}/out/build/mingw/${{ matrix.arch }}/Debug/*.dll
!${{ github.workspace }}/out/build/mingw/${{ matrix.arch }}/Debug/test_*.exe
# libtool puts some wrapper binaries in openvpn/tests/unit_tests/openvpn/
# and the real binaries in openvpn/tests/unit_tests/openvpn/.libs/
- name: Archive unittest artifacts
uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v3
with:
retention-days: 1
name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-tests
path: openvpn/tests/unit_tests/openvpn/.libs/*.exe
# Currently not used by the unit test but might in the future and also
# helpful if manually downloading and running openvpn.exe from a mingw
# build
- name: Archive openvpn binary
uses: actions/upload-artifact@v3
with:
retention-days: 1
name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-tests
path: openvpn/src/openvpn/.libs/*.exe
name: openvpn-mingw-${{ matrix.arch }}-tests
path: |
${{ github.workspace }}/out/build/mingw/${{ matrix.arch }}/Debug/test_*.exe
${{ github.workspace }}/out/build/mingw/${{ matrix.arch }}/Debug/*.dll
mingw-unittest:
needs: [ mingw ]
strategy:
fail-fast: false
matrix:
osslver: [ 1.1.1q, 3.0.5 ]
target: [ mingw64, mingw ]
arch: [x86, x64]
runs-on: windows-latest
name: "mingw unittests - ${{matrix.target}} - OSSL ${{ matrix.osslver }}"
name: "mingw unittests - ${{ matrix.arch }} - OSSL"
steps:
- name: Retrieve mingw unittest dlls
uses: actions/download-artifact@v3
with:
name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-dlls
path: unittests
- name: Retrieve mingw unittest
uses: actions/download-artifact@v3
with:
name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-tests
name: openvpn-mingw-${{ matrix.arch }}-tests
path: unittests
- name: List unittests directory
run: "dir unittests"
- name: Run argvunit test
run: ./unittests/argv_testdriver.exe
- name: Run argv unit test
run: ./unittests/test_argv.exe
- name: Run auth_tokenunit test
run: ./unittests/auth_token_testdriver.exe
- name: Run auth_token unit test
run: ./unittests/test_auth_token.exe
- name: Run bufferunit test
run: ./unittests/buffer_testdriver.exe
- name: Run buffer unit test
run: ./unittests/test_buffer.exe
- name: Run cryptoapi unit test
run: ./unittests/cryptoapi_testdriver.exe
run: ./unittests/test_cryptoapi.exe
- name: Run cryptounit test
run: ./unittests/crypto_testdriver.exe
- name: Run crypto unit test
run: ./unittests/test_crypto.exe
- name: Run miscunit test
run: ./unittests/misc_testdriver.exe
- name: Run misc unit test
run: ./unittests/test_misc.exe
- name: Run ncpunit test
run: ./unittests/ncp_testdriver.exe
- name: Run ncp unit test
run: ./unittests/test_ncp.exe
- name: Run packet idunit test
run: ./unittests/packet_id_testdriver.exe
- name: Run packet id unit test
run: ./unittests/test_packet_id.exe
- name: Run pktunit test
run: ./unittests/pkt_testdriver.exe
- name: Run pkt unit test
run: ./unittests/test_pkt.exe
- name: Run providerunit test
run: ./unittests/provider_testdriver.exe
- name: Run provider unit test
run: ./unittests/test_provider.exe
ubuntu:
strategy:
@ -411,60 +276,51 @@ jobs:
strategy:
fail-fast: false
matrix:
plat: [ARM64, Win32, x64]
include:
- plat: ARM64
triplet: arm64
- plat: Win32
triplet: x86
- plat: x64
triplet: x64
arch: [amd64, x86, arm64]
name: "msbuild - ${{matrix.triplet}} - openssl"
name: "msbuild - ${{ matrix.arch }} - openssl"
env:
BUILD_CONFIGURATION: Release
VCPKG_OVERLAY_PORTS: ${{ github.workspace }}/contrib/vcpkg-ports
VCPKG_OVERLAY_TRIPLETS: ${{ github.workspace }}/contrib/vcpkg-triplets
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.1
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- uses: lukka/get-cmake@latest
- name: Install rst2html
run: python -m pip install --upgrade pip rst2html
run: python -m pip install --upgrade pip docutils
- name: Restore artifacts, or setup vcpkg (do not install any package)
uses: lukka/run-vcpkg@v10
with:
vcpkgGitCommitId: 'd10d511f25620ca0f315cd83dcef6485efc63010'
vcpkgJsonGlob: '**/openvpn/vcpkg.json'
appendedCacheKey: '${{matrix.triplet}}'
vcpkgJsonGlob: '**/windows/vcpkg.json'
appendedCacheKey: msvc_${{ matrix.arch }}
- name: Run MSBuild consuming vcpkg.json
working-directory: ${{env.GITHUB_WORKSPACE}}
run: |
# workaround for GHA runner bug where vcpkg installation is detected at c:\vcpkg
# see https://github.com/lukka/run-vcpkg/issues/170
${{ github.workspace }}/vcpkg/vcpkg.exe integrate install
msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:Platform="${{ matrix.plat }}" .
- name: Archive artifacts
uses: actions/upload-artifact@v3
- name: Run CMake with vcpkg.json manifest (NO TESTS)
uses: lukka/run-cmake@v10
if: ${{ matrix.arch == 'arm64' }}
with:
name: artifacts-${{ matrix.plat }}
configurePreset: win-${{ matrix.arch }}-release
buildPreset: win-${{ matrix.arch }}-release
- name: Run CMake with vcpkg.json manifest
uses: lukka/run-cmake@v10
if: ${{ matrix.arch != 'arm64' }}
with:
configurePreset: win-${{ matrix.arch }}-release
buildPreset: win-${{ matrix.arch }}-release
testPreset: win-${{ matrix.arch }}-release
- uses: actions/upload-artifact@v3
with:
name: openvpn-msvc-${{ matrix.arch }}
path: |
${{ matrix.plat }}-Output/${{env.BUILD_CONFIGURATION}}/*.exe
${{ matrix.plat }}-Output/${{env.BUILD_CONFIGURATION}}/*.dll
${{ matrix.plat }}-Output/${{env.BUILD_CONFIGURATION}}/*.pdb
doc/openvpn.8.html
${{ github.workspace }}/out/**/*.exe
${{ github.workspace }}/out/**/*.dll
!${{ github.workspace }}/out/**/test_*.exe
!${{ github.workspace }}/out/**/CMakeFiles/**
!${{ github.workspace }}/out/**/vcpkg_installed/**
trigger_openvpn_build:
runs-on: windows-latest

1
.gitignore vendored
View File

@ -17,6 +17,7 @@
Release
Debug
Win32-Output
out
.vs
.deps
.libs

File diff suppressed because it is too large Load Diff

228
CMakePresets.json Normal file
View File

@ -0,0 +1,228 @@
{
"version": 3,
"configurePresets": [
{
"name": "base",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
},
"VCPKG_OVERLAY_TRIPLETS": {
"value": "${sourceDir}/contrib/vcpkg-triplets",
"type": "FILEPATH"
},
"VCPKG_OVERLAY_PORTS": {
"value": "${sourceDir}/contrib/vcpkg-ports",
"type": "FILEPATH"
}
}
},
{
"name": "base-windows",
"hidden": true,
"binaryDir": "${sourceDir}/out/build/${presetName}",
"generator": "Visual Studio 17 2022",
"cacheVariables": {
"VCPKG_MANIFEST_DIR": "${sourceDir}/contrib/vcpkg-manifests/windows",
"VCPKG_HOST_TRIPLET": "x64-windows"
},
"vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } }
},
{
"name": "base-mingw",
"hidden": true,
"generator": "Ninja Multi-Config",
"cacheVariables": {
"CMAKE_SYSTEM_NAME": {
"value": "Windows",
"type": "STRING"
},
"VCPKG_MANIFEST_DIR": "${sourceDir}/contrib/vcpkg-manifests/mingw"
}
},
{
"name": "x64",
"hidden": true,
"architecture": {
"value": "x64",
"strategy": "set"
},
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x64-windows-ovpn"
}
},
{
"name": "x64-mingw",
"hidden": true,
"binaryDir": "out/build/mingw/x64",
"cacheVariables": {
"CMAKE_C_COMPILER": {
"value": "x86_64-w64-mingw32-gcc",
"type": "STRING"
},
"CMAKE_CXX_COMPILER": {
"value": "x86_64-w64-mingw32-g++",
"type": "STRING"
},
"VCPKG_TARGET_TRIPLET": "x64-mingw-ovpn"
}
},
{
"name": "arm64",
"hidden": true,
"architecture": {
"value": "arm64",
"strategy": "set"
},
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "arm64-windows-ovpn"
}
},
{
"name": "x86",
"hidden": true,
"architecture": {
"value": "Win32",
"strategy": "set"
},
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x86-windows-ovpn"
}
},
{
"name": "i686-mingw",
"hidden": true,
"binaryDir": "out/build/mingw/x86",
"cacheVariables": {
"CMAKE_C_COMPILER": {
"value": "i686-w64-mingw32-gcc",
"type": "STRING"
},
"CMAKE_CXX_COMPILER": {
"value": "i686-w64-mingw32-g++",
"type": "STRING"
},
"VCPKG_TARGET_TRIPLET": "x86-mingw-ovpn"
}
},
{
"name": "debug",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "mingw-x64",
"inherits": [ "base", "base-mingw", "x64-mingw" ]
},
{
"name": "mingw-x86",
"inherits": [ "base", "base-mingw", "i686-mingw" ]
},
{
"name": "win-amd64-release",
"inherits": [ "base", "base-windows", "x64", "release" ]
},
{
"name": "win-arm64-release",
"inherits": [ "base", "base-windows", "arm64", "release" ]
},
{
"name": "win-x86-release",
"inherits": [ "base", "base-windows", "x86", "release" ]
},
{
"name": "win-amd64-debug",
"inherits": [ "base", "base-windows", "x64", "debug" ]
},
{
"name": "win-arm64-debug",
"inherits": [ "base", "base-windows", "arm64", "debug" ]
},
{
"name": "win-x86-debug",
"inherits": [ "base", "base-windows", "x86", "debug" ]
},
{
"name": "unix-native",
"generator": "Ninja Multi-Config",
"binaryDir": "out/build/unix"
}
],
"buildPresets": [
{
"name": "mingw-x64",
"configurePreset": "mingw-x64"
},
{
"name": "mingw-x86",
"configurePreset": "mingw-x86"
},
{
"name": "win-amd64-release",
"configurePreset": "win-amd64-release",
"configuration": "Release"
},
{
"name": "win-arm64-release",
"configurePreset": "win-arm64-release",
"configuration": "Release"
},
{
"name": "win-x86-release",
"configurePreset": "win-x86-release",
"configuration": "Release"
},
{
"name": "win-amd64-debug",
"configurePreset": "win-amd64-debug",
"configuration": "Debug"
},
{
"name": "win-arm64-debug",
"configurePreset": "win-arm64-debug",
"configuration": "Debug"
},
{
"name": "win-x86-debug",
"configurePreset": "win-x86-debug",
"configuration": "Debug"
},
{
"name": "unix-native",
"configurePreset": "unix-native"
}
],
"testPresets": [
{
"name": "win-amd64-release",
"configurePreset": "win-amd64-release"
},
{
"name": "win-x86-release",
"configurePreset": "win-x86-release"
},
{
"name": "win-amd64-debug",
"configurePreset": "win-amd64-debug"
},
{
"name": "win-x86-debug",
"configurePreset": "win-x86-debug"
},
{
"name": "unix-native",
"configurePreset": "unix-native"
}
]
}

View File

@ -41,7 +41,10 @@ CLEANFILES = \
EXTRA_DIST = \
contrib \
debug
debug \
CMakeLists.txt \
CMakePresets.json \
config.h.cmake.in
.PHONY: config-version.h doxygen

View File

@ -42,7 +42,7 @@
#define ENABLE_OFB_CFB_MODE
/* Enable PKCS11 */
/* #undef ENABLE_PKCS11 */
#cmakedefine ENABLE_PKCS11
/* Enable plug-in support */
#define ENABLE_PLUGIN 1
@ -83,6 +83,9 @@
/* struct cmsghdr needed for extended socket error support */
#cmakedefine HAVE_CMSGHDR
/* git version information in config-version.h */
#cmakedefine HAVE_CONFIG_VERSION_H
/* Define to 1 if you have the `daemon' function. */
#cmakedefine HAVE_DAEMON
@ -193,9 +196,6 @@ don't. */
/* Define to 1 if you have the <netinet/in.h> header file. */
#cmakedefine HAVE_NETINET_IN_H
/* Define to 1 if you have the <netinet/in_systm.h> header file. */
#undef HAVE_NETINET_IN_SYSTM_H
/* Define to 1 if you have the <netinet/ip.h> header file. */
#cmakedefine HAVE_NETINET_IP_H
@ -398,14 +398,8 @@ don't. */
/* Path to route tool */
#define ROUTE_PATH "@ROUTE_PATH@"
/* OpenVPN major version - integer */
#undef OPENVPN_VERSION_MAJOR
/* OpenVPN minor version - integer */
#undef OPENVPN_VERSION_MINOR
/* OpenVPN patch level - may be a string or integer */
#define OPENVPN_VERSION_PATCH "@OPENVPN_VERSION_PATCH@"
/* OpenVPN version in Windows resource format - string */
#define OPENVPN_VERSION_RESOURCE @OPENVPN_VERSION_RESOURCE@
/* Name of package */
#define PACKAGE "openvpn"
@ -422,12 +416,6 @@ don't. */
/* Define to the version of this package. */
#define PACKAGE_VERSION "@OPENVPN_VERSION_MAJOR@.@OPENVPN_VERSION_MINOR@@OPENVPN_VERSION_PATCH@"
/* OpenVPN major version - integer */
#define OPENVPN_VERSION_MAJOR @OPENVPN_VERSION_MAJOR@
/* OpenVPN minor version - integer */
#define OPENVPN_VERSION_MINOR @OPENVPN_VERSION_MINOR@
/* Path to systemd-ask-password tool */
#undef SYSTEMD_ASK_PASSWORD_PATH
@ -481,7 +469,6 @@ typedef SSIZE_T ssize_t;
#define strncasecmp strnicmp
#define strcasecmp _stricmp
#define S_IRUSR 0
#define S_IWUSR 0
#define R_OK 4

View File

@ -0,0 +1,75 @@
#
# OpenVPN -- An application to securely tunnel IP networks
# over a single UDP port, with support for SSL/TLS-based
# session authentication and key exchange,
# packet encryption, packet authentication, and
# packet compression.
#
# Copyright (C) 2022-2023 OpenVPN Inc <sales@openvpn.net>
# Copyright (C) 2022-2022 Lev Stipakov <lev@lestisoftware.fi>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
import os
import sys
import subprocess
def run_command(args):
sp = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
o, _ = sp.communicate()
return o.decode("utf-8")[:-1]
def get_branch_commit_id():
commit_id = run_command(["git", "rev-parse", "--short=16", "HEAD"])
if not commit_id:
raise
branch = run_command(["git", "describe", "--exact-match"])
if not branch:
# this returns an array like ["master"] or ["release", "2.6"]
branch = run_command(["git", "rev-parse", "--symbolic-full-name", "HEAD"]).split("/")[2:]
if not branch:
branch = ["none"]
branch = "/" .join(branch) # handle cases like release/2.6
return branch, commit_id
def main():
try:
branch, commit_id = get_branch_commit_id()
except:
branch, commit_id = "unknown", "unknown"
prev_content = ""
name = os.path.join("%s" % (sys.argv[1] if len(sys.argv) > 1 else "."), "config-version.h")
try:
with open(name, "r") as f:
prev_content = f.read()
except:
# file doesn't exist
pass
content = "#define CONFIGURE_GIT_REVISION \"%s/%s\"\n" % (branch, commit_id)
content += "#define CONFIGURE_GIT_FLAGS \"\"\n"
if prev_content != content:
print("Writing %s" % name)
with open(name, "w") as f:
f.write(content)
else:
print("Content of %s hasn't changed" % name)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,57 @@
#
# OpenVPN -- An application to securely tunnel IP networks
# over a single UDP port, with support for SSL/TLS-based
# session authentication and key exchange,
# packet encryption, packet authentication, and
# packet compression.
#
# Copyright (C) 2022-2023 OpenVPN Inc <sales@openvpn.net>
# Copyright (C) 2022-2022 Lev Stipakov <lev@lestisoftware.fi>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
import os
import re
import sys
def main():
assert len(sys.argv) > 1
version_path = sys.argv[1]
output = []
with open(version_path, 'r') as version_file:
for line in version_file:
match = re.match(r'[ \t]*define\(\[(.*)\],[ \t]*\[(.*)\]\)[ \t]*', line)
if match is not None:
output.append(match.expand(r'set(\1 \2)'))
out_path = os.path.join("%s" % (sys.argv[2] if len(sys.argv) > 2 else "."), "version.cmake")
prev_content = ""
try:
with open(out_path, "r") as out_file:
prev_content = out_file.read()
except:
# file doesn't exist
pass
content = "\n".join(output) + "\n"
if prev_content != content:
print("Writing %s" % out_path)
with open(out_path, "w") as out_file:
out_file.write(content)
else:
print("Content of %s hasn't changed" % out_path)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,13 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
"name": "openvpn",
"version": "2.7",
"dependencies": [
"openssl",
"tap-windows6",
"lzo",
"lz4",
"pkcs11-helper",
"cmocka"
]
}

View File

@ -0,0 +1,20 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
"name": "openvpn",
"version": "2.7",
"dependencies": [
{
"name": "openssl",
"features": ["tools"]
},
"tap-windows6",
"lzo",
"lz4",
"pkcs11-helper",
"cmocka",
{
"name": "pkgconf",
"host": true
}
]
}

View File

@ -28,12 +28,28 @@ if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
OPENSSL_HOME=${CURRENT_PACKAGES_DIR}/../openssl_${TARGET_TRIPLET}
)
file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/lib/pkcs11-helper.dll.lib DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/lib/pkcs11-helper.dll.lib DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/lib/pkcs11-helper.dll.lib DESTINATION ${CURRENT_PACKAGES_DIR}/lib RENAME pkcs11-helper.lib)
file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/lib/pkcs11-helper.dll.lib DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib RENAME pkcs11-helper.lib)
file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/lib/libpkcs11-helper-1.dll DESTINATION ${CURRENT_PACKAGES_DIR}/bin)
file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/lib/libpkcs11-helper-1.dll DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin)
set(PACKAGE_VERSION "${VERSION}")
set(libdir [[${prefix}/lib]])
set(exec_prefix [[${prefix}]])
set(PKCS11H_FEATURES key_prompt openssl engine_crypto_cryptoapi engine_crypto_openssl debug threading token data certificate slotevent engine_crypto)
set(LIBS -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32)
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
set(includedir [[${prefix}/include]])
set(outfile "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/libpkcs11-helper-1.pc")
configure_file("${SOURCE_PATH}/lib/libpkcs11-helper-1.pc.in" "${outfile}" @ONLY)
endif()
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
set(includedir [[${prefix}/../include]])
set(outfile "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/libpkcs11-helper-1.pc")
configure_file("${SOURCE_PATH}/lib/libpkcs11-helper-1.pc.in" "${outfile}" @ONLY)
endif()
file(INSTALL ${SOURCE_PATH}/include/pkcs11-helper-1.0 DESTINATION ${CURRENT_PACKAGES_DIR}/include/)
else()
@ -45,11 +61,11 @@ else()
--disable-crypto-engine-polarssl --disable-crypto-engine-mbedtls
)
vcpkg_install_make()
vcpkg_fixup_pkgconfig()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
endif()
vcpkg_fixup_pkgconfig()
vcpkg_copy_pdbs()
file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

80
doc/CMakeLists.txt Normal file
View File

@ -0,0 +1,80 @@
set(_GENERATE_HTML_DOC YES)
set(_GENERATE_MAN_DOC YES)
find_program(RST2HTML NAMES rst2html rst2html.py)
find_program(RST2MAN NAMES rst2man rst2man.py)
if (RST2HTML STREQUAL "RST2HTML-NOTFOUND")
message(STATUS "rst2html not found, not generating HTML documentation")
set(_GENERATE_HTML_DOC NO)
endif ()
if (RST2MAN STREQUAL "RST2MAN-NOTFOUND")
message(STATUS "rst2man not found, not generating HTML documentation")
set(_GENERATE_MAN_DOC NO)
endif ()
set(OPENVPN_SECTIONS
man-sections/advanced-options.rst
man-sections/cipher-negotiation.rst
man-sections/client-options.rst
man-sections/connection-profiles.rst
man-sections/encryption-options.rst
man-sections/generic-options.rst
man-sections/inline-files.rst
man-sections/link-options.rst
man-sections/log-options.rst
man-sections/management-options.rst
man-sections/network-config.rst
man-sections/pkcs11-options.rst
man-sections/plugin-options.rst
man-sections/protocol-options.rst
man-sections/proxy-options.rst
man-sections/renegotiation.rst
man-sections/signals.rst
man-sections/script-options.rst
man-sections/server-options.rst
man-sections/tls-options.rst
man-sections/unsupported-options.rst
man-sections/virtual-routing-and-forwarding.rst
man-sections/vpn-network-options.rst
man-sections/windows-options.rst
)
set(OPENVPN_EXAMPLES_SECTIONS
man-sections/example-fingerprint.rst
man-sections/examples.rst
)
set(RST_FLAGS --strict)
if (_GENERATE_HTML_DOC)
list(APPEND ALL_DOCS openvpn.8.html openvpn-examples.5.html)
add_custom_command(
OUTPUT openvpn.8.html
COMMAND ${PYTHON} ${RST2HTML} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn.8.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn.8.html
MAIN_DEPENDENCY openvpn.8.rst
DEPENDS ${OPENVPN_SECTIONS}
)
add_custom_command(
OUTPUT openvpn-examples.5.html
COMMAND ${PYTHON} ${RST2HTML} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn-examples.5.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn-examples.5.html
MAIN_DEPENDENCY openvpn-examples.5.rst
DEPENDS ${OPENVPN_EXAMPLES_SECTIONS}
)
endif ()
if (_GENERATE_MAN_DOC)
list(APPEND ALL_DOCS openvpn.8 openvpn-examples.5)
add_custom_command(
OUTPUT openvpn.8
COMMAND ${PYTHON} ${RST2MAN} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn.8.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn.8
MAIN_DEPENDENCY openvpn.8.rst
DEPENDS ${OPENVPN_SECTIONS}
)
add_custom_command(
OUTPUT openvpn-examples.5
COMMAND ${PYTHON} ${RST2MAN} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn-examples.5.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn-examples.5
MAIN_DEPENDENCY openvpn-examples.5.rst
DEPENDS ${OPENVPN_EXAMPLES_SECTIONS}
)
endif ()
add_custom_target(documentation ALL DEPENDS ${ALL_DOCS})

View File

@ -63,7 +63,8 @@ dist_noinst_DATA = \
README.plugins \
tls-crypt-v2.txt \
$(openvpn_sections) \
$(openvpn_examples_sections)
$(openvpn_examples_sections) \
CMakeLists.txt
EXTRA_DIST = tests

View File

@ -0,0 +1,36 @@
if (NOT WIN32)
return ()
endif ()
project(openvpnmsica)
add_library(openvpnmsica SHARED)
target_include_directories(openvpnmsica PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/../../
../../include/
../compat/
)
target_sources(openvpnmsica PRIVATE
dllmain.c
msiex.c msiex.h
msica_arg.c msica_arg.h
openvpnmsica.c openvpnmsica.h
../tapctl/basic.h
../tapctl/error.c ../tapctl/error.h
../tapctl/tap.c ../tapctl/tap.h
openvpnmsica_resources.rc
)
target_compile_options(openvpnmsica PRIVATE
-D_UNICODE
-UNTDDI_VERSION
-D_WIN32_WINNT=_WIN32_WINNT_VISTA
)
target_link_libraries(openvpnmsica
advapi32.lib ole32.lib msi.lib setupapi.lib iphlpapi.lib shell32.lib shlwapi.lib version.lib newdev.lib)
if (MINGW)
target_compile_options(openvpnmsica PRIVATE -municode)
target_link_options(openvpnmsica PRIVATE -municode)
target_link_options(openvpnmsica PRIVATE
-Wl,--kill-at)
endif ()

View File

@ -34,6 +34,9 @@ AM_CPPFLAGS = \
AM_CFLAGS = \
$(TAP_CFLAGS)
EXTRA_DIST = \
CMakeLists.txt
if WIN32
lib_LTLIBRARIES = libopenvpnmsica.la
libopenvpnmsica_la_CFLAGS = \

View File

@ -0,0 +1,34 @@
if (NOT WIN32)
return ()
endif ()
project(openvpnserv)
add_executable(openvpnserv)
target_include_directories(openvpnserv PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/../../
../../include/
../openvpn/
../compat/
)
target_sources(openvpnserv PRIVATE
common.c
interactive.c
service.c service.h
validate.c validate.h
../openvpn/block_dns.c ../openvpn/block_dns.h
openvpnserv_resources.rc
../openvpn/ring_buffer.h
)
target_compile_options(openvpnserv PRIVATE
-D_UNICODE
-UNTDDI_VERSION
-D_WIN32_WINNT=_WIN32_WINNT_VISTA
)
target_link_libraries(openvpnserv
advapi32.lib userenv.lib iphlpapi.lib fwpuclnt.lib rpcrt4.lib shlwapi.lib netapi32.lib ws2_32.lib ntdll.lib)
if (MINGW)
target_compile_options(openvpnserv PRIVATE -municode)
target_link_options(openvpnserv PRIVATE -municode)
endif ()

View File

@ -19,6 +19,9 @@ EXTRA_DIST = \
AM_CPPFLAGS = \
-I$(top_srcdir)/include -I$(top_srcdir)/src/openvpn -I$(top_srcdir)/src/compat
EXTRA_DIST = \
CMakeLists.txt
if WIN32
sbin_PROGRAMS = openvpnserv
openvpnserv_CFLAGS = \

31
src/tapctl/CMakeLists.txt Normal file
View File

@ -0,0 +1,31 @@
if (NOT WIN32)
return ()
endif ()
project(tapctl)
add_executable(tapctl)
target_include_directories(tapctl PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/../../
../../include/
../compat/
)
target_sources(tapctl PRIVATE
basic.h
error.c error.h
main.c
tap.c tap.h
tapctl_resources.rc
)
target_compile_options(tapctl PRIVATE
-D_UNICODE
-UNTDDI_VERSION
-D_WIN32_WINNT=_WIN32_WINNT_VISTA
)
target_link_libraries(tapctl
advapi32.lib ole32.lib setupapi.lib)
if (MINGW)
target_compile_options(tapctl PRIVATE -municode)
target_link_options(tapctl PRIVATE -municode)
endif ()

View File

@ -33,6 +33,10 @@ AM_CPPFLAGS = \
AM_CFLAGS = \
$(TAP_CFLAGS)
EXTRA_DIST = \
CMakeLists.txt \
tapctl.exe.manifest
if WIN32
sbin_PROGRAMS = tapctl
tapctl_CFLAGS = \