openvpn3 icon indicating copy to clipboard operation
openvpn3 copied to clipboard

How to include as library on CMakeLists?

Open 0rangeFox opened this issue 3 years ago • 1 comments

Hey folks 👋, I hope all is well with you guys, I have a question here, I don't have much knowledge about CMake. So my plan is as follows, I want to develop an application with the Qt 6 framework and OpenVPN 3 as the library for VPN connections. I'll put here my CMakeLists, I did git clone of this repository and add_subdirectory on the folder I just cloned and CMake doesn't give any error, it just says I don't have SWIG. In the target_link_libraries, I wrote OpenVPN3-core because that is the name of the project that is in the CMakeLists of the file I just cloned, I think this is how it is. Any kind of help is appreciated, thanks for your time!

cmake_minimum_required(VERSION 3.21)

project(SaphirexVPN CXX)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.c src/*.cpp src/*.hpp src/*.h)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

add_executable(${PROJECT_NAME} ${SOURCES})

# ##############################################################################

find_package(Qt6 COMPONENTS
    Core
    Gui
    Widgets
REQUIRED)

add_subdirectory(libraries/openvpn3)

target_link_libraries(${PROJECT_NAME} PRIVATE
    OpenVPN3-core
    Qt::Core
    Qt::Gui
    Qt::Widgets
)

# ##############################################################################

if (WIN32)
    target_compile_definitions(${PROJECT_NAME} PRIVATE -DTAP_WIN_COMPONENT_ID=tap0901)
endif (WIN32)

0rangeFox avatar Sep 21 '22 13:09 0rangeFox

You probably should not use swig with QT. The cmake files of openvpn3 are really really designed to give you a library to link against. The library is also header only. So basically add the include to your files and add the dependencies to your cmake file. Examples of building openvpn3 in a project are ics-openvpn (https://github.com/schwabe/ics-openvpn/blob/master/main/src/main/cpp/CMakeLists.txt) and openvpn3-linux (https://github.com/OpenVPN/openvpn3-linux/blob/master/contrib/cmake-clion/CMakeLists.txt). Note I wrote the openvpn3-linux a few years ago and it probably is not working anymore.

schwabe avatar Sep 21 '22 15:09 schwabe

By chance before I created this issue I was already looking at your repositories and it was from there that I was able to slowly work my way through this part. But thanks for your suggestion. Happy programming!

0rangeFox avatar Sep 22 '22 11:09 0rangeFox

@0rangeFox please share your implementation of the cmake file when you are done, so others might have another implementation to look at!

schwabe avatar Sep 22 '22 12:09 schwabe

For sure, when I get some success, I will create a template repository for people to reuse and mention it here.

0rangeFox avatar Sep 22 '22 12:09 0rangeFox

Hey @schwabe, I have opened a new repository to serve as an example, but I am not having much success, so I would like to ask for help if it is possible (If you are reading this and you are interested in joining on this deployment, your ideology or help is very important to me, because then in the future we can clear up all the doubts in just one template for other guys who wants same thing). The repository already contains a very minimalistic base but I will add more content when it is possible to integrate the library.

If I delete the following code, add_subdirectory(libraries/openvpn3) and OpenVPN3-core and add the OpenSSL library (With find_package(OpenSSL REQUIRED) and OpenSSL::SSL on target_link_libraries) on the CMakeLists, it lets me use the library and perform their functions. But if I do it in reverse and leave the file as it is in the repository, I don't have access to the include of OpenSSL. I think it should have access because the CMakeLists of OpenVPN3 already includes the OpenSSL library (At least that's what I think).

https://github.com/OpenVPN/openvpn3/blob/0fae5639ac2a7ba0285c6737787017cf18375598/cmake/findcoredeps.cmake#L41-L43

At the CMakeLists part it's not my strong point, correct me if I'm wrong.

0rangeFox avatar Sep 22 '22 16:09 0rangeFox