Skip to content

Separating openvpn3 lib and bin #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions test/ovpncli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ option(CLI_KOVPN "Build ovpncli variant with kovpn kernel module support" OFF)
option(CLI_OVPNDCO "Build ovpncli with ovpn-dco kernel module support" OFF)
option(CLI_OVPNDCOWIN "Build ovpncli with ovpn-dco-win driver support" OFF)
option(CLI_TUNBUILDER "Build ovpncli with tunbuilder interface support" OFF)
option(CLI_SINGLETHREAD "Build ovpncli with single thread support" ON)

set(KOVPN_SOURCE "${CORE_DIR}/../kovpn" CACHE PATH "ovpn-dco kernel module source tree")

Expand All @@ -13,27 +14,47 @@ add_library(
${CORE_DIR}/openvpn/openssl/xkey/xkey_provider.c
)

set(OVPNCLI_SOURCES src/main.cpp)
set(OVPNCLI_LIBS xkey ovpncliwrapper)


target_compile_definitions(xkey INTERFACE -DENABLE_EXTERNAL_PKI)
add_ssl_library(xkey)

add_library(openvpn_headers INTERFACE)
target_include_directories(openvpn_headers INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include
)


add_library(ovpncliwrapper STATIC src/ovpncli.cpp)
target_compile_definitions(ovpncliwrapper PUBLIC)
if (${CLI_SINGLETHREAD})
target_compile_definitions(ovpncliwrapper PRIVATE -DOPENVPN_OVPNCLI_SINGLE_THREAD)
endif ()
add_core_dependencies(ovpncliwrapper)
add_library(openvpn3::ovpncliwrapper ALIAS ovpncliwrapper)
target_link_libraries(ovpncliwrapper openvpn_headers)



add_executable(ovpncli cli.cpp)
add_executable(ovpncli ${OVPNCLI_SOURCES})
target_compile_definitions(ovpncli PRIVATE)
target_link_libraries(ovpncli xkey)
target_link_libraries(ovpncli ${OVPNCLI_LIBS})

add_core_dependencies(ovpncli)

if (${CLI_NULLTUN})
add_executable(ovpnclinull cli.cpp)
add_executable(ovpnclinull ${OVPNCLI_SOURCES})
add_core_dependencies(ovpnclinull)
target_compile_definitions(ovpnclinull PRIVATE -DOPENVPN_FORCE_TUN_NULL)
target_link_libraries(ovpnclinull xkey)
target_link_libraries(ovpnclinull ${OVPNCLI_LIBS})
endif ()

if (${CLI_KOVPN})
add_executable(ovpnclikovpn cli.cpp)
add_executable(ovpnclikovpn ${OVPNCLI_SOURCES})
add_core_dependencies(ovpnclikovpn)
target_link_libraries(ovpnclikovpn xkey)
target_link_libraries(ovpnclikovpn ${OVPNCLI_LIBS})

target_compile_definitions(ovpnclikovpn PRIVATE -DENABLE_KOVPN
-DOPENVPN_REMOTE_OVERRIDE -DPRIVATE_TUNNEL_PROXY)
Expand All @@ -55,10 +76,10 @@ if (${CLI_OVPNDCO})
endif()

if (WIN32)
add_executable(ovpncliagent cli.cpp)
add_executable(ovpncliagent ${OVPNCLI_SOURCES})
add_core_dependencies(ovpncliagent)
add_json_library(ovpncliagent)
target_link_libraries(ovpncliagent xkey)
target_link_libraries(ovpncliagent ${OVPNCLI_LIBS})
target_compile_definitions(ovpncliagent PRIVATE OPENVPN_COMMAND_AGENT
OVPNAGENT_DISABLE_PATH_CHECK)

Expand All @@ -71,8 +92,8 @@ if (WIN32)
endif ()

if (APPLE)
add_executable(ovpncliagent cli.cpp)
target_link_libraries(xkey)
add_executable(ovpncliagent ${OVPNCLI_SOURCES})
target_link_libraries(ovpncliagent ${OVPNCLI_LIBS})
add_core_dependencies(ovpncliagent)
add_json_library(ovpncliagent)
target_compile_definitions(ovpncliagent PRIVATE -DOPENVPN_COMMAND_AGENT)
Expand Down
4 changes: 4 additions & 0 deletions test/ovpncli/include/ovpncli.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once
#include <string>

int openvpn_client(int argc, char *argv[], const std::string *profile_content);
30 changes: 30 additions & 0 deletions test/ovpncli/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "ovpncli.hpp"
#include <iostream>

#ifndef OPENVPN_OVPNCLI_OMIT_MAIN

int main(int argc, char *argv[])
{
int ret = 0;

#ifdef OPENVPN_LOG_LOGBASE_H
LogBaseSimple log;
#endif

#if defined(OPENVPN_PLATFORM_WIN)
SetConsoleOutputCP(CP_UTF8);
#endif

try
{
ret = openvpn_client(argc, argv, nullptr);
}
catch (const std::exception &e)
{
std::cout << "Main thread exception: " << e.what() << std::endl;
ret = 1;
}
return ret;
}

#endif
31 changes: 3 additions & 28 deletions test/ovpncli/cli.cpp → test/ovpncli/src/ovpncli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#endif

// don't export core symbols
#define OPENVPN_CORE_API_VISIBILITY_HIDDEN
// #define OPENVPN_CORE_API_VISIBILITY_HIDDEN

// use SITNL on Linux by default
#if defined(OPENVPN_PLATFORM_LINUX) && !defined(OPENVPN_USE_IPROUTE2) && !defined(OPENVPN_USE_SITNL)
Expand All @@ -65,6 +65,8 @@
#include <openvpn/common/argv.hpp>
#include <openvpn/common/process.hpp>

#include "ovpncli.hpp"

#ifdef OPENVPN_REMOTE_OVERRIDE
#include <openvpn/common/process.hpp>
#endif
Expand Down Expand Up @@ -1634,30 +1636,3 @@ int openvpn_client(int argc, char *argv[], const std::string *profile_content)
return ret;
}

#ifndef OPENVPN_OVPNCLI_OMIT_MAIN

int main(int argc, char *argv[])
{
int ret = 0;

#ifdef OPENVPN_LOG_LOGBASE_H
LogBaseSimple log;
#endif

#if defined(OPENVPN_PLATFORM_WIN)
SetConsoleOutputCP(CP_UTF8);
#endif

try
{
ret = openvpn_client(argc, argv, nullptr);
}
catch (const std::exception &e)
{
std::cout << "Main thread exception: " << e.what() << std::endl;
ret = 1;
}
return ret;
}

#endif