]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Add (fake) Android cmake building
authorArne Schwabe <arne@rfc2549.org>
Fri, 14 Feb 2025 12:52:38 +0000 (13:52 +0100)
committerGert Doering <gert@greenie.muc.de>
Fri, 14 Feb 2025 12:59:32 +0000 (13:59 +0100)
There is a mode to build with a real Android NDK that requires setting
up cmake to build with the NDK and so.
For quick&dirty compile tests that do not actually use the Android NDK
on Linux, -DFAKE_ANDROID on Linux can be used to compile a binary using
TARGET_ANDROID.

Change-Id: If6afa1108f9234f98afdbe0de7b7320403871772
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Message-Id: <20250214125238.17558-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30885.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
CMakeLists.txt
config.h.cmake.in

index 5081e8188d593f25bc19c4f9f1d68aa0265a4731..b04adced24359d318e10fc7fbbe94d0327fd5e81 100644 (file)
@@ -39,6 +39,7 @@ option(ENABLE_LZ4 "BUILD with lz4" ON)
 option(ENABLE_LZO "BUILD with lzo" ON)
 option(ENABLE_PKCS11 "BUILD with pkcs11-helper" ON)
 option(USE_WERROR "Treat compiler warnings as errors (-Werror)" ON)
+option(FAKE_ANDROID "Target Android but do not use actual cross compile/Android cmake to build for simple compile checks on Linux")
 
 set(PLUGIN_DIR /usr/local/lib/openvpn/plugins CACHE FILEPATH "Location of the plugin directory")
 
@@ -122,7 +123,14 @@ set(OPENVPN_VERSION_RESOURCE ${PRODUCT_VERSION_RESOURCE})
 set(CMAKE_C_STANDARD 11)
 
 # Set the various defines for config.h.cmake.in
-if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+if (${CMAKE_SYSTEM_NAME} STREQUAL "Android" OR ${FAKE_ANDROID})
+    set(TARGET_ANDROID YES)
+    set(ENABLE_ASYNC_PUSH YES)
+    set(ENABLE_SITNL YES)
+    set(HAVE_LINUX_TYPES_H 1)
+    # Wacky workaround as OpenSSL package detection is otherwise broken (https://stackoverflow.com/questions/45958214/android-cmake-could-not-find-openssl)
+    list(APPEND CMAKE_FIND_ROOT_PATH ${OPENSSL_ROOT_DIR})
+elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
     set(TARGET_LINUX YES)
     set(ENABLE_ASYNC_PUSH YES)
     set(ENABLE_LINUXDCO YES)
index 74a53a6a11d4915ffd06be010f8a245d65b66998..2f7b43d227cb8368676f892586e88b06a9e16e8f 100644 (file)
@@ -432,6 +432,9 @@ don't. */
 /* Are we running WIN32? */
 #cmakedefine TARGET_WIN32
 
+/* Are we targeting Android? */
+#cmakedefine TARGET_ANDROID
+
 #define TARGET_ALIAS "@CMAKE_SYSTEM_NAME@"
 
 /* Enable GNU extensions on systems that have them.  */