1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-24 18:39:53 +03:00

CMake: add support for Windows (Visual C++ 2017 toolset)

This commit is contained in:
Davide Beatrici 2018-10-24 19:23:07 +02:00
parent 5fe90bb180
commit c1f522c10e
16 changed files with 381 additions and 172 deletions

7
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "src/Mayaqua/cpu_features"]
path = src/Mayaqua/cpu_features
[submodule "src/Mayaqua/3rdparty/cpu_features"]
path = src/Mayaqua/3rdparty/cpu_features
url = https://github.com/google/cpu_features.git
[submodule "src/Mayaqua/3rdparty/zlib"]
path = src/Mayaqua/3rdparty/zlib
url = https://github.com/madler/zlib.git

View File

@ -8,7 +8,7 @@ project(SoftEtherVPN
set(default_build_type "Release")
# Check that submodules are present only if source was downloaded with git
if(EXISTS "${SoftEtherVPN_SOURCE_DIR}/.git" AND NOT EXISTS "${SoftEtherVPN_SOURCE_DIR}/src/Mayaqua/cpu_features/CMakeLists.txt")
if(EXISTS "${SoftEtherVPN_SOURCE_DIR}/.git" AND NOT EXISTS "${SoftEtherVPN_SOURCE_DIR}/src/Mayaqua/3rdparty/cpu_features/CMakeLists.txt")
message (FATAL_ERROR "Submodules are not initialized. Run\n\tgit submodule update --init --recursive")
endif()
@ -26,11 +26,13 @@ if (NOT ${PROJECT_VERSION} VERSION_EQUAL "${CurrentBuild_MAJOR}.${CurrentBuild_M
message (FATAL_ERROR "PROJECT_VERSION does not match to src/CurrentBuild.txt")
endif()
if(UNIX)
include(GNUInstallDirs)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
include(CheckIncludeFile)
Check_Include_File(sys/auxv.h HAVE_SYS_AUXV)
endif()
configure_file("${SoftEtherVPN_SOURCE_DIR}/AUTHORS.TXT" "${SoftEtherVPN_SOURCE_DIR}/src/bin/hamcore/authors.txt" COPYONLY)
@ -39,6 +41,7 @@ set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
add_subdirectory(src)
if(UNIX)
# Packaging
set(CPACK_COMPONENTS_ALL common vpnserver vpnclient vpnbridge vpncmd)
set(CPACK_PACKAGE_DIRECTORY ${BUILD_DIRECTORY})
@ -49,7 +52,6 @@ set(CPACK_PACKAGE_DESCRIPTION_FILE "${SoftEtherVPN_SOURCE_DIR}/description")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "SoftEther VPN is an open-source cross-platform multi-protocol VPN program, created as an academic project in the University of Tsukuba.")
# DEB
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CPACK_DEBIAN_PACKAGE_DEBUG ON)
endif()
@ -67,3 +69,4 @@ set(CPACK_RPM_PACKAGE_GROUP "Applications/Internet")
set(CPACK_RPM_PACKAGE_LICENSE "GPLv2")
include(CPack)
endif()

33
configure.cmd Normal file
View File

@ -0,0 +1,33 @@
@echo off
echo ---------------------------------------------------------------------
echo SoftEther VPN for Windows
echo.
echo Copyright (c) SoftEther VPN Project at University of Tsukuba, Japan.
echo Copyright (c) Daiyuu Nobori. All Rights Reserved.
echo.
echo This program is free software; you can redistribute it and/or
echo modify it under the terms of the GNU General Public License
echo version 2 as published by the Free Software Foundation.
echo.
echo Read and understand README.TXT, LICENSE.TXT and WARNING.TXT before use.
echo ---------------------------------------------------------------------
echo.
echo Welcome to the corner-cutting configure script !
echo.
if not exist "tmp" (
mkdir tmp
)
cd tmp
cmake -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles" ..
if %errorlevel% == 0 (
echo.
echo The Makefile is generated. Run 'nmake' to build SoftEther VPN.
) else (
cd ..
)

View File

@ -1,3 +1,4 @@
if(UNIX)
# Creates wrapper scripts and installs them in the user's binaries directory, which is usually "/usr/local/bin".
# This is required because symlinks use the folder they are in as working directory.
macro(install_wrapper_script component target)
@ -13,6 +14,7 @@ macro(install_wrapper_script component target)
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endmacro(install_wrapper_script)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-D_DEBUG -DDEBUG)
@ -23,7 +25,10 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(COMPILER_ARCHITECTURE "x64")
add_definitions(-DCPU_64)
else()
set(COMPILER_ARCHITECTURE "x86")
endif()
add_definitions(-D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64)
@ -32,7 +37,7 @@ add_definitions(-D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_S
include_directories(.)
if(WIN32)
message(FATAL_ERROR "Windows compilation via CMake is currently not supported.")
add_definitions(-DWIN32 -D_WINDOWS -D_CRT_SECURE_NO_WARNINGS)
endif()
if(UNIX)
@ -103,6 +108,19 @@ add_custom_target(hamcore-archive-build
VERBATIM
)
if(WIN32)
# PenCore
add_subdirectory(PenCore)
add_dependencies(hamcore-archive-build PenCore)
# vpnsmgr
add_subdirectory(vpnsmgr)
# vpncmgr
add_subdirectory(vpncmgr)
endif()
if(UNIX)
# Print message after installing the targets
install(CODE "message(\"\n----------------------------------------------------------------------------------------------------------------------------\")")
install(CODE "message(\"Build completed successfully.\n\")")
@ -111,3 +129,4 @@ install(CODE "message(\"Execute 'vpnbridge start' to run the SoftEther VPN Bridg
install(CODE "message(\"Execute 'vpnclient start' to run the SoftEther VPN Client background service.\")")
install(CODE "message(\"Execute 'vpncmd' to run the SoftEther VPN Command-Line Utility to configure VPN Server, VPN Bridge or VPN Client.\")")
install(CODE "message(\"----------------------------------------------------------------------------------------------------------------------------\n\")")
endif()

View File

@ -1,7 +1,16 @@
file(GLOB SOURCES_CEDAR "*.c")
file(GLOB HEADERS_CEDAR "*.h")
add_library(cedar SHARED ${SOURCES_CEDAR} ${HEADERS_CEDAR})
if(WIN32)
enable_language(CXX)
file(GLOB SOURCES_CEDAR_CPP "*.cpp")
endif()
if(WIN32)
add_library(cedar STATIC ${SOURCES_CEDAR} ${SOURCES_CEDAR_CPP} ${HEADERS_CEDAR})
else()
add_library(cedar SHARED ${SOURCES_CEDAR} ${SOURCES_CEDAR_CPP} ${HEADERS_CEDAR})
endif()
set_target_properties(cedar
PROPERTIES
@ -10,6 +19,11 @@ set_target_properties(cedar
RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIRECTORY}"
)
if(WIN32)
target_include_directories(cedar PRIVATE winpcap)
endif()
if(UNIX)
find_library(LIB_READLINE readline)
find_package(Curses REQUIRED)
@ -18,6 +32,7 @@ target_link_libraries(cedar PRIVATE ${LIB_READLINE} ${CURSES_LIBRARIES})
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
target_link_libraries(cedar PRIVATE mayaqua pcap)
endif()
endif()
# Version
add_definitions(-DCEDAR_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} -DCEDAR_VERSION_MINOR=${PROJECT_VERSION_MINOR} -DCEDAR_VERSION_BUILD=${PROJECT_VERSION_PATCH})
@ -55,8 +70,10 @@ message(STATUS "Build time: ${BUILD_HOUR}:${BUILD_MINUTE}:${BUILD_SECOND}")
add_definitions(-DBUILD_DATE_D=${BUILD_DAY} -DBUILD_DATE_M=${BUILD_MONTH} -DBUILD_DATE_Y=${BUILD_YEAR})
add_definitions(-DBUILD_DATE_HO=${BUILD_HOUR} -DBUILD_DATE_MI=${BUILD_MINUTE} -DBUILD_DATE_SE=${BUILD_SECOND})
if(UNIX)
install(TARGETS cedar
COMPONENT "common"
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
endif()

1
src/Mayaqua/3rdparty/zlib vendored Submodule

@ -0,0 +1 @@
Subproject commit cacf7f1d4e3d44d871b605da3b647f07d718623f

View File

@ -1,7 +1,11 @@
file(GLOB SOURCES_MAYAQUA "*.c")
file(GLOB HEADERS_MAYAQUA "*.h")
if(WIN32)
add_library(mayaqua STATIC ${SOURCES_MAYAQUA} ${HEADERS_MAYAQUA})
else()
add_library(mayaqua SHARED ${SOURCES_MAYAQUA} ${HEADERS_MAYAQUA})
endif()
target_include_directories(mayaqua PUBLIC .)
@ -12,6 +16,38 @@ set_target_properties(mayaqua
RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIRECTORY}"
)
if(WIN32)
add_subdirectory(3rdparty/zlib)
target_include_directories(mayaqua PRIVATE win32_inc)
target_include_directories(mayaqua PRIVATE 3rdparty/zlib)
if(${COMPILER_ARCHITECTURE} STREQUAL "x64")
find_library(LIB_SSL
NAMES libssl ssleay32
HINTS "${CMAKE_SOURCE_DIR}/src/BuildFiles/Library/vs2017/x64_${CMAKE_BUILD_TYPE}"
)
find_library(LIB_CRYPTO
NAMES libcrypto libeay32
HINTS "${CMAKE_SOURCE_DIR}/src/BuildFiles/Library/vs2017/x64_${CMAKE_BUILD_TYPE}"
)
else()
find_library(LIB_SSL
NAMES libssl ssleay32
HINTS "${CMAKE_SOURCE_DIR}/src/BuildFiles/Library/vs2017/Win32_${CMAKE_BUILD_TYPE}"
)
find_library(LIB_CRYPTO
NAMES libcrypto libeay32
HINTS "${CMAKE_SOURCE_DIR}/src/BuildFiles/Library/vs2017/Win32_${CMAKE_BUILD_TYPE}"
)
endif()
target_link_libraries(mayaqua PRIVATE zlibstatic ${LIB_SSL} ${LIB_CRYPTO})
endif()
if(UNIX)
find_package(OpenSSL REQUIRED)
find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)
@ -19,24 +55,20 @@ find_package(ZLIB REQUIRED)
# In some cases libiconv is not included in libc
find_library(LIB_ICONV iconv)
if(HAVE_SYS_AUXV)
add_subdirectory(cpu_features)
set_property(TARGET cpu_features PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
target_include_directories(mayaqua PRIVATE cpu_features/include)
find_library(LIB_RT rt)
target_link_libraries(mayaqua PRIVATE OpenSSL::SSL OpenSSL::Crypto Threads::Threads ZLIB::ZLIB)
if(HAVE_SYS_AUXV)
add_subdirectory(3rdparty/cpu_features)
set_property(TARGET cpu_features PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(mayaqua PRIVATE cpu_features)
else()
add_definitions(-DSKIP_CPU_FEATURES)
endif()
find_library(LIB_RT rt)
if(LIB_RT)
target_link_libraries(mayaqua PRIVATE ${LIB_RT})
target_link_libraries(mayaqua PRIVATE rt)
endif()
if(LIB_ICONV)
@ -52,3 +84,4 @@ install(TARGETS mayaqua
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()

View File

@ -0,0 +1,14 @@
if(NOT WIN32)
message(FATAL_ERROR "PenCore is needed only on Windows.")
endif()
add_library(PenCore SHARED pencore.c pencore.rc)
set_target_properties(PenCore
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/src/bin/hamcore"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/src/bin/hamcore"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/src/bin/hamcore"
)
target_link_libraries(PenCore cedar mayaqua)

View File

@ -1,4 +1,10 @@
add_executable(vpnbridge vpnbridge.c)
set(VPNBRIDGE_SOURCES vpnbridge.c)
if(WIN32)
set(VPNBRIDGE_SOURCES ${VPNBRIDGE_SOURCES} vpnbridge.rc)
endif()
add_executable(vpnbridge ${VPNBRIDGE_SOURCES})
set_target_properties(vpnbridge
PROPERTIES
@ -9,6 +15,7 @@ set_target_properties(vpnbridge
target_link_libraries(vpnbridge cedar mayaqua)
if(UNIX)
# Copy binary and "hamcore.se2" to /usr/lib(exec)/softether/, install launch script and systemd service
install(TARGETS vpnbridge
COMPONENT "vpnbridge"
@ -31,3 +38,4 @@ if(EXISTS "/lib/systemd/system")
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
endif()
endif()

View File

@ -1,4 +1,10 @@
add_executable(vpnclient vpncsvc.c)
set(VPNCLIENT_SOURCES vpncsvc.c vpncsvc.h)
if(WIN32)
set(VPNCLIENT_SOURCES ${VPNCLIENT_SOURCES} vpnclient.rc)
endif()
add_executable(vpnclient ${VPNCLIENT_SOURCES})
set_target_properties(vpnclient
PROPERTIES
@ -9,6 +15,7 @@ set_target_properties(vpnclient
target_link_libraries(vpnclient cedar mayaqua)
if(UNIX)
# Copy binary and "hamcore.se2" to /usr/lib(exec)/softether/, install launch script and systemd service
install(TARGETS vpnclient
COMPONENT "vpnclient"
@ -31,3 +38,4 @@ if(EXISTS "/lib/systemd/system")
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
endif()
endif()

View File

@ -1,4 +1,10 @@
add_executable(vpncmd vpncmd.c)
set(VPNCMD_SOURCES vpncmd.c)
if(WIN32)
set(VPNCMD_SOURCES ${VPNCMD_SOURCES} vpncmd.rc)
endif()
add_executable(vpncmd ${VPNCMD_SOURCES})
set_target_properties(vpncmd
PROPERTIES
@ -9,6 +15,7 @@ set_target_properties(vpncmd
target_link_libraries(vpncmd cedar mayaqua)
if(UNIX)
# Copy binary and "hamcore.se2" to /usr/lib(exec)/softether/, install launch script
install(TARGETS vpncmd
COMPONENT "vpncmd"
@ -23,3 +30,4 @@ install(FILES "${BUILD_DIRECTORY}/hamcore.se2"
)
install_wrapper_script("vpncmd" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpncmd/vpncmd")
endif()

View File

@ -0,0 +1,22 @@
if(NOT WIN32)
message(FATAL_ERROR "VPN Client Manager is available only for Windows.")
endif()
set(VPNCMGR_SOURCES vpncmgr.c vpncmgr.rc)
if(${COMPILER_ARCHITECTURE} STREQUAL "x64")
set(VPNCMGR_SOURCES ${VPNCMGR_SOURCES} ${CMAKE_SOURCE_DIR}/src/BuildFiles/Manifests/x64_user.manifest)
else()
set(VPNCMGR_SOURCES ${VPNCMGR_SOURCES} ${CMAKE_SOURCE_DIR}/src/BuildFiles/Manifests/x86_user.manifest)
endif()
add_executable(vpncmgr WIN32 ${VPNCMGR_SOURCES})
set_target_properties(vpncmgr
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${BUILD_DIRECTORY}"
LIBRARY_OUTPUT_DIRECTORY "${BUILD_DIRECTORY}"
RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIRECTORY}"
)
target_link_libraries(vpncmgr cedar mayaqua)

View File

@ -1,4 +1,10 @@
add_executable(vpnserver vpnserver.c)
set(VPNSERVER_SOURCES vpnserver.c)
if(WIN32)
set(VPNSERVER_SOURCES ${VPNSERVER_SOURCES} vpnserver.rc)
endif()
add_executable(vpnserver ${VPNSERVER_SOURCES})
set_target_properties(vpnserver
PROPERTIES
@ -9,6 +15,7 @@ set_target_properties(vpnserver
target_link_libraries(vpnserver cedar mayaqua)
if(UNIX)
# Copy binary and "hamcore.se2" to /usr/lib(exec)/softether/, install launch script and systemd service
install(TARGETS vpnserver
COMPONENT "vpnserver"
@ -31,3 +38,4 @@ if(EXISTS "/lib/systemd/system")
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
endif()
endif()

View File

@ -0,0 +1,22 @@
if(NOT WIN32)
message(FATAL_ERROR "VPN Server Manager is available only for Windows.")
endif()
set(VPNSMGR_SOURCES vpnsmgr.c vpnsmgr.rc)
if(${COMPILER_ARCHITECTURE} STREQUAL "x64")
set(VPNSMGR_SOURCES ${VPNSMGR_SOURCES} ${CMAKE_SOURCE_DIR}/src/BuildFiles/Manifests/x64_user.manifest)
else()
set(VPNSMGR_SOURCES ${VPNSMGR_SOURCES} ${CMAKE_SOURCE_DIR}/src/BuildFiles/Manifests/x86_user.manifest)
endif()
add_executable(vpnsmgr WIN32 ${VPNSMGR_SOURCES})
set_target_properties(vpnsmgr
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${BUILD_DIRECTORY}"
LIBRARY_OUTPUT_DIRECTORY "${BUILD_DIRECTORY}"
RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIRECTORY}"
)
target_link_libraries(vpnsmgr cedar mayaqua)

View File

@ -1,4 +1,14 @@
add_executable(vpntest vpntest.c vpntest.h)
set(VPNTEST_SOURCES vpntest.c vpntest.h)
if(WIN32)
if(${COMPILER_ARCHITECTURE} STREQUAL "x64")
set(VPNTEST_SOURCES ${VPNTEST_SOURCES} ${CMAKE_SOURCE_DIR}/src/BuildFiles/Manifests/x64_user.manifest)
else()
set(VPNTEST_SOURCES ${VPNTEST_SOURCES} ${CMAKE_SOURCE_DIR}/src/BuildFiles/Manifests/x86_user.manifest)
endif()
endif()
add_executable(vpntest ${VPNTEST_SOURCES})
set_target_properties(vpntest
PROPERTIES