|
| 1 | + |
| 2 | +# Get the current file directory |
| 3 | +get_filename_component(WEAK_NODE_API_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) |
| 4 | + |
| 5 | +if(NOT DEFINED WEAK_NODE_API_LIB) |
| 6 | + # Auto-detect library path for Android NDK builds |
| 7 | + if(ANDROID) |
| 8 | + # Define the library path pattern for Android |
| 9 | + set(WEAK_NODE_API_LIB_PATH "weak-node-api.android.node/${ANDROID_ABI}/libweak-node-api.so") |
| 10 | + |
| 11 | + # Try Debug first, then Release using the packaged Android node structure |
| 12 | + set(WEAK_NODE_API_LIB_DEBUG "${WEAK_NODE_API_CMAKE_DIR}/build/Debug/${WEAK_NODE_API_LIB_PATH}") |
| 13 | + set(WEAK_NODE_API_LIB_RELEASE "${WEAK_NODE_API_CMAKE_DIR}/build/Release/${WEAK_NODE_API_LIB_PATH}") |
| 14 | + |
| 15 | + if(EXISTS "${WEAK_NODE_API_LIB_DEBUG}") |
| 16 | + set(WEAK_NODE_API_LIB "${WEAK_NODE_API_LIB_DEBUG}") |
| 17 | + message(STATUS "Using Debug weak-node-api library: ${WEAK_NODE_API_LIB}") |
| 18 | + elseif(EXISTS "${WEAK_NODE_API_LIB_RELEASE}") |
| 19 | + set(WEAK_NODE_API_LIB "${WEAK_NODE_API_LIB_RELEASE}") |
| 20 | + message(STATUS "Using Release weak-node-api library: ${WEAK_NODE_API_LIB}") |
| 21 | + else() |
| 22 | + message(FATAL_ERROR "Could not find weak-node-api library for Android ABI ${ANDROID_ABI}. Expected at:\n ${WEAK_NODE_API_LIB_DEBUG}\n ${WEAK_NODE_API_LIB_RELEASE}") |
| 23 | + endif() |
| 24 | + else() |
| 25 | + message(FATAL_ERROR "WEAK_NODE_API_LIB is not set") |
| 26 | + endif() |
| 27 | +endif() |
| 28 | + |
| 29 | +if(NOT DEFINED WEAK_NODE_API_INC) |
| 30 | + set(WEAK_NODE_API_INC "${WEAK_NODE_API_CMAKE_DIR}/include;${WEAK_NODE_API_CMAKE_DIR}/generated") |
| 31 | + message(STATUS "Using weak-node-api include directories: ${WEAK_NODE_API_INC}") |
| 32 | +endif() |
| 33 | + |
| 34 | +add_library(weak-node-api SHARED IMPORTED) |
| 35 | + |
| 36 | +set_target_properties(weak-node-api PROPERTIES |
| 37 | + IMPORTED_LOCATION "${WEAK_NODE_API_LIB}" |
| 38 | + INTERFACE_INCLUDE_DIRECTORIES "${WEAK_NODE_API_INC}" |
| 39 | +) |
0 commit comments