@@ -9,6 +9,8 @@ project(runner LANGUAGES CXX)
99add_executable (${BINARY_NAME}
1010 "main.cc"
1111 "my_application.cc"
12+ "defyx_core.cpp"
13+ "defyx_linux_plugin.cc"
1214 "${FLUTTER_MANAGED_DIR} /generated_plugin_registrant.cc"
1315)
1416
@@ -22,5 +24,96 @@ add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
2224# Add dependency libraries. Add any application-specific dependencies here.
2325target_link_libraries (${BINARY_NAME} PRIVATE flutter )
2426target_link_libraries (${BINARY_NAME} PRIVATE PkgConfig::GTK )
27+ target_link_libraries (${BINARY_NAME} PRIVATE dl )
2528
2629target_include_directories (${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR} " )
30+
31+ # --- DXcore native library build and packaging --------------------------------
32+
33+ # Allow overriding the DXcore source directory and built library via env vars.
34+ if (NOT DEFYX_DXCORE_DIR AND DEFINED ENV{DEFYX_DXCORE_DIR})
35+ set (DEFYX_DXCORE_DIR "$ENV{DEFYX_DXCORE_DIR} " )
36+ endif ()
37+ if (NOT DEFYX_DXCORE_LIB AND DEFINED ENV{DEFYX_DXCORE_LIB})
38+ set (DEFYX_DXCORE_LIB "$ENV{DEFYX_DXCORE_LIB} " )
39+ endif ()
40+
41+ get_filename_component (_runner_dir "${CMAKE_CURRENT_SOURCE_DIR} " ABSOLUTE )
42+
43+ set (_dxcore_source_candidates "" )
44+ if (DEFYX_DXCORE_LIB)
45+ get_filename_component (_override_lib "${DEFYX_DXCORE_LIB} " ABSOLUTE )
46+ list (APPEND _dxcore_source_candidates "${_override_lib} " )
47+ endif ()
48+
49+ set (_runner_local_lib "${_runner_dir} /libDXcore.so" )
50+ list (APPEND _dxcore_source_candidates "${_runner_local_lib} " )
51+
52+ if (DEFYX_DXCORE_DIR)
53+ get_filename_component (_dxcore_root "${DEFYX_DXCORE_DIR} " ABSOLUTE )
54+ else ()
55+ get_filename_component (_dxcore_root "${_runner_dir} /../../../DXcore-private" ABSOLUTE )
56+ endif ()
57+
58+ set (_dxcore_repo_lib "${_dxcore_root} /libDXcore.so" )
59+ list (APPEND _dxcore_source_candidates "${_dxcore_repo_lib} " )
60+
61+ set (_dxcore_source "" )
62+ foreach (candidate IN LISTS _dxcore_source_candidates)
63+ if (EXISTS "${candidate} " )
64+ set (_dxcore_source "${candidate} " )
65+ break ()
66+ endif ()
67+ endforeach ()
68+
69+ set (_have_dxcore_lib FALSE )
70+
71+ find_program (GO_EXECUTABLE go )
72+ if (NOT _dxcore_source AND GO_EXECUTABLE AND EXISTS "${_dxcore_root} " )
73+ set (_dxcore_source "${_dxcore_repo_lib} " )
74+ add_custom_target (dxcore_shared_lib
75+ COMMAND ${CMAKE_COMMAND} -E env GO111MODULE=on ${GO_EXECUTABLE} build -buildmode=c-shared -o "${_dxcore_source} " ./DXcore/linux
76+ WORKING_DIRECTORY "${_dxcore_root} "
77+ COMMENT "Building libDXcore.so via Go"
78+ VERBATIM
79+ )
80+ add_dependencies (${BINARY_NAME} dxcore_shared_lib )
81+ elseif (NOT _dxcore_source)
82+ if (NOT GO_EXECUTABLE)
83+ message (WARNING "Go executable not found; libDXcore.so will not be rebuilt automatically." )
84+ elseif (NOT EXISTS "${_dxcore_root} " )
85+ message (WARNING "DXcore source directory '${_dxcore_root} ' is missing; libDXcore.so cannot be rebuilt." )
86+ endif ()
87+ endif ()
88+
89+ if (_dxcore_source)
90+ set (_have_dxcore_lib TRUE )
91+ endif ()
92+
93+ if (_have_dxcore_lib)
94+ set (DEFYX_DXCORE_LIB_SOURCE "${_dxcore_source} " PARENT_SCOPE )
95+ set (DEFYX_DXCORE_LIB_NAME "libDXcore.so" PARENT_SCOPE )
96+ endif ()
97+
98+ if (NOT PROJECT_BUILD_DIR)
99+ set (PROJECT_BUILD_DIR "${PROJECT_DIR} /build/" )
100+ endif ()
101+
102+ set (_bundle_config "${CMAKE_BUILD_TYPE} " )
103+ if ("${_bundle_config} " STREQUAL "" )
104+ set (_bundle_config "Debug" )
105+ endif ()
106+ string (TOLOWER "${_bundle_config} " _bundle_config_lower)
107+ set (_bundle_dir "${PROJECT_BUILD_DIR} linux/x64/${_bundle_config_lower} /bundle" )
108+
109+ if (_have_dxcore_lib)
110+ add_custom_command (TARGET ${BINARY_NAME} POST_BUILD
111+ COMMAND ${CMAKE_COMMAND} -E make_directory "${_bundle_dir} "
112+ COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_dxcore_source} " "${_bundle_dir} /libDXcore.so"
113+ COMMAND ${CMAKE_COMMAND} -E make_directory "${_bundle_dir} /lib"
114+ COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_dxcore_source} " "${_bundle_dir} /lib/libDXcore.so"
115+ COMMENT "Copying libDXcore.so into Flutter Linux bundle (${_bundle_config_lower} )"
116+ )
117+ else ()
118+ message (WARNING "libDXcore.so not found and cannot be built; VPN core will be unavailable in the Linux build." )
119+ endif ()
0 commit comments