2018-07-06 04:09:48 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2018-05-02 21:40:01 +02:00
|
|
|
#
|
2023-03-21 15:41:11 +01:00
|
|
|
# Copyright © 2017-2023 WireGuard LLC. All Rights Reserved.
|
2018-05-02 21:40:01 +02:00
|
|
|
|
2017-12-05 03:50:36 +01:00
|
|
|
cmake_minimum_required(VERSION 3.4.1)
|
2021-01-23 10:10:39 +01:00
|
|
|
project("WireGuard")
|
2017-12-05 03:50:36 +01:00
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
|
2023-04-04 14:20:02 +02:00
|
|
|
add_link_options(LINKER:--build-id=none)
|
2023-04-11 16:23:37 +02:00
|
|
|
add_compile_options(-Wall -Werror)
|
2017-12-05 03:50:36 +01:00
|
|
|
|
2019-12-26 14:21:40 +01:00
|
|
|
add_executable(libwg-quick.so wireguard-tools/src/wg-quick/android.c ndk-compat/compat.c)
|
2023-04-11 16:23:37 +02:00
|
|
|
target_compile_options(libwg-quick.so PUBLIC -std=gnu11 -include ${CMAKE_CURRENT_SOURCE_DIR}/ndk-compat/compat.h -DWG_PACKAGE_NAME=\"${ANDROID_PACKAGE_NAME}\")
|
2019-10-04 16:58:58 +02:00
|
|
|
target_link_libraries(libwg-quick.so -ldl)
|
2017-12-05 03:50:36 +01:00
|
|
|
|
2020-02-03 17:09:45 +01:00
|
|
|
file(GLOB WG_SOURCES wireguard-tools/src/*.c ndk-compat/compat.c)
|
2017-12-05 03:50:36 +01:00
|
|
|
add_executable(libwg.so ${WG_SOURCES})
|
2020-06-07 09:52:21 +02:00
|
|
|
target_include_directories(libwg.so PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/wireguard-tools/src/uapi/linux/" "${CMAKE_CURRENT_SOURCE_DIR}/wireguard-tools/src/")
|
2023-04-11 16:23:37 +02:00
|
|
|
target_compile_options(libwg.so PUBLIC -std=gnu11 -include ${CMAKE_CURRENT_SOURCE_DIR}/ndk-compat/compat.h -DRUNSTATEDIR=\"/data/data/${ANDROID_PACKAGE_NAME}/cache\")
|
2018-02-07 19:19:20 +01:00
|
|
|
|
2023-03-28 18:31:19 +02:00
|
|
|
add_custom_target(libwg-go.so WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libwg-go" COMMENT "Building wireguard-go" VERBATIM COMMAND "${ANDROID_HOST_PREBUILTS}/bin/make"
|
2018-02-07 19:19:20 +01:00
|
|
|
ANDROID_ARCH_NAME=${ANDROID_ARCH_NAME}
|
2018-07-24 14:53:43 +02:00
|
|
|
ANDROID_PACKAGE_NAME=${ANDROID_PACKAGE_NAME}
|
2020-03-29 10:28:41 +02:00
|
|
|
GRADLE_USER_HOME=${GRADLE_USER_HOME}
|
2023-03-21 16:51:18 +01:00
|
|
|
CC=${CMAKE_C_COMPILER}
|
|
|
|
CFLAGS=${CMAKE_C_FLAGS}
|
|
|
|
LDFLAGS=${CMAKE_SHARED_LINKER_FLAGS}
|
|
|
|
SYSROOT=${CMAKE_SYSROOT}
|
|
|
|
TARGET=${CMAKE_C_COMPILER_TARGET}
|
2018-02-07 19:19:20 +01:00
|
|
|
DESTDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
|
2018-10-09 18:26:21 +02:00
|
|
|
BUILDDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../generated-src
|
2018-02-07 19:19:20 +01:00
|
|
|
)
|
2023-04-05 02:39:44 +02:00
|
|
|
|
|
|
|
# Strip unwanted ELF sections to prevent DT_FLAGS_1 warnings on old Android versions
|
|
|
|
file(GLOB ELF_CLEANER_SOURCES elf-cleaner/*.c elf-cleaner/*.cpp)
|
2023-04-21 15:43:25 +02:00
|
|
|
add_custom_target(elf-cleaner COMMENT "Building elf-cleaner" VERBATIM COMMAND cc
|
2023-04-05 02:39:44 +02:00
|
|
|
-O2 -DPACKAGE_NAME="elf-cleaner" -DPACKAGE_VERSION="" -DCOPYRIGHT=""
|
|
|
|
-o "${CMAKE_CURRENT_BINARY_DIR}/elf-cleaner" ${ELF_CLEANER_SOURCES}
|
|
|
|
)
|
|
|
|
add_custom_command(TARGET libwg.so POST_BUILD VERBATIM COMMAND "${CMAKE_CURRENT_BINARY_DIR}/elf-cleaner"
|
|
|
|
--api-level "${ANDROID_NATIVE_API_LEVEL}" "$<TARGET_FILE:libwg.so>")
|
|
|
|
add_dependencies(libwg.so elf-cleaner)
|
|
|
|
add_custom_command(TARGET libwg-quick.so POST_BUILD VERBATIM COMMAND "${CMAKE_CURRENT_BINARY_DIR}/elf-cleaner"
|
|
|
|
--api-level "${ANDROID_NATIVE_API_LEVEL}" "$<TARGET_FILE:libwg-quick.so>")
|
|
|
|
add_dependencies(libwg-quick.so elf-cleaner)
|