11cmake_minimum_required (VERSION 3.13 )
22
33file (GLOB_RECURSE ANDROID_CPP_SOURCES CONFIGURE_DEPENDS "${ANDROID_CPP_DIR} /*.cpp" )
4- file (GLOB_RECURSE COMMON_CPP_SOURCES CONFIGURE_DEPENDS "${COMMON_CPP_DIR} /*.cpp" )
5- file (GLOB_RECURSE COMMON_C_SOURCES CONFIGURE_DEPENDS "${COMMON_CPP_DIR} /*.c" )
4+
5+ # --- Source separation ---
6+ # Glob all common sources, then separate opencv-dependent and phonemizer-dependent
7+ # files so they can be conditionally included based on feature flags.
8+
9+ file (GLOB_RECURSE ALL_COMMON_CPP_SOURCES CONFIGURE_DEPENDS "${COMMON_CPP_DIR} /*.cpp" )
10+ file (GLOB_RECURSE ALL_COMMON_C_SOURCES CONFIGURE_DEPENDS "${COMMON_CPP_DIR} /*.c" )
11+
12+ # Exclude test sources unconditionally
613file (GLOB_RECURSE TEST_CPP_SOURCES "${COMMON_CPP_DIR} /rnexecutorch/tests/*.cpp" )
7- list (REMOVE_ITEM COMMON_CPP_SOURCES ${TEST_CPP_SOURCES} )
14+ list (REMOVE_ITEM ALL_COMMON_CPP_SOURCES ${TEST_CPP_SOURCES} )
15+
16+ # OpenCV-dependent sources: CV models + frame utilities + image processing
17+ file (GLOB_RECURSE OPENCV_CPP_SOURCES CONFIGURE_DEPENDS
18+ "${COMMON_CPP_DIR} /rnexecutorch/models/classification/*.cpp"
19+ "${COMMON_CPP_DIR} /rnexecutorch/models/object_detection/*.cpp"
20+ "${COMMON_CPP_DIR} /rnexecutorch/models/semantic_segmentation/*.cpp"
21+ "${COMMON_CPP_DIR} /rnexecutorch/models/instance_segmentation/*.cpp"
22+ "${COMMON_CPP_DIR} /rnexecutorch/models/style_transfer/*.cpp"
23+ "${COMMON_CPP_DIR} /rnexecutorch/models/ocr/*.cpp"
24+ "${COMMON_CPP_DIR} /rnexecutorch/models/vertical_ocr/*.cpp"
25+ "${COMMON_CPP_DIR} /rnexecutorch/models/embeddings/image/*.cpp"
26+ "${COMMON_CPP_DIR} /rnexecutorch/models/text_to_image/*.cpp"
27+ "${COMMON_CPP_DIR} /rnexecutorch/models/VisionModel.cpp"
28+ "${COMMON_CPP_DIR} /rnexecutorch/data_processing/ImageProcessing.cpp"
29+ "${COMMON_CPP_DIR} /rnexecutorch/utils/FrameExtractor.cpp"
30+ "${COMMON_CPP_DIR} /rnexecutorch/utils/FrameProcessor.cpp"
31+ "${COMMON_CPP_DIR} /rnexecutorch/utils/FrameTransform.cpp"
32+ "${COMMON_CPP_DIR} /rnexecutorch/utils/computer_vision/*.cpp"
33+ )
34+
35+ # Phonemizer-dependent sources: Kokoro TTS (only user of phonemis)
36+ file (GLOB_RECURSE PHONEMIZER_CPP_SOURCES CONFIGURE_DEPENDS
37+ "${COMMON_CPP_DIR} /rnexecutorch/models/text_to_speech/*.cpp"
38+ )
39+
40+ # Core = everything minus optional sources
41+ set (CORE_COMMON_CPP_SOURCES ${ALL_COMMON_CPP_SOURCES} )
42+ list (REMOVE_ITEM CORE_COMMON_CPP_SOURCES ${OPENCV_CPP_SOURCES} ${PHONEMIZER_CPP_SOURCES} )
43+
44+ # Build final source list
45+ set (ENABLED_COMMON_SOURCES ${CORE_COMMON_CPP_SOURCES} )
846
9- add_library (react-native-executorch SHARED ${ANDROID_CPP_SOURCES} ${COMMON_CPP_SOURCES} ${COMMON_C_SOURCES} )
47+ if (RNE_ENABLE_OPENCV)
48+ list (APPEND ENABLED_COMMON_SOURCES ${OPENCV_CPP_SOURCES} )
49+ endif ()
50+
51+ if (RNE_ENABLE_PHONEMIZER)
52+ list (APPEND ENABLED_COMMON_SOURCES ${PHONEMIZER_CPP_SOURCES} )
53+ endif ()
54+
55+ add_library (react-native-executorch SHARED
56+ ${ANDROID_CPP_SOURCES}
57+ ${ENABLED_COMMON_SOURCES}
58+ ${ALL_COMMON_C_SOURCES}
59+ )
60+
61+ # Propagate feature flags as preprocessor defines so C++ code can guard includes
62+ if (RNE_ENABLE_OPENCV)
63+ target_compile_definitions (react-native-executorch PRIVATE RNE_ENABLE_OPENCV )
64+ endif ()
65+
66+ if (RNE_ENABLE_PHONEMIZER)
67+ target_compile_definitions (react-native-executorch PRIVATE RNE_ENABLE_PHONEMIZER )
68+ endif ()
1069
1170find_package (ReactAndroid REQUIRED CONFIG )
1271find_package (fbjni REQUIRED CONFIG )
@@ -34,63 +93,55 @@ set(RN_VERSION_LINK_LIBRARIES
3493 ReactAndroid::reactnative
3594)
3695
37- # Dependencies:
38-
39- # ------- Executorch -------
96+ # ------- Executorch (always required) -------
4097
4198add_library (executorch SHARED IMPORTED )
4299
43100set_target_properties (executorch PROPERTIES
44101 IMPORTED_LOCATION "${LIBS_DIR} /executorch/${ANDROID_ABI} /libexecutorch.so" )
45102
46-
47103if (ANDROID_ABI STREQUAL "arm64-v8a" )
48104 target_compile_definitions (react-native-executorch PRIVATE ARCH_ARM64 )
49105
50- # ------- pthreadpool -------
51106 add_library (pthreadpool SHARED IMPORTED )
52-
53107 set_target_properties (pthreadpool PROPERTIES
54108 IMPORTED_LOCATION "${LIBS_DIR} /pthreadpool/${ANDROID_ABI} /libpthreadpool.so" )
55109
56- # ------- cpuinfo -------
57110 add_library (cpuinfo SHARED IMPORTED )
58-
59111 set_target_properties (cpuinfo PROPERTIES
60112 IMPORTED_LOCATION "${LIBS_DIR} /cpuinfo/${ANDROID_ABI} /libcpuinfo.so" )
61- set (EXECUTORCH_LIBS
62- "pthreadpool"
63- "cpuinfo"
64- )
113+
114+ set (EXECUTORCH_LIBS "pthreadpool" "cpuinfo" )
65115endif ()
66116
67- # ------- OpenCV -------
117+ # ------- OpenCV (optional) -------
68118
69- set (OPENCV_LIBS
70- "${LIBS_DIR} /opencv/${ANDROID_ABI} /libopencv_core.a"
71- "${LIBS_DIR} /opencv/${ANDROID_ABI} /libopencv_features2d.a"
72- "${LIBS_DIR} /opencv/${ANDROID_ABI} /libopencv_highgui.a"
73- "${LIBS_DIR} /opencv/${ANDROID_ABI} /libopencv_imgproc.a"
74- "${LIBS_DIR} /opencv/${ANDROID_ABI} /libopencv_photo.a"
75- "${LIBS_DIR} /opencv/${ANDROID_ABI} /libopencv_video.a"
76- )
77-
78- if (ANDROID_ABI STREQUAL "arm64-v8a" )
79- set (OPENCV_THIRD_PARTY_LIBS
80- "${LIBS_DIR} /opencv-third-party/${ANDROID_ABI} /libkleidicv_hal.a"
81- "${LIBS_DIR} /opencv-third-party/${ANDROID_ABI} /libkleidicv_thread.a"
82- "${LIBS_DIR} /opencv-third-party/${ANDROID_ABI} /libkleidicv.a"
119+ if (RNE_ENABLE_OPENCV)
120+ set (OPENCV_LINK_LIBS
121+ "${LIBS_DIR} /opencv/${ANDROID_ABI} /libopencv_core.a"
122+ "${LIBS_DIR} /opencv/${ANDROID_ABI} /libopencv_features2d.a"
123+ "${LIBS_DIR} /opencv/${ANDROID_ABI} /libopencv_highgui.a"
124+ "${LIBS_DIR} /opencv/${ANDROID_ABI} /libopencv_imgproc.a"
125+ "${LIBS_DIR} /opencv/${ANDROID_ABI} /libopencv_photo.a"
126+ "${LIBS_DIR} /opencv/${ANDROID_ABI} /libopencv_video.a"
83127 )
84- elseif (ANDROID_ABI STREQUAL "x86_64" )
85- set (OPENCV_THIRD_PARTY_LIBS "" )
86- endif ()
87128
129+ if (ANDROID_ABI STREQUAL "arm64-v8a" )
130+ list (APPEND OPENCV_LINK_LIBS
131+ "${LIBS_DIR} /opencv-third-party/${ANDROID_ABI} /libkleidicv_hal.a"
132+ "${LIBS_DIR} /opencv-third-party/${ANDROID_ABI} /libkleidicv_thread.a"
133+ "${LIBS_DIR} /opencv-third-party/${ANDROID_ABI} /libkleidicv.a"
134+ )
135+ endif ()
136+ endif ()
88137
89- # ------- phonemis -------
138+ # ------- Phonemizer (optional) -------
90139
91- set (PHONEMIS_LIBS
92- "${LIBS_DIR} /phonemis/${ANDROID_ABI} /libphonemis.a"
93- )
140+ if (RNE_ENABLE_PHONEMIZER)
141+ set (PHONEMIZER_LINK_LIBS
142+ "${LIBS_DIR} /phonemis/${ANDROID_ABI} /libphonemis.a"
143+ )
144+ endif ()
94145
95146# --------------
96147
@@ -100,9 +151,8 @@ target_link_libraries(
100151 react-native-executorch
101152 ${LINK_LIBRARIES}
102153 ${RN_VERSION_LINK_LIBRARIES}
103- ${OPENCV_LIBS}
104- ${OPENCV_THIRD_PARTY_LIBS}
105- ${PHONEMIS_LIBS}
154+ ${OPENCV_LINK_LIBS}
155+ ${PHONEMIZER_LINK_LIBS}
106156 executorch
107157 ${EXECUTORCH_LIBS}
108158 z
0 commit comments