Skip to content

Commit 7e0a6f2

Browse files
committed
feat: add all necessary options to generator
1 parent ba065b4 commit 7e0a6f2

1 file changed

Lines changed: 72 additions & 1 deletion

File tree

packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,75 @@ std::shared_ptr<TurboModule> ${libraryName}_ModuleProvider(const std::string &mo
6060
`;
6161
};
6262

63+
const ReactNativeFlagsTemplate = () => {
64+
return `
65+
# React Native specific compiler flags
66+
# This CMake file exposes the React Native Flags that all the libraries should use when
67+
# compiling a module that will end up inside libreactnative.so
68+
69+
SET(reactnative_FLAGS
70+
-Wall
71+
-Werror
72+
-fexceptions
73+
-frtti
74+
-std=c++20
75+
-DFOLLY_NO_CONFIG=1
76+
-DLOG_TAG=\"ReactNative\"
77+
)
78+
79+
# This function can be used to configure the reactnative flags for a specific target in
80+
# a convenient way. The usage is:
81+
#
82+
# target_compile_reactnative_options(target_name scope)
83+
#
84+
# scope is either PUBLIC, PRIVATE or INTERFACE
85+
86+
function(target_compile_reactnative_options target_name scope)
87+
target_compile_options(\${target_name} \${scope} \${reactnative_FLAGS})
88+
# TODO T228344694 improve this so that it works for all platforms
89+
if(ANDROID)
90+
target_compile_definitions(\${target_name} \${scope} RN_SERIALIZABLE_STATE)
91+
endif()
92+
endfunction()
93+
`;
94+
};
95+
const AdditionalSetupTemplate = () => {
96+
return `
97+
98+
SET(reactnative_FLAGS
99+
-Wall
100+
-Werror
101+
-fexceptions
102+
-frtti
103+
-std=c++20
104+
-DFOLLY_NO_CONFIG=1
105+
-DLOG_TAG=\"ReactNative\"
106+
)
107+
108+
SET(folly_FLAGS
109+
-DFOLLY_NO_CONFIG=1
110+
-DFOLLY_HAVE_CLOCK_GETTIME=1
111+
-DFOLLY_USE_LIBCPP=1
112+
-DFOLLY_CFG_NO_COROUTINES=1
113+
-DFOLLY_MOBILE=1
114+
-DFOLLY_HAVE_RECVMMSG=1
115+
-DFOLLY_HAVE_PTHREAD=1
116+
# Once we target android-23 above, we can comment
117+
# the following line. NDK uses GNU style stderror_r() after API 23.
118+
-DFOLLY_HAVE_XSI_STRERROR_R=1
119+
)
120+
121+
add_compile_options(\${folly_FLAGS})
122+
123+
find_package(fbjni REQUIRED CONFIG)
124+
find_package(ReactAndroid REQUIRED CONFIG)
125+
126+
add_library(jsi ALIAS ReactAndroid::jsi)
127+
add_library(reactnative ALIAS ReactAndroid::reactnative)
128+
add_library(fbjni ALIAS fbjni::fbjni)
129+
130+
`;
131+
};
63132
// Note: this CMakeLists.txt template includes dependencies for both NativeModule and components.
64133
const CMakeListsTemplate = ({
65134
libraryName,
@@ -73,11 +142,13 @@ const CMakeListsTemplate = ({
73142
cmake_minimum_required(VERSION 3.13)
74143
set(CMAKE_VERBOSE_MAKEFILE on)
75144
145+
${targetName !== 'rncore' ? ReactNativeFlagsTemplate() + AdditionalSetupTemplate() : ''}
146+
76147
file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/${libraryName}/*.cpp)
77148
78149
add_library(
79150
react_codegen_${targetName}
80-
SHARED
151+
${targetName !== 'rncore' ? 'SHARED' : 'OBJECT'}
81152
\${react_codegen_SRCS}
82153
)
83154

0 commit comments

Comments
 (0)