diff --git a/native/android/app/CMakeLists.txt b/native/android/app/CMakeLists.txt index 0a7f3863a..3b6848bfe 100644 --- a/native/android/app/CMakeLists.txt +++ b/native/android/app/CMakeLists.txt @@ -1,240 +1,245 @@ # For more information about using CMake with Android Studio, read the # documentation: https://d.android.com/studio/projects/add-native-code.html project(comm CXX C) set(CMAKE_CXX_STANDARD 17) # C0103 is a naming convention, but the variable names which need to be set # are determined by the upstream project # cmake-lint: disable=C0103 # Disable line length as some paths are hard to reduce without becoming cryptic # cmake-lint: disable=C0301 # Sets the minimum version of CMake required to build the native library. cmake_minimum_required(VERSION 3.18) # Creates and names a library, sets it as either STATIC # or SHARED, and provides the relative paths to its source code. # You can define multiple libraries, and CMake builds them for you. # Gradle automatically packages shared libraries with your APK. set(PACKAGE_NAME "comm_jni_module") find_package(fbjni REQUIRED CONFIG) set(BUILD_TESTING OFF) set(HAVE_SYMBOLIZE OFF) set(WITH_GTEST OFF CACHE BOOL "Use googletest" FORCE) set(WITH_GFLAGS OFF CACHE BOOL "Use gflags" FORCE) # General set(_third_party_dir ${CMAKE_CURRENT_SOURCE_DIR}/build/third-party-ndk) set(_android_build_dir build/${CMAKE_ANDROID_ARCH_ABI}) include(FetchContent) if(CMAKE_ANDROID_ARCH_ABI STREQUAL arm64-v8a) set(Rust_CARGO_TARGET aarch64-linux-android) elseif(CMAKE_ANDROID_ARCH_ABI STREQUAL x86) set(Rust_CARGO_TARGET i686-linux-android) elseif(CMAKE_ANDROID_ARCH_ABI STREQUAL x86_64) set(Rust_CARGO_TARGET x86_64-linux-android) elseif(CMAKE_ANDROID_ARCH_ABI STREQUAL armeabi-v7a) set(Rust_CARGO_TARGET armv7-linux-androideabi) endif() string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} CMAKE_HOST_SYSTEM_NAME_LOWER) set(_toolchain_path "$ENV{ANDROID_HOME}/ndk/${NDK_VERSION}/toolchains/llvm/prebuilt/${CMAKE_HOST_SYSTEM_NAME_LOWER}-x86_64/bin" ) if(EXISTS "${_toolchain_path}/${Rust_CARGO_TARGET}-ar") set(AR "${_toolchain_path}/${Rust_CARGO_TARGET}-ar") else() set(AR "${_toolchain_path}/llvm-ar") endif() FetchContent_Declare( Corrosion GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git GIT_TAG v0.2.1 ) FetchContent_MakeAvailable(Corrosion) include(../../../shared/cmake/corrosion-cxx.cmake) add_library_rust(PATH ../../native_rust_library NAMESPACE comm) # We're updating parameters below for Cmake's find_OpenSSL() function set(OPENSSL_ROOT_DIR "${_third_party_dir}/openssl/openssl-${OPENSSL_VERSION}/${_android_build_dir}" ) list(APPEND CMAKE_FIND_ROOT_PATH "${OPENSSL_ROOT_DIR}") # Override HAVE_EXECINFO_H in glog's CMakeLists.txt if( CMAKE_ANDROID_ARCH_ABI STREQUAL arm64-v8a OR CMAKE_ANDROID_ARCH_ABI STREQUAL armeabi-v7a ) set(HAVE_EXECINFO_H OFF CACHE BOOL "Whether platform has execinfo.h") endif() add_subdirectory(${_third_party_dir}/glog/glog-${GLOG_VERSION}/) file(GLOB LIBRN_DIR "${REACT_NATIVE_SO_DIR}/${ANDROID_ABI}") if (NOT LIBRN_DIR) # If /${ANDROID_ABI} dir not found, then ${REACT_NATIVE_SO_DIR} is probably: # ReactAndroid/build/react-ndk/exported file(GLOB LIBRN_DIR "${REACT_NATIVE_SO_DIR}") endif () include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/folly-target.cmake) add_subdirectory(../../node_modules/olm ./build) set(_node_modules_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../node_modules) set(_react_native_dir ${_node_modules_dir}/react-native) +add_subdirectory(../../cpp/CommonCpp/ + ${CMAKE_CURRENT_BINARY_DIR}/build/CommonCpp + EXCLUDE_FROM_ALL +) + file(GLOB SQLCIPHER "${_node_modules_dir}/@commapp/sqlcipher-amalgamation/src/*.c" ) file(GLOB ANDROID_NATIVE_CODE "./src/cpp/*.cpp") set(GENERATED_NATIVE_CODE "../../cpp/CommonCpp/_generated/commJSI-generated.cpp") file(GLOB CRYPTO_NATIVE_CODE "../../cpp/CommonCpp/CryptoTools/*.cpp") file(GLOB DB_NATIVE_CODE "../../cpp/CommonCpp/DatabaseManagers/*.cpp") file(GLOB DB_ENTITIES_NATIVE_CODE "../../cpp/CommonCpp/DatabaseManagers/entities/*.cpp") file(GLOB_RECURSE MODULE_NATIVE_CODE "../../cpp/CommonCpp/NativeModules/**/*.cpp") file(GLOB MODULE_ROOT_NATIVE_CODE "../../cpp/CommonCpp/NativeModules/*.cpp") file(GLOB TOOLS_NATIVE_CODE "../../cpp/CommonCpp/Tools/*.cpp") add_library( # Sets the name of the library ${PACKAGE_NAME} # Sets the library as a shared library SHARED # React dependencies ${_react_native_dir}/ReactCommon/jsi/jsi/jsi.cpp ${_react_native_dir}/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon/CallInvokerHolder.cpp ${_react_native_dir}/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp ${_react_native_dir}/ReactCommon/react/bridging/LongLivedObject.cpp ${_react_native_dir}/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.cpp # Third party dependencies ${SQLCIPHER} # comm code ${ANDROID_NATIVE_CODE} ${GENERATED_NATIVE_CODE} ${CRYPTO_NATIVE_CODE} ${DB_NATIVE_CODE} ${DB_ENTITIES_NATIVE_CODE} ${MODULE_NATIVE_CODE} ${MODULE_ROOT_NATIVE_CODE} ${TOOLS_NATIVE_CODE} ) set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build) target_include_directories( ${PACKAGE_NAME} PRIVATE # React Native ${_react_native_dir}/React ${_react_native_dir}/React/Base ${_react_native_dir}/ReactCommon ${_react_native_dir}/ReactCommon/jsi ${_react_native_dir}/ReactCommon/callinvoker ${_react_native_dir}/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon # OpenSSL ${_third_party_dir}/openssl/openssl-${OPENSSL_VERSION}/build/${CMAKE_ANDROID_ARCH_ABI}/include # SQLCipher amalgamation ${_node_modules_dir}/@commapp/sqlcipher-amalgamation/src # SQLite ORM ../../cpp/third-party/sqlite_orm # symlinked React Native headers ../headers # comm android specific code ./src/cpp # comm native mutual code ../../cpp/CommonCpp/ ../../cpp/CommonCpp/NativeModules ../../cpp/CommonCpp/NativeModules/InternalModules ../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities ../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/ThreadOperationsUtilities ../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities ../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs ../../cpp/CommonCpp/DatabaseManagers ../../cpp/CommonCpp/Tools # native rust library ${native_rust_library_include_dir} ) add_definitions( # SQLCipher -DSQLITE_THREADSAFE=0 -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLCIPHER_CRYPTO_OPENSSL ) find_library(log-lib log) add_library( # OpenSSL Crypto lib openssl-crypto STATIC IMPORTED ) set_target_properties( # OpenSSL Crypto lib openssl-crypto PROPERTIES IMPORTED_LOCATION "${_third_party_dir}/openssl/openssl-${OPENSSL_VERSION}/build/${CMAKE_ANDROID_ARCH_ABI}/lib/libcrypto.a" ) add_library( # OpenSSL SSL lib openssl-ssl STATIC IMPORTED ) set_target_properties( # OpenSSL SSL lib openssl-ssl PROPERTIES IMPORTED_LOCATION "${_third_party_dir}/openssl/openssl-${OPENSSL_VERSION}/build/${CMAKE_ANDROID_ARCH_ABI}/lib/libssl.a" ) target_link_libraries( ${PACKAGE_NAME} fbjni::fbjni android ${log-lib} Folly::folly glog::glog olm openssl-crypto openssl-ssl comm::native_rust_library ) # add a dummy library which is required by CallInvokerHolderImpl.java add_library( turbomodulejsijni # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). ./src/cpp/dummy.cpp ) diff --git a/native/cpp/CommonCpp/CryptoTools/CMakeLists.txt b/native/cpp/CommonCpp/CryptoTools/CMakeLists.txt index 0b7483f69..825599459 100644 --- a/native/cpp/CommonCpp/CryptoTools/CMakeLists.txt +++ b/native/cpp/CommonCpp/CryptoTools/CMakeLists.txt @@ -1,59 +1,36 @@ project(comm-cryptotools) cmake_minimum_required(VERSION 3.4) include(GNUInstallDirs) set(CMAKE_CXX_STANDARD 14) set(CRYPTO_HDRS "CryptoModule.h" "Persist.h" "Session.h" "Tools.h" ) set(CRYPTO_SRCS "CryptoModule.cpp" "Session.cpp" "Tools.cpp" ) add_library(comm-cryptotools ${CRYPTO_HDRS} ${CRYPTO_SRCS} ) -find_package(Olm) - target_link_libraries(comm-cryptotools Olm::Olm ) # reference local directory when building, use installation path when installing target_include_directories(comm-cryptotools PUBLIC $ $ $ ) - -install(TARGETS comm-cryptotools EXPORT comm-cryptotools-export - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT comm-cryptotools - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT comm-cryptotools - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT comm-cryptotools -) - -install(FILES ${TOOLS_HDRS} DESTINATION include/Tools) - -set(_builddir_export_path cmake/comm-cryptotools/comm-cryptotools-targets.cmake) -export(TARGETS comm-cryptotools - NAMESPACE comm-cryptotools:: - FILE ${CMAKE_CURRENT_BINARY_DIR}/${_builddir_export_path} -) - -# For installation -install(EXPORT comm-cryptotools-export - FILE comm-cryptotools-targets.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/comm-cryptotools - NAMESPACE comm-cryptotools:: -) diff --git a/native/cpp/CommonCpp/DatabaseManagers/CMakeLists.txt b/native/cpp/CommonCpp/DatabaseManagers/CMakeLists.txt index 8f16db6c3..b84a23c44 100644 --- a/native/cpp/CommonCpp/DatabaseManagers/CMakeLists.txt +++ b/native/cpp/CommonCpp/DatabaseManagers/CMakeLists.txt @@ -1,66 +1,44 @@ project(comm-databasemanagers) cmake_minimum_required(VERSION 3.4) include(GNUInstallDirs) -find_package(Folly REQUIRED) - set(DBM_HDRS "DatabaseManager.h" "DatabaseQueryExecutor.h" "SQLiteQueryExecutor.h" "entities/Draft.h" "entities/Media.h" "entities/Message.h" "entities/Metadata.h" "entities/OlmPersistAccount.h" "entities/OlmPersistSession.h" "entities/Thread.h" ) set(DBM_SRCS "SQLiteQueryExecutor.cpp" ) add_library(comm-databasemanagers ${DBM_HDRS} ${DBM_SRCS} ) target_include_directories(comm-databasemanagers PUBLIC $ $ $ $ # TODO: Remove once native/cpp has a CMakeLists.txt $ PRIVATE # HACK "../../../node_modules/react-native/ReactCommon/jsi" "../../../node_modules/olm/include" ) target_link_libraries(comm-databasemanagers Folly::folly ) - -install(TARGETS comm-databasemanagers EXPORT comm-databasemanagers-export - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT comm-databasemanagers - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT comm-databasemanagers - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT comm-databasemanagers -) - -install(FILES ${TOOLS_HDRS} DESTINATION include/comm/DatabaseManagers) - -set(_builddir_export_path cmake/comm-tools/comm-databasemanagers-targets.cmake) -export(TARGETS comm-databasemanagers - NAMESPACE comm-databasemanagers:: - FILE ${CMAKE_CURRENT_BINARY_DIR}/${_builddir_export_path} -) - -# For installation -install(EXPORT comm-databasemanagers-export - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/comm-databasemanagers - NAMESPACE comm-tools:: -) diff --git a/native/cpp/CommonCpp/NativeModules/CMakeLists.txt b/native/cpp/CommonCpp/NativeModules/CMakeLists.txt index 3e08e624b..165d9ef57 100644 --- a/native/cpp/CommonCpp/NativeModules/CMakeLists.txt +++ b/native/cpp/CommonCpp/NativeModules/CMakeLists.txt @@ -1,112 +1,82 @@ project(comm-modules) cmake_minimum_required(VERSION 3.4) # For C++17 on MacOS, we must set minimum target to 10.14+ set(CMAKE_CXX_STANDARD 17) set(CMAKE_OSX_DEPLOYMENT_TARGET 10.14) include(GNUInstallDirs) set(NATIVE_HDRS "CommCoreModule.h" "MessageStoreOperations.h" "ThreadStoreOperations.h" ) set(NATIVE_SRCS "CommCoreModule.cpp" ) add_library(comm-modules-native ${NATIVE_HDRS} ${NATIVE_SRCS} ) set_target_properties(comm-modules-native PROPERTIES LINKER_LANGUAGE CXX) target_compile_options(comm-modules-native PRIVATE -Wc++17-extensions) # reference local directory when building, use installation path when installing target_include_directories(comm-modules-native PUBLIC $ $ # HACK PRIVATE "../../../../node_modules/react-native/ReactCommon/jsi" "../../../../node_modules/react-native/ReactCommon/react/nativemodule/core" "../../../../node_modules/react-native/ReactCommon/callinvoker" "../../../../node_modules/react-native/ReactCommon" "../../../native_rust_library" ) set(_message_path ./PersistentStorageUtilities/MessageOperationsUtilities) set(MESSAGE_HDRS ${_message_path}/MessageOperationsUtilities.h ${_message_path}/MessageSpecs.h ) set(MESSAGE_SRCS ${_message_path}/MessageOperationsUtilities.cpp ) file(GLOB MESSAGE_SPEC_HDRS ${_message_path}/MessageSpecs/*.h ) file(GLOB THREAD_OP_HDRS ./PersistentStorageUtilities/ThreadOperationsUtilities/*.h ) set(THREAD_OP_SRCS ./PersistentStorageUtilities/ThreadOperationsUtilities/ThreadOperations.cpp ) add_library(comm-modules-persistentstorage ${MESSAGE_HDRS} ${MESSAGE_SRCS} ${MESSAGE_SPEC_HDRS} ${THREAD_OP_HDRS} ${THREAD_OP_SRCS} ) # reference local directory when building, use installation path when installing target_include_directories(comm-modules-persistentstorage PUBLIC $ $ $ PRIVATE # HACK "../../../node_modules/react-native/ReactCommon/jsi" ) - -set(_components native persistentstorage) - -foreach(component ${_components}) - install(TARGETS comm-modules-${component} EXPORT comm-modules-export - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT comm-modules - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT comm-modules - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT comm-modules - ) -endforeach() - -install(FILES ${INTERNAL_HDRS} DESTINATION include/InternalModules) -install(FILES ${NATIVE_HDRS} DESTINATION include/NativeModules) -install(FILES ${MESSAGE_HDRS} DESTINATION include/PersistentStorageUtilities) -install(FILES ${MESSAGE_SPEC_HDRS} - DESTINATION include/PersistentStorageUtilities/MessageSpecs -) -install(FILES ${THREAD_OP_HDRS} DESTINATION include/ThreadOperationsUtilities) - -export(TARGETS comm-modules-native - NAMESPACE comm-modules:: - FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/comm-modules/comm-modules-targets.cmake -) - -# For installation -install(EXPORT comm-modules-export - FILE comm-modules-targets.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/comm-modules - NAMESPACE comm-modules:: -) diff --git a/native/cpp/CommonCpp/Tools/CMakeLists.txt b/native/cpp/CommonCpp/Tools/CMakeLists.txt index 9b07241c8..aff1c864e 100644 --- a/native/cpp/CommonCpp/Tools/CMakeLists.txt +++ b/native/cpp/CommonCpp/Tools/CMakeLists.txt @@ -1,53 +1,31 @@ project(comm-tools) cmake_minimum_required(VERSION 3.4) include(GNUInstallDirs) -find_package(Folly REQUIRED) - set(TOOLS_HDRS "CommSecureStore.h" "Logger.h" "PlatformSpecificTools.h" "WorkerThread.h" ) set(TOOLS_SRCS "WorkerThread.cpp" ) add_library(comm-tools ${TOOLS_HDRS} ${TOOLS_SRCS} ) target_link_libraries(comm-tools Folly::folly ) target_include_directories(comm-tools PUBLIC $ $ $ ) - -install(TARGETS comm-tools EXPORT comm-tools-export - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT comm-tools - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT comm-tools - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT comm-tools -) - -install(FILES ${TOOLS_HDRS} DESTINATION include/Tools) - -export(TARGETS comm-tools - NAMESPACE comm-tools:: - FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/comm-tools/comm-tools-targets.cmake -) - -# For installation -install(EXPORT comm-tools-export - FILE comm-tools-targets.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/comm-tool - NAMESPACE comm-tools:: -)