Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 54 additions & 63 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,120 +1,111 @@
cmake_minimum_required(VERSION 3.21)

# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()

include(FetchContent)

# Modules declaration
FetchContent_Declare(CMakeExtensions
GIT_REPOSITORY https://github.com/BabylonJS/CMakeExtensions.git
GIT_TAG ea28b7689530bfdc4905806f27ecf7e8ed4b5419)
FetchContent_Declare(ios-cmake
GIT_REPOSITORY https://github.com/leetal/ios-cmake.git
GIT_TAG 4.4.1)
# --------------------------------------------------
# Declarations
# --------------------------------------------------
FetchContent_Declare(arcana.cpp
GIT_REPOSITORY https://github.com/microsoft/arcana.cpp.git
GIT_TAG f2757396e80bc4169f2ddb938ce25367a98ffdd0)
FetchContent_Declare(UrlLib
GIT_REPOSITORY https://github.com/BabylonJS/UrlLib.git
GIT_TAG 59917f32f6ddfa26af07dd981842c51ce02dafcd)
FetchContent_Declare(asio
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
GIT_TAG f693a3eb7fe72a5f19b975289afc4f437d373d9c)
FetchContent_Declare(llhttp
URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v8.1.0.tar.gz")
FetchContent_Declare(CMakeExtensions
GIT_REPOSITORY https://github.com/BabylonJS/CMakeExtensions.git
GIT_TAG ea28b7689530bfdc4905806f27ecf7e8ed4b5419)
FetchContent_Declare(googletest
URL "https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz")
FetchContent_Declare(ios-cmake
GIT_REPOSITORY https://github.com/leetal/ios-cmake.git
GIT_TAG 4.4.1)
FetchContent_Declare(llhttp
URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v8.1.0.tar.gz")
FetchContent_Declare(UrlLib
GIT_REPOSITORY https://github.com/bghgary/UrlLib.git
GIT_TAG 59917f32f6ddfa26af07dd981842c51ce02dafcd)
# --------------------------------------------------

set(CONTENT_TO_FETCH CMakeExtensions googletest)
FetchContent_MakeAvailable(CMakeExtensions)

if(IOS)
FetchContent_MakeAvailable(ios-cmake)
FetchContent_MakeAvailable_With_Message(ios-cmake)
set(CMAKE_TOOLCHAIN_FILE "${ios-cmake_SOURCE_DIR}/ios.toolchain.cmake" CACHE PATH "")
set(PLATFORM "OS64COMBINED" CACHE STRING "")
set(DEPLOYMENT_TARGET "12" CACHE STRING "")
endif()

# Project
project(JsRuntimeHost)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# --------------------------------------------------
# Options
# --------------------------------------------------

# General
option(JSRUNTIMEHOST_TESTS "Include JsRuntimeHost Tests." ${PROJECT_IS_TOP_LEVEL})
option(NAPI_BUILD_ABI "Build the ABI layer." ON)

## Core
# Core
option(JSRUNTIMEHOST_CORE_APPRUNTIME "Include JsRuntimeHost Core AppRuntime" ON)
option(JSRUNTIMEHOST_CORE_APPRUNTIME_V8_INSPECTOR "Include the V8 inspector protocol required to debug JavaScript with a V8 debugger." ON)
option(JSRUNTIMEHOST_CORE_SCRIPTLOADER "Include JsRuntimeHost Core ScriptLoader" ON)

## Polyfills
# Polyfills
option(JSRUNTIMEHOST_POLYFILL_CONSOLE "Include JsRuntimeHost Polyfill Console." ON)
option(JSRUNTIMEHOST_POLYFILL_SCHEDULING "Include JsRuntimeHost Polyfill Scheduling." ON)
option(JSRUNTIMEHOST_POLYFILL_XMLHTTPREQUEST "Include JsRuntimeHost Polyfill XMLHttpRequest." ON)
option(JSRUNTIMEHOST_POLYFILL_URL "Include JsRuntimeHost Polyfill URL and URLSearchParams." ON)
option(JSRUNTIMEHOST_POLYFILL_ABORT_CONTROLLER "Include JsRuntimeHost Polyfills AbortController and AbortSignal." ON)
option(JSRUNTIMEHOST_POLYFILL_WEBSOCKET "Include JsRuntimeHost Polyfill WebSocket." ON)

## Tests
option(JSRUNTIMEHOST_TESTS "Include JsRuntimeHost Tests." ${PROJECT_IS_TOP_LEVEL})

## Node-API
option(NAPI_BUILD_ABI "Build the ABI layer." ON)
# --------------------------------------------------

# Dependencies
FetchContent_MakeAvailable_With_Message(arcana.cpp)
set_property(TARGET arcana PROPERTY FOLDER Dependencies)

if(NOT TARGET arcana)
set(CONTENT_TO_FETCH ${CONTENT_TO_FETCH} arcana.cpp)
endif()

if(NOT TARGET UrlLib AND JSRUNTIMEHOST_POLYFILL_XMLHTTPREQUEST)
set(CONTENT_TO_FETCH ${CONTENT_TO_FETCH} UrlLib)
if(JSRUNTIMEHOST_POLYFILL_XMLHTTPREQUEST)
FetchContent_MakeAvailable_With_Message(UrlLib)
set_property(TARGET UrlLib PROPERTY FOLDER Dependencies)
endif()

if(NAPI_JAVASCRIPT_ENGINE STREQUAL "V8" AND JSRUNTIMEHOST_CORE_APPRUNTIME_V8_INSPECTOR)
if(NOT TARGET asio)
set(CONTENT_TO_FETCH ${CONTENT_TO_FETCH} asio)
endif()

if(NOT TARGET llhttp_static)
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
set(BUILD_STATIC_LIBS ON CACHE INTERNAL "")
set(CONTENT_TO_FETCH ${CONTENT_TO_FETCH} llhttp)
endif()
FetchContent_MakeAvailable_With_Message(asio)
add_library(asio INTERFACE)
target_include_directories(asio INTERFACE "${asio_SOURCE_DIR}/asio/include")
set_property(TARGET asio PROPERTY FOLDER Dependencies)

set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
set(BUILD_STATIC_LIBS ON CACHE INTERNAL "")
FetchContent_MakeAvailable_With_Message(llhttp)
set_property(TARGET llhttp_static PROPERTY FOLDER Dependencies)
endif()

# Fetching content
message(STATUS "Fetching dependencies for ${PROJECT_NAME} (${CONTENT_TO_FETCH})")
FetchContent_MakeAvailable(${CONTENT_TO_FETCH})
message(STATUS "Fetching dependencies for ${PROJECT_NAME} - done")

# Set properties after fetching content
if(TARGET arcana)
set_property(TARGET arcana PROPERTY FOLDER Dependencies)
endif()
if(JSRUNTIMEHOST_TESTS)
if(WIN32)
# For Windows: Prevent overriding the parent project's compiler/linker settings
# Default build type for my test projects are /MDd (MultiThreaded DLL) but GTests default to /MTd (MultiThreaded)
# see https://github.com/google/googletest/blob/main/googletest/README.md
# "Enabling this option will make gtest link the runtimes dynamically too, and match the project in which it is included."
set(gtest_force_shared_crt OFF CACHE BOOL "" FORCE)
endif()

if(TARGET UrlLib AND JSRUNTIMEHOST_POLYFILL_XMLHTTPREQUEST)
set_property(TARGET UrlLib PROPERTY FOLDER Dependencies)
endif()
FetchContent_MakeAvailable_With_Message(googletest)

if(NAPI_JAVASCRIPT_ENGINE STREQUAL "V8" AND JSRUNTIMEHOST_CORE_APPRUNTIME_V8_INSPECTOR)
if(NOT TARGET asio)
add_library(asio INTERFACE)
target_include_directories(asio INTERFACE "${asio_SOURCE_DIR}/asio/include")
set_property(TARGET asio PROPERTY FOLDER Dependencies)
endif()
if(NOT TARGET llhttp_static)
set_property(TARGET llhttp_static PROPERTY FOLDER Dependencies)
endif()
set_property(TARGET gmock PROPERTY FOLDER Dependencies/GoogleTest)
set_property(TARGET gmock_main PROPERTY FOLDER Dependencies/GoogleTest)
set_property(TARGET gtest PROPERTY FOLDER Dependencies/GoogleTest)
set_property(TARGET gtest_main PROPERTY FOLDER Dependencies/GoogleTest)
endif()

# Subdirectories

if(ANDROID)
set(JSRUNTIMEHOST_PLATFORM "Android")
elseif(IOS)
Expand Down
4 changes: 3 additions & 1 deletion Tests/UnitTests/Android/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ get_filename_component(UNIT_TESTS_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../.."
get_filename_component(TESTS_DIR "${UNIT_TESTS_DIR}/.." ABSOLUTE)
get_filename_component(REPO_ROOT_DIR "${TESTS_DIR}/.." ABSOLUTE)

set(JSRUNTIMEHOST_TESTS OFF) # Turn off the tests folder for Android Studio path
add_subdirectory(${REPO_ROOT_DIR} "${CMAKE_CURRENT_BINARY_DIR}/JsRuntimeHost")

FetchContent_MakeAvailable_With_Message(googletest)

npm(install --silent WORKING_DIRECTORY ${TESTS_DIR})

add_library(UnitTestsJNI SHARED
JNI.cpp
${UNIT_TESTS_DIR}/Shared/Shared.h
${UNIT_TESTS_DIR}/Shared/Shared.cpp)

target_compile_definitions(UnitTestsJNI PRIVATE JSRUNTIMEHOST_PLATFORM="${JSRUNTIMEHOST_PLATFORM}")

target_include_directories(UnitTestsJNI
Expand Down
2 changes: 1 addition & 1 deletion Tests/UnitTests/Shared/Shared.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "gtest/gtest.h"
#include "Shared.h"
#include <Babylon/AppRuntime.h>
#include <Babylon/ScriptLoader.h>
Expand All @@ -7,6 +6,7 @@
#include <Babylon/Polyfills/URL.h>
#include <Babylon/Polyfills/AbortController.h>
#include <Babylon/Polyfills/WebSocket.h>
#include <gtest/gtest.h>
#include <future>

const char* EnumToString(Babylon::Polyfills::Console::LogLevel logLevel)
Expand Down