Skip to content

Commit 0fd282f

Browse files
cortinicofacebook-github-bot
authored andcommitted
Link against the app codegen if available (facebook#35176)
Summary: Pull Request resolved: facebook#35176 This commit extends the ReactNative-application.cmake logic so that if the app is using codegen at the app level, the generate library is properly built and linked. It helps us simplify the RN Tester setup and makes it easier for app users to use the codegen at the app level. Changelog: [Internal] [Changed] - [Android] Link against the app codegen if available Reviewed By: cipolleschi Differential Revision: D40936941 fbshipit-source-id: 26fa4d764fb369c987e94e0c3bce61841b982b27
1 parent e89d223 commit 0fd282f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

ReactAndroid/cmake-utils/ReactNative-application.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
9595
turbomodulejsijni # prefab ready
9696
yoga) # prefab ready
9797

98-
# We use an interface targe to propagate flags to all the generated targets
98+
# We use an interface target to propagate flags to all the generated targets
9999
# such as the folly flags or others.
100100
add_library(common_flags INTERFACE)
101101
target_compile_options(common_flags INTERFACE ${folly_FLAGS})
@@ -106,6 +106,14 @@ if(EXISTS ${PROJECT_BUILD_DIR}/generated/rncli/src/main/jni/Android-rncli.cmake)
106106
include(${PROJECT_BUILD_DIR}/generated/rncli/src/main/jni/Android-rncli.cmake)
107107
target_link_libraries(${CMAKE_PROJECT_NAME} ${AUTOLINKED_LIBRARIES})
108108
foreach(autolinked_library ${AUTOLINKED_LIBRARIES})
109-
target_link_libraries(autolinked_library INTERFACE common_flags)
109+
target_link_libraries(autolinked_library common_flags)
110110
endforeach()
111111
endif()
112+
113+
# If project is running codegen at the app level, we want to link and build the generated library.
114+
if(EXISTS ${PROJECT_BUILD_DIR}/generated/source/codegen/jni/CMakeLists.txt)
115+
add_subdirectory(${PROJECT_BUILD_DIR}/generated/source/codegen/jni/ codegen_app_build)
116+
get_property(APP_CODEGEN_TARGET DIRECTORY ${PROJECT_BUILD_DIR}/generated/source/codegen/jni/ PROPERTY BUILDSYSTEM_TARGETS)
117+
target_link_libraries(${CMAKE_PROJECT_NAME} ${APP_CODEGEN_TARGET})
118+
target_link_libraries(${APP_CODEGEN_TARGET} common_flags)
119+
endif()

packages/rn-tester/android/app/src/main/jni/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ project(appmodules)
1010

1111
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)
1212

13-
add_subdirectory(${PROJECT_BUILD_DIR}/generated/source/codegen/jni/ codegen_build)
1413
add_subdirectory(${REACT_COMMON_DIR}/react/nativemodule/samples/platform/android/ sampleturbomodule_build)
1514

16-
# RN Tester needs to link against the local codegen-ned library and a sample turbomobule
15+
# RN Tester needs to link against the sample turbomobule
1716
target_link_libraries(${CMAKE_PROJECT_NAME}
18-
react_codegen_AppSpecs
1917
sampleturbomodule)

0 commit comments

Comments
 (0)