0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 04:02:15 +02:00

client: Switch to UseSWIG instead of manual custom command

On modern CMake this gets us swig dependency management,
which should reduce problems for incremental builds.
Also it is just cleaner.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
This commit is contained in:
Frank Lichtenheld 2023-10-13 13:31:13 +02:00 committed by David Sommerseth
parent cb06f9e330
commit 72275db1d5
No known key found for this signature in database
GPG Key ID: 86CF944C9671FDF2
3 changed files with 20 additions and 17 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0048 NEW) cmake_policy(SET CMP0048 NEW)
project(OpenVPN3-core VERSION 3) project(OpenVPN3-core VERSION 3)

View File

@ -1,19 +1,21 @@
include(findcoredeps) include(findcoredeps)
include(findswigdeps) include(findswigdeps)
if (${BUILD_SWIG_LIB}) if (BUILD_SWIG_LIB)
add_custom_command( set_property(SOURCE ovpncli.i PROPERTY CPLUSPLUS ON)
OUTPUT ovpncli_wrap.cxx ovpncli_wrap.h if (NOT MSVC)
COMMENT "Generating ovpncli Python swig files" # Swig generates code with deprecated python declarations
COMMAND ${SWIG_EXECUTABLE} -c++ -python -threads -DSWIG_PYTHON_2_UNICODE -outcurrentdir -I${CORE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/ovpncli.i set_property(SOURCE ovpncli.i PROPERTY GENERATED_COMPILE_OPTIONS -Wno-deprecated-declarations -Wno-sometimes-uninitialized -Wno-class-memaccess -Wno-unknown-warning-option)
DEPENDS ovpncli.i endif()
)
add_library(ovpnclilib SHARED swig_add_library(ovpnclilib
ovpncli.cpp TYPE SHARED
ovpncli_wrap.cxx LANGUAGE python
ovpncli_wrap.h SOURCES ovpncli.cpp ovpncli.i
) )
set_property(TARGET ovpnclilib PROPERTY SWIG_COMPILE_DEFINITIONS SWIG_PYTHON_2_UNICODE)
set_property(TARGET ovpnclilib PROPERTY SWIG_COMPILE_OPTIONS -threads)
set_property(TARGET ovpnclilib PROPERTY SWIG_INCLUDE_DIRECTORIES ${CORE_DIR})
add_core_dependencies(ovpnclilib) add_core_dependencies(ovpnclilib)
target_link_libraries(ovpnclilib ${Python3_LIBRARIES}) target_link_libraries(ovpnclilib ${Python3_LIBRARIES})
@ -23,8 +25,4 @@ if (${BUILD_SWIG_LIB})
set_target_properties(ovpnclilib PROPERTIES OUTPUT_NAME "_ovpncli") set_target_properties(ovpnclilib PROPERTIES OUTPUT_NAME "_ovpncli")
set_target_properties(ovpnclilib PROPERTIES PREFIX "") set_target_properties(ovpnclilib PROPERTIES PREFIX "")
if (NOT WIN32)
# Swig generates code with deprecated python declarations
set_source_files_properties(ovpncli_wrap.cxx PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-sometimes-uninitialized -Wno-class-memaccess -Wno-unknown-warning-option")
endif()
endif () endif ()

View File

@ -2,6 +2,11 @@ find_package(Python3 COMPONENTS Interpreter Development)
FIND_PACKAGE(SWIG 3.0) FIND_PACKAGE(SWIG 3.0)
include(UseSWIG)
if (CMAKE_VERSION VERSION_GREATER "3.20")
set(SWIG_USE_SWIG_DEPENDENCIES TRUE)
endif()
# We test building this library with python instead of java since that is easier to do and both languages should work # We test building this library with python instead of java since that is easier to do and both languages should work
if (Python3_Development_FOUND AND SWIG_FOUND) if (Python3_Development_FOUND AND SWIG_FOUND)