From 8dccab24055a71184bc851d31cb7c26a6d21b5ef Mon Sep 17 00:00:00 2001 From: Doominika Date: Mon, 24 Feb 2025 13:03:46 +0100 Subject: [PATCH 1/6] chore: prepare files to compile native libraries using conan. --- privmx-endpoint/src/main/cpp/CMakeLists.txt | 114 +++----------------- privmx-endpoint/src/main/cpp/conanfile.txt | 9 ++ 2 files changed, 21 insertions(+), 102 deletions(-) create mode 100644 privmx-endpoint/src/main/cpp/conanfile.txt diff --git a/privmx-endpoint/src/main/cpp/CMakeLists.txt b/privmx-endpoint/src/main/cpp/CMakeLists.txt index 2f033738..f3891685 100644 --- a/privmx-endpoint/src/main/cpp/CMakeLists.txt +++ b/privmx-endpoint/src/main/cpp/CMakeLists.txt @@ -1,97 +1,8 @@ -# For more information about using CMake with Android Studio, read the -# documentation: https://d.android.com/studio/projects/add-native-code.html. -# For more examples on how to use CMake, see https://github.com/android/ndk-samples. - -# Sets the minimum CMake version required for this project. -cmake_minimum_required(VERSION 3.22.1) - -# Declares the project name. The project name can be accessed via ${ PROJECT_NAME}, -# Since this is the top level CMakeLists.txt, the project name is also accessible -# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level -# build script scope). +cmake_minimum_required(VERSION 3.15) project("privmx-endpoint-java") +set(CMAKE_CXX_STANDARD 17) -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s") - -if( NOT DEFINED CMAKE_DESTINATION_OS ) - set(CMAKE_DESTINATION_OS ${CMAKE_SYSTEM_NAME}) -endif () - -if( NOT DEFINED CMAKE_DESTINATION_ARCHITECTURE) - if(CMAKE_DESTINATION_OS STREQUAL "Android" AND DEFINED CMAKE_ANDROID_ARCH_ABI) - set(CMAKE_DESTINATION_ARCHITECTURE ${CMAKE_ANDROID_ARCH_ABI}) - else() - set(CMAKE_DESTINATION_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) - endif () -endif() - -if("${CMAKE_DESTINATION_OS}" STREQUAL "Darwin") - set(file_extension "dylib") - set(CMAKE_MACOSX_RPATH 1) - set(CMAKE_INSTALL_RPATH "@loader_path") -elseif ("${CMAKE_DESTINATION_OS}" STREQUAL "Windows") - set(file_extension "dll") -else () - set(file_extension "so") -endif () - -message(DEBUG "CMAKE DEST OS ${CMAKE_DESTINATION_OS}") -message(DEBUG "CMAKE DEST PROCESSOR ${CMAKE_DESTINATION_ARCHITECTURE}") - -add_library(ssl SHARED IMPORTED GLOBAL) -set_target_properties(ssl PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libssl.${file_extension}) - -add_library(crypto SHARED IMPORTED GLOBAL) -set_target_properties(crypto PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libcrypto.${file_extension}) - -add_library(gmp SHARED IMPORTED GLOBAL) -set_target_properties(gmp PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libgmp.${file_extension}) - -add_library(PocoFoundation SHARED IMPORTED GLOBAL) -set_target_properties(PocoFoundation PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoFoundation.${file_extension}) - -add_library(PocoJSON SHARED IMPORTED GLOBAL) -set_target_properties(PocoJSON PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoJSON.${file_extension}) - -add_library(PocoNet SHARED IMPORTED GLOBAL) -set_target_properties(PocoNet PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoNet.${file_extension}) - -add_library(PocoCrypto SHARED IMPORTED GLOBAL) -set_target_properties(PocoCrypto PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoCrypto.${file_extension}) - -add_library(PocoXML SHARED IMPORTED GLOBAL) -set_target_properties(PocoXML PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoXML.${file_extension}) - -add_library(PocoNetSSL SHARED IMPORTED GLOBAL) -set_target_properties(PocoNetSSL PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoNetSSL.${file_extension}) - -add_library(PocoUtil SHARED IMPORTED GLOBAL) -set_target_properties(PocoUtil PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoUtil.${file_extension}) - -add_library(Pson SHARED IMPORTED GLOBAL) -set_target_properties(Pson PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPson.${file_extension}) - -add_library(libprivmx SHARED IMPORTED GLOBAL) -set_target_properties(libprivmx PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmx.${file_extension}) - -add_library(privmxendpointcore SHARED IMPORTED GLOBAL) -set_target_properties(privmxendpointcore PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmxendpointcore.${file_extension}) - -add_library(privmxendpointcrypto SHARED IMPORTED GLOBAL) -set_target_properties(privmxendpointcrypto PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmxendpointcrypto.${file_extension}) - -add_library(privmxendpointstore SHARED IMPORTED GLOBAL) -set_target_properties(privmxendpointstore PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmxendpointstore.${file_extension}) - -add_library(privmxendpointthread SHARED IMPORTED GLOBAL) -set_target_properties(privmxendpointthread PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmxendpointthread.${file_extension}) - -add_library(privmxendpointinbox SHARED IMPORTED GLOBAL) -set_target_properties(privmxendpointinbox PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmxendpointinbox.${file_extension}) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/include ${JAVA_HOME}/include ${JAVA_HOME}/include/darwin) - +find_package(privmxendpoint REQUIRED) add_library(${CMAKE_PROJECT_NAME} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/parser.cpp ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp @@ -106,13 +17,12 @@ add_library(${CMAKE_PROJECT_NAME} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/modules/BackendRequester.cpp ) -# Android Debugging -#find_library( log-lib log ) -#target_link_libraries(${CMAKE_PROJECT_NAME} ${log-lib} ${log}) -target_link_libraries(${CMAKE_PROJECT_NAME} ssl crypto) -target_link_libraries(${CMAKE_PROJECT_NAME} gmp) -target_link_libraries(${CMAKE_PROJECT_NAME} PocoFoundation PocoXML PocoJSON PocoNet PocoNetSSL PocoUtil PocoCrypto) -target_link_libraries(${CMAKE_PROJECT_NAME} Pson libprivmx privmxendpointcore privmxendpointcrypto privmxendpointstore privmxendpointthread privmxendpointinbox) -message(DEBUG "Install to ${CMAKE_INSTALL_PREFIX}") -install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}) -install(IMPORTED_RUNTIME_ARTIFACTS crypto ssl gmp PocoFoundation PocoXML PocoJSON PocoNet PocoNetSSL PocoUtil PocoCrypto Pson libprivmx privmxendpointcore privmxendpointcrypto privmxendpointstore privmxendpointthread privmxendpointinbox DESTINATION ${CMAKE_INSTALL_PREFIX}) \ No newline at end of file +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/include ${JAVA_HOME}/include ${JAVA_HOME}/include/darwin) + +target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC + privmxendpoint::privmxendpointcore + privmxendpoint::privmxendpointstore + privmxendpoint::privmxendpointinbox + privmxendpoint::privmxendpointthread + privmxendpoint::privmxendpointcrypto +) diff --git a/privmx-endpoint/src/main/cpp/conanfile.txt b/privmx-endpoint/src/main/cpp/conanfile.txt new file mode 100644 index 00000000..ad310c9c --- /dev/null +++ b/privmx-endpoint/src/main/cpp/conanfile.txt @@ -0,0 +1,9 @@ +[requires] +privmx-endpoint/2.2.2 + +[generators] +CMakeDeps +CMakeToolchain + +[layout] +cmake_layout \ No newline at end of file From 7a116ee6869a9a659b4389be64f9ace5b2fc0041 Mon Sep 17 00:00:00 2001 From: Doominika Date: Mon, 24 Feb 2025 15:46:24 +0100 Subject: [PATCH 2/6] test --- settings.gradle | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/settings.gradle b/settings.gradle index 92e34452..e96f93c6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,17 +16,21 @@ plugins { } dependencyResolutionManagement { + def props = new Properties() + file("./local.properties").withInputStream { props.load(it) } repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() + maven { + url = uri(props.repositoryURL) + } } } -rootProject.name = "PrivmxEndpoint" +rootProject.name = "PrivmxEndpointBuildScripts" include ':privmx-endpoint' include ':privmx-endpoint-extra' include ':privmx-endpoint-android' include ':privmx-endpoint-jni' -include ':examples:privmx-snippets' project(':privmx-endpoint-jni').projectDir = file("privmx-endpoint/src/main/cpp") \ No newline at end of file From ae6a3f11f451f5bb19ec47bca068594f8f811f63 Mon Sep 17 00:00:00 2001 From: Doominika Date: Tue, 25 Feb 2025 17:16:17 +0100 Subject: [PATCH 3/6] chore: add including JAVA_HOME directory in CMakeLists.txt for linux compilation --- privmx-endpoint/src/main/cpp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/privmx-endpoint/src/main/cpp/CMakeLists.txt b/privmx-endpoint/src/main/cpp/CMakeLists.txt index f3891685..74a9a864 100644 --- a/privmx-endpoint/src/main/cpp/CMakeLists.txt +++ b/privmx-endpoint/src/main/cpp/CMakeLists.txt @@ -17,7 +17,7 @@ add_library(${CMAKE_PROJECT_NAME} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/modules/BackendRequester.cpp ) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/include ${JAVA_HOME}/include ${JAVA_HOME}/include/darwin) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/include ${JAVA_HOME}/include ${JAVA_HOME}/include/linux ${JAVA_HOME}/include/darwin) target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC privmxendpoint::privmxendpointcore From 89a7a963339ca4a7d71fcba137a6c0c0f095fcb9 Mon Sep 17 00:00:00 2001 From: Doominika Date: Wed, 26 Feb 2025 11:14:34 +0100 Subject: [PATCH 4/6] fix: restore proper settings.gradle --- settings.gradle | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/settings.gradle b/settings.gradle index e96f93c6..067dba7a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,19 +16,14 @@ plugins { } dependencyResolutionManagement { - def props = new Properties() - file("./local.properties").withInputStream { props.load(it) } repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() - maven { - url = uri(props.repositoryURL) - } } } -rootProject.name = "PrivmxEndpointBuildScripts" +rootProject.name = "PrivmxEndpointJava" include ':privmx-endpoint' include ':privmx-endpoint-extra' include ':privmx-endpoint-android' From 83f5462fe51cbe53a929a5fd63cd9247d75e3834 Mon Sep 17 00:00:00 2001 From: Doominika Date: Wed, 26 Feb 2025 11:23:11 +0100 Subject: [PATCH 5/6] chore: set JAVA_HOME default value as user environment variable. --- privmx-endpoint/src/main/cpp/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/privmx-endpoint/src/main/cpp/CMakeLists.txt b/privmx-endpoint/src/main/cpp/CMakeLists.txt index 74a9a864..937ee06a 100644 --- a/privmx-endpoint/src/main/cpp/CMakeLists.txt +++ b/privmx-endpoint/src/main/cpp/CMakeLists.txt @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.15) project("privmx-endpoint-java") set(CMAKE_CXX_STANDARD 17) +if ("${JAVA_HOME}" STREQUAL "") + SET(JAVA_HOME "$ENV{JAVA_HOME}") +endif () + find_package(privmxendpoint REQUIRED) add_library(${CMAKE_PROJECT_NAME} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/parser.cpp From e2bb3baeeea18198b014509f5c1f90c916744485 Mon Sep 17 00:00:00 2001 From: Doominika Date: Fri, 28 Feb 2025 12:18:11 +0100 Subject: [PATCH 6/6] chore: update privmx-endpoint version 2.2.4 in conanfile.txt --- privmx-endpoint/src/main/cpp/conanfile.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/privmx-endpoint/src/main/cpp/conanfile.txt b/privmx-endpoint/src/main/cpp/conanfile.txt index ad310c9c..0f247d5c 100644 --- a/privmx-endpoint/src/main/cpp/conanfile.txt +++ b/privmx-endpoint/src/main/cpp/conanfile.txt @@ -1,5 +1,5 @@ [requires] -privmx-endpoint/2.2.2 +privmx-endpoint/2.2.4 [generators] CMakeDeps