Skip to content

Commit

Permalink
Extend the RN Application.cmake file to support Android autolinking (#…
Browse files Browse the repository at this point in the history
…34082)

Summary:
This is the companion PR of react-native-community/cli#1630
It extends the `ReactNative-application.cmake` file with instructions to pickup the autolinked libraries.

## Changelog

[Internal] [Changed] - Extend the RN Application.cmake file to support Android autolinking

Pull Request resolved: #34082

Test Plan: Tested locally as we don't have a way to test autolinking on CI.

Reviewed By: cipolleschi

Differential Revision: D37463203

Pulled By: cortinico

fbshipit-source-id: 0b28e7f214c265ebfec4ccc59ae321f682299cf8
  • Loading branch information
cortinico authored and facebook-github-bot committed Jun 28, 2022
1 parent a5a956b commit ef0392b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ReactAndroid/cmake-utils/ReactNative-application.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@
# - Take care of setting the correct compile options
# - Include all the pre-built libraries in your build graph
# - Link your library against those prebuilt libraries so you can access JSI, Fabric, etc.
# - Link your library against any autolinked library.

cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)

include(${REACT_ANDROID_DIR}/cmake-utils/Android-prebuilt.cmake)

file(GLOB input_SRC CONFIGURE_DEPENDS *.cpp)
file(GLOB input_SRC CONFIGURE_DEPENDS
*.cpp
${PROJECT_BUILD_DIR}/generated/rncli/src/main/jni/*.cpp)

add_library(${CMAKE_PROJECT_NAME} SHARED ${input_SRC})

target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${CMAKE_PROJECT_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_BUILD_DIR}/generated/rncli/src/main/jni)

target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wall -Werror -fexceptions -frtti -std=c++17 -DWITH_INSPECTOR=1 -DLOG_TAG=\"ReactNative\")

Expand All @@ -41,3 +48,9 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
runtimeexecutor
turbomodulejsijni
yoga)

# If project is on RN CLI v9, then we can use the following lines to link against the autolinked 3rd party libraries.
if(EXISTS ${PROJECT_BUILD_DIR}/generated/rncli/src/main/jni/Android-rncli.cmake)
include(${PROJECT_BUILD_DIR}/generated/rncli/src/main/jni/Android-rncli.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} ${AUTOLINKED_LIBRARIES})
endif()

0 comments on commit ef0392b

Please sign in to comment.