# Generated by uniffi-bindgen-react-native cmake_minimum_required(VERSION 3.9.0) project(Payjoin) set (CMAKE_VERBOSE_MAKEFILE ON) set (CMAKE_CXX_STANDARD 17) # Resolve the path to the uniffi-bindgen-react-native package. # # PATCHED by scripts/patch-bindings.sh -- do not hand-edit; see that script. # # The ubrn template resolves 'uniffi-bindgen-react-native/package.json', but # 0.31.0-3 added an "exports" map that does not expose "./package.json", so # require.resolve throws ERR_PACKAGE_PATH_NOT_EXPORTED. execute_process leaves # OUTPUT_VARIABLE empty on failure, the include path silently degrades to # "/cpp/includes", and the build dies much later with a confusing # "'UniffiCallInvoker.h' file not found". # # Instead resolve the "." export (always present) and walk up to whichever # directory actually contains cpp/includes. That works whether the package is # hoisted to the app's root node_modules or nested under this library. # # Resolution is anchored to CMAKE_CURRENT_SOURCE_DIR, passed as argv[1]: # execute_process runs in the *build* directory, which lives under .cxx/ and # would resolve to the wrong node_modules (or none at all). execute_process( COMMAND node -e "const path=require('path'),fs=require('fs');const{createRequire}=require('module');const req=createRequire(path.join(process.argv[1],'noop.js'));let d=path.dirname(req.resolve('uniffi-bindgen-react-native'));while(d!==path.parse(d).root&&!fs.existsSync(path.join(d,'cpp','includes')))d=path.dirname(d);process.stdout.write(d)" "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE UNIFFI_BINDGEN_PATH OUTPUT_STRIP_TRAILING_WHITESPACE ) # get_filename_component normalizes Windows path separators. get_filename_component(UNIFFI_BINDGEN_PATH "${UNIFFI_BINDGEN_PATH}" ABSOLUTE) # Fail at configure time rather than emitting a broken -I flag and failing in # the middle of the C++ compile. if (NOT EXISTS "${UNIFFI_BINDGEN_PATH}/cpp/includes/UniffiCallInvoker.h") message(FATAL_ERROR "Could not locate the uniffi-bindgen-react-native C++ includes.\n" "Resolved to: '${UNIFFI_BINDGEN_PATH}'\n" "Expected: '${UNIFFI_BINDGEN_PATH}/cpp/includes/UniffiCallInvoker.h'\n" "Is uniffi-bindgen-react-native installed and resolvable from " "${CMAKE_CURRENT_SOURCE_DIR}?") endif() # Specifies a path to native header files. include_directories( ../cpp ../cpp/generated ${UNIFFI_BINDGEN_PATH}/cpp/includes ) add_library(react-native-payjoin SHARED ../cpp/react-native-payjoin.cpp ../cpp/generated/payjoin.cpp cpp-adapter.cpp ) # Set C++ compiler flags set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") # Set linker flags for 16KB page size alignment (required for Android 15+) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=16384") cmake_path( SET MY_RUST_LIB ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libpayjoin_ffi.so NORMALIZE ) add_library(my_rust_lib SHARED IMPORTED) set_target_properties(my_rust_lib PROPERTIES IMPORTED_LOCATION ${MY_RUST_LIB} IMPORTED_NO_SONAME ON) # Add ReactAndroid libraries, being careful to account for different versions. find_package(ReactAndroid REQUIRED CONFIG) find_library(LOGCAT log) # REACTNATIVE_MERGED_SO seems to be only be set in a build.gradle.kt file, # which we don't use. Thus falling back to version number sniffing. if (ReactAndroid_VERSION_MINOR GREATER_EQUAL 76) set(REACTNATIVE_MERGED_SO true) endif() # https://github.com/react-native-community/discussions-and-proposals/discussions/816 # This if-then-else can be removed once this library does not support version below 0.76 if (REACTNATIVE_MERGED_SO) target_link_libraries(react-native-payjoin ReactAndroid::reactnative) else() target_link_libraries(react-native-payjoin ReactAndroid::turbomodulejsijni ReactAndroid::react_nativemodule_core ) endif() find_package(fbjni REQUIRED CONFIG) target_link_libraries( react-native-payjoin fbjni::fbjni ReactAndroid::jsi ${LOGCAT} my_rust_lib )