Skip to content

Commit

Permalink
First Round of CMake files for React Android
Browse files Browse the repository at this point in the history
Summary:
This is the first round of CMake files to support the React Native build on Android.
They're supposed to eventually replace the various Android.mk files we have around in the codebase.

So far we're not actively using them. This is the first step towards migrating our
setup to use CMake

Changelog:
[Internal] [Changed] - First Round of CMake files for React Android

Reviewed By: ShikaSD

Differential Revision: D34762524

fbshipit-source-id: 6671e203a2c83b8874cefe796aa55aa987902a3b
  • Loading branch information
cortinico authored and facebook-github-bot committed Mar 11, 2022
1 parent 2829146 commit b676ca5
Show file tree
Hide file tree
Showing 64 changed files with 1,708 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

add_compile_options(-fexceptions -frtti -std=c++17 -Wall -DLOG_TAG=\"Fabric\")

add_library(
mapbufferjni
SHARED
react/common/mapbuffer/OnLoad.cpp
react/common/mapbuffer/ReadableMapBuffer.cpp
)

target_include_directories(mapbufferjni
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/react/common/mapbuffer/
)

target_link_libraries(mapbufferjni
fb
fbjni
folly_futures
folly_json
glog
glog_init
react_debug
react_render_mapbuffer
react_utils
react_config
yoga
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

add_compile_options(-fvisibility=hidden -fexceptions -frtti)

add_library(jscexecutor SHARED OnLoad.cpp)

target_include_directories(jscexecutor PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(jscexecutor
jsireact
jscruntime
fb
fbjni
folly_json
jsi
reactnativejni)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

add_compile_options(-fvisibility=hidden -fexceptions -frtti)

add_library(reactnativeblob SHARED
BlobCollector.cpp
OnLoad.cpp)

target_include_directories(reactnativeblob PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(reactnativeblob
jsireact
fb
fbjni
folly_json
jsi
reactnativejni)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

add_compile_options(-fexceptions -frtti -std=c++17 -Wall)

add_library(reactperfloggerjni SHARED reactperflogger/OnLoad.cpp)

target_include_directories(reactperfloggerjni
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/reactperflogger
)

target_link_libraries(reactperfloggerjni
fb
fbjni
android
reactperflogger)
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

add_compile_options(
-fexceptions
-frtti
-Wno-unused-lambda-capture
-std=c++17)

#########################
### callinvokerholder ###
#########################

# TODO This should be exported to its own folder hierarchy
add_library(
callinvokerholder
STATIC
ReactCommon/CallInvokerHolder.cpp
)

target_include_directories(callinvokerholder
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(callinvokerholder
fb
fbjni
runtimeexecutor
callinvoker
reactperfloggerjni)

##################################
### react_nativemodule_manager ###
##################################

# TODO: rename to react_nativemodule_manager
add_library(
turbomodulejsijni
SHARED
ReactCommon/TurboModuleManager.cpp
ReactCommon/OnLoad.cpp
)

target_include_directories(
turbomodulejsijni
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(turbomodulejsijni
fb
fbjni
jsi
react_nativemodule_core
callinvokerholder
reactperfloggerjni)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

add_compile_options(-fexceptions -frtti -std=c++17 -Wall -DLOG_TAG=\"ReactNative\")

add_library(uimanagerjni SHARED
OnLoad.cpp
ComponentNameResolverManager.cpp)

target_include_directories(uimanagerjni PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(uimanagerjni
fb
fbjni
folly_futures
folly_json
glog
glog_init
rrc_native
yoga
callinvokerholder
reactnativejni
react_render_componentregistry)
28 changes: 28 additions & 0 deletions ReactAndroid/src/main/jni/first-party/fb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

add_library(fb
SHARED
assert.cpp
log.cpp)

add_compile_options(
-DLOG_TAG=\"libfb\"
-DDISABLE_CPUCAP
-DDISABLE_XPLAT
-fexceptions
-frtti
-Wno-unused-parameter
-Wno-error=unused-but-set-variable
-DHAVE_POSIX_CLOCKS
)

# Yogacore needs to link towards android and log from the NDK libs
target_link_libraries(fb dl android log)

target_include_directories(fb PUBLIC include)
15 changes: 15 additions & 0 deletions ReactAndroid/src/main/jni/first-party/fbgloginit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

add_compile_options(-fexceptions -fno-omit-frame-pointer)

add_library(glog_init SHARED glog_init.cpp)

target_include_directories(yoga PUBLIC .)

target_link_libraries(glog_init log glog)
15 changes: 15 additions & 0 deletions ReactAndroid/src/main/jni/first-party/fbjni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

add_library(fbjni SHARED IMPORTED GLOBAL)
set_target_properties(fbjni
PROPERTIES
IMPORTED_LOCATION
${CMAKE_CURRENT_SOURCE_DIR}/jni/${ANDROID_ABI}/libfbjni.so)

target_include_directories(fbjni INTERFACE headers)
13 changes: 13 additions & 0 deletions ReactAndroid/src/main/jni/first-party/hermes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

add_library(hermes SHARED IMPORTED GLOBAL)
set_target_properties(hermes
PROPERTIES
IMPORTED_LOCATION
${CMAKE_CURRENT_SOURCE_DIR}/jni/${ANDROID_ABI}/libhermes.so)
20 changes: 20 additions & 0 deletions ReactAndroid/src/main/jni/first-party/yogajni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

add_compile_options(
-fvisibility=hidden
-fexceptions
-frtti
-O3)

file(GLOB_RECURSE yoga_SRC jni/*.cpp)
add_library(yoga SHARED ${yoga_SRC})

target_include_directories(yoga PUBLIC jni)

target_link_libraries(yoga yogacore fb fbjni log android)
72 changes: 72 additions & 0 deletions ReactAndroid/src/main/jni/react/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

# TODO Those two libraries are building against the same sources
# and should probably be merged
file(GLOB reactnativejni_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)

add_compile_options(
-fexceptions
-frtti
-Wno-unused-lambda-capture
-std=c++17)

##########################
### React Native Utils ###
##########################

add_library(
reactnativeutilsjni
SHARED
${reactnativejni_SRC}
)

# TODO This should not be ../../
target_include_directories(reactnativeutilsjni PUBLIC ../../)

target_link_libraries(reactnativeutilsjni
android
callinvokerholder
fb
fbjni
folly_json
glog_init
react_render_runtimescheduler
reactnative
runtimeexecutor
yoga
)

######################
### reactnativejni ###
######################


add_library(
reactnativejni
SHARED
${reactnativejni_SRC}
)

# TODO This should not be ../../
target_include_directories(reactnativejni PUBLIC ../../)

target_link_libraries(reactnativejni
android
callinvokerholder
fb
fbjni
folly_json
glog_init
logger
react_render_runtimescheduler
reactnative
reactnativeutilsjni
runtimeexecutor
yoga
)
2 changes: 1 addition & 1 deletion ReactAndroid/src/main/jni/third-party/boost/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include $(CLEAR_VARS)
# These ASM files are picked from the boost release separately,
# because the react native version does not include anything outside of headers.
# They are required for Folly futures to compile successfully.
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/asm/$(TARGET_ARCH)/*.S)
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/asm/$(TARGET_ARCH_ABI)/*.S)

LOCAL_C_INCLUDES := $(LOCAL_PATH)/boost_1_63_0
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/boost_1_63_0
Expand Down
Loading

0 comments on commit b676ca5

Please sign in to comment.