From fda4173050088d4ae5158554e35d34415eee4069 Mon Sep 17 00:00:00 2001 From: johnche Date: Fri, 15 Nov 2024 12:12:35 +0800 Subject: [PATCH] =?UTF-8?q?[unreal]=E5=88=A0=E9=99=A4native=5Fsrc=5Fil2cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/unity_build_plugins.yml | 38 - .github/workflows/unity_unittest.yml | 1 - unity/cli/test.mjs | 8 - unity/native_src_il2cpp/CMakeLists.txt | 258 --- unity/native_src_il2cpp/Inc/CppObjectMapper.h | 99 - unity/native_src_il2cpp/Inc/DataTransfer.h | 445 ----- unity/native_src_il2cpp/Inc/JSClassRegister.h | 175 -- unity/native_src_il2cpp/Inc/NamespaceDef.h | 15 - unity/native_src_il2cpp/Inc/ObjectCacheNode.h | 134 -- unity/native_src_il2cpp/Inc/ObjectMapper.h | 123 -- .../Inc/PuertsNamespaceDef.h | 46 - unity/native_src_il2cpp/Inc/TypeInfo.hpp | 536 ----- unity/native_src_il2cpp/Inc/pesapi.h | 358 ---- .../native_src_il2cpp/Src/CppObjectMapper.cpp | 460 ----- unity/native_src_il2cpp/Src/DataTransfer.cpp | 77 - .../native_src_il2cpp/Src/JSClassRegister.cpp | 392 ---- .../native_src_il2cpp/Src/PesapiAddonLoad.cpp | 18 - unity/native_src_il2cpp/Src/PesapiV8Impl.cpp | 1142 ----------- unity/native_src_il2cpp/Src/Puerts.cpp | 220 --- .../cmake/android.toolchain.cmake | 1745 ----------------- .../cmake/android.windows.toolchain.cmake | 607 ------ unity/native_src_il2cpp/cmake/iOS.cmake | 213 -- .../cmake/ios.toolchain.cmake | 672 ------- 23 files changed, 7782 deletions(-) delete mode 100644 unity/native_src_il2cpp/CMakeLists.txt delete mode 100644 unity/native_src_il2cpp/Inc/CppObjectMapper.h delete mode 100644 unity/native_src_il2cpp/Inc/DataTransfer.h delete mode 100644 unity/native_src_il2cpp/Inc/JSClassRegister.h delete mode 100644 unity/native_src_il2cpp/Inc/NamespaceDef.h delete mode 100644 unity/native_src_il2cpp/Inc/ObjectCacheNode.h delete mode 100644 unity/native_src_il2cpp/Inc/ObjectMapper.h delete mode 100644 unity/native_src_il2cpp/Inc/PuertsNamespaceDef.h delete mode 100644 unity/native_src_il2cpp/Inc/TypeInfo.hpp delete mode 100644 unity/native_src_il2cpp/Inc/pesapi.h delete mode 100644 unity/native_src_il2cpp/Src/CppObjectMapper.cpp delete mode 100644 unity/native_src_il2cpp/Src/DataTransfer.cpp delete mode 100644 unity/native_src_il2cpp/Src/JSClassRegister.cpp delete mode 100644 unity/native_src_il2cpp/Src/PesapiAddonLoad.cpp delete mode 100644 unity/native_src_il2cpp/Src/PesapiV8Impl.cpp delete mode 100644 unity/native_src_il2cpp/Src/Puerts.cpp delete mode 100644 unity/native_src_il2cpp/cmake/android.toolchain.cmake delete mode 100644 unity/native_src_il2cpp/cmake/android.windows.toolchain.cmake delete mode 100644 unity/native_src_il2cpp/cmake/iOS.cmake delete mode 100644 unity/native_src_il2cpp/cmake/ios.toolchain.cmake diff --git a/.github/workflows/unity_build_plugins.yml b/.github/workflows/unity_build_plugins.yml index b19c2fd026..8bdcb3d0ab 100644 --- a/.github/workflows/unity_build_plugins.yml +++ b/.github/workflows/unity_build_plugins.yml @@ -14,7 +14,6 @@ on: push: paths: - unity/native_src/** - - unity/native_src_il2cpp/** - unity/cli/** - unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.cpp - unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.h @@ -65,12 +64,6 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} backend: mult - - name: BuildAndroidIl2cpp - uses: ./.github/workflows/composites/unity-build-plugins/android/ - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - backend: v8_9.4.146.24 - build_proj_dir: native_src_il2cpp ohos: runs-on: ubuntu-latest @@ -106,12 +99,6 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} backend: mult - - name: BuildOHOSIl2cpp - uses: ./.github/workflows/composites/unity-build-plugins/ohos/ - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - backend: v8_9.4.146.24 - build_proj_dir: native_src_il2cpp ios: runs-on: macos-13 @@ -144,12 +131,6 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} backend: mult - - name: BuildiOSIl2cpp - uses: ./.github/workflows/composites/unity-build-plugins/ios/ - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - backend: v8_9.4.146.24 - build_proj_dir: native_src_il2cpp osx: runs-on: macos-13 @@ -182,12 +163,6 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} backend: mult - - name: BuildOSXIl2cpp - uses: ./.github/workflows/composites/unity-build-plugins/osx/ - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - backend: v8_9.4.146.24 - build_proj_dir: native_src_il2cpp windows: runs-on: windows-2019 @@ -220,13 +195,6 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} backend: mult - - name: BuildWindowsIl2cpp - uses: ./.github/workflows/composites/unity-build-plugins/windows/ - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - backend: v8_9.4.146.24 - build_proj_dir: native_src_il2cpp - arch: x64 linux64: runs-on: ubuntu-latest @@ -259,12 +227,6 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} backend: mult - - name: BuildLinuxIl2cpp - uses: ./.github/workflows/composites/unity-build-plugins/linux/ - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - backend: v8_9.4.146.24 - build_proj_dir: native_src_il2cpp wasm: runs-on: ubuntu-latest diff --git a/.github/workflows/unity_unittest.yml b/.github/workflows/unity_unittest.yml index 70a04e3590..96cb2ee4e5 100644 --- a/.github/workflows/unity_unittest.yml +++ b/.github/workflows/unity_unittest.yml @@ -7,7 +7,6 @@ on: - unity/Assets/** - unity/test/** - unity/native_src/** - - unity/native_src_il2cpp/** - unity/cli/** - unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.cpp - unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.h diff --git a/unity/cli/test.mjs b/unity/cli/test.mjs index b65d818675..8f05916cf9 100644 --- a/unity/cli/test.mjs +++ b/unity/cli/test.mjs @@ -211,14 +211,6 @@ export async function unityTest(cwd, unityPath) { `); execUnityEditor(`-executeMethod TestBuilder.GenV2`); rm("-rf", `${cwd}/Library/ScriptAssemblies`); - - await runPuertsMake(join(cwd, '../../native_src_il2cpp'), { - backend: 'v8_9.4.146.24', - platform: platform, - config: 'Debug', - arch: 'x64', - websocket: 1 - }); console.log("[Puer] Building testplayer for v2"); mkdir("-p", `${cwd}/build/v2`); diff --git a/unity/native_src_il2cpp/CMakeLists.txt b/unity/native_src_il2cpp/CMakeLists.txt deleted file mode 100644 index a5e1ff1f03..0000000000 --- a/unity/native_src_il2cpp/CMakeLists.txt +++ /dev/null @@ -1,258 +0,0 @@ -# Tencent is pleased to support the open source community by making xLua available. -# Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. -# Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at -# http://opensource.org/licenses/MIT -# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - -cmake_minimum_required(VERSION 3.15) -cmake_policy(SET CMP0091 NEW) - -project(PuertsPlugin) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -set(CMAKE_CXX_STANDARD 14) - -if ( IOS ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fembed-bitcode") -endif () - -find_path(PUERTS_PROJECT_DIR NAMES SConstruct - PATHS - ${PROJECT_SOURCE_DIR} - NO_DEFAULT_PATH -) - -MARK_AS_ADVANCED(PUERTS_PROJECT_DIR) - -if ( NOT DEFINED JS_ENGINE ) - set(JS_ENGINE v8) -endif() - -set(BACKEND_ROOT ${PROJECT_SOURCE_DIR}/../native_src/.backends/${JS_ENGINE}) - -set(ThirdParty ${PROJECT_SOURCE_DIR}/../../unreal/Puerts/ThirdParty) - -string (REPLACE ";" "$${BACKEND_ROOT}" BACKEND_INC_NAMES "${BACKEND_ROOT}${BACKEND_INC_NAMES}") -string (REPLACE ";" "$${BACKEND_ROOT}" BACKEND_LIB_NAMES "${BACKEND_ROOT}${BACKEND_LIB_NAMES}") -string (REPLACE ";" "$" BACKEND_DEFINITIONS "${BACKEND_DEFINITIONS}") - -set(ThirdParty ${PROJECT_SOURCE_DIR}/../../unreal/Puerts/ThirdParty) -include_directories( - Inc - ../Assets/core/upm/Plugins/puerts_il2cpp - ${BACKEND_INC_NAMES} - ${PROJECT_SOURCE_DIR}/../native_src/Inc - ${PROJECT_SOURCE_DIR}/../../unreal/Puerts/Source/JsEnv/Private - ${ThirdParty}/Include/websocketpp - ${ThirdParty}/Include/asio -) - -set ( PUERTS_INC - ${PROJECT_SOURCE_DIR}/../../unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.h - ${PROJECT_SOURCE_DIR}/../../unreal/Puerts/Source/JsEnv/Private/PromiseRejectCallback.hpp -) - -set ( PUERTS_SRC - Src/Puerts.cpp - Src/PesapiV8Impl.cpp - Src/PesapiAddonLoad.cpp - Src/CppObjectMapper.cpp - Src/DataTransfer.cpp - Src/JSClassRegister.cpp - ${PROJECT_SOURCE_DIR}/../native_src/Src/BackendEnv.cpp - ${PROJECT_SOURCE_DIR}/../../unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.cpp -) - -set(PUERTS_COMPILE_DEFINITIONS) - -if ( WITH_WEBSOCKET ) - list(APPEND PUERTS_COMPILE_DEFINITIONS WITH_WEBSOCKET) - list(APPEND PUERTS_SRC ${PROJECT_SOURCE_DIR}/../../unreal/Puerts/Source/JsEnv/Private/WebSocketImpl.cpp) -endif() - -if(DEFINED PUERTS_EXTRA_SRC) - list(APPEND PUERTS_SRC ${PUERTS_EXTRA_SRC}) -endif() - -if(DEFINED PUERTS_EXTRA_INC) - include_directories(${PUERTS_EXTRA_INC}) -endif() - -macro(source_group_by_dir proj_dir source_files) - if(MSVC OR APPLE) - get_filename_component(sgbd_cur_dir ${proj_dir} ABSOLUTE) - foreach(sgbd_file ${${source_files}}) - get_filename_component(sgbd_abs_file ${sgbd_file} ABSOLUTE) - file(RELATIVE_PATH sgbd_fpath ${sgbd_cur_dir} ${sgbd_abs_file}) - string(REGEX REPLACE "\(.*\)/.*" \\1 sgbd_group_name ${sgbd_fpath}) - string(COMPARE EQUAL ${sgbd_fpath} ${sgbd_group_name} sgbd_nogroup) - string(REPLACE "/" "\\" sgbd_group_name ${sgbd_group_name}) - if(sgbd_nogroup) - set(sgbd_group_name "\\") - endif(sgbd_nogroup) - source_group(${sgbd_group_name} FILES ${sgbd_file}) - endforeach(sgbd_file) - endif(MSVC OR APPLE) -endmacro(source_group_by_dir) - -source_group_by_dir(${CMAKE_CURRENT_SOURCE_DIR} PUERTS_INC) -source_group_by_dir(${CMAKE_CURRENT_SOURCE_DIR} PUERTS_SRC) - - -if ( APPLE ) - if ( IOS ) - set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)") - add_library(puerts_il2cpp STATIC - ${PUERTS_SRC} ${PUERTS_INC} - ) - set_xcode_property (puerts_il2cpp IPHONEOS_DEPLOYMENT_TARGET "7.0" "all") - else () - if ( NOT DEFINED FOR_SILICON ) - set(CMAKE_OSX_ARCHITECTURES x86_64) - else () - set(CMAKE_OSX_ARCHITECTURES arm64) - endif () - - set(CMAKE_SKIP_RPATH FALSE) - add_link_options(-rpath "@loader_path/") - add_library(puerts_il2cpp SHARED - ${PUERTS_SRC} ${PUERTS_INC} - ) - endif () -else () - add_library(puerts_il2cpp SHARED - ${PUERTS_SRC} ${PUERTS_INC} - ) -endif () - -# target_compile_definitions (puerts_il2cpp PRIVATE THREAD_SAFE) -target_compile_definitions (puerts_il2cpp PRIVATE PUERTS_IL2CPP_OPTIMIZATION) - -if ( WIN32 AND NOT CYGWIN ) - target_compile_definitions (puerts_il2cpp PRIVATE BUILDING_V8_SHARED) -endif () - -if ( NOT CMAKE_BUILD_TYPE MATCHES "Release" ) - target_compile_definitions (puerts_il2cpp PRIVATE PUERTS_DEBUG) -endif () - -if ( MSYS OR WIN32 ) - if ( WIN32 ) - target_compile_options(puerts_il2cpp - PRIVATE - $<$:/bigobj> - ) - target_link_libraries(puerts_il2cpp - winmm.lib - dbghelp.lib - shlwapi.lib - ) - endif () - - # definition - target_compile_definitions (puerts_il2cpp PRIVATE PLATFORM_WINDOWS) - -elseif ( ANDROID ) - - find_library(log-lib log) - target_link_libraries(puerts_il2cpp - ${log-lib} - ) - - if( ANDROID_ABI STREQUAL "armeabi-v7a") - # definition - target_compile_definitions (puerts_il2cpp PRIVATE PLATFORM_ANDROID_ARM) - - else () - # link - target_link_libraries(puerts_il2cpp - ${log-lib} - ) - - # definition - target_compile_definitions (puerts_il2cpp PRIVATE PLATFORM_ANDROID_ARM64) - endif () - - target_link_options(puerts_il2cpp PRIVATE -s) - - #set_target_properties( puerts_il2cpp PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/android_version.script) - #set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/android_version.script") - #set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections") - #add_custom_command(TARGET puerts_il2cpp POST_BUILD - # COMMAND "${ANDROID_TOOLCHAIN_PREFIX}strip" -s --verbose - # "${CMAKE_BINARY_DIR}/libpuerts_il2cpp.so" -o - # "${CMAKE_BINARY_DIR}/libpuerts_il2cpp.stripped.so~" - # COMMENT "Strip debug symbols done on final binary.") - #if (JS_ENGINE STREQUAL "v8_9.4" OR JS_ENGINE STREQUAL "v8") - # add_custom_command(TARGET puerts_il2cpp POST_BUILD - # COMMAND cp ARGS ${BACKEND_LIB_NAMES} ./ - # COMMAND cp ARGS ${CMAKE_BINARY_DIR}/libpuerts_il2cpp.a ./libpuerts_il2cpp_tmp.a - # COMMAND ${ANDROID_TOOLCHAIN_PREFIX}ar ARGS -x libpuerts_il2cpp_tmp.a - # COMMAND ${ANDROID_TOOLCHAIN_PREFIX}ar ARGS -rs libwee8.a *.o - # COMMAND mv ARGS libwee8.a ${CMAKE_BINARY_DIR}/libpuerts_il2cpp.a - # COMMAND rm ARGS libpuerts_il2cpp_tmp.a - # COMMAND rm ARGS -f *.o - # COMMENT "combine wee8." - # ) - #endif() -elseif ( OHOS ) - set(BACKEND_LIB_NAMES "-Wl,--whole-archive$${BACKEND_LIB_NAMES}$-Wl,--no-whole-archive") - list(APPEND PUERTS_COMPILE_DEFINITIONS PLATFORM_OHOS) - if ( OHOS_ARCH STREQUAL "armeabi-v7a") - # definition - list(APPEND PUERTS_COMPILE_DEFINITIONS PLATFORM_OHOS_ARM) - - elseif ( OHOS_ARCH STREQUAL "arm64-v8a") - # definition - list(APPEND PUERTS_COMPILE_DEFINITIONS PLATFORM_OHOS_ARM64) - else () - # definition - list(APPEND PUERTS_COMPILE_DEFINITIONS PLATFORM_OHOS_x64) - endif () -elseif ( APPLE ) - - if ( IOS ) - #definition - if(PLATFORM STREQUAL "SIMULATOR64") - target_compile_definitions (puerts_il2cpp PRIVATE PLATFORM_IOS_SIMULATOR) - message(STATUS "SIMULATOR64 BUILD...") - else () - target_compile_definitions (puerts_il2cpp PRIVATE PLATFORM_IOS) - endif () - - else () - - #definition - if ( DEFINED FOR_SILICON ) - target_compile_definitions (puerts_il2cpp PRIVATE PLATFORM_MAC_ARM64) - endif() - target_compile_definitions (puerts_il2cpp PRIVATE PLATFORM_MAC) - endif () - -elseif (UNIX) - # link - target_link_libraries(puerts_il2cpp pthread) - - # definition - target_compile_definitions (puerts_il2cpp PRIVATE PLATFORM_LINUX) - if (NOT ("${JS_ENGINE}" STREQUAL "nodejs_16")) - set(CMAKE_CXX_COMPILER "clang++") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi") - endif () -endif () - -# link -target_link_libraries(puerts_il2cpp - ${BACKEND_LIB_NAMES} -) -target_compile_definitions (puerts_il2cpp PRIVATE ${BACKEND_DEFINITIONS}) -target_compile_definitions (puerts_il2cpp PRIVATE ${PUERTS_COMPILE_DEFINITIONS}) - -if ( WIN32 AND NOT CYGWIN AND NOT ( CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" ) AND NOT ANDROID AND NOT MSYS) - set_property(TARGET puerts_il2cpp PROPERTY - MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") -endif () - -install(TARGETS puerts_il2cpp DESTINATION bin) \ No newline at end of file diff --git a/unity/native_src_il2cpp/Inc/CppObjectMapper.h b/unity/native_src_il2cpp/Inc/CppObjectMapper.h deleted file mode 100644 index f45ce39053..0000000000 --- a/unity/native_src_il2cpp/Inc/CppObjectMapper.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#pragma once - -#include "NamespaceDef.h" - -PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS -#pragma warning(push, 0) -#include "v8.h" -#pragma warning(pop) -PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS - -#include -#include "JSClassRegister.h" -#include "ObjectCacheNode.h" -#include "ObjectMapper.h" - -namespace v8impl -{ -extern pesapi_ffi g_pesapi_ffi; -} - -namespace PUERTS_NAMESPACE -{ -struct PointerHash -{ - std::size_t operator()(const void* ptr) const - { - return reinterpret_cast(ptr); - } -}; - -struct PointerEqual -{ - bool operator()(const void* lhs, const void* rhs) const - { - return lhs == rhs; - } -}; - -struct PesapiCallbackData -{ - pesapi_callback Callback; - void* Data; -}; - -class FCppObjectMapper final : public ICppObjectMapper -{ -public: - void Initialize(v8::Isolate* InIsolate, v8::Local InContext); - - void LoadCppType(const v8::FunctionCallbackInfo& Info); - - virtual bool IsInstanceOfCppObject(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject) override; - - virtual std::weak_ptr GetJsEnvLifeCycleTracker() override; - - virtual v8::Local FindOrAddCppObject( - v8::Isolate* Isolate, v8::Local& Context, const void* TypeId, void* Ptr, bool PassByPointer) override; - - virtual v8::MaybeLocal CreateFunction(v8::Local Context, pesapi_callback Callback, void* Data) override; - - virtual void UnBindCppObject(v8::Isolate* Isolate, JSClassDefinition* ClassDefinition, void* Ptr) override; - - virtual void BindCppObject(v8::Isolate* Isolate, JSClassDefinition* ClassDefinition, void* Ptr, v8::Local JSObject, - bool PassByPointer) override; - - virtual void* GetPrivateData(v8::Local Context, v8::Local JSObject) override; - - virtual void SetPrivateData(v8::Local Context, v8::Local JSObject, void* Ptr) override; - - virtual v8::MaybeLocal LoadTypeById(v8::Local Context, const void* TypeId) override; - - void UnInitialize(v8::Isolate* InIsolate); - - v8::Local GetTemplateOfClass(v8::Isolate* Isolate, const JSClassDefinition* ClassDefinition); - -private: - std::unordered_map CDataCache; - - std::unordered_map, PointerHash, PointerEqual> TypeIdToTemplateMap; - - v8::UniquePersistent PointerTemplate; - - std::vector FunctionDatas; -#ifndef WITH_QUICKJS - v8::Global PrivateKey; -#endif - - std::shared_ptr Ref = std::make_shared(0); -}; - -} // namespace PUERTS_NAMESPACE \ No newline at end of file diff --git a/unity/native_src_il2cpp/Inc/DataTransfer.h b/unity/native_src_il2cpp/Inc/DataTransfer.h deleted file mode 100644 index 72ee9c6485..0000000000 --- a/unity/native_src_il2cpp/Inc/DataTransfer.h +++ /dev/null @@ -1,445 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#pragma once - -#if USING_IN_UNREAL_ENGINE -#include "CoreMinimal.h" -#include "UObject/Package.h" -#include "UObject/Class.h" -#else -#include "JSClassRegister.h" -#endif - -#include "NamespaceDef.h" - -PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS -#pragma warning(push, 0) -#include "v8.h" -#pragma warning(pop) -PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS - -#if !defined(MAPPER_ISOLATE_DATA_POS) -#define MAPPER_ISOLATE_DATA_POS 0 -#endif -#if !defined(BACKENDENV_DATA_POS) -#define BACKENDENV_DATA_POS 1 -#endif -#if !defined(PESAPI_PRIVATE_DATA_POS_IN_ISOLATE) -#define PESAPI_PRIVATE_DATA_POS_IN_ISOLATE 2 -#endif - -#define RELEASED_UOBJECT ((UObject*) 12) -#define RELEASED_UOBJECT_MEMBER ((void*) 12) - -#include - -namespace PUERTS_NAMESPACE -{ -template -struct TOuterLinker -{ - V8_INLINE static void Link(v8::Local Context, v8::Local Outer, v8::Local Inner) - { - } -}; - -V8_INLINE void LinkOuterImpl(v8::Local Context, v8::Local Outer, v8::Local Inner) -{ -#ifdef WITH_OUTER_LINK - Inner.As()->Set(Context, 0, Outer); -#endif -} - -#if USING_IN_UNREAL_ENGINE -FORCEINLINE UScriptStruct* GetScriptStructInCoreUObject(const TCHAR* Name) -{ - static UPackage* CoreUObjectPkg = FindObjectChecked(nullptr, TEXT("/Script/CoreUObject")); - return FindObjectChecked(CoreUObjectPkg, Name); -} - -template -struct TScriptStructTraits -{ -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return TBaseStructure::Get(); - } -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return TBaseStructure::Get(); - } -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return TBaseStructure::Get(); - } -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return TBaseStructure::Get(); - } -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return TBaseStructure::Get(); - } -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return TBaseStructure::Get(); - } -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return TBaseStructure::Get(); - } -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return TBaseStructure::Get(); - } -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return TBaseStructure::Get(); - } -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return TBaseStructure::Get(); - } -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return GetScriptStructInCoreUObject(TEXT("IntPoint")); - } -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return GetScriptStructInCoreUObject(TEXT("IntVector")); - } -}; - -template <> -struct TScriptStructTraits -{ - static UScriptStruct* Get() - { - return GetScriptStructInCoreUObject(TEXT("Plane")); - } -}; - -template -using ToVoid = void; - -template -struct HasStaticStructHelper : std::false_type -{ -}; - -template -struct HasStaticStructHelper> : std::true_type -{ -}; - -template -struct TScriptStructTraits::value>::type> -{ - static UScriptStruct* Get() - { - return T::StaticStruct(); - } -}; - -template -struct TOuterLinker::Get)>> -{ - V8_INLINE static void Link(v8::Local Context, v8::Local Outer, v8::Local Inner) - { - LinkOuterImpl(Context, Outer, Inner); - } -}; -#endif - -class JSENV_API DataTransfer -{ -public: - FORCEINLINE static void* MakeAddressWithHighPartOfTwo(void* Address1, void* Address2) - { - UPTRINT High = reinterpret_cast(Address1) & (((UPTRINT) -1) << (sizeof(UPTRINT) / 2)); //清除低位 - UPTRINT Low = (reinterpret_cast(Address2) >> (sizeof(UPTRINT) / 2)) & - ~(((UPTRINT) -1) << (sizeof(UPTRINT) / 2)); //右移,然后清除高位 - return reinterpret_cast(High | Low); - } - - FORCEINLINE static void SplitAddressToHighPartOfTwo(const void* Address, UPTRINT& High, UPTRINT& Low) - { - High = reinterpret_cast(Address) & (((UPTRINT) -1) << (sizeof(UPTRINT) / 2)); //清除低位 - Low = reinterpret_cast(Address) << (sizeof(UPTRINT) / 2); - } - - template - FORCEINLINE static T* GetPointerFast(v8::Local Object, int Index) - { - int P1 = Index << 1; - int P2 = P1 + 1; - if (V8_LIKELY(Object->InternalFieldCount() > P2)) - { - return static_cast(MakeAddressWithHighPartOfTwo( - Object->GetAlignedPointerFromInternalField(P1), Object->GetAlignedPointerFromInternalField(P2))); - } - return nullptr; - } - - template - FORCEINLINE static T* GetPointerFast(v8::Local Object) - { - if (V8_LIKELY(Object->InternalFieldCount() > 1)) - { - return static_cast(MakeAddressWithHighPartOfTwo( - Object->GetAlignedPointerFromInternalField(0), Object->GetAlignedPointerFromInternalField(1))); - } - return nullptr; - } - - template - FORCEINLINE static T* GetPointer(v8::Local Object, int Index = 0) - { - if (Object.IsEmpty() || Object->IsUndefined() || Object->IsNull()) - { - return nullptr; - } - return GetPointerFast(Object, Index); - } - - template - FORCEINLINE static T* GetPointer(v8::Local& Context, v8::Local Value, int Index = 0) - { - if (Value.IsEmpty() || !Value->IsObject() || Value->IsUndefined() || Value->IsNull()) - { - return nullptr; - } - auto Object = Value->ToObject(Context).ToLocalChecked(); - return GetPointerFast(Object, Index); - } - - //替代 Object->SetAlignedPointerInInternalField(Index, Ptr); - FORCEINLINE static void SetPointer(v8::Isolate* Isolate, v8::Local Object, const void* Ptr, int Index) - { - // Object->SetInternalField(Index, v8::External::New(Isolate, Ptr)); - // Object->SetAlignedPointerInInternalField(Index, Ptr); - UPTRINT High; - UPTRINT Low; - SplitAddressToHighPartOfTwo(Ptr, High, Low); - Object->SetAlignedPointerInInternalField(Index * 2, reinterpret_cast(High)); - Object->SetAlignedPointerInInternalField(Index * 2 + 1, reinterpret_cast(Low)); - } - - FORCEINLINE static void SetPointer(v8::Object* Object, const void* Ptr, int Index) - { - UPTRINT High; - UPTRINT Low; - SplitAddressToHighPartOfTwo(Ptr, High, Low); - Object->SetAlignedPointerInInternalField(Index * 2, reinterpret_cast(High)); - Object->SetAlignedPointerInInternalField(Index * 2 + 1, reinterpret_cast(Low)); - } - - template - FORCEINLINE static T* IsolateData(v8::Isolate* Isolate) - { - return static_cast(Isolate->GetData(MAPPER_ISOLATE_DATA_POS)); - } - - FORCEINLINE static void* GetIsolatePrivateData(v8::Isolate* Isolate) - { - return Isolate->GetData(PESAPI_PRIVATE_DATA_POS_IN_ISOLATE); - } - - FORCEINLINE static void SetIsolatePrivateData(v8::Isolate* Isolate, void* PrivateData) - { - Isolate->SetData(PESAPI_PRIVATE_DATA_POS_IN_ISOLATE, PrivateData); - } - - static v8::Local FindOrAddCData( - v8::Isolate* Isolate, v8::Local Context, const void* TypeId, const void* Ptr, bool PassByPointer); - - static bool IsInstanceOf(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject); - - static v8::Local UnRef(v8::Isolate* Isolate, const v8::Local& Value); - - static void UpdateRef(v8::Isolate* Isolate, v8::Local Outer, const v8::Local& Value); - - static std::weak_ptr GetJsEnvLifeCycleTracker(v8::Isolate* Isolate); - -#if USING_IN_UNREAL_ENGINE - template - static v8::Local FindOrAddObject(v8::Isolate* Isolate, v8::Local& Context, T* UEObject) - { - return FindOrAddObject(Isolate, Context, UEObject == nullptr ? T::StaticClass() : UEObject->GetClass(), UEObject); - } - - static v8::Local FindOrAddObject( - v8::Isolate* Isolate, v8::Local& Context, UClass* Class, UObject* UEObject); - - template - static v8::Local FindOrAddStruct(v8::Isolate* Isolate, v8::Local Context, void* Ptr, bool PassByPointer) - { - return FindOrAddStruct(Isolate, Context, TScriptStructTraits::Get(), Ptr, PassByPointer); - } - - static v8::Local FindOrAddStruct( - v8::Isolate* Isolate, v8::Local Context, UScriptStruct* ScriptStruct, void* Ptr, bool PassByPointer); - - template - static bool IsInstanceOf(v8::Isolate* Isolate, v8::Local JsObject) - { - return IsInstanceOf(Isolate, TScriptStructTraits::Get(), JsObject); - } - - static bool IsInstanceOf(v8::Isolate* Isolate, UStruct* Struct, v8::Local JsObject); - - static FString ToFString(v8::Isolate* Isolate, v8::Local Value); - - static void ThrowException(v8::Isolate* Isolate, const char* Message); -#endif - - template - FORCEINLINE static void LinkOuter(v8::Local Context, v8::Local Outer, v8::Local Inner) - { - TOuterLinker::Link(Context, Outer, Inner); - } - - FORCEINLINE static v8::Local NewArrayBuffer(v8::Local Context, void* Data, size_t DataLength) - { -#if defined(HAS_ARRAYBUFFER_NEW_WITHOUT_STL) - return v8::ArrayBuffer_New_Without_Stl(Context->GetIsolate(), Data, DataLength); -#else -#if USING_IN_UNREAL_ENGINE - return v8::ArrayBuffer::New(Context->GetIsolate(), Data, DataLength); -#else - auto Backing = v8::ArrayBuffer::NewBackingStore(Data, DataLength, v8::BackingStore::EmptyDeleter, nullptr); - return v8::ArrayBuffer::New(Context->GetIsolate(), std::move(Backing)); -#endif -#endif - } - - FORCEINLINE static void* GetArrayBufferData(v8::Local InArrayBuffer) - { - size_t DataLength; - return GetArrayBufferData(InArrayBuffer, DataLength); - } - - FORCEINLINE static void* GetArrayBufferData(v8::Local InArrayBuffer, size_t& DataLength) - { -#if defined(HAS_ARRAYBUFFER_NEW_WITHOUT_STL) - return v8::ArrayBuffer_Get_Data(InArrayBuffer, DataLength); -#else -#if USING_IN_UNREAL_ENGINE - DataLength = InArrayBuffer->GetContents().ByteLength(); - return InArrayBuffer->GetContents().Data(); -#else - auto BS = InArrayBuffer->GetBackingStore(); - DataLength = BS->ByteLength(); - return BS->Data(); -#endif -#endif - } - - FORCEINLINE static void ThrowException(v8::Isolate* Isolate, const char* Message) - { - auto ExceptionStr = v8::String::NewFromUtf8(Isolate, Message, v8::NewStringType::kNormal).ToLocalChecked(); - Isolate->ThrowException(v8::Exception::Error(ExceptionStr)); - } - - FORCEINLINE static std::string ExceptionToString(v8::Isolate* Isolate, v8::Local ExceptionValue) - { - v8::String::Utf8Value Exception(Isolate, ExceptionValue); - const char * StrException = *Exception; - std::string ExceptionStr(StrException == nullptr ? "" : StrException); - v8::Local Message = v8::Exception::CreateMessage(Isolate, ExceptionValue); - if (Message.IsEmpty()) - { - // 如果没有提供更详细的信息,直接输出Exception - return ExceptionStr; - } - else - { - v8::Local Context(Isolate->GetCurrentContext()); - - // 输出 (filename):(line number): (message). - std::ostringstream stm; - v8::String::Utf8Value FileName(Isolate, Message->GetScriptResourceName()); - int LineNum = Message->GetLineNumber(Context).FromJust(); - const char * StrFileName = *FileName; - stm << (StrFileName == nullptr ? "unknow file" : StrFileName) << ":" << LineNum << ": " << ExceptionStr; - - stm << std::endl; - - // 输出调用栈信息 - v8::MaybeLocal MaybeStackTrace = v8::TryCatch::StackTrace(Context, ExceptionValue); - if (!MaybeStackTrace.IsEmpty()) - { - v8::String::Utf8Value StackTraceVal(Isolate, MaybeStackTrace.ToLocalChecked()); - stm << std::endl << *StackTraceVal; - } - return stm.str(); - } - } -}; -} // namespace PUERTS_NAMESPACE diff --git a/unity/native_src_il2cpp/Inc/JSClassRegister.h b/unity/native_src_il2cpp/Inc/JSClassRegister.h deleted file mode 100644 index bf1f4d619c..0000000000 --- a/unity/native_src_il2cpp/Inc/JSClassRegister.h +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#pragma once - -#include "functional" - -#if USING_IN_UNREAL_ENGINE -#include "CoreMinimal.h" - -PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS -#pragma warning(push, 0) -#include "v8.h" -#pragma warning(pop) -PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS -#else -#define JSENV_API -#define FORCEINLINE V8_INLINE -#define UPTRINT uintptr_t -#endif - -#include - -#include "PuertsNamespaceDef.h" - -#include "pesapi.h" -#include "TypeInfo.hpp" - -#if USING_IN_UNREAL_ENGINE -static const FAnsiStringView EditorOnlyPropertySuffix = "_EditorOnly"; -#endif - -namespace PUERTS_NAMESPACE -{ -class CFunctionInfo; - -MSVC_PRAGMA(warning(push)) -MSVC_PRAGMA(warning(disable : 4191)) -struct JSENV_API JSFunctionInfo -{ - JSFunctionInfo() : Name(nullptr), Callback(nullptr) - { - } - - JSFunctionInfo( - const char* InName, pesapi_callback InCallback, void* InData = nullptr, const CFunctionInfo* InReflectionInfo = nullptr) - : Name(InName), Callback(InCallback), Data(InData), ReflectionInfo(InReflectionInfo) - { - } - - template - JSFunctionInfo( - const char* InName, CallbackType InCallback, void* InData = nullptr, const CFunctionInfo* InReflectionInfo = nullptr) - : Name(InName), Callback(reinterpret_cast(InCallback)), Data(InData), ReflectionInfo(InReflectionInfo) - { - } - - const char* Name; - pesapi_callback Callback; - void* Data = nullptr; - const CFunctionInfo* ReflectionInfo = nullptr; -}; - -struct JSENV_API JSPropertyInfo -{ - JSPropertyInfo() : Name(nullptr), Getter(nullptr), Setter(nullptr) - { - } - - JSPropertyInfo(const char* InName, pesapi_callback InGetter, pesapi_callback InSetter, void* InGetterData = nullptr, - void* InSetterData = nullptr) - : Name(InName), Getter(InGetter), Setter(InSetter), GetterData(InGetterData), SetterData(InSetterData) - { - } - - template - JSPropertyInfo(const char* InName, CallbackType InGetter, CallbackType InSetter, void* InGetterData = nullptr, - void* InSetterData = nullptr) - : Name(InName) - , Getter(reinterpret_cast(InGetter)) - , Setter(reinterpret_cast(InSetter)) - , GetterData(InGetterData) - , SetterData(InSetterData) - { - } - - const char* Name; - pesapi_callback Getter; - pesapi_callback Setter; - void* GetterData = nullptr; - void* SetterData = nullptr; -}; - -struct NamedFunctionInfo; -struct NamedPropertyInfo; - -struct JSENV_API JSClassDefinition -{ - const void* TypeId; - const void* SuperTypeId; - const char* ScriptName; - const char* UETypeName; - pesapi_constructor Initialize; - template - void SetInitialize(InitializeType InInitialize) - { - Initialize = reinterpret_cast(InInitialize); - } - JSFunctionInfo* Methods; //成员方法 - JSFunctionInfo* Functions; //静态方法 - JSPropertyInfo* Properties; //成员属性 - JSPropertyInfo* Variables; //静态属性 - pesapi_finalize Finalize; - // int InternalFieldCount; - NamedFunctionInfo* ConstructorInfos; - NamedFunctionInfo* MethodInfos; - NamedFunctionInfo* FunctionInfos; - NamedPropertyInfo* PropertyInfos; - NamedPropertyInfo* VariableInfos; - void* Data = nullptr; - pesapi_on_native_object_enter OnEnter = nullptr; - pesapi_on_native_object_exit OnExit = nullptr; -}; -MSVC_PRAGMA(warning(pop)) - -#define JSClassEmptyDefinition \ - { \ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \ - } - -void JSENV_API RegisterJSClass(const JSClassDefinition& ClassDefinition); - -void JSENV_API SetClassTypeInfo(const void* TypeId, const NamedFunctionInfo* ConstructorInfos, const NamedFunctionInfo* MethodInfos, - const NamedFunctionInfo* FunctionInfos, const NamedPropertyInfo* PropertyInfos, const NamedPropertyInfo* VariableInfos); - -void JSENV_API ForeachRegisterClass(std::function); - -JSENV_API const JSClassDefinition* FindClassByID(const void* TypeId); - -JSENV_API void OnClassNotFound(pesapi_class_not_found_callback Callback); - -JSENV_API const JSClassDefinition* LoadClassByID(const void* TypeId); - -JSENV_API const JSClassDefinition* FindCppTypeClassByName(const std::string& Name); - -JSENV_API bool TraceObjectLifecycle(const void* TypeId, pesapi_on_native_object_enter OnEnter, pesapi_on_native_object_exit OnExit); - -#if USING_IN_UNREAL_ENGINE -typedef void (*AddonRegisterFunc)(v8::Local Context, v8::Local Exports); - -AddonRegisterFunc FindAddonRegisterFunc(const std::string& Name); - -void RegisterAddon(const char* Name, AddonRegisterFunc RegisterFunc); - -JSENV_API const JSClassDefinition* FindClassByType(UStruct* Type); - -JSENV_API bool IsEditorOnlyUFunction(const UFunction* Func); - -#endif - -} // namespace PUERTS_NAMESPACE - -#define PUERTS_MODULE(Name, RegFunc) \ - static struct FAutoRegisterFor##Name \ - { \ - FAutoRegisterFor##Name() \ - { \ - PUERTS_NAMESPACE::RegisterAddon(#Name, (RegFunc)); \ - } \ - } _AutoRegisterFor##Name diff --git a/unity/native_src_il2cpp/Inc/NamespaceDef.h b/unity/native_src_il2cpp/Inc/NamespaceDef.h deleted file mode 100644 index 3a55a8c1e7..0000000000 --- a/unity/native_src_il2cpp/Inc/NamespaceDef.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#pragma once - -#include "PuertsNamespaceDef.h" - -#if defined(WITH_QJS_NAMESPACE_SUFFIX) -namespace v8 = v8_qjs; -#endif diff --git a/unity/native_src_il2cpp/Inc/ObjectCacheNode.h b/unity/native_src_il2cpp/Inc/ObjectCacheNode.h deleted file mode 100644 index e047d440be..0000000000 --- a/unity/native_src_il2cpp/Inc/ObjectCacheNode.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#pragma once - -#include "NamespaceDef.h" - -PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS -#pragma warning(push, 0) -#include "v8.h" -#pragma warning(pop) -PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS - -namespace PUERTS_NAMESPACE -{ -class FObjectCacheNode -{ -public: - V8_INLINE FObjectCacheNode(const void* TypeId_) : TypeId(TypeId_), UserData(nullptr), Next(nullptr), MustCallFinalize(false) - { - } - - V8_INLINE FObjectCacheNode(const void* TypeId_, FObjectCacheNode* Next_) - : TypeId(TypeId_), UserData(nullptr), Next(Next_), MustCallFinalize(false) - { - } - - V8_INLINE FObjectCacheNode(FObjectCacheNode&& other) noexcept - : TypeId(other.TypeId) - , UserData(other.UserData) - , Next(other.Next) - , Value(std::move(other.Value)) - , MustCallFinalize(other.MustCallFinalize) - { - other.TypeId = nullptr; - other.UserData = nullptr; - other.Next = nullptr; - other.MustCallFinalize = false; - } - - V8_INLINE FObjectCacheNode& operator=(FObjectCacheNode&& rhs) noexcept - { - TypeId = rhs.TypeId; - Next = rhs.Next; - Value = std::move(rhs.Value); - UserData = rhs.UserData; - MustCallFinalize = rhs.MustCallFinalize; - rhs.UserData = nullptr; - rhs.TypeId = nullptr; - rhs.Next = nullptr; - rhs.MustCallFinalize = false; - return *this; - } - - ~FObjectCacheNode() - { - if (Next) - delete Next; - } - - V8_INLINE FObjectCacheNode* Find(const void* TypeId_) - { - if (TypeId_ == TypeId) - { - return this; - } - if (Next) - { - return Next->Find(TypeId_); - } - return nullptr; - } - - FObjectCacheNode* Remove(const void* TypeId_, bool IsHead) - { - if (TypeId_ == TypeId) - { - if (IsHead) - { - if (Next) - { - auto PreNext = Next; - *this = std::move(*Next); - delete PreNext; - } - else - { - TypeId = nullptr; - Next = nullptr; - Value.Reset(); - } - } - return this; - } - if (Next) - { - auto Removed = Next->Remove(TypeId_, false); - if (Removed && Removed == Next) // detach & delete by prev node - { - Next = Removed->Next; - Removed->Next = nullptr; - delete Removed; - } - return Removed; - } - return nullptr; - } - - V8_INLINE FObjectCacheNode* Add(const void* TypeId_) - { - Next = new FObjectCacheNode(TypeId_, Next); - return Next; - } - - const void* TypeId; - - void* UserData; - - FObjectCacheNode* Next; - - v8::UniquePersistent Value; - - bool MustCallFinalize; - - FObjectCacheNode(const FObjectCacheNode&) = delete; - void operator=(const FObjectCacheNode&) = delete; -}; - -} // namespace PUERTS_NAMESPACE diff --git a/unity/native_src_il2cpp/Inc/ObjectMapper.h b/unity/native_src_il2cpp/Inc/ObjectMapper.h deleted file mode 100644 index 4cd48a43ba..0000000000 --- a/unity/native_src_il2cpp/Inc/ObjectMapper.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#pragma once - -#if USING_IN_UNREAL_ENGINE -#include "CoreMinimal.h" -#include "PropertyTranslator.h" -#include "StructWrapper.h" -#endif -#include "JSClassRegister.h" - -#include "NamespaceDef.h" - -PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS -#pragma warning(push, 0) -#include "v8.h" -#pragma warning(pop) -PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS - -#include - -namespace PUERTS_NAMESPACE -{ -class ICppObjectMapper -{ -public: - virtual void BindCppObject(v8::Isolate* Isolate, JSClassDefinition* ClassDefinition, void* Ptr, v8::Local JSObject, - bool PassByPointer) = 0; - - virtual void UnBindCppObject(v8::Isolate* Isolate, JSClassDefinition* ClassDefinition, void* Ptr) = 0; - - virtual v8::Local FindOrAddCppObject( - v8::Isolate* Isolate, v8::Local& Context, const void* TypeId, void* Ptr, bool PassByPointer) = 0; - - - virtual v8::MaybeLocal CreateFunction(v8::Local Context, pesapi_callback Callback, void* Data) = 0; - - virtual bool IsInstanceOfCppObject(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject) = 0; - - virtual void* GetPrivateData(v8::Local Context, v8::Local JSObject) = 0; - - virtual void SetPrivateData(v8::Local Context, v8::Local JSObject, void* Ptr) = 0; - - virtual v8::MaybeLocal LoadTypeById(v8::Local Context, const void* TypeId) = 0; - - virtual std::weak_ptr GetJsEnvLifeCycleTracker() = 0; - - virtual ~ICppObjectMapper() - { - } -}; - -#if USING_IN_UNREAL_ENGINE -class IObjectMapper : public ICppObjectMapper -{ -public: - virtual void Bind(FClassWrapper* ClassWrapper, UObject* UEObject, v8::Local JSObject) = 0; - - virtual void UnBind(UClass* Class, UObject* UEObject) = 0; - - virtual v8::Local FindOrAdd( - v8::Isolate* Isolate, v8::Local& Context, UClass* Class, UObject* UEObject) = 0; - - virtual void BindStruct( - FScriptStructWrapper* ScriptStructWrapper, void* Ptr, v8::Local JSObject, bool PassByPointer) = 0; - - virtual void UnBindStruct(FScriptStructWrapper* ScriptStructWrapper, void* Ptr) = 0; - - // PassByPointer为false代表需要在js对象释放时,free相应的内存 - // 相关信息见该issue:https://github.com/Tencent/puerts/issues/693 - virtual v8::Local FindOrAddStruct( - v8::Isolate* Isolate, v8::Local& Context, UScriptStruct* ScriptStruct, void* Ptr, bool PassByPointer) = 0; - - virtual void Merge( - v8::Isolate* Isolate, v8::Local Context, v8::Local Src, UStruct* DesType, void* Des) = 0; - - virtual void UnBindContainer(void* Ptr) = 0; - - virtual v8::Local FindOrAddContainer( - v8::Isolate* Isolate, v8::Local& Context, PropertyMacro* Property, FScriptArray* Ptr, bool PassByPointer) = 0; - - virtual v8::Local FindOrAddContainer( - v8::Isolate* Isolate, v8::Local& Context, PropertyMacro* Property, FScriptSet* Ptr, bool PassByPointer) = 0; - - virtual v8::Local FindOrAddContainer(v8::Isolate* Isolate, v8::Local& Context, - PropertyMacro* KeyProperty, PropertyMacro* ValueProperty, FScriptMap* Ptr, bool PassByPointer) = 0; - - virtual v8::Local FindOrAddDelegate(v8::Isolate* Isolate, v8::Local& Context, UObject* Owner, - PropertyMacro* Property, void* DelegatePtr, bool PassByPointer) = 0; - - virtual bool AddToDelegate( - v8::Isolate* Isolate, v8::Local& Context, void* DelegatePtr, v8::Local JsFunction) = 0; - - virtual PropertyMacro* FindDelegateProperty(void* DelegatePtr) = 0; - - virtual FScriptDelegate NewDelegate(v8::Isolate* Isolate, v8::Local& Context, UObject* Owner, - v8::Local JsFunction, UFunction* SignatureFunction) = 0; - - virtual bool RemoveFromDelegate( - v8::Isolate* Isolate, v8::Local& Context, void* DelegatePtr, v8::Local JsFunction) = 0; - - virtual bool ClearDelegate(v8::Isolate* Isolate, v8::Local& Context, void* DelegatePtr) = 0; - - virtual void ExecuteDelegate(v8::Isolate* Isolate, v8::Local& Context, - const v8::FunctionCallbackInfo& Info, void* DelegatePtr) = 0; - - virtual v8::Local CreateArray( - v8::Isolate* Isolate, v8::Local& Context, FPropertyTranslator* Property, void* ArrayPtr) = 0; - - virtual bool IsInstanceOf(UStruct* Struct, v8::Local JsObject) = 0; - - virtual v8::Local AddSoftObjectPtr( - v8::Isolate* Isolate, v8::Local Context, FSoftObjectPtr* SoftObjectPtr, UClass* Class, bool IsSoftClass) = 0; -}; -#endif - -} // namespace PUERTS_NAMESPACE diff --git a/unity/native_src_il2cpp/Inc/PuertsNamespaceDef.h b/unity/native_src_il2cpp/Inc/PuertsNamespaceDef.h deleted file mode 100644 index 7cb5b16516..0000000000 --- a/unity/native_src_il2cpp/Inc/PuertsNamespaceDef.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#pragma once - -#if !defined(PUERTS_NAMESPACE) -#if defined(WITH_QJS_NAMESPACE_SUFFIX) -#define PUERTS_NAMESPACE puerts_qjs -#else -#define PUERTS_NAMESPACE puerts -#endif -#endif - -#ifndef PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS -#if defined(_MSC_VER) -#define PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS __pragma(warning(push)) __pragma(warning(disable : 4668)) -#elif defined(__clang__) -#define PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS \ - _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wundef\"") -#elif defined(__GNUC__) -#define PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wundef\"") -#endif -#endif // PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS - -#ifndef PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS -#if defined(_MSC_VER) -#define PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS __pragma(warning(pop)) -#elif defined(__clang__) -#define PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS _Pragma("clang diagnostic pop") -#elif defined(__GNUC__) -#define PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS _Pragma("GCC diagnostic pop") -#endif -#endif // PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS - -#ifndef MSVC_PRAGMA -#if !defined(__clang__) && defined(_MSC_VER) -#define MSVC_PRAGMA(Pragma) __pragma(Pragma) -#else -#define MSVC_PRAGMA(...) -#endif -#endif diff --git a/unity/native_src_il2cpp/Inc/TypeInfo.hpp b/unity/native_src_il2cpp/Inc/TypeInfo.hpp deleted file mode 100644 index 2400fd95ed..0000000000 --- a/unity/native_src_il2cpp/Inc/TypeInfo.hpp +++ /dev/null @@ -1,536 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#pragma once - -#include -#ifdef WITH_V8_FAST_CALL -#include "V8FastCall.hpp" -#endif -#include "PuertsNamespaceDef.h" - -#define __DefScriptTTypeName(CLSNAME, CLS) \ - namespace PUERTS_NAMESPACE \ - { \ - template <> \ - struct ScriptTypeName \ - { \ - static constexpr auto value() \ - { \ - return internal::Literal(#CLSNAME); \ - } \ - }; \ - } - -#define PUERTS_BINDING_PROTO_ID() "fdq4falqlqcq" - -#if defined(WITH_QJS_NAMESPACE_SUFFIX) -namespace v8_qjs -{ -class CFunction; -} - -namespace v8 = v8_qjs; -#else -namespace v8 -{ -class CFunction; -} -#endif - -namespace PUERTS_NAMESPACE -{ -namespace internal -{ -template -class StringLiteral -{ -public: - template - constexpr StringLiteral(Characters... characters) : m_value{characters..., '\0'} - { - } - - template - constexpr StringLiteral(const char (&value)[N + 1], std::index_sequence dummy) : StringLiteral(value[Indexes]...) - { - } - - constexpr StringLiteral(const char (&value)[N + 1]) : StringLiteral(value, std::make_index_sequence{}) - { - } - - constexpr char operator[](const std::size_t index) const - { - return m_value[index]; - } - - constexpr const char* Data() const - { - return m_value; - } - - template - constexpr StringLiteral Sub(std::index_sequence dummy) const - { - return StringLiteral(m_value[Start + Index]...); - } - - template - constexpr StringLiteral Sub() const - { - return Sub(std::make_index_sequence()); - } - -private: - const char m_value[N + 1]; -}; - -template -constexpr StringLiteral ConcatStrings( - const Left& lhs, const Right& rhs, std::index_sequence dummy1, std::index_sequence dummy2) -{ - return StringLiteral(lhs[IndexesLeft]..., rhs[IndexesRight]...); -} - -template -constexpr StringLiteral operator+(const StringLiteral& lhs, const StringLiteral& rhs) -{ - return ConcatStrings(lhs, rhs, std::make_index_sequence(), std::make_index_sequence()); -} - -template -constexpr auto Literal(const char (&value)[N]) -{ - return StringLiteral(value, typename std::make_index_sequence{}); -} - -} // namespace internal - -template -struct ScriptTypeName -{ -}; - -template -struct ScriptTypeNameWithNamespace -{ - static constexpr auto value() - { - return ScriptTypeName::value(); - } -}; - -template -struct ScriptTypeName -{ - static constexpr auto value() - { - return ScriptTypeName::type>::value(); - } -}; - -template -struct ScriptTypeName -{ - static constexpr auto value() - { - return ScriptTypeName::type>::value(); - } -}; - -template -struct ScriptTypeName -{ - static constexpr auto value() - { - return ScriptTypeName::type>::value(); - } -}; - -template -struct ScriptTypeName::value && sizeof(T) == 8>::type> -{ - static constexpr auto value() - { - return internal::Literal("bigint"); - } -}; - -template -struct ScriptTypeName::value>::type> -{ - static constexpr auto value() - { - return internal::Literal("number"); - } -}; - -template -struct ScriptTypeName::value || (std::is_integral::value && sizeof(T) < 8)>::type> -{ - static constexpr auto value() - { - return internal::Literal("number"); - } -}; - -template <> -struct ScriptTypeName -{ - static constexpr auto value() - { - return internal::Literal("string"); - } -}; - -template <> -struct ScriptTypeName -{ - static constexpr auto value() - { - return internal::Literal("cstring"); - } -}; - -template <> -struct ScriptTypeName -{ - static constexpr auto value() - { - return internal::Literal("boolean"); - } -}; - -template <> -struct ScriptTypeName -{ - static constexpr auto value() - { - return internal::Literal("void"); - } -}; - -template -struct StaticTypeId -{ - static const void* get() - { - static T* dummy = nullptr; - return &dummy; - } -}; - -template -struct DynamicTypeId -{ - static const void* get(T* Obj) - { - return StaticTypeId::get(); - } -}; - -template -struct is_uetype : std::false_type -{ -}; - -template -struct is_objecttype : std::false_type -{ -}; - -template -struct is_script_type : std::false_type -{ -}; - -template -struct is_script_type::value && !std::is_same::value>::type> - : std::true_type -{ -}; - -template <> -struct is_script_type : std::true_type -{ -}; - -template -struct ScriptTypeName::value && !std::is_const::value>::type> -{ - static constexpr auto value() - { - return internal::Literal("ArrayBuffer"); - } -}; - -template <> -struct ScriptTypeName -{ - static constexpr auto value() - { - return internal::Literal("any"); - } -}; - -template <> -struct ScriptTypeName -{ - static constexpr auto value() - { - return internal::Literal("any"); - } -}; - -class CTypeInfo -{ -public: - virtual const char* Name() const = 0; - virtual bool IsPointer() const = 0; - virtual bool IsRef() const = 0; - virtual bool IsConst() const = 0; - virtual bool IsUEType() const = 0; - virtual bool IsObjectType() const = 0; -}; - -class CFunctionInfo -{ -public: - virtual const CTypeInfo* Return() const = 0; - virtual unsigned int ArgumentCount() const = 0; - virtual unsigned int DefaultCount() const = 0; - virtual const CTypeInfo* Argument(unsigned int index) const = 0; - virtual const char* CustomSignature() const = 0; - virtual const class v8::CFunction* FastCallInfo() const = 0; -}; - -template -class CTypeInfoImpl : CTypeInfo -{ -public: - virtual const char* Name() const override - { - static auto NameLiteral = ScriptTypeName::value(); - return NameLiteral.Data(); - } - virtual bool IsPointer() const override - { - return std::is_pointer::value && !ScriptTypePtrAsRef; - }; - virtual bool IsRef() const override - { - return (std::is_reference::value && !std::is_const::type>::value) || - (std::is_pointer::value && - !std::is_same::type>::type>::value && - !std::is_same::type>::type>::value && - ScriptTypePtrAsRef && !IsUEType() && !IsObjectType()); - }; - virtual bool IsConst() const override - { - return std::is_const::type>::type>::value; - }; - virtual bool IsUEType() const override - { - return is_uetype::type>::type>::type>::value; - }; - virtual bool IsObjectType() const override - { - return is_objecttype< - typename std::remove_const::type>::type>::type>::value; - }; - - static const CTypeInfo* get() - { - static CTypeInfoImpl instance; - return &instance; - } -}; - -template -class CFunctionInfoImpl : public CFunctionInfo -{ -protected: - const CTypeInfo* return_; - const unsigned int argCount_; - const CTypeInfo* arguments_[sizeof...(Args) + 1]; - unsigned int defaultCount_; - - CFunctionInfoImpl() - : return_(CTypeInfoImpl::get()) - , argCount_(sizeof...(Args)) - , arguments_{CTypeInfoImpl::get()...} - , defaultCount_(0) - { - } - - virtual ~CFunctionInfoImpl() - { - } - -public: - virtual const CTypeInfo* Return() const override - { - return return_; - } - virtual unsigned int ArgumentCount() const override - { - return argCount_ - StartParameter; - } - virtual unsigned int DefaultCount() const override - { - return defaultCount_; - } - virtual const CTypeInfo* Argument(unsigned int index) const override - { - return arguments_[index + StartParameter]; - } - virtual const char* CustomSignature() const override - { - return nullptr; - } - virtual const class v8::CFunction* FastCallInfo() const override - { - return nullptr; - }; - - static const CFunctionInfo* get(unsigned int defaultCount) - { - static CFunctionInfoImpl instance{}; - instance.defaultCount_ = defaultCount; - return &instance; - } -}; - -template -class CFunctionInfoByPtrImpl -{ -}; - -template -class CFunctionInfoByPtrImpl - : public CFunctionInfoImpl -{ -public: - virtual ~CFunctionInfoByPtrImpl() - { - } -#ifdef WITH_V8_FAST_CALL - virtual const class v8::CFunction* FastCallInfo() const override - { - return V8FastCall::info(); - }; -#endif - - static const CFunctionInfo* get(unsigned int defaultCount) - { - static CFunctionInfoByPtrImpl instance{}; - instance.defaultCount_ = defaultCount; - return &instance; - } -}; - -template -class CFunctionInfoByPtrImpl - : public CFunctionInfoImpl -{ -public: - virtual ~CFunctionInfoByPtrImpl() - { - } -#ifdef WITH_V8_FAST_CALL - virtual const class v8::CFunction* FastCallInfo() const override - { - return V8FastCall::info(); - }; -#endif - - static const CFunctionInfo* get(unsigned int defaultCount) - { - static CFunctionInfoByPtrImpl instance{}; - instance.defaultCount_ = defaultCount; - return &instance; - } -}; - -template -class CFunctionInfoByPtrImpl - : public CFunctionInfoImpl -{ -public: - virtual ~CFunctionInfoByPtrImpl() - { - } -#ifdef WITH_V8_FAST_CALL - virtual const class v8::CFunction* FastCallInfo() const override - { - return V8FastCall::info(); - }; -#endif - - static const CFunctionInfo* get(unsigned int defaultCount) - { - static CFunctionInfoByPtrImpl instance{}; - instance.defaultCount_ = defaultCount; - return &instance; - } -}; - -class CFunctionInfoWithCustomSignature : public CFunctionInfo -{ - const char* _signature; - -public: - CFunctionInfoWithCustomSignature(const char* signature) : _signature(signature) - { - } - - virtual ~CFunctionInfoWithCustomSignature() - { - } - - virtual const CTypeInfo* Return() const override - { - return nullptr; - } - virtual unsigned int ArgumentCount() const override - { - return 0; - } - virtual unsigned int DefaultCount() const override - { - return 0; - } - virtual const CTypeInfo* Argument(unsigned int index) const override - { - return nullptr; - } - virtual const char* CustomSignature() const override - { - return _signature; - } - virtual const class v8::CFunction* FastCallInfo() const override - { - return nullptr; - }; -}; - -struct NamedFunctionInfo -{ - const char* Name; - const CFunctionInfo* Type; -}; - -struct NamedPropertyInfo -{ - const char* Name; - const CTypeInfo* Type; -}; - -} // namespace PUERTS_NAMESPACE diff --git a/unity/native_src_il2cpp/Inc/pesapi.h b/unity/native_src_il2cpp/Inc/pesapi.h deleted file mode 100644 index cd421a7314..0000000000 --- a/unity/native_src_il2cpp/Inc/pesapi.h +++ /dev/null @@ -1,358 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#ifndef PS_API_H_ -#define PS_API_H_ - -#include -#include -#include - -// Portable Embedded Scripting API - -#define PESAPI_VERSION 11 - -#define PESAPI_EXTERN - -#if defined(__APPLE__) && defined(BUILDING_PES_EXTENSION) && !defined(PESAPI_ADPT_C) -#include "TargetConditionals.h" -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR -#define USING_OBJC_REFLECTION -#endif -#endif - -#ifdef USING_OBJC_REFLECTION -#import -#endif - -#ifdef _WIN32 -#define PESAPI_MODULE_EXPORT __declspec(dllexport) -#else -#define PESAPI_MODULE_EXPORT __attribute__((visibility("default"))) -#endif - -#if defined(__GNUC__) -#define PESAPI_NO_RETURN __attribute__((noreturn)) -#elif defined(_WIN32) -#define PESAPI_NO_RETURN __declspec(noreturn) -#else -#define PESAPI_NO_RETURN -#endif - -#ifdef __cplusplus -#define EXTERN_C_START \ - extern "C" \ - { -#define EXTERN_C_END } -#else -#define EXTERN_C_START -#define EXTERN_C_END -#endif - -#define PESAPI_MODULE_INITIALIZER_X(base, module, version) PESAPI_MODULE_INITIALIZER_X_HELPER(base, module, version) - -#define PESAPI_MODULE_INITIALIZER_X_HELPER(base, module, version) base##module##_v##version - -#define PESAPI_MODULE_INITIALIZER_BASE pesapi_register_ - -#define PESAPI_MODULE_INITIALIZER(modname) PESAPI_MODULE_INITIALIZER_X(PESAPI_MODULE_INITIALIZER_BASE, modname, PESAPI_VERSION) - -#define PESAPI_MODULE_VERSION() PESAPI_MODULE_INITIALIZER_X(PESAPI_MODULE_INITIALIZER_BASE, version, 0) - -#ifdef USING_OBJC_REFLECTION - -#define PESAPI_MODULE(modname, initfunc) \ - @interface PESAPI_MODULE_INITIALIZER (modname) : NSObject \ -@end \ - @implementation PESAPI_MODULE_INITIALIZER (modname) \ - +(void) initlib : (pesapi_func_ptr*) func_ptr_array \ - { \ - pesapi_init(func_ptr_array); \ - initfunc(); \ - } \ - @end - -#else - -#define PESAPI_MODULE(modname, initfunc) \ - EXTERN_C_START \ - PESAPI_MODULE_EXPORT void PESAPI_MODULE_INITIALIZER(modname)(pesapi_func_ptr * func_ptr_array); \ - PESAPI_MODULE_EXPORT const char* PESAPI_MODULE_INITIALIZER(dynamic)(pesapi_func_ptr * func_ptr_array); \ - PESAPI_MODULE_EXPORT int PESAPI_MODULE_VERSION()(); \ - EXTERN_C_END \ - PESAPI_MODULE_EXPORT void PESAPI_MODULE_INITIALIZER(modname)(pesapi_func_ptr * func_ptr_array) \ - { \ - pesapi_init(func_ptr_array); \ - initfunc(); \ - } \ - PESAPI_MODULE_EXPORT const char* PESAPI_MODULE_INITIALIZER(dynamic)(pesapi_func_ptr * func_ptr_array) \ - { \ - if (func_ptr_array) \ - { \ - pesapi_init(func_ptr_array); \ - initfunc(); \ - } \ - return #modname; \ - } \ - PESAPI_MODULE_EXPORT int PESAPI_MODULE_VERSION()() \ - { \ - return PESAPI_VERSION; \ - } - -#endif - -EXTERN_C_START - -// alloc on stack -struct pesapi_scope_memory -{ - int padding__[32]; -}; - -typedef struct pesapi_env__* pesapi_env; -typedef struct pesapi_env_ref__* pesapi_env_ref; -typedef struct pesapi_value__* pesapi_value; -typedef struct pesapi_value_ref__* pesapi_value_ref; -typedef struct pesapi_callback_info__* pesapi_callback_info; -typedef struct pesapi_scope__* pesapi_scope; -typedef struct pesapi_type_info__* pesapi_type_info; -typedef struct pesapi_signature_info__* pesapi_signature_info; -typedef struct pesapi_property_descriptor__* pesapi_property_descriptor; - -typedef void (*pesapi_callback)(struct pesapi_ffi* apis, pesapi_callback_info info); -typedef void* (*pesapi_constructor)(struct pesapi_ffi* apis, pesapi_callback_info info); -typedef void (*pesapi_finalize)(struct pesapi_ffi* apis, void* ptr, void* class_data, void* env_private); -typedef void* (*pesapi_on_native_object_enter)(void* ptr, void* class_data, void* env_private); -// userdata: return of pesapi_on_native_object_enter -typedef void (*pesapi_on_native_object_exit)(void* ptr, void* class_data, void* env_private, void* userdata); -typedef bool (*pesapi_class_not_found_callback)(const void* type_id); -typedef void (*pesapi_func_ptr)(void); - -#ifdef BUILDING_PES_EXTENSION -PESAPI_EXTERN void pesapi_init(pesapi_func_ptr* func_array); -#else -PESAPI_MODULE_EXPORT int pesapi_load_addon(const char* path, const char* module_name); -#endif - -// value process -typedef pesapi_value (*pesapi_create_null_func)(pesapi_env env); -typedef pesapi_value (*pesapi_create_undefined_func)(pesapi_env env); -typedef pesapi_value (*pesapi_create_boolean_func)(pesapi_env env, bool value); -typedef pesapi_value (*pesapi_create_int32_func)(pesapi_env env, int32_t value); -typedef pesapi_value (*pesapi_create_uint32_func)(pesapi_env env, uint32_t value); -typedef pesapi_value (*pesapi_create_int64_func)(pesapi_env env, int64_t value); -typedef pesapi_value (*pesapi_create_uint64_func)(pesapi_env env, uint64_t value); -typedef pesapi_value (*pesapi_create_double_func)(pesapi_env env, double value); -typedef pesapi_value (*pesapi_create_string_utf8_func)(pesapi_env env, const char* str, size_t length); -typedef pesapi_value (*pesapi_create_binary_func)(pesapi_env env, void* str, size_t length); -typedef pesapi_value (*pesapi_create_array_func)(pesapi_env env); -typedef pesapi_value (*pesapi_create_object_func)(pesapi_env env); -typedef pesapi_value (*pesapi_create_function_func)(pesapi_env env, pesapi_callback native_impl, void* data); -typedef pesapi_value (*pesapi_create_class_func)(pesapi_env env, const void* type_id); - -typedef bool (*pesapi_get_value_bool_func)(pesapi_env env, pesapi_value value); -typedef int32_t (*pesapi_get_value_int32_func)(pesapi_env env, pesapi_value value); -typedef uint32_t (*pesapi_get_value_uint32_func)(pesapi_env env, pesapi_value value); -typedef int64_t (*pesapi_get_value_int64_func)(pesapi_env env, pesapi_value value); -typedef uint64_t (*pesapi_get_value_uint64_func)(pesapi_env env, pesapi_value value); -typedef double (*pesapi_get_value_double_func)(pesapi_env env, pesapi_value value); -typedef const char* (*pesapi_get_value_string_utf8_func)(pesapi_env env, pesapi_value value, char* buf, size_t* bufsize); -typedef void* (*pesapi_get_value_binary_func)(pesapi_env env, pesapi_value pvalue, size_t* bufsize); -typedef uint32_t (*pesapi_get_array_length_func)(pesapi_env env, pesapi_value value); - -typedef bool (*pesapi_is_null_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_undefined_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_boolean_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_int32_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_uint32_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_int64_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_uint64_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_double_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_string_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_object_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_function_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_binary_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_array_func)(pesapi_env env, pesapi_value value); - -typedef pesapi_value (*pesapi_native_object_to_value_func)(pesapi_env env, const void* type_id, void* object_ptr, bool call_finalize); -typedef void* (*pesapi_get_native_object_ptr_func)(pesapi_env env, pesapi_value value); -typedef const void* (*pesapi_get_native_object_typeid_func)(pesapi_env env, pesapi_value value); -typedef bool (*pesapi_is_instance_of_func)(pesapi_env env, const void* type_id, pesapi_value value); - -typedef pesapi_value (*pesapi_boxing_func)(pesapi_env env, pesapi_value value); -typedef pesapi_value (*pesapi_unboxing_func)(pesapi_env env, pesapi_value value); -typedef void (*pesapi_update_boxed_value_func)(pesapi_env env, pesapi_value boxed_value, pesapi_value value); -typedef bool (*pesapi_is_boxed_value_func)(pesapi_env env, pesapi_value value); - -typedef int (*pesapi_get_args_len_func)(pesapi_callback_info info); -typedef pesapi_value (*pesapi_get_arg_func)(pesapi_callback_info info, int index); -typedef pesapi_env (*pesapi_get_env_func)(pesapi_callback_info info); -typedef pesapi_value (*pesapi_get_this_func)(pesapi_callback_info info); -typedef pesapi_value (*pesapi_get_holder_func)(pesapi_callback_info info); -typedef void* (*pesapi_get_userdata_func)(pesapi_callback_info info); -typedef void (*pesapi_add_return_func)(pesapi_callback_info info, pesapi_value value); -typedef void (*pesapi_throw_by_string_func)(pesapi_callback_info pinfo, const char* msg); - -typedef pesapi_env_ref (*pesapi_create_env_ref_func)(pesapi_env env); -typedef bool (*pesapi_env_ref_is_valid_func)(pesapi_env_ref env); -typedef pesapi_env (*pesapi_get_env_from_ref_func)(pesapi_env_ref env_ref); -typedef pesapi_env_ref (*pesapi_duplicate_env_ref_func)(pesapi_env_ref env_ref); -typedef void (*pesapi_release_env_ref_func)(pesapi_env_ref env_ref); -typedef pesapi_scope (*pesapi_open_scope_func)(pesapi_env_ref env_ref); -typedef pesapi_scope (*pesapi_open_scope_placement_func)(pesapi_env_ref env_ref, struct pesapi_scope_memory* memory); -typedef bool (*pesapi_has_caught_func)(pesapi_scope scope); -typedef const char* (*pesapi_get_exception_as_string_func)(pesapi_scope scope, bool with_stack); -typedef void (*pesapi_close_scope_func)(pesapi_scope scope); -typedef void (*pesapi_close_scope_placement_func)(pesapi_scope scope); - -typedef pesapi_value_ref (*pesapi_create_value_ref_func)(pesapi_env env, pesapi_value value, uint32_t internal_field_count); -typedef pesapi_value_ref (*pesapi_duplicate_value_ref_func)(pesapi_value_ref value_ref); -typedef void (*pesapi_release_value_ref_func)(pesapi_value_ref value_ref); -typedef pesapi_value (*pesapi_get_value_from_ref_func)(pesapi_env env, pesapi_value_ref value_ref); -typedef void (*pesapi_set_ref_weak_func)(pesapi_env env, pesapi_value_ref value_ref); -// Optional api: return false if can not fulfill -typedef bool (*pesapi_set_owner_func)(pesapi_env env, pesapi_value value, pesapi_value owner); -// suggestion: struct pesapi_value_ref : pesapi_env_ref {...}; -typedef pesapi_env_ref (*pesapi_get_ref_associated_env_func)(pesapi_value_ref value_ref); -typedef void** (*pesapi_get_ref_internal_fields_func)(pesapi_value_ref value_ref, uint32_t* pinternal_field_count); - -typedef pesapi_value (*pesapi_get_property_func)(pesapi_env env, pesapi_value object, const char* key); -typedef void (*pesapi_set_property_func)(pesapi_env env, pesapi_value object, const char* key, pesapi_value value); -typedef bool (*pesapi_get_private_func)(pesapi_env env, pesapi_value object, void** out_ptr); -typedef bool (*pesapi_set_private_func)(pesapi_env env, pesapi_value object, void* ptr); -typedef pesapi_value (*pesapi_get_property_uint32_func)(pesapi_env env, pesapi_value object, uint32_t key); -typedef void (*pesapi_set_property_uint32_func)(pesapi_env env, pesapi_value object, uint32_t key, pesapi_value value); - -typedef pesapi_value (*pesapi_call_function_func)(pesapi_env env, pesapi_value func, pesapi_value this_object, int argc, const pesapi_value argv[]); -typedef pesapi_value (*pesapi_eval_func)(pesapi_env env, const uint8_t* code, size_t code_size, const char* path); -typedef pesapi_value (*pesapi_global_func)(pesapi_env env); -typedef const void* (*pesapi_get_env_private_func)(pesapi_env env); -typedef void (*pesapi_set_env_private_func)(pesapi_env env, const void* ptr); - -struct pesapi_ffi -{ - pesapi_create_null_func create_null; - pesapi_create_undefined_func create_undefined; - pesapi_create_boolean_func create_boolean; - pesapi_create_int32_func create_int32; - pesapi_create_uint32_func create_uint32; - pesapi_create_int64_func create_int64; - pesapi_create_uint64_func create_uint64; - pesapi_create_double_func create_double; - pesapi_create_string_utf8_func create_string_utf8; - pesapi_create_binary_func create_binary; - pesapi_create_array_func create_array; - pesapi_create_object_func create_object; - pesapi_create_function_func create_function; - pesapi_create_class_func create_class; - pesapi_get_value_bool_func get_value_bool; - pesapi_get_value_int32_func get_value_int32; - pesapi_get_value_uint32_func get_value_uint32; - pesapi_get_value_int64_func get_value_int64; - pesapi_get_value_uint64_func get_value_uint64; - pesapi_get_value_double_func get_value_double; - pesapi_get_value_string_utf8_func get_value_string_utf8; - pesapi_get_value_binary_func get_value_binary; - pesapi_get_array_length_func get_array_length; - pesapi_is_null_func is_null; - pesapi_is_undefined_func is_undefined; - pesapi_is_boolean_func is_boolean; - pesapi_is_int32_func is_int32; - pesapi_is_uint32_func is_uint32; - pesapi_is_int64_func is_int64; - pesapi_is_uint64_func is_uint64; - pesapi_is_double_func is_double; - pesapi_is_string_func is_string; - pesapi_is_object_func is_object; - pesapi_is_function_func is_function; - pesapi_is_binary_func is_binary; - pesapi_is_array_func is_array; - pesapi_native_object_to_value_func native_object_to_value; - pesapi_get_native_object_ptr_func get_native_object_ptr; - pesapi_get_native_object_typeid_func get_native_object_typeid; - pesapi_is_instance_of_func is_instance_of; - pesapi_boxing_func boxing; - pesapi_unboxing_func unboxing; - pesapi_update_boxed_value_func update_boxed_value; - pesapi_is_boxed_value_func is_boxed_value; - pesapi_get_args_len_func get_args_len; - pesapi_get_arg_func get_arg; - pesapi_get_env_func get_env; - pesapi_get_this_func get_this; - pesapi_get_holder_func get_holder; - pesapi_get_userdata_func get_userdata; - pesapi_add_return_func add_return; - pesapi_throw_by_string_func throw_by_string; - pesapi_create_env_ref_func create_env_ref; - pesapi_env_ref_is_valid_func env_ref_is_valid; - pesapi_get_env_from_ref_func get_env_from_ref; - pesapi_duplicate_env_ref_func duplicate_env_ref; - pesapi_release_env_ref_func release_env_ref; - pesapi_open_scope_func open_scope; - pesapi_open_scope_placement_func open_scope_placement; - pesapi_has_caught_func has_caught; - pesapi_get_exception_as_string_func get_exception_as_string; - pesapi_close_scope_func close_scope; - pesapi_close_scope_placement_func close_scope_placement; - pesapi_create_value_ref_func create_value_ref; - pesapi_duplicate_value_ref_func duplicate_value_ref; - pesapi_release_value_ref_func release_value_ref; - pesapi_get_value_from_ref_func get_value_from_ref; - pesapi_set_ref_weak_func set_ref_weak; - pesapi_set_owner_func set_owner; - pesapi_get_ref_associated_env_func get_ref_associated_env; - pesapi_get_ref_internal_fields_func get_ref_internal_fields; - pesapi_get_property_func get_property; - pesapi_set_property_func set_property; - pesapi_get_private_func get_private; - pesapi_set_private_func set_private; - pesapi_get_property_uint32_func get_property_uint32; - pesapi_set_property_uint32_func set_property_uint32; - pesapi_call_function_func call_function; - pesapi_eval_func eval; - pesapi_global_func global; - pesapi_get_env_private_func get_env_private; - pesapi_set_env_private_func set_env_private; -}; - -PESAPI_EXTERN pesapi_type_info pesapi_alloc_type_infos(size_t count); - -PESAPI_EXTERN void pesapi_set_type_info( - pesapi_type_info type_infos, size_t index, const char* name, bool is_pointer, bool is_const, bool is_ref, bool is_primitive); - -PESAPI_EXTERN pesapi_signature_info pesapi_create_signature_info( - pesapi_type_info return_type, size_t parameter_count, pesapi_type_info parameter_types); - -PESAPI_EXTERN pesapi_property_descriptor pesapi_alloc_property_descriptors(size_t count); - -// using pesapi_get_userdata obtain userdata in callback -PESAPI_EXTERN void pesapi_set_method_info(pesapi_property_descriptor properties, size_t index, const char* name, bool is_static, - pesapi_callback method, void* data, pesapi_signature_info signature_info); - -PESAPI_EXTERN void pesapi_set_property_info(pesapi_property_descriptor properties, size_t index, const char* name, bool is_static, - pesapi_callback getter, pesapi_callback setter, void* getter_data, void* setter_data, pesapi_type_info type_info); - -PESAPI_EXTERN void pesapi_define_class(const void* type_id, const void* super_type_id, const char* type_name, - pesapi_constructor constructor, pesapi_finalize finalize, size_t property_count, pesapi_property_descriptor properties, - void* data); - -PESAPI_EXTERN void* pesapi_get_class_data(const void* type_id, bool force_load); - -PESAPI_EXTERN bool pesapi_trace_native_object_lifecycle( - const void* type_id, pesapi_on_native_object_enter on_enter, pesapi_on_native_object_exit on_exit); - -PESAPI_EXTERN void pesapi_on_class_not_found(pesapi_class_not_found_callback callback); - -PESAPI_EXTERN void pesapi_class_type_info(const char* proto_magic_id, const void* type_id, const void* constructor_info, - const void* methods_info, const void* functions_info, const void* properties_info, const void* variables_info); - -PESAPI_EXTERN const void* pesapi_find_type_id(const char* module_name, const char* type_name); - -EXTERN_C_END - -#endif diff --git a/unity/native_src_il2cpp/Src/CppObjectMapper.cpp b/unity/native_src_il2cpp/Src/CppObjectMapper.cpp deleted file mode 100644 index 308e721a80..0000000000 --- a/unity/native_src_il2cpp/Src/CppObjectMapper.cpp +++ /dev/null @@ -1,460 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#include "CppObjectMapper.h" -#include "DataTransfer.h" -#include "pesapi.h" - -namespace PUERTS_NAMESPACE -{ -template -inline void __USE(T&&) -{ -} - -#define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member))) - -static void ThrowException(v8::Isolate* Isolate, const char* Message) -{ - auto ExceptionStr = v8::String::NewFromUtf8(Isolate, Message, v8::NewStringType::kNormal).ToLocalChecked(); - Isolate->ThrowException(v8::Exception::Error(ExceptionStr)); -} - -void FCppObjectMapper::LoadCppType(const v8::FunctionCallbackInfo& Info) -{ - v8::Isolate* Isolate = Info.GetIsolate(); - v8::Isolate::Scope IsolateScope(Isolate); - v8::HandleScope HandleScope(Isolate); - v8::Local Context = Isolate->GetCurrentContext(); - v8::Context::Scope ContextScope(Context); - - if (!Info[0]->IsString()) - { - ThrowException(Isolate, "#0 argument expect a string"); - return; - } - - std::string TypeName = *(v8::String::Utf8Value(Isolate, Info[0])); - - auto ClassDef = FindCppTypeClassByName(TypeName); - if (ClassDef) - { - Info.GetReturnValue().Set(GetTemplateOfClass(Isolate, ClassDef)->GetFunction(Context).ToLocalChecked()); - } - else - { - const std::string ErrMsg = "can not find type: " + TypeName; - ThrowException(Isolate, ErrMsg.c_str()); - } -} - -v8::MaybeLocal FCppObjectMapper::LoadTypeById(v8::Local Context, const void* TypeId) -{ - auto ClassDef = puerts::LoadClassByID(TypeId); - if (!ClassDef) - { - return v8::MaybeLocal(); - } - auto Template = GetTemplateOfClass(Context->GetIsolate(), ClassDef); - return Template->GetFunction(Context); -} - -static void PointerNew(const v8::FunctionCallbackInfo& Info) -{ - // do nothing -} - -void FCppObjectMapper::Initialize(v8::Isolate* InIsolate, v8::Local InContext) -{ - auto LocalTemplate = v8::FunctionTemplate::New(InIsolate, PointerNew); - LocalTemplate->InstanceTemplate()->SetInternalFieldCount(4); // 0 Ptr, 1, CDataName - PointerTemplate = v8::UniquePersistent(InIsolate, LocalTemplate); -#ifndef WITH_QUICKJS - PrivateKey.Reset(InIsolate, v8::Symbol::New(InIsolate)); -#endif -} - -v8::Local FCppObjectMapper::FindOrAddCppObject( - v8::Isolate* Isolate, v8::Local& Context, const void* TypeId, void* Ptr, bool PassByPointer) -{ - if (Ptr == nullptr) - { - return v8::Null(Isolate); - } - - if (PassByPointer) - { - auto Iter = CDataCache.find(Ptr); - if (Iter != CDataCache.end()) - { - auto CacheNodePtr = Iter->second.Find(TypeId); - if (CacheNodePtr) - { - return CacheNodePtr->Value.Get(Isolate); - } - } - } - - // create and link - auto ClassDefinition = LoadClassByID(TypeId); - if (ClassDefinition) - { - auto Result = GetTemplateOfClass(Isolate, ClassDefinition)->InstanceTemplate()->NewInstance(Context).ToLocalChecked(); - BindCppObject(Isolate, const_cast(ClassDefinition), Ptr, Result, PassByPointer); - return Result; - } - else - { - auto Result = PointerTemplate.Get(Isolate)->InstanceTemplate()->NewInstance(Context).ToLocalChecked(); - DataTransfer::SetPointer(Isolate, Result, Ptr, 0); - DataTransfer::SetPointer(Isolate, Result, TypeId, 1); - return Result; - } -} - -static void PesapiFunctionCallback(const v8::FunctionCallbackInfo& info) -{ - PesapiCallbackData* FunctionInfo = container_of(v8::Local::Cast(info.Data())->Value(), struct PesapiCallbackData, Data); - FunctionInfo->Callback(&v8impl::g_pesapi_ffi, (pesapi_callback_info)(&info)); -} - -v8::MaybeLocal FCppObjectMapper::CreateFunction(v8::Local Context, pesapi_callback Callback, void* Data) -{ - auto CallbackData = new PesapiCallbackData {Callback, Data}; - FunctionDatas.push_back(CallbackData); - auto V8Data = v8::External::New(Context->GetIsolate(), &CallbackData->Data); - return v8::FunctionTemplate::New(Context->GetIsolate(), PesapiFunctionCallback, V8Data)->GetFunction(Context); -} - -bool FCppObjectMapper::IsInstanceOfCppObject(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject) -{ - if (DataTransfer::GetPointerFast(JsObject, 1) == TypeId) - { - return true; - } - auto ClassDefinition = FindClassByID(TypeId); - if (ClassDefinition) - { - auto Template = GetTemplateOfClass(Isolate, ClassDefinition); - return Template->HasInstance(JsObject); - } - return false; -} - -std::weak_ptr FCppObjectMapper::GetJsEnvLifeCycleTracker() -{ - return std::weak_ptr(Ref); -} - -static void CDataNew(const v8::FunctionCallbackInfo& Info) -{ - v8::Isolate* Isolate = Info.GetIsolate(); - v8::Isolate::Scope IsolateScope(Isolate); - v8::HandleScope HandleScope(Isolate); - v8::Local Context = Isolate->GetCurrentContext(); - v8::Context::Scope ContextScope(Context); - - if (Info.IsConstructCall()) - { - auto Self = Info.This(); - JSClassDefinition* ClassDefinition = container_of(v8::Local::Cast(Info.Data())->Value(), JSClassDefinition, Data); - void* Ptr = nullptr; - - if (ClassDefinition->Initialize) - Ptr = ClassDefinition->Initialize(&v8impl::g_pesapi_ffi, (pesapi_callback_info) &Info); - if (Ptr == nullptr) - return; - - DataTransfer::IsolateData(Isolate)->BindCppObject(Isolate, ClassDefinition, Ptr, Self, false); - } - else - { - ThrowException(Isolate, "only call as Construct is supported!"); - } -} - -static void PesapiCallbackWrap(const v8::FunctionCallbackInfo& Info) -{ - JSFunctionInfo* FunctionInfo = container_of(v8::Local::Cast(Info.Data())->Value(), JSFunctionInfo, Data); - FunctionInfo->Callback(&v8impl::g_pesapi_ffi, (pesapi_callback_info)(&Info)); -} - -static void PesapiGetterWrap(const v8::FunctionCallbackInfo& Info) -{ - JSPropertyInfo* PropertyInfo = container_of(v8::Local::Cast(Info.Data())->Value(), JSPropertyInfo, GetterData); - PropertyInfo->Getter(&v8impl::g_pesapi_ffi, (pesapi_callback_info)(&Info)); -} - -static void PesapiSetterWrap(const v8::FunctionCallbackInfo& Info) -{ - JSPropertyInfo* PropertyInfo = container_of(v8::Local::Cast(Info.Data())->Value(), JSPropertyInfo, SetterData); - PropertyInfo->Setter(&v8impl::g_pesapi_ffi, (pesapi_callback_info)(&Info)); -} - -v8::Local FCppObjectMapper::GetTemplateOfClass(v8::Isolate* Isolate, const JSClassDefinition* ClassDefinition) -{ - auto Iter = TypeIdToTemplateMap.find(ClassDefinition->TypeId); - if (Iter == TypeIdToTemplateMap.end()) - { - auto Template = v8::FunctionTemplate::New( - Isolate, CDataNew, v8::External::New(Isolate, &(const_cast(ClassDefinition)->Data))); - Template->InstanceTemplate()->SetInternalFieldCount(4); - - JSPropertyInfo* PropertyInfo = ClassDefinition->Properties; - while (PropertyInfo && PropertyInfo->Name && PropertyInfo->Getter) - { - v8::PropertyAttribute PropertyAttribute = v8::DontDelete; - if (!PropertyInfo->Setter) - PropertyAttribute = (v8::PropertyAttribute)(PropertyAttribute | v8::ReadOnly); - auto GetterData = v8::External::New(Isolate, &PropertyInfo->GetterData); - auto SetterData = v8::External::New(Isolate, &PropertyInfo->SetterData); - Template->PrototypeTemplate()->SetAccessorProperty( - v8::String::NewFromUtf8(Isolate, PropertyInfo->Name, v8::NewStringType::kNormal).ToLocalChecked(), - PropertyInfo->Getter ? v8::FunctionTemplate::New(Isolate, &PesapiGetterWrap, GetterData) - : v8::Local(), - PropertyInfo->Setter ? v8::FunctionTemplate::New(Isolate, &PesapiSetterWrap, SetterData) - : v8::Local(), - PropertyAttribute); - ++PropertyInfo; - } - - PropertyInfo = ClassDefinition->Variables; - while (PropertyInfo && PropertyInfo->Name && PropertyInfo->Getter) - { - v8::PropertyAttribute PropertyAttribute = v8::DontDelete; - if (!PropertyInfo->Setter) - PropertyAttribute = (v8::PropertyAttribute)(PropertyAttribute | v8::ReadOnly); - auto GetterData = v8::External::New(Isolate, &PropertyInfo->GetterData); - auto SetterData = v8::External::New(Isolate, &PropertyInfo->SetterData); - Template->SetAccessorProperty( - v8::String::NewFromUtf8(Isolate, PropertyInfo->Name, v8::NewStringType::kNormal).ToLocalChecked(), - PropertyInfo->Getter ? v8::FunctionTemplate::New(Isolate, &PesapiGetterWrap, GetterData) - : v8::Local(), - PropertyInfo->Setter ? v8::FunctionTemplate::New(Isolate, &PesapiSetterWrap, SetterData) - : v8::Local(), - PropertyAttribute); - ++PropertyInfo; - } - - JSFunctionInfo* FunctionInfo = ClassDefinition->Methods; - while (FunctionInfo && FunctionInfo->Name && FunctionInfo->Callback) - { -#ifndef WITH_QUICKJS - auto FastCallInfo = FunctionInfo->ReflectionInfo ? FunctionInfo->ReflectionInfo->FastCallInfo() : nullptr; - if (FastCallInfo) - { - Template->PrototypeTemplate()->Set( - v8::String::NewFromUtf8(Isolate, FunctionInfo->Name, v8::NewStringType::kNormal).ToLocalChecked(), - v8::FunctionTemplate::New(Isolate, &PesapiCallbackWrap, - v8::External::New(Isolate, &FunctionInfo->Data), v8::Local(), 0, - v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasSideEffect, FastCallInfo)); - } - else -#endif - { - Template->PrototypeTemplate()->Set( - v8::String::NewFromUtf8(Isolate, FunctionInfo->Name, v8::NewStringType::kNormal).ToLocalChecked(), - v8::FunctionTemplate::New( - Isolate, &PesapiCallbackWrap, v8::External::New(Isolate, &FunctionInfo->Data) -#ifndef WITH_QUICKJS - , - v8::Local(), 0, v8::ConstructorBehavior::kThrow -#endif - )); - } - ++FunctionInfo; - } - FunctionInfo = ClassDefinition->Functions; - while (FunctionInfo && FunctionInfo->Name && FunctionInfo->Callback) - { -#ifndef WITH_QUICKJS - auto FastCallInfo = FunctionInfo->ReflectionInfo ? FunctionInfo->ReflectionInfo->FastCallInfo() : nullptr; - if (FastCallInfo) - { - Template->Set(v8::String::NewFromUtf8(Isolate, FunctionInfo->Name, v8::NewStringType::kNormal).ToLocalChecked(), - v8::FunctionTemplate::New(Isolate, &PesapiCallbackWrap, - v8::External::New(Isolate, &FunctionInfo->Data), v8::Local(), 0, - v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasSideEffect, FastCallInfo)); - } - else -#endif - { - Template->Set(v8::String::NewFromUtf8(Isolate, FunctionInfo->Name, v8::NewStringType::kNormal).ToLocalChecked(), - v8::FunctionTemplate::New( - Isolate, &PesapiCallbackWrap, v8::External::New(Isolate, &FunctionInfo->Data) -#ifndef WITH_QUICKJS - , - v8::Local(), 0, v8::ConstructorBehavior::kThrow -#endif - )); - } - ++FunctionInfo; - } - - if (ClassDefinition->SuperTypeId) - { - if (auto SuperDefinition = LoadClassByID(ClassDefinition->SuperTypeId)) - { - Template->Inherit(GetTemplateOfClass(Isolate, SuperDefinition)); - } - } - - TypeIdToTemplateMap[ClassDefinition->TypeId] = v8::UniquePersistent(Isolate, Template); - - return Template; - } - else - { - return v8::Local::New(Isolate, Iter->second); - } -} - -static void CDataGarbageCollectedWithFree(const v8::WeakCallbackInfo& Data) -{ - JSClassDefinition* ClassDefinition = Data.GetParameter(); - void* Ptr = DataTransfer::MakeAddressWithHighPartOfTwo(Data.GetInternalField(0), Data.GetInternalField(1)); - if (ClassDefinition->Finalize) - ClassDefinition->Finalize(&v8impl::g_pesapi_ffi, Ptr, ClassDefinition->Data, DataTransfer::GetIsolatePrivateData(Data.GetIsolate())); - DataTransfer::IsolateData(Data.GetIsolate())->UnBindCppObject(Data.GetIsolate(), ClassDefinition, Ptr); -} - -static void CDataGarbageCollectedWithoutFree(const v8::WeakCallbackInfo& Data) -{ - JSClassDefinition* ClassDefinition = Data.GetParameter(); - void* Ptr = DataTransfer::MakeAddressWithHighPartOfTwo(Data.GetInternalField(0), Data.GetInternalField(1)); - DataTransfer::IsolateData(Data.GetIsolate())->UnBindCppObject(Data.GetIsolate(), ClassDefinition, Ptr); -} - -void FCppObjectMapper::BindCppObject( - v8::Isolate* Isolate, JSClassDefinition* ClassDefinition, void* Ptr, v8::Local JSObject, bool PassByPointer) -{ - DataTransfer::SetPointer(Isolate, JSObject, Ptr, 0); - DataTransfer::SetPointer(Isolate, JSObject, ClassDefinition->TypeId, 1); - - auto Iter = CDataCache.find(Ptr); - FObjectCacheNode* CacheNodePtr; - if (Iter != CDataCache.end()) - { - CacheNodePtr = Iter->second.Add(ClassDefinition->TypeId); - } - else - { - auto Ret = CDataCache.insert({Ptr, FObjectCacheNode(ClassDefinition->TypeId)}); - CacheNodePtr = &Ret.first->second; - } - CacheNodePtr->Value.Reset(Isolate, JSObject); - - if (!PassByPointer) - { - CacheNodePtr->MustCallFinalize = true; - CacheNodePtr->Value.SetWeak( - ClassDefinition, CDataGarbageCollectedWithFree, v8::WeakCallbackType::kInternalFields); - } - else - { - CacheNodePtr->Value.SetWeak( - ClassDefinition, CDataGarbageCollectedWithoutFree, v8::WeakCallbackType::kInternalFields); - } - - if (ClassDefinition->OnEnter) - { - CacheNodePtr->UserData = ClassDefinition->OnEnter(Ptr, ClassDefinition->Data, DataTransfer::GetIsolatePrivateData(Isolate)); - } -} - -#define QJS_PRIVATE_KEY_STR "__,kp@" - -void* FCppObjectMapper::GetPrivateData(v8::Local Context, v8::Local JSObject) -{ -#ifndef WITH_QUICKJS - auto Key = PrivateKey.Get(Context->GetIsolate()); -#else - auto Key = FV8Utils::InternalString(Context->GetIsolate(), QJS_PRIVATE_KEY_STR); -#endif - v8::MaybeLocal maybeValue = JSObject->Get(Context, Key); - if (maybeValue.IsEmpty()) - { - return nullptr; - } - - v8::Local maybeExternal = maybeValue.ToLocalChecked(); - if (!maybeExternal->IsExternal()) - { - return nullptr; - } - - return v8::Local::Cast(maybeExternal)->Value(); -} - -void FCppObjectMapper::SetPrivateData(v8::Local Context, v8::Local JSObject, void* Ptr) -{ -#ifndef WITH_QUICKJS - auto Key = PrivateKey.Get(Context->GetIsolate()); -#else - auto Key = FV8Utils::InternalString(Context->GetIsolate(), QJS_PRIVATE_KEY_STR); -#endif - (void) (JSObject->Set(Context, Key, v8::External::New(Context->GetIsolate(), Ptr))); -} - -void FCppObjectMapper::UnBindCppObject(v8::Isolate* Isolate, JSClassDefinition* ClassDefinition, void* Ptr) -{ - auto Iter = CDataCache.find(Ptr); - if (Iter != CDataCache.end()) - { - if (ClassDefinition->OnExit) - { - ClassDefinition->OnExit( - Ptr, ClassDefinition->Data, DataTransfer::GetIsolatePrivateData(Isolate), Iter->second.UserData); - } - auto Removed = Iter->second.Remove(ClassDefinition->TypeId, true); - if (!Iter->second.TypeId) // last one - { - CDataCache.erase(Ptr); - } - } -} - -void FCppObjectMapper::UnInitialize(v8::Isolate* InIsolate) -{ - auto PData = DataTransfer::GetIsolatePrivateData(InIsolate); - for (auto& KV : CDataCache) - { - FObjectCacheNode* PNode = &KV.second; - while (PNode) - { - const JSClassDefinition* ClassDefinition = FindClassByID(PNode->TypeId); - if (PNode->MustCallFinalize) - { - if (ClassDefinition && ClassDefinition->Finalize) - { - ClassDefinition->Finalize(&v8impl::g_pesapi_ffi, KV.first, ClassDefinition->Data, PData); - } - PNode->MustCallFinalize = false; - } - if (ClassDefinition->OnExit) - { - ClassDefinition->OnExit( - KV.first, ClassDefinition->Data, DataTransfer::GetIsolatePrivateData(InIsolate), PNode->UserData); - } - PNode = PNode->Next; - } - } - for(int i = 0;i < FunctionDatas.size(); ++i) - { - delete FunctionDatas[i]; - } - FunctionDatas.clear(); - CDataCache.clear(); - TypeIdToTemplateMap.clear(); -#ifndef WITH_QUICKJS - PrivateKey.Reset(); -#endif - PointerTemplate.Reset(); -} - -} // namespace PUERTS_NAMESPACE diff --git a/unity/native_src_il2cpp/Src/DataTransfer.cpp b/unity/native_src_il2cpp/Src/DataTransfer.cpp deleted file mode 100644 index b16f15c821..0000000000 --- a/unity/native_src_il2cpp/Src/DataTransfer.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#include "DataTransfer.h" -#include "ObjectMapper.h" -#if USING_IN_UNREAL_ENGINE -#include "V8Utils.h" -#endif - -namespace PUERTS_NAMESPACE -{ -v8::Local DataTransfer::FindOrAddCData( - v8::Isolate* Isolate, v8::Local Context, const void* TypeId, const void* Ptr, bool PassByPointer) -{ - return IsolateData(Isolate)->FindOrAddCppObject( - Isolate, Context, TypeId, const_cast(Ptr), PassByPointer); -} - -bool DataTransfer::IsInstanceOf(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject) -{ - return IsolateData(Isolate)->IsInstanceOfCppObject(Isolate, TypeId, JsObject); -} - -v8::Local DataTransfer::UnRef(v8::Isolate* Isolate, const v8::Local& Value) -{ - v8::Local Context = Isolate->GetCurrentContext(); - v8::Local ReturnValue = Value->ToObject(Context).ToLocalChecked()->Get(Context, 0).ToLocalChecked(); - - return ReturnValue; -} - -void DataTransfer::UpdateRef(v8::Isolate* Isolate, v8::Local Outer, const v8::Local& Value) -{ - v8::Local Context = Isolate->GetCurrentContext(); - - auto Ret = Outer->ToObject(Context).ToLocalChecked()->Set(Context, 0, Value); -} - -std::weak_ptr DataTransfer::GetJsEnvLifeCycleTracker(v8::Isolate* Isolate) -{ - return IsolateData(Isolate)->GetJsEnvLifeCycleTracker(); -} - -#if USING_IN_UNREAL_ENGINE -FString DataTransfer::ToFString(v8::Isolate* Isolate, v8::Local Value) -{ - return FV8Utils::ToFString(Isolate, Value); -} - -v8::Local DataTransfer::FindOrAddObject( - v8::Isolate* Isolate, v8::Local& Context, UClass* Class, UObject* UEObject) -{ - return FV8Utils::IsolateData(Isolate)->FindOrAdd(Isolate, Context, Class, UEObject); -} - -v8::Local DataTransfer::FindOrAddStruct( - v8::Isolate* Isolate, v8::Local Context, UScriptStruct* ScriptStruct, void* Ptr, bool PassByPointer) -{ - return FV8Utils::IsolateData(Isolate)->FindOrAddStruct(Isolate, Context, ScriptStruct, Ptr, PassByPointer); -} - -bool DataTransfer::IsInstanceOf(v8::Isolate* Isolate, UStruct* Struct, v8::Local JsObject) -{ - return FV8Utils::IsolateData(Isolate)->IsInstanceOf(Struct, JsObject); -} - -void DataTransfer::ThrowException(v8::Isolate* Isolate, const char* Message) -{ - FV8Utils::ThrowException(Isolate, Message); -} -#endif -} // namespace PUERTS_NAMESPACE diff --git a/unity/native_src_il2cpp/Src/JSClassRegister.cpp b/unity/native_src_il2cpp/Src/JSClassRegister.cpp deleted file mode 100644 index d8cec9020e..0000000000 --- a/unity/native_src_il2cpp/Src/JSClassRegister.cpp +++ /dev/null @@ -1,392 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#include "JSClassRegister.h" -#if USING_IN_UNREAL_ENGINE -#include "UObject/Class.h" -#endif -#include -#include - -namespace PUERTS_NAMESPACE -{ -template -static T* PropertyInfoDuplicate(T* Arr) -{ - if (Arr == nullptr) - return nullptr; - int Count = 0; - ; - while (true) - { - if (Arr[Count++].Name == nullptr) - break; - } - T* Ret = new T[Count]; - ::memcpy(Ret, Arr, sizeof(T) * Count); - return Ret; -} - -JSClassDefinition* JSClassDefinitionDuplicate(const JSClassDefinition* ClassDefinition) -{ - auto Ret = new JSClassDefinition; - ::memcpy(Ret, ClassDefinition, sizeof(JSClassDefinition)); - Ret->Methods = PropertyInfoDuplicate(ClassDefinition->Methods); - Ret->Functions = PropertyInfoDuplicate(ClassDefinition->Functions); - Ret->Properties = PropertyInfoDuplicate(ClassDefinition->Properties); - Ret->Variables = PropertyInfoDuplicate(ClassDefinition->Variables); - Ret->ConstructorInfos = PropertyInfoDuplicate(ClassDefinition->ConstructorInfos); - Ret->MethodInfos = PropertyInfoDuplicate(ClassDefinition->MethodInfos); - Ret->FunctionInfos = PropertyInfoDuplicate(ClassDefinition->FunctionInfos); - Ret->PropertyInfos = PropertyInfoDuplicate(ClassDefinition->PropertyInfos); - Ret->VariableInfos = PropertyInfoDuplicate(ClassDefinition->VariableInfos); - return Ret; -} - -void JSClassDefinitionDelete(JSClassDefinition* ClassDefinition) -{ - delete[] ClassDefinition->Methods; - delete[] ClassDefinition->Functions; - delete[] ClassDefinition->Properties; - delete[] ClassDefinition->Variables; - delete[] ClassDefinition->ConstructorInfos; - delete[] ClassDefinition->MethodInfos; - delete[] ClassDefinition->FunctionInfos; - delete[] ClassDefinition->PropertyInfos; - delete[] ClassDefinition->VariableInfos; - delete ClassDefinition; -} - -class JSClassRegister -{ -public: - JSClassRegister(); - ~JSClassRegister(); - - void RegisterClass(const JSClassDefinition& ClassDefinition); - - void SetClassTypeInfo(const void* TypeId, const NamedFunctionInfo* ConstructorInfos, const NamedFunctionInfo* MethodInfos, - const NamedFunctionInfo* FunctionInfos, const NamedPropertyInfo* PropertyInfos, const NamedPropertyInfo* VariableInfos); - - void ForeachRegisterClass(std::function); - - const JSClassDefinition* FindClassByID(const void* TypeId); - - void OnClassNotFound(pesapi_class_not_found_callback InCallback) - { - ClassNotFoundCallback = InCallback; - } - - const JSClassDefinition* LoadClassByID(const void* TypeId) - { - if (!TypeId) - { - return nullptr; - } - auto clsDef = FindClassByID(TypeId); - if (!clsDef && ClassNotFoundCallback) - { - if (!ClassNotFoundCallback(TypeId)) - { - return nullptr; - } - clsDef = FindClassByID(TypeId); - } - return clsDef; - } - - const JSClassDefinition* FindCppTypeClassByName(const std::string& Name); - -#if USING_IN_UNREAL_ENGINE - void RegisterAddon(const std::string& Name, AddonRegisterFunc RegisterFunc); - - AddonRegisterFunc FindAddonRegisterFunc(const std::string& Name); - - const JSClassDefinition* FindClassByType(UStruct* Type); -#endif - -private: - std::map CDataIdToClassDefinition; - std::map CDataNameToClassDefinition; - pesapi_class_not_found_callback ClassNotFoundCallback = nullptr; -#if USING_IN_UNREAL_ENGINE - std::map AddonRegisterInfos; - std::map StructNameToClassDefinition; -#endif -}; - -JSClassRegister::JSClassRegister() -{ -} - -JSClassRegister::~JSClassRegister() -{ - for (auto& KV : CDataIdToClassDefinition) - { - JSClassDefinitionDelete(KV.second); - } - CDataIdToClassDefinition.clear(); -#if USING_IN_UNREAL_ENGINE - for (auto& KV : StructNameToClassDefinition) - { - JSClassDefinitionDelete(KV.second); - } - StructNameToClassDefinition.clear(); -#endif -} - -void JSClassRegister::RegisterClass(const JSClassDefinition& ClassDefinition) -{ - if (ClassDefinition.TypeId && ClassDefinition.ScriptName) - { - auto cd_iter = CDataIdToClassDefinition.find(ClassDefinition.TypeId); - if (cd_iter != CDataIdToClassDefinition.end()) - { - JSClassDefinitionDelete(cd_iter->second); - } - CDataIdToClassDefinition[ClassDefinition.TypeId] = JSClassDefinitionDuplicate(&ClassDefinition); - std::string SN = ClassDefinition.ScriptName; - CDataNameToClassDefinition[SN] = CDataIdToClassDefinition[ClassDefinition.TypeId]; - CDataIdToClassDefinition[ClassDefinition.TypeId]->ScriptName = CDataNameToClassDefinition.find(SN)->first.c_str(); - } -#if USING_IN_UNREAL_ENGINE - else if (ClassDefinition.UETypeName) - { - FString SN = UTF8_TO_TCHAR(ClassDefinition.UETypeName); - auto ud_iter = StructNameToClassDefinition.find(SN); - if (ud_iter != StructNameToClassDefinition.end()) - { - JSClassDefinitionDelete(ud_iter->second); - } - StructNameToClassDefinition[SN] = JSClassDefinitionDuplicate(&ClassDefinition); - } -#endif -} - -void SetReflectoinInfo(JSFunctionInfo* Methods, const NamedFunctionInfo* MethodInfos) -{ - std::map> InfoMap; - const NamedFunctionInfo* MethodInfo = MethodInfos; - while (MethodInfo->Name) - { - auto Iter = InfoMap.find(MethodInfo->Name); - if (Iter == InfoMap.end()) - { - InfoMap[MethodInfo->Name] = std::make_tuple(1, MethodInfo); - } - else - { - std::get<0>(Iter->second) = 2; - } - ++MethodInfo; - } - - JSFunctionInfo* Method = Methods; - while (Method->Name) - { - auto Iter = InfoMap.find(Method->Name); - if (Iter != InfoMap.end() && std::get<0>(Iter->second) == 1) - { - Method->ReflectionInfo = std::get<1>(Iter->second)->Type; - } - ++Method; - } -} - -void JSClassRegister::SetClassTypeInfo(const void* TypeId, const NamedFunctionInfo* ConstructorInfos, - const NamedFunctionInfo* MethodInfos, const NamedFunctionInfo* FunctionInfos, const NamedPropertyInfo* PropertyInfos, - const NamedPropertyInfo* VariableInfos) -{ - auto ClassDef = const_cast(FindClassByID(TypeId)); - if (ClassDef) - { - ClassDef->ConstructorInfos = PropertyInfoDuplicate(const_cast(ConstructorInfos)); - ClassDef->MethodInfos = PropertyInfoDuplicate(const_cast(MethodInfos)); - ClassDef->FunctionInfos = PropertyInfoDuplicate(const_cast(FunctionInfos)); - ClassDef->PropertyInfos = PropertyInfoDuplicate(const_cast(PropertyInfos)); - ClassDef->VariableInfos = PropertyInfoDuplicate(const_cast(VariableInfos)); - SetReflectoinInfo(ClassDef->Methods, ClassDef->MethodInfos); - SetReflectoinInfo(ClassDef->Functions, ClassDef->FunctionInfos); - } -} - -const JSClassDefinition* JSClassRegister::FindClassByID(const void* TypeId) -{ - if (!TypeId) - { - return nullptr; - } - auto Iter = CDataIdToClassDefinition.find(TypeId); - if (Iter == CDataIdToClassDefinition.end()) - { - return nullptr; - } - else - { - return Iter->second; - } -} - -const JSClassDefinition* JSClassRegister::FindCppTypeClassByName(const std::string& Name) -{ - auto Iter = CDataNameToClassDefinition.find(Name); - if (Iter == CDataNameToClassDefinition.end()) - { - return nullptr; - } - else - { - return Iter->second; - } -} - -#if USING_IN_UNREAL_ENGINE -void JSClassRegister::RegisterAddon(const std::string& Name, AddonRegisterFunc RegisterFunc) -{ - AddonRegisterInfos[Name] = RegisterFunc; -} - -AddonRegisterFunc JSClassRegister::FindAddonRegisterFunc(const std::string& Name) -{ - auto Iter = AddonRegisterInfos.find(Name); - if (Iter == AddonRegisterInfos.end()) - { - return nullptr; - } - else - { - return Iter->second; - } -} - -const JSClassDefinition* JSClassRegister::FindClassByType(UStruct* Type) -{ - auto Iter = StructNameToClassDefinition.find(Type->GetName()); - if (Iter == StructNameToClassDefinition.end()) - { - return nullptr; - } - else - { - return Iter->second; - } -} -#endif - -void JSClassRegister::ForeachRegisterClass(std::function Callback) -{ - for (auto& KV : CDataNameToClassDefinition) - { - Callback(KV.second); - } -#if USING_IN_UNREAL_ENGINE - for (auto& KV : StructNameToClassDefinition) - { - Callback(KV.second); - } -#endif -} - -JSClassRegister* GetJSClassRegister() -{ - static JSClassRegister S_JSClassRegister; - return &S_JSClassRegister; -} - -void RegisterJSClass(const JSClassDefinition& ClassDefinition) -{ - GetJSClassRegister()->RegisterClass(ClassDefinition); -} - -void SetClassTypeInfo(const void* TypeId, const NamedFunctionInfo* ConstructorInfos, const NamedFunctionInfo* MethodInfos, - const NamedFunctionInfo* FunctionInfos, const NamedPropertyInfo* PropertyInfos, const NamedPropertyInfo* VariableInfos) -{ - GetJSClassRegister()->SetClassTypeInfo(TypeId, ConstructorInfos, MethodInfos, FunctionInfos, PropertyInfos, VariableInfos); -} - -void ForeachRegisterClass(std::function Callback) -{ - GetJSClassRegister()->ForeachRegisterClass(Callback); -} - -const JSClassDefinition* FindClassByID(const void* TypeId) -{ - return GetJSClassRegister()->FindClassByID(TypeId); -} - -void OnClassNotFound(pesapi_class_not_found_callback Callback) -{ - GetJSClassRegister()->OnClassNotFound(Callback); -} - -const JSClassDefinition* LoadClassByID(const void* TypeId) -{ - return GetJSClassRegister()->LoadClassByID(TypeId); -} - -const JSClassDefinition* FindCppTypeClassByName(const std::string& Name) -{ - return GetJSClassRegister()->FindCppTypeClassByName(Name); -} - -bool TraceObjectLifecycle(const void* TypeId, pesapi_on_native_object_enter OnEnter, pesapi_on_native_object_exit OnExit) -{ - if (auto clsDef = const_cast(GetJSClassRegister()->FindClassByID(TypeId))) - { - clsDef->OnEnter = OnEnter; - clsDef->OnExit = OnExit; - return true; - } - return false; -} - -#if USING_IN_UNREAL_ENGINE - -bool IsEditorOnlyUFunction(const UFunction* Func) -{ - // a simplified version of IsEditorOnlyObject(), sadly it's a EditorOnly Function so I have to reimplement a toy one - if (!Func) - { - return false; - } - if (Func->HasAnyFunctionFlags(FUNC_EditorOnly)) - { - return true; - } - auto InObject = Func; - if (InObject->HasAnyMarks(OBJECTMARK_EditorOnly) || InObject->IsEditorOnly()) - { - return true; - } - - auto Package = Func->GetPackage(); - if (Package && Package->HasAnyPackageFlags(PKG_EditorOnly)) - { - return true; - } - - return false; -} - -void RegisterAddon(const char* Name, AddonRegisterFunc RegisterFunc) -{ - GetJSClassRegister()->RegisterAddon(Name, RegisterFunc); -} - -AddonRegisterFunc FindAddonRegisterFunc(const std::string& Name) -{ - return GetJSClassRegister()->FindAddonRegisterFunc(Name); -} - -const JSClassDefinition* FindClassByType(UStruct* Type) -{ - return GetJSClassRegister()->FindClassByType(Type); -} -#endif - -} // namespace PUERTS_NAMESPACE diff --git a/unity/native_src_il2cpp/Src/PesapiAddonLoad.cpp b/unity/native_src_il2cpp/Src/PesapiAddonLoad.cpp deleted file mode 100644 index 8bdf4d9e78..0000000000 --- a/unity/native_src_il2cpp/Src/PesapiAddonLoad.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#include "pesapi.h" - -EXTERN_C_START -int pesapi_load_addon(const char* path, const char* module_name) -{ - return -1; -} - -EXTERN_C_END - diff --git a/unity/native_src_il2cpp/Src/PesapiV8Impl.cpp b/unity/native_src_il2cpp/Src/PesapiV8Impl.cpp deleted file mode 100644 index c6d018263b..0000000000 --- a/unity/native_src_il2cpp/Src/PesapiV8Impl.cpp +++ /dev/null @@ -1,1142 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Puerts available. - * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. - * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may - * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', - * which is part of this source code package. - */ - -#ifndef WITH_QUICKJS - -#include "pesapi.h" -#include "DataTransfer.h" -#include "JSClassRegister.h" -#include "ObjectMapper.h" - -#include -#include -#include -#include - -struct pesapi_env_ref__ -{ - explicit pesapi_env_ref__(v8::Local context) - : context_persistent(context->GetIsolate(), context) - , isolate(context->GetIsolate()) - , ref_count(1) - , env_life_cycle_tracker(puerts::DataTransfer::GetJsEnvLifeCycleTracker(context->GetIsolate())) - { - } - - v8::Persistent context_persistent; - v8::Isolate* const isolate; - int ref_count; - std::weak_ptr env_life_cycle_tracker; -}; - -struct pesapi_value_ref__ : pesapi_env_ref__ -{ - explicit pesapi_value_ref__(v8::Local context, v8::Local value, uint32_t field_count) - : pesapi_env_ref__(context), value_persistent(context->GetIsolate(), value), internal_field_count(field_count) - { - } - - v8::Persistent value_persistent; - uint32_t internal_field_count; - void* internal_fields[0]; -}; - -struct pesapi_scope__ -{ - explicit pesapi_scope__(v8::Isolate* isolate) : scope(isolate), trycatch(isolate) - { - } - v8::HandleScope scope; - v8::TryCatch trycatch; - std::string errinfo; -}; - -static_assert(sizeof(pesapi_scope_memory) >= sizeof(pesapi_scope__), "sizeof(pesapi_scope__) > sizeof(pesapi_scope_memory__)"); - -namespace v8impl -{ -static_assert(sizeof(v8::Local) == sizeof(pesapi_value), "Cannot convert between v8::Local and pesapi_value"); - -static_assert(sizeof(v8::Local) == sizeof(pesapi_env), "Cannot convert between v8::Local and pesapi_env"); - -inline pesapi_value PesapiValueFromV8LocalValue(v8::Local local) -{ - return reinterpret_cast(*local); -} - -inline v8::Local V8LocalValueFromPesapiValue(pesapi_value v) -{ - v8::Local local; - *reinterpret_cast(&local) = v; - return local; -} - -inline pesapi_env PesapiEnvFromV8LocalContext(v8::Local local) -{ - return reinterpret_cast(*local); -} - -inline v8::Local V8LocalContextFromPesapiEnv(pesapi_env v) -{ - v8::Local local; - *reinterpret_cast(&local) = v; - return local; -} - -// value process -pesapi_value pesapi_create_null(pesapi_env env) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue(v8::Null(context->GetIsolate())); -} - -pesapi_value pesapi_create_undefined(pesapi_env env) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue(v8::Undefined(context->GetIsolate())); -} - -pesapi_value pesapi_create_boolean(pesapi_env env, bool value) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue(v8::Boolean::New(context->GetIsolate(), value)); -} - -pesapi_value pesapi_create_int32(pesapi_env env, int32_t value) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue(v8::Integer::New(context->GetIsolate(), value)); -} - -pesapi_value pesapi_create_uint32(pesapi_env env, uint32_t value) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue(v8::Integer::NewFromUnsigned(context->GetIsolate(), value)); -} - -pesapi_value pesapi_create_int64(pesapi_env env, int64_t value) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue(v8::BigInt::New(context->GetIsolate(), value)); -} - -pesapi_value pesapi_create_uint64(pesapi_env env, uint64_t value) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue(v8::BigInt::NewFromUnsigned(context->GetIsolate(), value)); -} - -pesapi_value pesapi_create_double(pesapi_env env, double value) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue(v8::Number::New(context->GetIsolate(), value)); -} - -pesapi_value pesapi_create_string_utf8(pesapi_env env, const char* str, size_t length) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue( - v8::String::NewFromUtf8(context->GetIsolate(), str, v8::NewStringType::kNormal, static_cast(length)).ToLocalChecked()); -} - -pesapi_value pesapi_create_binary(pesapi_env env, void* bin, size_t length) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue(puerts::DataTransfer::NewArrayBuffer(context, bin, length)); -} - -pesapi_value pesapi_create_array(pesapi_env env) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue(v8::Array::New(context->GetIsolate())); -} - -pesapi_value pesapi_create_object(pesapi_env env) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue(v8::Object::New(context->GetIsolate())); -} - -pesapi_value pesapi_create_function(pesapi_env env, pesapi_callback native_impl, void* data) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto func = puerts::DataTransfer::IsolateData(context->GetIsolate())->CreateFunction(context, native_impl, data); - if (func.IsEmpty()) - return nullptr; - return v8impl::PesapiValueFromV8LocalValue(func.ToLocalChecked()); -} - -pesapi_value pesapi_create_class(pesapi_env env, const void* type_id) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto cls = puerts::DataTransfer::IsolateData(context->GetIsolate())->LoadTypeById(context, type_id); - if (cls.IsEmpty()) - return nullptr; - return v8impl::PesapiValueFromV8LocalValue(cls.ToLocalChecked()); -} - -bool pesapi_get_value_bool(pesapi_env env, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->BooleanValue(context->GetIsolate()); -} - -int32_t pesapi_get_value_int32(pesapi_env env, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->Int32Value(context).ToChecked(); -} - -uint32_t pesapi_get_value_uint32(pesapi_env env, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->Uint32Value(context).ToChecked(); -} - -int64_t pesapi_get_value_int64(pesapi_env env, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsBigInt() ? value->ToBigInt(context).ToLocalChecked()->Int64Value() : 0; -} - -uint64_t pesapi_get_value_uint64(pesapi_env env, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsBigInt() ? value->ToBigInt(context).ToLocalChecked()->Uint64Value() : 0; -} - -double pesapi_get_value_double(pesapi_env env, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->NumberValue(context).ToChecked(); -} - -const char* pesapi_get_value_string_utf8(pesapi_env env, pesapi_value pvalue, char* buf, size_t* bufsize) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - - if (buf == nullptr) - { - auto str = value->ToString(context).ToLocalChecked(); - *bufsize = str->Utf8Length(context->GetIsolate()); - } - else - { - auto str = value->ToString(context).ToLocalChecked(); - str->WriteUtf8(context->GetIsolate(), buf, *bufsize); - } - return buf; -} - -void* pesapi_get_value_binary(pesapi_env env, pesapi_value pvalue, size_t* bufsize) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - - if (value->IsArrayBufferView()) - { - v8::Local buffView = value.As(); - *bufsize = buffView->ByteLength(); - auto Ab = buffView->Buffer(); - return static_cast(puerts::DataTransfer::GetArrayBufferData(Ab)) + buffView->ByteOffset(); - } - if (value->IsArrayBuffer()) - { - auto ab = v8::Local::Cast(value); - return puerts::DataTransfer::GetArrayBufferData(ab, *bufsize); - } - return nullptr; -} - -uint32_t pesapi_get_array_length(pesapi_env env, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - if (value->IsArray()) - { - return value.As()->Length(); - } - return 0; -} - -bool pesapi_is_null(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsNull(); -} - -bool pesapi_is_undefined(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsUndefined(); -} - -bool pesapi_is_boolean(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsBoolean(); -} - -bool pesapi_is_int32(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsInt32(); -} - -bool pesapi_is_uint32(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsUint32(); -} - -bool pesapi_is_int64(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsBigInt(); -} - -bool pesapi_is_uint64(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsBigInt(); -} - -bool pesapi_is_double(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsNumber(); -} - -bool pesapi_is_string(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsString(); -} - -bool pesapi_is_object(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsObject(); -} - -bool pesapi_is_function(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsFunction(); -} - -bool pesapi_is_binary(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsArrayBuffer() || value->IsArrayBufferView(); -} - -bool pesapi_is_array(pesapi_env env, pesapi_value pvalue) -{ - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return value->IsArray(); -} - -pesapi_value pesapi_native_object_to_value(pesapi_env env, const void* type_id, void* object_ptr, bool call_finalize) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return v8impl::PesapiValueFromV8LocalValue( - ::puerts::DataTransfer::FindOrAddCData(context->GetIsolate(), context, type_id, object_ptr, !call_finalize)); -} - -void* pesapi_get_native_object_ptr(pesapi_env env, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - if (value.IsEmpty() || !value->IsObject()) - return nullptr; - return puerts::DataTransfer::GetPointerFast(value.As()); -} - -const void* pesapi_get_native_object_typeid(pesapi_env env, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - if (value.IsEmpty() || !value->IsObject()) - return nullptr; - return puerts::DataTransfer::GetPointerFast(value.As(), 1); -} - -bool pesapi_is_instance_of(pesapi_env env, const void* type_id, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - return ::puerts::DataTransfer::IsInstanceOf(context->GetIsolate(), static_cast(type_id), value.As()); -} - -pesapi_value pesapi_boxing(pesapi_env env, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - - auto result = v8::Object::New(context->GetIsolate()); - auto _unused = result->Set(context, 0, value); - return v8impl::PesapiValueFromV8LocalValue(result); -} - -pesapi_value pesapi_unboxing(pesapi_env env, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - - auto outer = value->ToObject(context).ToLocalChecked(); - auto realvalue = outer->Get(context, 0).ToLocalChecked(); - return v8impl::PesapiValueFromV8LocalValue(realvalue); -} - -void pesapi_update_boxed_value(pesapi_env env, pesapi_value boxed_value, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto holder = v8impl::V8LocalValueFromPesapiValue(boxed_value); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - if (holder->IsObject()) - { - auto outer = holder->ToObject(context).ToLocalChecked(); - auto _unused = outer->Set(context, 0, value); - } -} - -bool pesapi_is_boxed_value(pesapi_env env, pesapi_value value) -{ - return pesapi_is_object(env, value); -} - -int pesapi_get_args_len(pesapi_callback_info pinfo) -{ - auto info = reinterpret_cast*>(pinfo); - return (*info).Length(); -} - -pesapi_value pesapi_get_arg(pesapi_callback_info pinfo, int index) -{ - auto info = reinterpret_cast*>(pinfo); - return v8impl::PesapiValueFromV8LocalValue((*info)[index]); -} - -PESAPI_EXTERN pesapi_env pesapi_get_env(pesapi_callback_info pinfo) -{ - auto info = reinterpret_cast*>(pinfo); - return v8impl::PesapiEnvFromV8LocalContext((*info).GetIsolate()->GetCurrentContext()); -} - -pesapi_value pesapi_get_this(pesapi_callback_info pinfo) -{ - auto info = reinterpret_cast*>(pinfo); - return v8impl::PesapiValueFromV8LocalValue((*info).This()); -} - -pesapi_value pesapi_get_holder(pesapi_callback_info pinfo) -{ - auto info = reinterpret_cast*>(pinfo); - return v8impl::PesapiValueFromV8LocalValue((*info).Holder()); -} - -void* pesapi_get_userdata(pesapi_callback_info pinfo) -{ - auto info = reinterpret_cast*>(pinfo); - return *(static_cast(v8::Local::Cast((*info).Data())->Value())); -} - -void pesapi_add_return(pesapi_callback_info pinfo, pesapi_value value) -{ - auto info = reinterpret_cast*>(pinfo); - (*info).GetReturnValue().Set(v8impl::V8LocalValueFromPesapiValue(value)); -} - -void pesapi_throw_by_string(pesapi_callback_info pinfo, const char* msg) -{ - auto info = reinterpret_cast*>(pinfo); - v8::Isolate* isolate = info->GetIsolate(); - isolate->ThrowException( - v8::Exception::Error(v8::String::NewFromUtf8(isolate, msg, v8::NewStringType::kNormal).ToLocalChecked())); -} - -pesapi_env_ref pesapi_create_env_ref(pesapi_env env) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return new pesapi_env_ref__(context); -} - -bool pesapi_env_ref_is_valid(pesapi_env_ref env_ref) -{ - return !env_ref->env_life_cycle_tracker.expired(); -} - -pesapi_env pesapi_get_env_from_ref(pesapi_env_ref env_ref) -{ - if (env_ref->env_life_cycle_tracker.expired()) - { - return nullptr; - } - return v8impl::PesapiEnvFromV8LocalContext(env_ref->context_persistent.Get(env_ref->isolate)); -} - -pesapi_env_ref pesapi_duplicate_env_ref(pesapi_env_ref env_ref) -{ - ++env_ref->ref_count; - return env_ref; -} - -void pesapi_release_env_ref(pesapi_env_ref env_ref) -{ - if (--env_ref->ref_count == 0) - { - if (env_ref->env_life_cycle_tracker.expired()) - { -#if V8_MAJOR_VERSION < 11 - env_ref->context_persistent.Empty(); - delete env_ref; -#else - ::operator delete(static_cast(env_ref)); -#endif - } - else - { - delete env_ref; - } - } -} - -pesapi_scope pesapi_open_scope(pesapi_env_ref env_ref) -{ - if (env_ref->env_life_cycle_tracker.expired()) - { - return nullptr; - } - env_ref->isolate->Enter(); - auto scope = new pesapi_scope__(env_ref->isolate); - env_ref->context_persistent.Get(env_ref->isolate)->Enter(); - return scope; -} - -pesapi_scope pesapi_open_scope_placement(pesapi_env_ref env_ref, struct pesapi_scope_memory* memory) -{ - if (env_ref->env_life_cycle_tracker.expired()) - { - return nullptr; - } - env_ref->isolate->Enter(); - auto scope = new (memory) pesapi_scope__(env_ref->isolate); - env_ref->context_persistent.Get(env_ref->isolate)->Enter(); - return scope; -} - -bool pesapi_has_caught(pesapi_scope scope) -{ - return scope && scope->trycatch.HasCaught(); -} - -const char* pesapi_get_exception_as_string(pesapi_scope scope, bool with_stack) -{ - if (!scope) - return nullptr; - scope->errinfo = *v8::String::Utf8Value(scope->scope.GetIsolate(), scope->trycatch.Exception()); - if (with_stack) - { - auto isolate = scope->scope.GetIsolate(); - v8::Local context(isolate->GetCurrentContext()); - v8::Local message = scope->trycatch.Message(); - - // 输出 (filename):(line number): (message). - std::ostringstream stm; - v8::String::Utf8Value fileName(isolate, message->GetScriptResourceName()); - int lineNum = message->GetLineNumber(context).FromJust(); - stm << *fileName << ":" << lineNum << ": " << scope->errinfo; - - stm << std::endl; - - // 输出调用栈信息 - v8::Local stackTrace; - if (scope->trycatch.StackTrace(context).ToLocal(&stackTrace)) - { - v8::String::Utf8Value stackTraceVal(isolate, stackTrace); - stm << std::endl << *stackTraceVal; - } - scope->errinfo = stm.str(); - } - return scope->errinfo.c_str(); -} - -void pesapi_close_scope(pesapi_scope scope) -{ - if (!scope) - return; - auto isolate = scope->scope.GetIsolate(); - isolate->GetCurrentContext()->Exit(); - delete (scope); - isolate->Exit(); -} - -void pesapi_close_scope_placement(pesapi_scope scope) -{ - if (!scope) - return; - auto isolate = scope->scope.GetIsolate(); - isolate->GetCurrentContext()->Exit(); - scope->~pesapi_scope__(); - isolate->Exit(); -} - -pesapi_value_ref pesapi_create_value_ref(pesapi_env env, pesapi_value pvalue, uint32_t internal_field_count) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - size_t totalSize = sizeof(pesapi_value_ref__) + sizeof(void*) * internal_field_count; - void* buffer = ::operator new(totalSize); - return new (buffer) pesapi_value_ref__(context, value, internal_field_count); -} - -pesapi_value_ref pesapi_duplicate_value_ref(pesapi_value_ref value_ref) -{ - ++value_ref->ref_count; - return value_ref; -} - -void pesapi_release_value_ref(pesapi_value_ref value_ref) -{ - if (--value_ref->ref_count == 0) - { - if (!value_ref->env_life_cycle_tracker.expired()) - { - value_ref->~pesapi_value_ref__(); - } - ::operator delete(static_cast(value_ref)); - } -} - -pesapi_value pesapi_get_value_from_ref(pesapi_env env, pesapi_value_ref value_ref) -{ - return v8impl::PesapiValueFromV8LocalValue(value_ref->value_persistent.Get(value_ref->isolate)); -} - -void pesapi_set_ref_weak(pesapi_env env, pesapi_value_ref value_ref) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - value_ref->value_persistent.SetWeak(); -} - -bool pesapi_set_owner(pesapi_env env, pesapi_value pvalue, pesapi_value powner) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - auto owner = v8impl::V8LocalValueFromPesapiValue(powner); - - if (owner->IsObject()) - { - auto jsObj = owner.template As(); -#if V8_MAJOR_VERSION < 8 - jsObj->Set(context, v8::String::NewFromUtf8(context->GetIsolate(), "_p_i_only_one_child").ToLocalChecked(), value).Check(); -#else - jsObj->Set(context, v8::String::NewFromUtf8Literal(context->GetIsolate(), "_p_i_only_one_child"), value).Check(); -#endif - return true; - } - return false; -} - -pesapi_env_ref pesapi_get_ref_associated_env(pesapi_value_ref value_ref) -{ - return value_ref; -} - -void** pesapi_get_ref_internal_fields(pesapi_value_ref value_ref, uint32_t* pinternal_field_count) -{ - *pinternal_field_count = value_ref->internal_field_count; - return &value_ref->internal_fields[0]; -} - -pesapi_value pesapi_get_property(pesapi_env env, pesapi_value pobject, const char* key) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto object = v8impl::V8LocalValueFromPesapiValue(pobject); - if (object->IsObject()) - { - auto MaybeValue = object.As()->Get( - context, v8::String::NewFromUtf8(context->GetIsolate(), key, v8::NewStringType::kNormal).ToLocalChecked()); - v8::Local Val; - if (MaybeValue.ToLocal(&Val)) - { - return v8impl::PesapiValueFromV8LocalValue(Val); - } - } - return pesapi_create_undefined(env); -} - -void pesapi_set_property(pesapi_env env, pesapi_value pobject, const char* key, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto object = v8impl::V8LocalValueFromPesapiValue(pobject); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - - if (object->IsObject()) - { - auto _un_used = object.As()->Set( - context, v8::String::NewFromUtf8(context->GetIsolate(), key, v8::NewStringType::kNormal).ToLocalChecked(), value); - } -} - -bool pesapi_get_private(pesapi_env env, pesapi_value pobject, void** out_ptr) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto object = v8impl::V8LocalValueFromPesapiValue(pobject); - if (object.IsEmpty() || !object->IsObject()) - { - *out_ptr = nullptr; - return false; - } - *out_ptr = puerts::DataTransfer::IsolateData(context->GetIsolate()) - ->GetPrivateData(context, object.As()); - return true; -} - -bool pesapi_set_private(pesapi_env env, pesapi_value pobject, void* ptr) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto object = v8impl::V8LocalValueFromPesapiValue(pobject); - if (object.IsEmpty() || !object->IsObject()) - { - return false; - } - puerts::DataTransfer::IsolateData(context->GetIsolate()) - ->SetPrivateData(context, object.As(), ptr); - return true; -} - -pesapi_value pesapi_get_property_uint32(pesapi_env env, pesapi_value pobject, uint32_t key) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto object = v8impl::V8LocalValueFromPesapiValue(pobject); - if (object->IsObject()) - { - auto MaybeValue = object.As()->Get(context, key); - v8::Local Val; - if (MaybeValue.ToLocal(&Val)) - { - return v8impl::PesapiValueFromV8LocalValue(Val); - } - } - return pesapi_create_undefined(env); -} - -void pesapi_set_property_uint32(pesapi_env env, pesapi_value pobject, uint32_t key, pesapi_value pvalue) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto object = v8impl::V8LocalValueFromPesapiValue(pobject); - auto value = v8impl::V8LocalValueFromPesapiValue(pvalue); - - if (object->IsObject()) - { - auto _un_used = object.As()->Set(context, key, value); - } -} - -pesapi_value pesapi_call_function(pesapi_env env, pesapi_value pfunc, pesapi_value this_object, int argc, const pesapi_value argv[]) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - v8::Local recv = v8::Undefined(context->GetIsolate()); - if (this_object) - { - recv = v8impl::V8LocalValueFromPesapiValue(this_object); - } - v8::Local func = v8impl::V8LocalValueFromPesapiValue(pfunc).As(); - - auto maybe_ret = func->Call(context, recv, argc, reinterpret_cast*>(const_cast(argv))); - if (maybe_ret.IsEmpty()) - { - return nullptr; - } - return v8impl::PesapiValueFromV8LocalValue(maybe_ret.ToLocalChecked()); -} - -pesapi_value pesapi_eval(pesapi_env env, const uint8_t* code, size_t code_size, const char* path) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto isolate = context->GetIsolate(); - v8::Local url = - v8::String::NewFromUtf8(isolate, path == nullptr ? "" : path, v8::NewStringType::kNormal).ToLocalChecked(); - std::vector buff; - buff.reserve(code_size + 1); - memcpy(buff.data(), code, code_size); - buff.data()[code_size] = '\0'; - v8::Local source = v8::String::NewFromUtf8(isolate, buff.data(), v8::NewStringType::kNormal).ToLocalChecked(); -#if V8_MAJOR_VERSION > 8 - v8::ScriptOrigin origin(isolate, url); -#else - v8::ScriptOrigin origin(url); -#endif - - auto CompiledScript = v8::Script::Compile(context, source, &origin); - if (CompiledScript.IsEmpty()) - { - return nullptr; - } - auto maybe_ret = CompiledScript.ToLocalChecked()->Run(context); - if (maybe_ret.IsEmpty()) - { - return nullptr; - } - return v8impl::PesapiValueFromV8LocalValue(maybe_ret.ToLocalChecked()); -} - -pesapi_value pesapi_global(pesapi_env env) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - auto global = context->Global(); - return v8impl::PesapiValueFromV8LocalValue(global); -} - -const void* pesapi_get_env_private(pesapi_env env) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - return puerts::DataTransfer::GetIsolatePrivateData(context->GetIsolate()); -} - -void pesapi_set_env_private(pesapi_env env, const void* ptr) -{ - auto context = v8impl::V8LocalContextFromPesapiEnv(env); - puerts::DataTransfer::SetIsolatePrivateData(context->GetIsolate(), const_cast(ptr)); -} - -pesapi_ffi g_pesapi_ffi { - &pesapi_create_null, - &pesapi_create_undefined, - &pesapi_create_boolean, - &pesapi_create_int32, - &pesapi_create_uint32, - &pesapi_create_int64, - &pesapi_create_uint64, - &pesapi_create_double, - &pesapi_create_string_utf8, - &pesapi_create_binary, - &pesapi_create_array, - &pesapi_create_object, - &pesapi_create_function, - &pesapi_create_class, - &pesapi_get_value_bool, - &pesapi_get_value_int32, - &pesapi_get_value_uint32, - &pesapi_get_value_int64, - &pesapi_get_value_uint64, - &pesapi_get_value_double, - &pesapi_get_value_string_utf8, - &pesapi_get_value_binary, - &pesapi_get_array_length, - &pesapi_is_null, - &pesapi_is_undefined, - &pesapi_is_boolean, - &pesapi_is_int32, - &pesapi_is_uint32, - &pesapi_is_int64, - &pesapi_is_uint64, - &pesapi_is_double, - &pesapi_is_string, - &pesapi_is_object, - &pesapi_is_function, - &pesapi_is_binary, - &pesapi_is_array, - &pesapi_native_object_to_value, - &pesapi_get_native_object_ptr, - &pesapi_get_native_object_typeid, - &pesapi_is_instance_of, - &pesapi_boxing, - &pesapi_unboxing, - &pesapi_update_boxed_value, - &pesapi_is_boxed_value, - &pesapi_get_args_len, - &pesapi_get_arg, - &pesapi_get_env, - &pesapi_get_this, - &pesapi_get_holder, - &pesapi_get_userdata, - &pesapi_add_return, - &pesapi_throw_by_string, - &pesapi_create_env_ref, - &pesapi_env_ref_is_valid, - &pesapi_get_env_from_ref, - &pesapi_duplicate_env_ref, - &pesapi_release_env_ref, - &pesapi_open_scope, - &pesapi_open_scope_placement, - &pesapi_has_caught, - &pesapi_get_exception_as_string, - &pesapi_close_scope, - &pesapi_close_scope_placement, - &pesapi_create_value_ref, - &pesapi_duplicate_value_ref, - &pesapi_release_value_ref, - &pesapi_get_value_from_ref, - &pesapi_set_ref_weak, - &pesapi_set_owner, - &pesapi_get_ref_associated_env, - &pesapi_get_ref_internal_fields, - &pesapi_get_property, - &pesapi_set_property, - &pesapi_get_private, - &pesapi_set_private, - &pesapi_get_property_uint32, - &pesapi_set_property_uint32, - &pesapi_call_function, - &pesapi_eval, - &pesapi_global, - &pesapi_get_env_private, - &pesapi_set_env_private -}; - -} // namespace v8impl - -EXTERN_C_START - -struct pesapi_type_info__ -{ - const char* name; - bool is_pointer; - bool is_const; - bool is_ref; - bool is_primitive; -}; - -struct pesapi_signature_info__ -{ - pesapi_type_info return_type; - size_t parameter_count; - pesapi_type_info parameter_types; -}; - -struct pesapi_property_descriptor__ -{ - const char* name; - bool is_static; - pesapi_callback method; - pesapi_callback getter; - pesapi_callback setter; - void* data0; - void* data1; - - union - { - pesapi_type_info type_info; - pesapi_signature_info signature_info; - } info; -}; - -pesapi_type_info pesapi_alloc_type_infos(size_t count) -{ - auto ret = new pesapi_type_info__[count]; - memset(ret, 0, sizeof(pesapi_type_info__) * count); - return ret; -} - -void pesapi_set_type_info( - pesapi_type_info type_infos, size_t index, const char* name, bool is_pointer, bool is_const, bool is_ref, bool is_primitive) -{ - type_infos[index] = {name, is_pointer, is_const, is_ref, is_primitive}; -} - -pesapi_signature_info pesapi_create_signature_info( - pesapi_type_info return_type, size_t parameter_count, pesapi_type_info parameter_types) -{ - return new pesapi_signature_info__{return_type, parameter_count, parameter_types}; -} - -pesapi_property_descriptor pesapi_alloc_property_descriptors(size_t count) -{ - auto ret = new pesapi_property_descriptor__[count]; - memset(ret, 0, sizeof(pesapi_property_descriptor__) * count); - return ret; -} - -void pesapi_set_method_info(pesapi_property_descriptor properties, size_t index, const char* name, bool is_static, - pesapi_callback method, void* data, pesapi_signature_info signature_info) -{ - properties[index].name = name; - properties[index].is_static = is_static; - properties[index].method = method; - properties[index].data0 = data; - properties[index].info.signature_info = signature_info; -} - -void pesapi_set_property_info(pesapi_property_descriptor properties, size_t index, const char* name, bool is_static, - pesapi_callback getter, pesapi_callback setter, void* getter_data, void* setter_data, pesapi_type_info type_info) -{ - properties[index].name = name; - properties[index].is_static = is_static; - properties[index].getter = getter; - properties[index].setter = setter; - properties[index].data0 = getter_data; - properties[index].data1 = setter_data; - properties[index].info.type_info = type_info; -} - -static void free_property_descriptor(pesapi_property_descriptor properties, size_t property_count) -{ - for (size_t i = 0; i < property_count; i++) - { - pesapi_property_descriptor p = properties + i; - if (p->getter != nullptr || p->setter != nullptr) - { - if (p->info.type_info) - { - delete[] p->info.type_info; - } - } - else if (p->method != nullptr) - { - if (p->info.signature_info) - { - if (p->info.signature_info->return_type) - { - delete p->info.signature_info->return_type; - } - if (p->info.signature_info->parameter_types) - { - delete[] p->info.signature_info->parameter_types; - } - delete p->info.signature_info; - } - } - } -} - -// set module name here during loading, set nullptr after module loaded -const char* GPesapiModuleName = nullptr; - -void pesapi_define_class(const void* type_id, const void* super_type_id, const char* type_name, pesapi_constructor constructor, - pesapi_finalize finalize, size_t property_count, pesapi_property_descriptor properties, void* data) -{ - puerts::JSClassDefinition classDef = JSClassEmptyDefinition; - classDef.TypeId = type_id; - classDef.SuperTypeId = super_type_id; - std::string ScriptNameWithModuleName = GPesapiModuleName == nullptr ? std::string() : GPesapiModuleName; - if (GPesapiModuleName) - { - ScriptNameWithModuleName += "."; - ScriptNameWithModuleName += type_name; - classDef.ScriptName = ScriptNameWithModuleName.c_str(); - } - else - { - classDef.ScriptName = type_name; - } - classDef.Data = data; - - classDef.Initialize = constructor; - classDef.Finalize = finalize; - - std::vector p_methods; - std::vector p_functions; - std::vector p_properties; - std::vector p_variables; - - for (int i = 0; i < property_count; i++) - { - pesapi_property_descriptor p = properties + i; - if (p->getter != nullptr || p->setter != nullptr) - { - if (p->is_static) - { - p_variables.push_back({p->name, p->getter, p->setter, p->data0, p->data1}); - } - else - { - p_properties.push_back({p->name, p->getter, p->setter, p->data0, p->data1}); - } - } - else if (p->method != nullptr) - { - puerts::JSFunctionInfo finfo{p->name, p->method, p->data0}; - if (p->is_static) - { - p_functions.push_back(finfo); - } - else - { - p_methods.push_back(finfo); - } - } - } - - free_property_descriptor(properties, property_count); - - p_methods.push_back(puerts::JSFunctionInfo()); - p_functions.push_back(puerts::JSFunctionInfo()); - p_properties.push_back(puerts::JSPropertyInfo()); - p_variables.push_back(puerts::JSPropertyInfo()); - - classDef.Methods = p_methods.data(); - classDef.Functions = p_functions.data(); - classDef.Properties = p_properties.data(); - classDef.Variables = p_variables.data(); - - puerts::RegisterJSClass(classDef); -} - -void* pesapi_get_class_data(const void* type_id, bool force_load) -{ - auto clsDef = force_load ? puerts::LoadClassByID(type_id) : puerts::FindClassByID(type_id); - return clsDef ? clsDef->Data : nullptr; -} - -bool pesapi_trace_native_object_lifecycle( - const void* type_id, pesapi_on_native_object_enter on_enter, pesapi_on_native_object_exit on_exit) -{ - return puerts::TraceObjectLifecycle(type_id, on_enter, on_exit); -} - -void pesapi_on_class_not_found(pesapi_class_not_found_callback callback) -{ - puerts::OnClassNotFound(callback); -} - -void pesapi_class_type_info(const char* proto_magic_id, const void* type_id, const void* constructor_info, const void* methods_info, - const void* functions_info, const void* properties_info, const void* variables_info) -{ - if (strcmp(proto_magic_id, PUERTS_BINDING_PROTO_ID()) != 0) - { - return; - } - - puerts::SetClassTypeInfo(type_id, static_cast(constructor_info), - static_cast(methods_info), static_cast(functions_info), - static_cast(properties_info), - static_cast(variables_info)); -} - -const void* pesapi_find_type_id(const char* module_name, const char* type_name) -{ - std::string fullname = module_name; - fullname += "."; - fullname += type_name; - const auto class_def = puerts::FindCppTypeClassByName(fullname); - return class_def ? class_def->TypeId : nullptr; -} - -EXTERN_C_END - -MSVC_PRAGMA(warning(push)) -MSVC_PRAGMA(warning(disable : 4191)) -pesapi_func_ptr reg_apis[] = {(pesapi_func_ptr) &pesapi_alloc_type_infos, (pesapi_func_ptr) &pesapi_set_type_info, - (pesapi_func_ptr) &pesapi_create_signature_info, (pesapi_func_ptr) &pesapi_alloc_property_descriptors, - (pesapi_func_ptr) &pesapi_set_method_info, (pesapi_func_ptr) &pesapi_set_property_info, (pesapi_func_ptr) &pesapi_define_class, - (pesapi_func_ptr) &pesapi_get_class_data, (pesapi_func_ptr) &pesapi_trace_native_object_lifecycle, - (pesapi_func_ptr) &pesapi_on_class_not_found, (pesapi_func_ptr) &pesapi_class_type_info, - (pesapi_func_ptr) &pesapi_find_type_id}; -MSVC_PRAGMA(warning(pop)) - -#endif diff --git a/unity/native_src_il2cpp/Src/Puerts.cpp b/unity/native_src_il2cpp/Src/Puerts.cpp deleted file mode 100644 index 6bf7f4489a..0000000000 --- a/unity/native_src_il2cpp/Src/Puerts.cpp +++ /dev/null @@ -1,220 +0,0 @@ -#include - -#pragma warning(push, 0) -#include "v8.h" -#pragma warning(pop) - -#if defined(WITH_NODEJS) - -#pragma warning(push, 0) -#include "node.h" -#include "uv.h" -#pragma warning(pop) - -#endif // WITH_NODEJS - -#include "CppObjectMapper.h" -#include "DataTransfer.h" -#include "pesapi.h" -#include "JSClassRegister.h" -#include -#include "BackendEnv.h" - -#define USE_OUTSIZE_UNITY 1 - -namespace puerts -{ -enum Backend -{ - V8 = 0, - Node = 1, - QuickJS = 2, -}; -#if defined(WITH_NODEJS) -static std::vector* Args; -static std::vector* ExecArgs; -static std::vector* Errors; -#endif - -typedef void(*LogCallback)(const char* value); - -static LogCallback GLogCallback = nullptr; - -void PLog(LogLevel Level, const std::string Fmt, ...) -{ - static char SLogBuffer[1024]; - va_list list; - va_start(list, Fmt); - vsnprintf(SLogBuffer, sizeof(SLogBuffer), Fmt.c_str(), list); - va_end(list); - - if (GLogCallback) - { - GLogCallback(SLogBuffer); - } -} - -struct JSEnv -{ - JSEnv() - { - puerts::FBackendEnv::GlobalPrepare(); - -#if defined(WITH_NODEJS) - std::string Flags = "--stack_size=856"; -#else - std::string Flags = "--no-harmony-top-level-await --stack_size=856"; -#endif - Flags += " --expose-gc"; -#if defined(PLATFORM_IOS) || defined(PLATFORM_OHOS) - Flags += " --jitless --no-expose-wasm"; -#endif - v8::V8::SetFlagsFromString(Flags.c_str(), static_cast(Flags.size())); - - BackendEnv.Initialize(nullptr, nullptr); - MainIsolate = BackendEnv.MainIsolate; - - auto Isolate = MainIsolate; - -#ifdef THREAD_SAFE - v8::Locker Locker(Isolate); -#endif - v8::Isolate::Scope Isolatescope(Isolate); - v8::HandleScope HandleScope(Isolate); - - v8::Local Context = BackendEnv.MainContext.Get(Isolate);; - v8::Context::Scope ContextScope(Context); - - MainContext.Reset(Isolate, Context); - - CppObjectMapper.Initialize(Isolate, Context); - Isolate->SetData(MAPPER_ISOLATE_DATA_POS, static_cast(&CppObjectMapper)); - //TODO: 在FBackendEnv写死了,先不修改native_src,后续需要优化 - //V8_INLINE static FBackendEnv* Get(v8::Isolate* Isolate) - //{ - // return (FBackendEnv*)Isolate->GetData(1); - //} - Isolate->SetData(BACKENDENV_DATA_POS, &BackendEnv); - - BackendEnv.StartPolling(); - } - - ~JSEnv() - { - BackendEnv.LogicTick(); - BackendEnv.StopPolling(); - - CppObjectMapper.UnInitialize(MainIsolate); - BackendEnv.PathToModuleMap.clear(); - BackendEnv.ScriptIdToPathMap.clear(); - BackendEnv.JsPromiseRejectCallback.Reset(); - if (BackendEnv.Inspector) - { - delete BackendEnv.Inspector; - BackendEnv.Inspector = nullptr; - } - - MainContext.Reset(); - BackendEnv.UnInitialize(); - } - - v8::Isolate* MainIsolate; - v8::Global MainContext; - - puerts::FCppObjectMapper CppObjectMapper; - puerts::FBackendEnv BackendEnv; -}; - -} - -extern pesapi_func_ptr reg_apis[]; - -#ifdef __cplusplus -extern "C" { -#endif - -V8_EXPORT int GetLibBackend() -{ -#if WITH_NODEJS - return puerts::Backend::Node; -#elif WITH_QUICKJS - return puerts::Backend::QuickJS; -#else - return puerts::Backend::V8; -#endif -} - -V8_EXPORT puerts::JSEnv* CreateNativeJSEnv() -{ - return new puerts::JSEnv(); -} - -V8_EXPORT void DestroyNativeJSEnv(puerts::JSEnv* jsEnv) -{ - delete jsEnv; -} - -V8_EXPORT void SetLogCallback(puerts::LogCallback Log) -{ - puerts::GLogCallback = Log; -} - -V8_EXPORT pesapi_env_ref GetPapiEnvRef(puerts::JSEnv* jsEnv) -{ - v8::Isolate* Isolate = jsEnv->MainIsolate; -#ifdef THREAD_SAFE - v8::Locker Locker(Isolate); -#endif - v8::Isolate::Scope IsolateScope(Isolate); - v8::HandleScope HandleScope(Isolate); - v8::Local Context = jsEnv->MainContext.Get(Isolate); - v8::Context::Scope ContextScope(Context); - - auto env = reinterpret_cast(*Context); //TODO: 实现相关 - return v8impl::g_pesapi_ffi.create_env_ref(env); -} - -/*V8_EXPORT void SetObjectPool(puerts::JSEnv* jsEnv, void* ObjectPoolAddMethodInfo, puerts::ObjectPoolAddFunc ObjectPoolAdd, void* ObjectPoolRemoveMethodInfo, puerts::ObjectPoolRemoveFunc ObjectPoolRemove, void* ObjectPoolInstance) -{ - jsEnv->CppObjectMapper.ObjectPoolAddMethodInfo = ObjectPoolAddMethodInfo; - jsEnv->CppObjectMapper.ObjectPoolAdd = ObjectPoolAdd; - jsEnv->CppObjectMapper.ObjectPoolRemoveMethodInfo = ObjectPoolRemoveMethodInfo; - jsEnv->CppObjectMapper.ObjectPoolRemove = ObjectPoolRemove; - jsEnv->CppObjectMapper.ObjectPoolInstance = ObjectPoolInstance; -}*/ - -V8_EXPORT void CreateInspector(puerts::JSEnv* jsEnv, int32_t Port) -{ - jsEnv->BackendEnv.CreateInspector(jsEnv->MainIsolate, &jsEnv->MainContext, Port); -} - -V8_EXPORT void DestroyInspector(puerts::JSEnv* jsEnv) -{ - jsEnv->BackendEnv.DestroyInspector(jsEnv->MainIsolate, &jsEnv->MainContext); -} - -V8_EXPORT int InspectorTick(puerts::JSEnv* jsEnv) -{ - return jsEnv->BackendEnv.InspectorTick() ? 1 : 0; -} - -V8_EXPORT void LogicTick(puerts::JSEnv* jsEnv) -{ - jsEnv->BackendEnv.LogicTick(); -} - -V8_EXPORT pesapi_ffi* GetFFIApi() -{ - return &v8impl::g_pesapi_ffi; -} - -V8_EXPORT pesapi_func_ptr* GetRegsterApi() -{ - return reg_apis; -} - -#ifdef __cplusplus -} -#endif - - diff --git a/unity/native_src_il2cpp/cmake/android.toolchain.cmake b/unity/native_src_il2cpp/cmake/android.toolchain.cmake deleted file mode 100644 index a19d19b5b0..0000000000 --- a/unity/native_src_il2cpp/cmake/android.toolchain.cmake +++ /dev/null @@ -1,1745 +0,0 @@ -# Copyright (c) 2010-2011, Ethan Rublee -# Copyright (c) 2011-2014, Andrey Kamaev -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from this -# software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. - -# ------------------------------------------------------------------------------ -# Android CMake toolchain file, for use with the Android NDK r5-r10d -# Requires cmake 2.6.3 or newer (2.8.9 or newer is recommended). -# See home page: https://github.com/taka-no-me/android-cmake -# -# Usage Linux: -# $ export ANDROID_NDK=/absolute/path/to/the/android-ndk -# $ mkdir build && cd build -# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake .. -# $ make -j8 -# -# Usage Windows: -# You need native port of make to build your project. -# Android NDK r7 (and newer) already has make.exe on board. -# For older NDK you have to install it separately. -# For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm -# -# $ SET ANDROID_NDK=C:\absolute\path\to\the\android-ndk -# $ mkdir build && cd build -# $ cmake.exe -G"MinGW Makefiles" -# -DCMAKE_TOOLCHAIN_FILE=path\to\the\android.toolchain.cmake -# -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK%\prebuilt\windows\bin\make.exe" .. -# $ cmake.exe --build . -# -# -# Options (can be set as cmake parameters: -D=): -# ANDROID_NDK=/opt/android-ndk - path to the NDK root. -# Can be set as environment variable. Can be set only at first cmake run. -# -# ANDROID_ABI=armeabi-v7a - specifies the target Application Binary -# Interface (ABI). This option nearly matches to the APP_ABI variable -# used by ndk-build tool from Android NDK. -# -# Possible targets are: -# "armeabi" - ARMv5TE based CPU with software floating point operations -# "armeabi-v7a" - ARMv7 based devices with hardware FPU instructions -# this ABI target is used by default -# "armeabi-v7a with NEON" - same as armeabi-v7a, but -# sets NEON as floating-point unit -# "armeabi-v7a with VFPV3" - same as armeabi-v7a, but -# sets VFPV3 as floating-point unit (has 32 registers instead of 16) -# "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP -# "x86" - IA-32 instruction set -# "mips" - MIPS32 instruction set -# -# 64-bit ABIs for NDK r10 and newer: -# "arm64-v8a" - ARMv8 AArch64 instruction set -# "x86_64" - Intel64 instruction set (r1) -# "mips64" - MIPS64 instruction set (r6) -# -# ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for. -# Option is read-only when standalone toolchain is used. -# Note: building for "android-L" requires explicit configuration. -# -# ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 - the name of compiler -# toolchain to be used. The list of possible values depends on the NDK -# version. For NDK r10c the possible values are: -# -# * aarch64-linux-android-4.9 -# * aarch64-linux-android-clang3.4 -# * aarch64-linux-android-clang3.5 -# * arm-linux-androideabi-4.6 -# * arm-linux-androideabi-4.8 -# * arm-linux-androideabi-4.9 (default) -# * arm-linux-androideabi-clang3.4 -# * arm-linux-androideabi-clang3.5 -# * mips64el-linux-android-4.9 -# * mips64el-linux-android-clang3.4 -# * mips64el-linux-android-clang3.5 -# * mipsel-linux-android-4.6 -# * mipsel-linux-android-4.8 -# * mipsel-linux-android-4.9 -# * mipsel-linux-android-clang3.4 -# * mipsel-linux-android-clang3.5 -# * x86-4.6 -# * x86-4.8 -# * x86-4.9 -# * x86-clang3.4 -# * x86-clang3.5 -# * x86_64-4.9 -# * x86_64-clang3.4 -# * x86_64-clang3.5 -# -# ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions -# instead of Thumb. Is not available for "armeabi-v6 with VFP" -# (is forced to be ON) ABI. -# -# ANDROID_NO_UNDEFINED=ON - set ON to show all undefined symbols as linker -# errors even if they are not used. -# -# ANDROID_SO_UNDEFINED=OFF - set ON to allow undefined symbols in shared -# libraries. Automatically turned for NDK r5x and r6x due to GLESv2 -# problems. -# -# ANDROID_STL=gnustl_static - specify the runtime to use. -# -# Possible values are: -# none -> Do not configure the runtime. -# system -> Use the default minimal system C++ runtime library. -# Implies -fno-rtti -fno-exceptions. -# Is not available for standalone toolchain. -# system_re -> Use the default minimal system C++ runtime library. -# Implies -frtti -fexceptions. -# Is not available for standalone toolchain. -# gabi++_static -> Use the GAbi++ runtime as a static library. -# Implies -frtti -fno-exceptions. -# Available for NDK r7 and newer. -# Is not available for standalone toolchain. -# gabi++_shared -> Use the GAbi++ runtime as a shared library. -# Implies -frtti -fno-exceptions. -# Available for NDK r7 and newer. -# Is not available for standalone toolchain. -# stlport_static -> Use the STLport runtime as a static library. -# Implies -fno-rtti -fno-exceptions for NDK before r7. -# Implies -frtti -fno-exceptions for NDK r7 and newer. -# Is not available for standalone toolchain. -# stlport_shared -> Use the STLport runtime as a shared library. -# Implies -fno-rtti -fno-exceptions for NDK before r7. -# Implies -frtti -fno-exceptions for NDK r7 and newer. -# Is not available for standalone toolchain. -# gnustl_static -> Use the GNU STL as a static library. -# Implies -frtti -fexceptions. -# gnustl_shared -> Use the GNU STL as a shared library. -# Implies -frtti -fno-exceptions. -# Available for NDK r7b and newer. -# Silently degrades to gnustl_static if not available. -# -# ANDROID_STL_FORCE_FEATURES=ON - turn rtti and exceptions support based on -# chosen runtime. If disabled, then the user is responsible for settings -# these options. -# -# What?: -# android-cmake toolchain searches for NDK/toolchain in the following order: -# ANDROID_NDK - cmake parameter -# ANDROID_NDK - environment variable -# ANDROID_STANDALONE_TOOLCHAIN - cmake parameter -# ANDROID_STANDALONE_TOOLCHAIN - environment variable -# ANDROID_NDK - default locations -# ANDROID_STANDALONE_TOOLCHAIN - default locations -# -# Make sure to do the following in your scripts: -# SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" ) -# SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" ) -# The flags will be prepopulated with critical flags, so don't loose them. -# Also be aware that toolchain also sets configuration-specific compiler -# flags and linker flags. -# -# ANDROID and BUILD_ANDROID will be set to true, you may test any of these -# variables to make necessary Android-specific configuration changes. -# -# Also ARMEABI or ARMEABI_V7A or X86 or MIPS or ARM64_V8A or X86_64 or MIPS64 -# will be set true, mutually exclusive. NEON option will be set true -# if VFP is set to NEON. -# -# ------------------------------------------------------------------------------ - -cmake_minimum_required( VERSION 2.6.3 ) - -if( DEFINED CMAKE_CROSSCOMPILING ) - # subsequent toolchain loading is not really needed - return() -endif() - -if( CMAKE_TOOLCHAIN_FILE ) - # touch toolchain variable to suppress "unused variable" warning -endif() - -# inherit settings in recursive loads -get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE ) -if( _CMAKE_IN_TRY_COMPILE ) - include( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL ) -endif() - -# this one is important -if( CMAKE_VERSION VERSION_GREATER "3.0.99" ) - set( CMAKE_SYSTEM_NAME Android ) -else() - set( CMAKE_SYSTEM_NAME Linux ) -endif() - -# this one not so much -set( CMAKE_SYSTEM_VERSION 1 ) - -# rpath makes low sense for Android -set( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "" ) -set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." ) - -# NDK search paths -set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r10d -r10c -r10b -r10 -r9d -r9c -r9b -r9 -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) -if( NOT DEFINED ANDROID_NDK_SEARCH_PATHS ) - if( CMAKE_HOST_WIN32 ) - file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) - set( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}" "$ENV{SystemDrive}/NVPACK" ) - else() - file( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS ) - set( ANDROID_NDK_SEARCH_PATHS /opt "${ANDROID_NDK_SEARCH_PATHS}/NVPACK" ) - endif() -endif() -if( NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH ) - set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain ) -endif() - -# known ABIs -set( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP" ) -set( ANDROID_SUPPORTED_ABIS_arm64 "arm64-v8a" ) -set( ANDROID_SUPPORTED_ABIS_x86 "x86" ) -set( ANDROID_SUPPORTED_ABIS_x86_64 "x86_64" ) -set( ANDROID_SUPPORTED_ABIS_mips "mips" ) -set( ANDROID_SUPPORTED_ABIS_mips64 "mips64" ) - -# API level defaults -set( ANDROID_DEFAULT_NDK_API_LEVEL 8 ) -set( ANDROID_DEFAULT_NDK_API_LEVEL_arm64 21 ) -set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 ) -set( ANDROID_DEFAULT_NDK_API_LEVEL_x86_64 21 ) -set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 ) -set( ANDROID_DEFAULT_NDK_API_LEVEL_mips64 21 ) - - -macro( __LIST_FILTER listvar regex ) - if( ${listvar} ) - foreach( __val ${${listvar}} ) - if( __val MATCHES "${regex}" ) - list( REMOVE_ITEM ${listvar} "${__val}" ) - endif() - endforeach() - endif() -endmacro() - -macro( __INIT_VARIABLE var_name ) - set( __test_path 0 ) - foreach( __var ${ARGN} ) - if( __var STREQUAL "PATH" ) - set( __test_path 1 ) - break() - endif() - endforeach() - - if( __test_path AND NOT EXISTS "${${var_name}}" ) - unset( ${var_name} CACHE ) - endif() - - if( " ${${var_name}}" STREQUAL " " ) - set( __values 0 ) - foreach( __var ${ARGN} ) - if( __var STREQUAL "VALUES" ) - set( __values 1 ) - elseif( NOT __var STREQUAL "PATH" ) - if( __var MATCHES "^ENV_.*$" ) - string( REPLACE "ENV_" "" __var "${__var}" ) - set( __value "$ENV{${__var}}" ) - elseif( DEFINED ${__var} ) - set( __value "${${__var}}" ) - elseif( __values ) - set( __value "${__var}" ) - else() - set( __value "" ) - endif() - - if( NOT " ${__value}" STREQUAL " " AND (NOT __test_path OR EXISTS "${__value}") ) - set( ${var_name} "${__value}" ) - break() - endif() - endif() - endforeach() - unset( __value ) - unset( __values ) - endif() - - if( __test_path ) - file( TO_CMAKE_PATH "${${var_name}}" ${var_name} ) - endif() - unset( __test_path ) -endmacro() - -macro( __DETECT_NATIVE_API_LEVEL _var _path ) - set( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*.*$" ) - file( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" ) - if( NOT __apiFileContent ) - message( SEND_ERROR "Could not get Android native API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." ) - endif() - string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" ) - unset( __apiFileContent ) - unset( __ndkApiLevelRegex ) -endmacro() - -macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root ) - if( EXISTS "${_root}" ) - file( GLOB __gccExePath RELATIVE "${_root}/bin/" "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) - __LIST_FILTER( __gccExePath "^[.].*" ) - list( LENGTH __gccExePath __gccExePathsCount ) - if( NOT __gccExePathsCount EQUAL 1 AND NOT _CMAKE_IN_TRY_COMPILE ) - message( WARNING "Could not determine machine name for compiler from ${_root}" ) - set( ${_var} "" ) - else() - get_filename_component( __gccExeName "${__gccExePath}" NAME_WE ) - string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" ) - endif() - unset( __gccExePath ) - unset( __gccExePathsCount ) - unset( __gccExeName ) - else() - set( ${_var} "" ) - endif() -endmacro() - - -# fight against cygwin -set( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL "Prevent cmake from working under cygwin and using cygwin tools") -mark_as_advanced( ANDROID_FORBID_SYGWIN ) -if( ANDROID_FORBID_SYGWIN ) - if( CYGWIN ) - message( FATAL_ERROR "Android NDK and android-cmake toolchain are not welcome Cygwin. It is unlikely that this cmake toolchain will work under cygwin. But if you want to try then you can set cmake variable ANDROID_FORBID_SYGWIN to FALSE and rerun cmake." ) - endif() - - if( CMAKE_HOST_WIN32 ) - # remove cygwin from PATH - set( __new_path "$ENV{PATH}") - __LIST_FILTER( __new_path "cygwin" ) - set(ENV{PATH} "${__new_path}") - unset(__new_path) - endif() -endif() - - -# detect current host platform -if( NOT DEFINED ANDROID_NDK_HOST_X64 AND (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64" OR CMAKE_HOST_APPLE) ) - set( ANDROID_NDK_HOST_X64 1 CACHE BOOL "Try to use 64-bit compiler toolchain" ) - mark_as_advanced( ANDROID_NDK_HOST_X64 ) -endif() - -set( TOOL_OS_SUFFIX "" ) -if( CMAKE_HOST_APPLE ) - set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86_64" ) - set( ANDROID_NDK_HOST_SYSTEM_NAME2 "darwin-x86" ) -elseif( CMAKE_HOST_WIN32 ) - set( ANDROID_NDK_HOST_SYSTEM_NAME "windows-x86_64" ) - set( ANDROID_NDK_HOST_SYSTEM_NAME2 "windows" ) - set( TOOL_OS_SUFFIX ".exe" ) -elseif( CMAKE_HOST_UNIX ) - set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86_64" ) - set( ANDROID_NDK_HOST_SYSTEM_NAME2 "linux-x86" ) -else() - message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" ) -endif() - -if( NOT ANDROID_NDK_HOST_X64 ) - set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) -endif() - -# see if we have path to Android NDK -if( NOT ANDROID_NDK AND NOT ANDROID_STANDALONE_TOOLCHAIN ) - __INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK ) -endif() -if( NOT ANDROID_NDK ) - # see if we have path to Android standalone toolchain - __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN ) - - if( NOT ANDROID_STANDALONE_TOOLCHAIN ) - #try to find Android NDK in one of the the default locations - set( __ndkSearchPaths ) - foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} ) - foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} ) - list( APPEND __ndkSearchPaths "${__ndkSearchPath}/android-ndk${suffix}" ) - endforeach() - endforeach() - __INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} ) - unset( __ndkSearchPaths ) - - if( ANDROID_NDK ) - message( STATUS "Using default path for Android NDK: ${ANDROID_NDK}" ) - message( STATUS " If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK" ) - else() - #try to find Android standalone toolchain in one of the the default locations - __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH ) - - if( ANDROID_STANDALONE_TOOLCHAIN ) - message( STATUS "Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}" ) - message( STATUS " If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN" ) - endif( ANDROID_STANDALONE_TOOLCHAIN ) - endif( ANDROID_NDK ) - endif( NOT ANDROID_STANDALONE_TOOLCHAIN ) -endif( NOT ANDROID_NDK ) - -# remember found paths -if( ANDROID_NDK ) - get_filename_component( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE ) - set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" FORCE ) - set( BUILD_WITH_ANDROID_NDK True ) - if( EXISTS "${ANDROID_NDK}/RELEASE.TXT" ) - file( STRINGS "${ANDROID_NDK}/RELEASE.TXT" ANDROID_NDK_RELEASE_FULL LIMIT_COUNT 1 REGEX "r[0-9]+[a-z]?" ) - string( REGEX MATCH "r([0-9]+)([a-z]?)" ANDROID_NDK_RELEASE "${ANDROID_NDK_RELEASE_FULL}" ) - else() - set( ANDROID_NDK_RELEASE "r1x" ) - set( ANDROID_NDK_RELEASE_FULL "unreleased" ) - endif() - string( REGEX REPLACE "r([0-9]+)([a-z]?)" "\\1*1000" ANDROID_NDK_RELEASE_NUM "${ANDROID_NDK_RELEASE}" ) - string( FIND " abcdefghijklmnopqastuvwxyz" "${CMAKE_MATCH_2}" __ndkReleaseLetterNum ) - math( EXPR ANDROID_NDK_RELEASE_NUM "${ANDROID_NDK_RELEASE_NUM}+${__ndkReleaseLetterNum}" ) -elseif( ANDROID_STANDALONE_TOOLCHAIN ) - get_filename_component( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE ) - # try to detect change - if( CMAKE_AR ) - string( LENGTH "${ANDROID_STANDALONE_TOOLCHAIN}" __length ) - string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidStandaloneToolchainPreviousPath ) - if( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN ) - message( FATAL_ERROR "It is not possible to change path to the Android standalone toolchain on subsequent run." ) - endif() - unset( __androidStandaloneToolchainPreviousPath ) - unset( __length ) - endif() - set( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" FORCE ) - set( BUILD_WITH_STANDALONE_TOOLCHAIN True ) -else() - list(GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH) - message( FATAL_ERROR "Could not find neither Android NDK nor Android standalone toolchain. - You should either set an environment variable: - export ANDROID_NDK=~/my-android-ndk - or - export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain - or put the toolchain or NDK in the default path: - sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH}/android-ndk - sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" ) -endif() - -# android NDK layout -if( BUILD_WITH_ANDROID_NDK ) - if( NOT DEFINED ANDROID_NDK_LAYOUT ) - # try to automatically detect the layout - if( EXISTS "${ANDROID_NDK}/RELEASE.TXT") - set( ANDROID_NDK_LAYOUT "RELEASE" ) - elseif( EXISTS "${ANDROID_NDK}/../../linux-x86/toolchain/" ) - set( ANDROID_NDK_LAYOUT "LINARO" ) - elseif( EXISTS "${ANDROID_NDK}/../../gcc/" ) - set( ANDROID_NDK_LAYOUT "ANDROID" ) - endif() - endif() - set( ANDROID_NDK_LAYOUT "${ANDROID_NDK_LAYOUT}" CACHE STRING "The inner layout of NDK" ) - mark_as_advanced( ANDROID_NDK_LAYOUT ) - if( ANDROID_NDK_LAYOUT STREQUAL "LINARO" ) - set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment - set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../${ANDROID_NDK_HOST_SYSTEM_NAME}/toolchain" ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH "" ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" ) - elseif( ANDROID_NDK_LAYOUT STREQUAL "ANDROID" ) - set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment - set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../gcc/${ANDROID_NDK_HOST_SYSTEM_NAME}/arm" ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH "" ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" ) - else() # ANDROID_NDK_LAYOUT STREQUAL "RELEASE" - set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/toolchains" ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME2}" ) - endif() - get_filename_component( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK_TOOLCHAINS_PATH}" ABSOLUTE ) - - # try to detect change of NDK - if( CMAKE_AR ) - string( LENGTH "${ANDROID_NDK_TOOLCHAINS_PATH}" __length ) - string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidNdkPreviousPath ) - if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK_TOOLCHAINS_PATH ) - message( FATAL_ERROR "It is not possible to change the path to the NDK on subsequent CMake run. You must remove all generated files from your build folder first. - " ) - endif() - unset( __androidNdkPreviousPath ) - unset( __length ) - endif() -endif() - - -# get all the details about standalone toolchain -if( BUILD_WITH_STANDALONE_TOOLCHAIN ) - __DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" ) - set( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) - set( __availableToolchains "standalone" ) - __DETECT_TOOLCHAIN_MACHINE_NAME( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" ) - if( NOT __availableToolchainMachines ) - message( FATAL_ERROR "Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken." ) - endif() - if( __availableToolchainMachines MATCHES x86_64 ) - set( __availableToolchainArchs "x86_64" ) - elseif( __availableToolchainMachines MATCHES i686 ) - set( __availableToolchainArchs "x86" ) - elseif( __availableToolchainMachines MATCHES aarch64 ) - set( __availableToolchainArchs "arm64" ) - elseif( __availableToolchainMachines MATCHES arm ) - set( __availableToolchainArchs "arm" ) - elseif( __availableToolchainMachines MATCHES mips64el ) - set( __availableToolchainArchs "mips64" ) - elseif( __availableToolchainMachines MATCHES mipsel ) - set( __availableToolchainArchs "mips" ) - endif() - execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" -dumpversion - OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) - string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) - if( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/bin/clang${TOOL_OS_SUFFIX}" ) - list( APPEND __availableToolchains "standalone-clang" ) - list( APPEND __availableToolchainMachines ${__availableToolchainMachines} ) - list( APPEND __availableToolchainArchs ${__availableToolchainArchs} ) - list( APPEND __availableToolchainCompilerVersions ${__availableToolchainCompilerVersions} ) - endif() -endif() - -macro( __GLOB_NDK_TOOLCHAINS __availableToolchainsVar __availableToolchainsLst __toolchain_subpath ) - foreach( __toolchain ${${__availableToolchainsLst}} ) - if( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}${__toolchain_subpath}" ) - SET( __toolchainVersionRegex "^TOOLCHAIN_VERSION[\t ]+:=[\t ]+(.*)$" ) - FILE( STRINGS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}/setup.mk" __toolchainVersionStr REGEX "${__toolchainVersionRegex}" ) - if( __toolchainVersionStr ) - string( REGEX REPLACE "${__toolchainVersionRegex}" "\\1" __toolchainVersionStr "${__toolchainVersionStr}" ) - string( REGEX REPLACE "-clang3[.][0-9]$" "-${__toolchainVersionStr}" __gcc_toolchain "${__toolchain}" ) - else() - string( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" ) - endif() - unset( __toolchainVersionStr ) - unset( __toolchainVersionRegex ) - else() - set( __gcc_toolchain "${__toolchain}" ) - endif() - __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK_TOOLCHAINS_PATH}/${__gcc_toolchain}${__toolchain_subpath}" ) - if( __machine ) - string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9x]+)?$" __version "${__gcc_toolchain}" ) - if( __machine MATCHES x86_64 ) - set( __arch "x86_64" ) - elseif( __machine MATCHES i686 ) - set( __arch "x86" ) - elseif( __machine MATCHES aarch64 ) - set( __arch "arm64" ) - elseif( __machine MATCHES arm ) - set( __arch "arm" ) - elseif( __machine MATCHES mips64el ) - set( __arch "mips64" ) - elseif( __machine MATCHES mipsel ) - set( __arch "mips" ) - else() - set( __arch "" ) - endif() - #message("machine: !${__machine}!\narch: !${__arch}!\nversion: !${__version}!\ntoolchain: !${__toolchain}!\n") - if (__arch) - list( APPEND __availableToolchainMachines "${__machine}" ) - list( APPEND __availableToolchainArchs "${__arch}" ) - list( APPEND __availableToolchainCompilerVersions "${__version}" ) - list( APPEND ${__availableToolchainsVar} "${__toolchain}" ) - endif() - endif() - unset( __gcc_toolchain ) - endforeach() -endmacro() - -# get all the details about NDK -if( BUILD_WITH_ANDROID_NDK ) - file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" ) - string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" ) - set( __availableToolchains "" ) - set( __availableToolchainMachines "" ) - set( __availableToolchainArchs "" ) - set( __availableToolchainCompilerVersions "" ) - if( ANDROID_TOOLCHAIN_NAME AND EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_TOOLCHAIN_NAME}/" ) - # do not go through all toolchains if we know the name - set( __availableToolchainsLst "${ANDROID_TOOLCHAIN_NAME}" ) - __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) - if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 ) - __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" ) - if( __availableToolchains ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} ) - endif() - endif() - endif() - if( NOT __availableToolchains ) - file( GLOB __availableToolchainsLst RELATIVE "${ANDROID_NDK_TOOLCHAINS_PATH}" "${ANDROID_NDK_TOOLCHAINS_PATH}/*" ) - if( __availableToolchainsLst ) - list(SORT __availableToolchainsLst) # we need clang to go after gcc - endif() - __LIST_FILTER( __availableToolchainsLst "^[.]" ) - __LIST_FILTER( __availableToolchainsLst "llvm" ) - __LIST_FILTER( __availableToolchainsLst "renderscript" ) - __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) - if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 ) - __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" ) - if( __availableToolchains ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} ) - endif() - endif() - endif() - if( NOT __availableToolchains ) - message( FATAL_ERROR "Could not find any working toolchain in the NDK. Probably your Android NDK is broken." ) - endif() -endif() - -# build list of available ABIs -set( ANDROID_SUPPORTED_ABIS "" ) -set( __uniqToolchainArchNames ${__availableToolchainArchs} ) -list( REMOVE_DUPLICATES __uniqToolchainArchNames ) -list( SORT __uniqToolchainArchNames ) -foreach( __arch ${__uniqToolchainArchNames} ) - list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} ) -endforeach() -unset( __uniqToolchainArchNames ) -if( NOT ANDROID_SUPPORTED_ABIS ) - message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." ) -endif() - -# choose target ABI -__INIT_VARIABLE( ANDROID_ABI VALUES ${ANDROID_SUPPORTED_ABIS} ) -# verify that target ABI is supported -list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx ) -if( __androidAbiIdx EQUAL -1 ) - string( REPLACE ";" "\", \"" PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" ) - message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain. - Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\" - " ) -endif() -unset( __androidAbiIdx ) - -# set target ABI options -if( ANDROID_ABI STREQUAL "x86" ) - set( X86 true ) - set( ANDROID_NDK_ABI_NAME "x86" ) - set( ANDROID_ARCH_NAME "x86" ) - set( ANDROID_LLVM_TRIPLE "i686-none-linux-android" ) - set( CMAKE_SYSTEM_PROCESSOR "i686" ) -elseif( ANDROID_ABI STREQUAL "x86_64" ) - set( X86 true ) - set( X86_64 true ) - set( ANDROID_NDK_ABI_NAME "x86_64" ) - set( ANDROID_ARCH_NAME "x86_64" ) - set( CMAKE_SYSTEM_PROCESSOR "x86_64" ) - set( ANDROID_LLVM_TRIPLE "x86_64-none-linux-android" ) -elseif( ANDROID_ABI STREQUAL "mips64" ) - set( MIPS64 true ) - set( ANDROID_NDK_ABI_NAME "mips64" ) - set( ANDROID_ARCH_NAME "mips64" ) - set( ANDROID_LLVM_TRIPLE "mips64el-none-linux-android" ) - set( CMAKE_SYSTEM_PROCESSOR "mips64" ) -elseif( ANDROID_ABI STREQUAL "mips" ) - set( MIPS true ) - set( ANDROID_NDK_ABI_NAME "mips" ) - set( ANDROID_ARCH_NAME "mips" ) - set( ANDROID_LLVM_TRIPLE "mipsel-none-linux-android" ) - set( CMAKE_SYSTEM_PROCESSOR "mips" ) -elseif( ANDROID_ABI STREQUAL "arm64-v8a" ) - set( ARM64_V8A true ) - set( ANDROID_NDK_ABI_NAME "arm64-v8a" ) - set( ANDROID_ARCH_NAME "arm64" ) - set( ANDROID_LLVM_TRIPLE "aarch64-none-linux-android" ) - set( CMAKE_SYSTEM_PROCESSOR "aarch64" ) - set( VFPV3 true ) - set( NEON true ) -elseif( ANDROID_ABI STREQUAL "armeabi" ) - set( ARMEABI true ) - set( ANDROID_NDK_ABI_NAME "armeabi" ) - set( ANDROID_ARCH_NAME "arm" ) - set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" ) - set( CMAKE_SYSTEM_PROCESSOR "armv5te" ) -elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" ) - set( ARMEABI_V6 true ) - set( ANDROID_NDK_ABI_NAME "armeabi" ) - set( ANDROID_ARCH_NAME "arm" ) - set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" ) - set( CMAKE_SYSTEM_PROCESSOR "armv6" ) - # need always fallback to older platform - set( ARMEABI true ) -elseif( ANDROID_ABI STREQUAL "armeabi-v7a") - set( ARMEABI_V7A true ) - set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) - set( ANDROID_ARCH_NAME "arm" ) - set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) - set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) -elseif( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" ) - set( ARMEABI_V7A true ) - set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) - set( ANDROID_ARCH_NAME "arm" ) - set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) - set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) - set( VFPV3 true ) -elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" ) - set( ARMEABI_V7A true ) - set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) - set( ANDROID_ARCH_NAME "arm" ) - set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) - set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) - set( VFPV3 true ) - set( NEON true ) -else() - message( SEND_ERROR "Unknown ANDROID_ABI=\"${ANDROID_ABI}\" is specified." ) -endif() - -if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" ) - # really dirty hack - # it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run... - file( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \"${CMAKE_SYSTEM_PROCESSOR}\")\n" ) -endif() - -if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 ) - __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD VALUES OFF ) - set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE ) - mark_as_advanced( ANDROID_FORCE_ARM_BUILD ) -else() - unset( ANDROID_FORCE_ARM_BUILD CACHE ) -endif() - -# choose toolchain -if( ANDROID_TOOLCHAIN_NAME ) - list( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx ) - if( __toolchainIdx EQUAL -1 ) - list( SORT __availableToolchains ) - string( REPLACE ";" "\n * " toolchains_list "${__availableToolchains}" ) - set( toolchains_list " * ${toolchains_list}") - message( FATAL_ERROR "Specified toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is missing in your NDK or broken. Please verify that your NDK is working or select another compiler toolchain. -To configure the toolchain set CMake variable ANDROID_TOOLCHAIN_NAME to one of the following values:\n${toolchains_list}\n" ) - endif() - list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch ) - if( NOT __toolchainArch STREQUAL ANDROID_ARCH_NAME ) - message( SEND_ERROR "Selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." ) - endif() -else() - set( __toolchainIdx -1 ) - set( __applicableToolchains "" ) - set( __toolchainMaxVersion "0.0.0" ) - list( LENGTH __availableToolchains __availableToolchainsCount ) - math( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" ) - foreach( __idx RANGE ${__availableToolchainsCount} ) - list( GET __availableToolchainArchs ${__idx} __toolchainArch ) - if( __toolchainArch STREQUAL ANDROID_ARCH_NAME ) - list( GET __availableToolchainCompilerVersions ${__idx} __toolchainVersion ) - string( REPLACE "x" "99" __toolchainVersion "${__toolchainVersion}") - if( __toolchainVersion VERSION_GREATER __toolchainMaxVersion ) - set( __toolchainMaxVersion "${__toolchainVersion}" ) - set( __toolchainIdx ${__idx} ) - endif() - endif() - endforeach() - unset( __availableToolchainsCount ) - unset( __toolchainMaxVersion ) - unset( __toolchainVersion ) -endif() -unset( __toolchainArch ) -if( __toolchainIdx EQUAL -1 ) - message( FATAL_ERROR "No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform." ) -endif() -list( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME ) -list( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME ) -list( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION ) - -unset( __toolchainIdx ) -unset( __availableToolchains ) -unset( __availableToolchainMachines ) -unset( __availableToolchainArchs ) -unset( __availableToolchainCompilerVersions ) - -# choose native API level -__INIT_VARIABLE( ANDROID_NATIVE_API_LEVEL ENV_ANDROID_NATIVE_API_LEVEL ANDROID_API_LEVEL ENV_ANDROID_API_LEVEL ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME} ANDROID_DEFAULT_NDK_API_LEVEL ) -string( REPLACE "android-" "" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" ) -string( STRIP "${ANDROID_NATIVE_API_LEVEL}" ANDROID_NATIVE_API_LEVEL ) -# adjust API level -set( __real_api_level ${ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME}} ) -foreach( __level ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) - if( (__level LESS ANDROID_NATIVE_API_LEVEL OR __level STREQUAL ANDROID_NATIVE_API_LEVEL) AND NOT __level LESS __real_api_level ) - set( __real_api_level ${__level} ) - endif() -endforeach() -if( __real_api_level AND NOT ANDROID_NATIVE_API_LEVEL STREQUAL __real_api_level ) - message( STATUS "Adjusting Android API level 'android-${ANDROID_NATIVE_API_LEVEL}' to 'android-${__real_api_level}'") - set( ANDROID_NATIVE_API_LEVEL ${__real_api_level} ) -endif() -unset(__real_api_level) -# validate -list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx ) -if( __levelIdx EQUAL -1 ) - message( SEND_ERROR "Specified Android native API level 'android-${ANDROID_NATIVE_API_LEVEL}' is not supported by your NDK/toolchain." ) -else() - if( BUILD_WITH_ANDROID_NDK ) - __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) - if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL AND NOT __realApiLevel GREATER 9000 ) - message( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." ) - endif() - unset( __realApiLevel ) - endif() - set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) - set( CMAKE_ANDROID_API ${ANDROID_NATIVE_API_LEVEL} ) - if( CMAKE_VERSION VERSION_GREATER "2.8" ) - list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) - set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) - endif() -endif() -unset( __levelIdx ) - - -# remember target ABI -set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE ) -if( CMAKE_VERSION VERSION_GREATER "2.8" ) - list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME} ) - set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} ) -endif() - - -# runtime choice (STL, rtti, exceptions) -if( NOT ANDROID_STL ) - set( ANDROID_STL gnustl_static ) -endif() -set( ANDROID_STL "${ANDROID_STL}" CACHE STRING "C++ runtime" ) -set( ANDROID_STL_FORCE_FEATURES ON CACHE BOOL "automatically configure rtti and exceptions support based on C++ runtime" ) -mark_as_advanced( ANDROID_STL ANDROID_STL_FORCE_FEATURES ) - -if( BUILD_WITH_ANDROID_NDK ) - if( NOT "${ANDROID_STL}" MATCHES "^(none|system|system_re|gabi\\+\\+_static|gabi\\+\\+_shared|stlport_static|stlport_shared|gnustl_static|gnustl_shared|c\\+\\+_shared|c\\+\\+_static)$") - message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\". -The possible values are: - none -> Do not configure the runtime. - system -> Use the default minimal system C++ runtime library. - system_re -> Same as system but with rtti and exceptions. - gabi++_static -> Use the GAbi++ runtime as a static library. - gabi++_shared -> Use the GAbi++ runtime as a shared library. - stlport_static -> Use the STLport runtime as a static library. - stlport_shared -> Use the STLport runtime as a shared library. - gnustl_static -> (default) Use the GNU STL as a static library. - gnustl_shared -> Use the GNU STL as a shared library. - c++_shared -> Use the LLVM STL as a shared library. - c++_static -> Use the LLVM STL as a static library. -" ) - endif() -elseif( BUILD_WITH_STANDALONE_TOOLCHAIN ) - if( NOT "${ANDROID_STL}" MATCHES "^(none|gnustl_static|gnustl_shared)$") - message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\". -The possible values are: - none -> Do not configure the runtime. - gnustl_static -> (default) Use the GNU STL as a static library. - gnustl_shared -> Use the GNU STL as a shared library. -" ) - endif() -endif() - -unset( ANDROID_RTTI ) -unset( ANDROID_EXCEPTIONS ) -unset( ANDROID_STL_INCLUDE_DIRS ) -unset( __libstl ) -unset( __libsupcxx ) - -if( NOT _CMAKE_IN_TRY_COMPILE AND ANDROID_NDK_RELEASE STREQUAL "r7b" AND ARMEABI_V7A AND NOT VFPV3 AND ANDROID_STL MATCHES "gnustl" ) - message( WARNING "The GNU STL armeabi-v7a binaries from NDK r7b can crash non-NEON devices. The files provided with NDK r7b were not configured properly, resulting in crashes on Tegra2-based devices and others when trying to use certain floating-point functions (e.g., cosf, sinf, expf). -You are strongly recommended to switch to another NDK release. -" ) -endif() - -if( NOT _CMAKE_IN_TRY_COMPILE AND X86 AND ANDROID_STL MATCHES "gnustl" AND ANDROID_NDK_RELEASE STREQUAL "r6" ) - message( WARNING "The x86 system header file from NDK r6 has incorrect definition for ptrdiff_t. You are recommended to upgrade to a newer NDK release or manually patch the header: -See https://android.googlesource.com/platform/development.git f907f4f9d4e56ccc8093df6fee54454b8bcab6c2 - diff --git a/ndk/platforms/android-9/arch-x86/include/machine/_types.h b/ndk/platforms/android-9/arch-x86/include/machine/_types.h - index 5e28c64..65892a1 100644 - --- a/ndk/platforms/android-9/arch-x86/include/machine/_types.h - +++ b/ndk/platforms/android-9/arch-x86/include/machine/_types.h - @@ -51,7 +51,11 @@ typedef long int ssize_t; - #endif - #ifndef _PTRDIFF_T - #define _PTRDIFF_T - -typedef long ptrdiff_t; - +# ifdef __ANDROID__ - + typedef int ptrdiff_t; - +# else - + typedef long ptrdiff_t; - +# endif - #endif -" ) -endif() - - -# setup paths and STL for standalone toolchain -if( BUILD_WITH_STANDALONE_TOOLCHAIN ) - set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) - set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) - set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) - - if( NOT ANDROID_STL STREQUAL "none" ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/include/c++/${ANDROID_COMPILER_VERSION}" ) - if( NOT EXISTS "${ANDROID_STL_INCLUDE_DIRS}" ) - # old location ( pre r8c ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" ) - endif() - if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) - list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) - list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" ) - else() - list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) - endif() - # always search static GNU STL to get the location of libsupc++.a - if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" ) - elseif( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}" ) - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb" ) - elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" ) - endif() - if( __libstl ) - set( __libsupcxx "${__libstl}/libsupc++.a" ) - set( __libstl "${__libstl}/libstdc++.a" ) - endif() - if( NOT EXISTS "${__libsupcxx}" ) - message( FATAL_ERROR "The required libstdsupc++.a is missing in your standalone toolchain. - Usually it happens because of bug in make-standalone-toolchain.sh script from NDK r7, r7b and r7c. - You need to either upgrade to newer NDK or manually copy - $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a - to - ${__libsupcxx} - " ) - endif() - if( ANDROID_STL STREQUAL "gnustl_shared" ) - if( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) - elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) - endif() - elseif( ANDROID_STL STREQUAL "c\\+\\+_shared" ) - set( __libstl "${ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${TARGET_ARCH}/libc++_shared.so" ) - endif() - endif() -endif() - -# clang -if( "${ANDROID_TOOLCHAIN_NAME}" STREQUAL "standalone-clang" ) - set( ANDROID_COMPILER_IS_CLANG 1 ) - execute_process( COMMAND "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/clang${TOOL_OS_SUFFIX}" --version OUTPUT_VARIABLE ANDROID_CLANG_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ) - string( REGEX MATCH "[0-9]+[.][0-9]+" ANDROID_CLANG_VERSION "${ANDROID_CLANG_VERSION}") -elseif( "${ANDROID_TOOLCHAIN_NAME}" MATCHES "-clang3[.][0-9]?$" ) - string( REGEX MATCH "3[.][0-9]$" ANDROID_CLANG_VERSION "${ANDROID_TOOLCHAIN_NAME}") - string( REGEX REPLACE "-clang${ANDROID_CLANG_VERSION}$" "-${ANDROID_COMPILER_VERSION}" ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" ) - if( NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}/bin/clang${TOOL_OS_SUFFIX}" ) - message( FATAL_ERROR "Could not find the Clang compiler driver" ) - endif() - set( ANDROID_COMPILER_IS_CLANG 1 ) - set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) -else() - set( ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" ) - unset( ANDROID_COMPILER_IS_CLANG CACHE ) -endif() - -string( REPLACE "." "" _clang_name "clang${ANDROID_CLANG_VERSION}" ) -if( NOT EXISTS "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" ) - set( _clang_name "clang" ) -endif() - - -# setup paths and STL for NDK -if( BUILD_WITH_ANDROID_NDK ) - set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) - set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" ) - - if( ANDROID_STL STREQUAL "none" ) - # do nothing - elseif( ANDROID_STL STREQUAL "system" ) - set( ANDROID_RTTI OFF ) - set( ANDROID_EXCEPTIONS OFF ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" ) - elseif( ANDROID_STL STREQUAL "system_re" ) - set( ANDROID_RTTI ON ) - set( ANDROID_EXCEPTIONS ON ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" ) - elseif( ANDROID_STL MATCHES "gabi" ) - if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 - message( FATAL_ERROR "gabi++ is not available in your NDK. You have to upgrade to NDK r7 or newer to use gabi++.") - endif() - set( ANDROID_RTTI ON ) - set( ANDROID_EXCEPTIONS OFF ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/gabi++/include" ) - set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gabi++/libs/${ANDROID_NDK_ABI_NAME}/libgabi++_static.a" ) - elseif( ANDROID_STL MATCHES "stlport" ) - if( NOT ANDROID_NDK_RELEASE_NUM LESS 8004 ) # before r8d - set( ANDROID_EXCEPTIONS ON ) - else() - set( ANDROID_EXCEPTIONS OFF ) - endif() - if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 - set( ANDROID_RTTI OFF ) - else() - set( ANDROID_RTTI ON ) - endif() - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/stlport/stlport" ) - set( __libstl "${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}/libstlport_static.a" ) - elseif( ANDROID_STL MATCHES "gnustl" ) - set( ANDROID_EXCEPTIONS ON ) - set( ANDROID_RTTI ON ) - if( EXISTS "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" ) - if( ARMEABI_V7A AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.7" AND ANDROID_NDK_RELEASE STREQUAL "r8d" ) - # gnustl binary for 4.7 compiler is buggy :( - # TODO: look for right fix - set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.6" ) - else() - set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" ) - endif() - else() - set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++" ) - endif() - set( ANDROID_STL_INCLUDE_DIRS "${__libstl}/include" "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/include" "${__libstl}/include/backward" ) - if( EXISTS "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" ) - set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" ) - else() - set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libstdc++.a" ) - endif() - elseif( ANDROID_STL MATCHES "c\\+\\+_shared" ) - set( ANDROID_EXCEPTIONS ON ) - set( ANDROID_RTTI ON ) - set( ANDROID_CXX_ROOT "${ANDROID_NDK}/sources/cxx-stl/" ) - set( ANDROID_LLVM_ROOT "${ANDROID_CXX_ROOT}/llvm-libc++" ) - if( X86 ) - set( ANDROID_ABI_INCLUDE_DIRS "${ANDROID_CXX_ROOT}/gabi++/include" ) - else() - set( ANDROID_ABI_INCLUDE_DIRS "${ANDROID_CXX_ROOT}/llvm-libc++abi/libcxxabi/include" ) - endif() - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_LLVM_ROOT}/libcxx/include" "${ANDROID_ABI_INCLUDE_DIRS}" ) - # android support sfiles - include_directories ( SYSTEM ${ANDROID_NDK}/sources/android/support/include ) - if( EXISTS "${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/libc++_shared.so" ) - set( __libstl "${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/libc++_shared.so" ) - else() - message( "c++ shared library doesn't exist" ) - endif() - elseif( ANDROID_STL MATCHES "c\\+\\+_static" ) - set( ANDROID_EXCEPTIONS ON ) - set( ANDROID_RTTI ON ) - set( ANDROID_CXX_ROOT "${ANDROID_NDK}/sources/cxx-stl/" ) - set( ANDROID_LLVM_ROOT "${ANDROID_CXX_ROOT}/llvm-libc++" ) - if( X86 ) - set( ANDROID_ABI_INCLUDE_DIRS "${ANDROID_CXX_ROOT}/gabi++/include" ) - else() - set( ANDROID_ABI_INCLUDE_DIRS "${ANDROID_CXX_ROOT}/llvm-libc++abi/libcxxabi/include" ) - endif() - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_LLVM_ROOT}/libcxx/include" "${ANDROID_ABI_INCLUDE_DIRS}" ) - # android support sfiles - include_directories ( SYSTEM ${ANDROID_NDK}/sources/android/support/include ) - if( NOT ANDROID_FORCE_ARM_BUILD ) - if( EXISTS "${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/thumb/libc++_static.a" ) - set( __libstl "${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/thumb/libc++_static.a" ) - else() - message( "c++ static library doesn't exist" ) - endif() - else() - if( EXISTS "${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/libc++_static.a" ) - set( __libstl "${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/libc++_static.a" ) - else() - message( "c++ static library doesn't exist" ) - endif() - endif() - else() - message( FATAL_ERROR "Unknown runtime: ${ANDROID_STL}" ) - endif() - # find libsupc++.a - rtti & exceptions - if( ANDROID_STL STREQUAL "system_re" OR ANDROID_STL MATCHES "gnustl" ) - set( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r8b or newer - if( NOT EXISTS "${__libsupcxx}" ) - set( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r7-r8 - endif() - if( NOT EXISTS "${__libsupcxx}" ) # before r7 - if( ARMEABI_V7A ) - if( ANDROID_FORCE_ARM_BUILD ) - set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" ) - else() - set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" ) - endif() - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD ) - set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" ) - else() - set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" ) - endif() - endif() - if( NOT EXISTS "${__libsupcxx}") - message( ERROR "Could not find libsupc++.a for a chosen platform. Either your NDK is not supported or is broken.") - endif() - endif() -endif() - - -# case of shared STL linkage -if( ANDROID_STL MATCHES "shared" AND DEFINED __libstl ) - string( REPLACE "_static.a" "_shared.so" __libstl "${__libstl}" ) - # TODO: check if .so file exists before the renaming -endif() - - -# ccache support -__INIT_VARIABLE( _ndk_ccache NDK_CCACHE ENV_NDK_CCACHE ) -if( _ndk_ccache ) - if( DEFINED NDK_CCACHE AND NOT EXISTS NDK_CCACHE ) - unset( NDK_CCACHE CACHE ) - endif() - find_program( NDK_CCACHE "${_ndk_ccache}" DOC "The path to ccache binary") -else() - unset( NDK_CCACHE CACHE ) -endif() -unset( _ndk_ccache ) - - -# setup the cross-compiler -if( NOT CMAKE_C_COMPILER ) - if( NDK_CCACHE AND NOT ANDROID_SYSROOT MATCHES "[ ;\"]" ) - set( CMAKE_C_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C compiler" ) - set( CMAKE_CXX_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C++ compiler" ) - if( ANDROID_COMPILER_IS_CLANG ) - set( CMAKE_C_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") - set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") - else() - set( CMAKE_C_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") - set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") - endif() - else() - if( ANDROID_COMPILER_IS_CLANG ) - set( CMAKE_C_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") - set( CMAKE_CXX_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") - else() - set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler" ) - set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler" ) - endif() - endif() - set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "assembler" ) - set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" ) - set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) - if( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}" ) - # Use gcc-ar if we have it for better LTO support. - set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) - else() - set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) - endif() - set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" ) - set( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" ) - set( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" ) - set( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" ) - set( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" ) -endif() - -set( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" ) -if( CMAKE_VERSION VERSION_LESS 2.8.5 ) - set( CMAKE_ASM_COMPILER_ARG1 "-c" ) -endif() -if( APPLE ) - find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool ) - if( NOT CMAKE_INSTALL_NAME_TOOL ) - message( FATAL_ERROR "Could not find install_name_tool, please check your installation." ) - endif() - mark_as_advanced( CMAKE_INSTALL_NAME_TOOL ) -endif() - -# Force set compilers because standard identification works badly for us -include( CMakeForceCompiler ) -CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU ) -if( ANDROID_COMPILER_IS_CLANG ) - set( CMAKE_C_COMPILER_ID Clang ) -endif() -set( CMAKE_C_PLATFORM_ID Linux ) -if( X86_64 OR MIPS64 OR ARM64_V8A ) - set( CMAKE_C_SIZEOF_DATA_PTR 8 ) -else() - set( CMAKE_C_SIZEOF_DATA_PTR 4 ) -endif() -set( CMAKE_C_HAS_ISYSROOT 1 ) -set( CMAKE_C_COMPILER_ABI ELF ) -CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU ) -if( ANDROID_COMPILER_IS_CLANG ) - set( CMAKE_CXX_COMPILER_ID Clang) -endif() -set( CMAKE_CXX_PLATFORM_ID Linux ) -set( CMAKE_CXX_SIZEOF_DATA_PTR ${CMAKE_C_SIZEOF_DATA_PTR} ) -set( CMAKE_CXX_HAS_ISYSROOT 1 ) -set( CMAKE_CXX_COMPILER_ABI ELF ) -set( CMAKE_CXX_SOURCE_FILE_EXTENSIONS cc cp cxx cpp CPP c++ C ) -# force ASM compiler (required for CMake < 2.8.5) -set( CMAKE_ASM_COMPILER_ID_RUN TRUE ) -set( CMAKE_ASM_COMPILER_ID GNU ) -set( CMAKE_ASM_COMPILER_WORKS TRUE ) -set( CMAKE_ASM_COMPILER_FORCED TRUE ) -set( CMAKE_COMPILER_IS_GNUASM 1) -set( CMAKE_ASM_SOURCE_FILE_EXTENSIONS s S asm ) - -foreach( lang C CXX ASM ) - if( ANDROID_COMPILER_IS_CLANG ) - set( CMAKE_${lang}_COMPILER_VERSION ${ANDROID_CLANG_VERSION} ) - else() - set( CMAKE_${lang}_COMPILER_VERSION ${ANDROID_COMPILER_VERSION} ) - endif() -endforeach() - -# flags and definitions -remove_definitions( -DANDROID ) -add_definitions( -DANDROID ) - -if( ANDROID_SYSROOT MATCHES "[ ;\"]" ) - if( CMAKE_HOST_WIN32 ) - # try to convert path to 8.3 form - file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd" "@echo %~s1" ) - execute_process( COMMAND "$ENV{ComSpec}" /c "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd" "${ANDROID_SYSROOT}" - OUTPUT_VARIABLE __path OUTPUT_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE __result ERROR_QUIET ) - if( __result EQUAL 0 ) - file( TO_CMAKE_PATH "${__path}" ANDROID_SYSROOT ) - set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" ) - else() - set( ANDROID_CXX_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" ) - endif() - else() - set( ANDROID_CXX_FLAGS "'--sysroot=${ANDROID_SYSROOT}'" ) - endif() - if( NOT _CMAKE_IN_TRY_COMPILE ) - # quotes can break try_compile and compiler identification - message(WARNING "Path to your Android NDK (or toolchain) has non-alphanumeric symbols.\nThe build might be broken.\n") - endif() -else() - set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" ) -endif() -set( CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${ANDROID_CXX_FLAGS}" ) - -# NDK flags -if (ARM64_V8A ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" ) - set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" ) - set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" ) - if( NOT ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" ) - endif() -elseif( ARMEABI OR ARMEABI_V7A) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" ) - if( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 ) - set( ANDROID_CXX_FLAGS_RELEASE "-mthumb -fomit-frame-pointer -fno-strict-aliasing" ) - set( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" ) - if( NOT ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -finline-limit=64" ) - endif() - else() - # always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI - set( ANDROID_CXX_FLAGS_RELEASE "-marm -fomit-frame-pointer -fstrict-aliasing" ) - set( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" ) - if( NOT ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" ) - endif() - endif() -elseif( X86 OR X86_64 ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" ) - if( NOT ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" ) - endif() - set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" ) - set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" ) -elseif( MIPS OR MIPS64 ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-strict-aliasing -finline-functions -funwind-tables -fmessage-length=0" ) - set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer" ) - set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer" ) - if( NOT ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" ) - set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" ) - endif() -elseif() - set( ANDROID_CXX_FLAGS_RELEASE "" ) - set( ANDROID_CXX_FLAGS_DEBUG "" ) -endif() - -set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) # good/necessary when porting desktop libraries - -if( NOT X86 AND NOT ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "-Wno-psabi ${ANDROID_CXX_FLAGS}" ) -endif() - -if( NOT ANDROID_COMPILER_VERSION VERSION_LESS "4.6" ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -no-canonical-prefixes" ) # see https://android-review.googlesource.com/#/c/47564/ -endif() - -# ABI-specific flags -if( ARMEABI_V7A ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) - if( NEON ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" ) - elseif( VFPV3 ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" ) - else() - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d16" ) - endif() -elseif( ARMEABI_V6 ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) # vfp == vfpv2 -elseif( ARMEABI ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" ) -endif() - -if( ANDROID_STL MATCHES "gnustl" AND (EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}") ) - set( CMAKE_CXX_CREATE_SHARED_LIBRARY " -o " ) - set( CMAKE_CXX_CREATE_SHARED_MODULE " -o " ) - set( CMAKE_CXX_LINK_EXECUTABLE " -o " ) -else() - set( CMAKE_CXX_CREATE_SHARED_LIBRARY " -o " ) - set( CMAKE_CXX_CREATE_SHARED_MODULE " -o " ) - set( CMAKE_CXX_LINK_EXECUTABLE " -o " ) -endif() - -# STL -if( EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}" ) - if( EXISTS "${__libstl}" ) - set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${__libstl}\"" ) - set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${__libstl}\"" ) - set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \"${__libstl}\"" ) - endif() - if( EXISTS "${__libsupcxx}" ) - set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${__libsupcxx}\"" ) - set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${__libsupcxx}\"" ) - set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \"${__libsupcxx}\"" ) - # C objects: - set( CMAKE_C_CREATE_SHARED_LIBRARY " -o " ) - set( CMAKE_C_CREATE_SHARED_MODULE " -o " ) - set( CMAKE_C_LINK_EXECUTABLE " -o " ) - set( CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY} \"${__libsupcxx}\"" ) - set( CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE} \"${__libsupcxx}\"" ) - set( CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} \"${__libsupcxx}\"" ) - endif() - if( ANDROID_STL MATCHES "gnustl" ) - if( NOT EXISTS "${ANDROID_LIBM_PATH}" ) - set( ANDROID_LIBM_PATH -lm ) - endif() - set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} ${ANDROID_LIBM_PATH}" ) - set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} ${ANDROID_LIBM_PATH}" ) - set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${ANDROID_LIBM_PATH}" ) - endif() -endif() - -# variables controlling optional build flags -if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 - # libGLESv2.so in NDK's prior to r7 refers to missing external symbols. - # So this flag option is required for all projects using OpenGL from native. - __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES ON ) -else() - __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES OFF ) -endif() -__INIT_VARIABLE( ANDROID_NO_UNDEFINED VALUES ON ) -__INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON ) -__INIT_VARIABLE( ANDROID_GOLD_LINKER VALUES ON ) -__INIT_VARIABLE( ANDROID_NOEXECSTACK VALUES ON ) -__INIT_VARIABLE( ANDROID_RELRO VALUES ON ) - -set( ANDROID_NO_UNDEFINED ${ANDROID_NO_UNDEFINED} CACHE BOOL "Show all undefined symbols as linker errors" ) -set( ANDROID_SO_UNDEFINED ${ANDROID_SO_UNDEFINED} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" ) -set( ANDROID_FUNCTION_LEVEL_LINKING ${ANDROID_FUNCTION_LEVEL_LINKING} CACHE BOOL "Put each function in separate section and enable garbage collection of unused input sections at link time" ) -set( ANDROID_GOLD_LINKER ${ANDROID_GOLD_LINKER} CACHE BOOL "Enables gold linker" ) -set( ANDROID_NOEXECSTACK ${ANDROID_NOEXECSTACK} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" ) -set( ANDROID_RELRO ${ANDROID_RELRO} CACHE BOOL "Enables RELRO - a memory corruption mitigation technique" ) -mark_as_advanced( ANDROID_NO_UNDEFINED ANDROID_SO_UNDEFINED ANDROID_FUNCTION_LEVEL_LINKING ANDROID_GOLD_LINKER ANDROID_NOEXECSTACK ANDROID_RELRO ) - -# linker flags -set( ANDROID_LINKER_FLAGS "" ) - -if( ARMEABI_V7A ) - # this is *required* to use the following linker flags that routes around - # a CPU bug in some Cortex-A8 implementations: - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--fix-cortex-a8" ) -endif() - -if( ANDROID_NO_UNDEFINED ) - if( MIPS ) - # there is some sysroot-related problem in mips linker... - if( NOT ANDROID_SYSROOT MATCHES "[ ;\"]" ) - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined -Wl,-rpath-link,${ANDROID_SYSROOT}/usr/lib" ) - endif() - else() - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined" ) - endif() -endif() - -if( ANDROID_SO_UNDEFINED ) - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined" ) -endif() - -if( ANDROID_FUNCTION_LEVEL_LINKING ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" ) - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--gc-sections" ) -endif() - -if( ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" ) - if( ANDROID_GOLD_LINKER AND (CMAKE_HOST_UNIX OR ANDROID_NDK_RELEASE_NUM GREATER 8002) AND (ARMEABI OR ARMEABI_V7A OR X86) ) - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold" ) - elseif( ANDROID_NDK_RELEASE_NUM GREATER 8002 ) # after r8b - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=bfd" ) - elseif( ANDROID_NDK_RELEASE STREQUAL "r8b" AND ARMEABI AND NOT _CMAKE_IN_TRY_COMPILE ) - message( WARNING "The default bfd linker from arm GCC 4.6 toolchain can fail with 'unresolvable R_ARM_THM_CALL relocation' error message. See https://code.google.com/p/android/issues/detail?id=35342 - On Linux and OS X host platform you can workaround this problem using gold linker (default). - Rerun cmake with -DANDROID_GOLD_LINKER=ON option in case of problems. -" ) - endif() -endif() # version 4.6 - -if( ANDROID_NOEXECSTACK ) - if( ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Xclang -mnoexecstack" ) - else() - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Wa,--noexecstack" ) - endif() - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,noexecstack" ) -endif() - -if( ANDROID_RELRO ) - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now" ) -endif() - -if( ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "-target ${ANDROID_LLVM_TRIPLE} -Qunused-arguments ${ANDROID_CXX_FLAGS}" ) - if( BUILD_WITH_ANDROID_NDK ) - set( ANDROID_CXX_FLAGS "-gcc-toolchain ${ANDROID_TOOLCHAIN_ROOT} ${ANDROID_CXX_FLAGS}" ) - endif() -endif() - -# cache flags -set( CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags" ) -set( CMAKE_C_FLAGS "" CACHE STRING "c flags" ) -set( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c++ Release flags" ) -set( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c Release flags" ) -set( CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c++ Debug flags" ) -set( CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c Debug flags" ) -set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "shared linker flags" ) -set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "module linker flags" ) -set( CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "executable linker flags" ) - -# put flags to cache (for debug purpose only) -set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Android specific c/c++ flags" ) -set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE}" CACHE INTERNAL "Android specific c/c++ Release flags" ) -set( ANDROID_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG}" CACHE INTERNAL "Android specific c/c++ Debug flags" ) -set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Android specific c/c++ linker flags" ) - -# finish flags -set( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" ) -set( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" ) -set( CMAKE_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}" ) -set( CMAKE_C_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}" ) -set( CMAKE_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}" ) -set( CMAKE_C_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}" ) -set( CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" ) -set( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" ) -set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) - -if( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL "r8" ) - set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}" ) - set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}" ) - set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" ) -endif() - -# pie/pic -if( NOT (ANDROID_NATIVE_API_LEVEL LESS 16) AND (NOT DEFINED ANDROID_APP_PIE OR ANDROID_APP_PIE) AND (CMAKE_VERSION VERSION_GREATER 2.8.8) ) - set( CMAKE_POSITION_INDEPENDENT_CODE TRUE ) - set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie") -else() - set( CMAKE_POSITION_INDEPENDENT_CODE FALSE ) - set( CMAKE_CXX_FLAGS "-fpic ${CMAKE_CXX_FLAGS}" ) - set( CMAKE_C_FLAGS "-fpic ${CMAKE_C_FLAGS}" ) -endif() - -# configure rtti -if( DEFINED ANDROID_RTTI AND ANDROID_STL_FORCE_FEATURES ) - if( ANDROID_RTTI ) - set( CMAKE_CXX_FLAGS "-frtti ${CMAKE_CXX_FLAGS}" ) - else() - set( CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}" ) - endif() -endif() - -# configure exceptios -if( DEFINED ANDROID_EXCEPTIONS AND ANDROID_STL_FORCE_FEATURES ) - if( ANDROID_EXCEPTIONS ) - set( CMAKE_CXX_FLAGS "-fexceptions ${CMAKE_CXX_FLAGS}" ) - set( CMAKE_C_FLAGS "-fexceptions ${CMAKE_C_FLAGS}" ) - else() - set( CMAKE_CXX_FLAGS "-fno-exceptions ${CMAKE_CXX_FLAGS}" ) - set( CMAKE_C_FLAGS "-fno-exceptions ${CMAKE_C_FLAGS}" ) - endif() -endif() - -# global includes and link directories -include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_STL_INCLUDE_DIRS} ) -get_filename_component(__android_install_path "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ABSOLUTE) # avoid CMP0015 policy warning -link_directories( "${__android_install_path}" ) - -# detect if need link crtbegin_so.o explicitly -if( NOT DEFINED ANDROID_EXPLICIT_CRT_LINK ) - set( __cmd "${CMAKE_CXX_CREATE_SHARED_LIBRARY}" ) - string( REPLACE "" "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" __cmd "${__cmd}" ) - string( REPLACE "" "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}" __cmd "${__cmd}" ) - string( REPLACE "" "${CMAKE_CXX_FLAGS}" __cmd "${__cmd}" ) - string( REPLACE "" "" __cmd "${__cmd}" ) - string( REPLACE "" "${CMAKE_SHARED_LINKER_FLAGS}" __cmd "${__cmd}" ) - string( REPLACE "" "-shared" __cmd "${__cmd}" ) - string( REPLACE "" "" __cmd "${__cmd}" ) - string( REPLACE "" "" __cmd "${__cmd}" ) - string( REPLACE "" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/toolchain_crtlink_test.so" __cmd "${__cmd}" ) - string( REPLACE "" "\"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" __cmd "${__cmd}" ) - string( REPLACE "" "" __cmd "${__cmd}" ) - separate_arguments( __cmd ) - foreach( __var ANDROID_NDK ANDROID_NDK_TOOLCHAINS_PATH ANDROID_STANDALONE_TOOLCHAIN ) - if( ${__var} ) - set( __tmp "${${__var}}" ) - separate_arguments( __tmp ) - string( REPLACE "${__tmp}" "${${__var}}" __cmd "${__cmd}") - endif() - endforeach() - string( REPLACE "'" "" __cmd "${__cmd}" ) - string( REPLACE "\"" "" __cmd "${__cmd}" ) - execute_process( COMMAND ${__cmd} RESULT_VARIABLE __cmd_result OUTPUT_QUIET ERROR_QUIET ) - if( __cmd_result EQUAL 0 ) - set( ANDROID_EXPLICIT_CRT_LINK ON ) - else() - set( ANDROID_EXPLICIT_CRT_LINK OFF ) - endif() -endif() - -if( ANDROID_EXPLICIT_CRT_LINK ) - set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" ) - set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" ) -endif() - -# setup output directories -set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) - -if( DEFINED LIBRARY_OUTPUT_PATH_ROOT - OR EXISTS "${CMAKE_SOURCE_DIR}/android/AndroidManifest.xml" - OR (EXISTS "${CMAKE_SOURCE_DIR}/../AndroidManifest.xml" AND EXISTS "${CMAKE_SOURCE_DIR}/../jni/") ) - set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR}/android CACHE PATH "Root for binaries output, set this to change where Android libs are installed to" ) - if( NOT _CMAKE_IN_TRY_COMPILE ) - if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) - set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) - else() - set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) - endif() - set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for Android libs" ) - endif() -endif() - -# copy shaed stl library to build directory -if( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" AND DEFINED LIBRARY_OUTPUT_PATH ) - get_filename_component( __libstlname "${__libstl}" NAME ) - execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess ) - if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${LIBRARY_OUTPUT_PATH}/${__libstlname}") - message( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" ) - endif() - unset( __fileCopyProcess ) - unset( __libstlname ) -endif() - - -# set these global flags for cmake client scripts to change behavior -set( ANDROID True ) -set( BUILD_ANDROID True ) - -# where is the target environment -# http://www.vtk.org/Wiki/CMake_Cross_Compiling -# we need to use find_path in our custorm modules, so disable it. -# set( CMAKE_FIND_ROOT_PATH "${ANDROID_TOOLCHAIN_ROOT}/bin" "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" "${ANDROID_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" ) - -# only search for libraries and includes in the ndk toolchain -set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) -set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) -set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) - - -# macro to find packages on the host OS -macro( find_host_package ) - set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) - set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) - set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) - if( CMAKE_HOST_WIN32 ) - SET( WIN32 1 ) - SET( UNIX ) - elseif( CMAKE_HOST_APPLE ) - SET( APPLE 1 ) - SET( UNIX ) - endif() - find_package( ${ARGN} ) - SET( WIN32 ) - SET( APPLE ) - SET( UNIX 1 ) - set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) - set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) - set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) -endmacro() - - -# macro to find programs on the host OS -macro( find_host_program ) - set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) - set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) - set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) - if( CMAKE_HOST_WIN32 ) - SET( WIN32 1 ) - SET( UNIX ) - elseif( CMAKE_HOST_APPLE ) - SET( APPLE 1 ) - SET( UNIX ) - endif() - find_program( ${ARGN} ) - SET( WIN32 ) - SET( APPLE ) - SET( UNIX 1 ) - set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) - set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) - set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) -endmacro() - - -# export toolchain settings for the try_compile() command -if( NOT _CMAKE_IN_TRY_COMPILE ) - set( __toolchain_config "") - foreach( __var NDK_CCACHE LIBRARY_OUTPUT_PATH_ROOT ANDROID_FORBID_SYGWIN - ANDROID_NDK_HOST_X64 - ANDROID_NDK - ANDROID_NDK_LAYOUT - ANDROID_STANDALONE_TOOLCHAIN - ANDROID_TOOLCHAIN_NAME - ANDROID_ABI - ANDROID_NATIVE_API_LEVEL - ANDROID_STL - ANDROID_STL_FORCE_FEATURES - ANDROID_FORCE_ARM_BUILD - ANDROID_NO_UNDEFINED - ANDROID_SO_UNDEFINED - ANDROID_FUNCTION_LEVEL_LINKING - ANDROID_GOLD_LINKER - ANDROID_NOEXECSTACK - ANDROID_RELRO - ANDROID_LIBM_PATH - ANDROID_EXPLICIT_CRT_LINK - ANDROID_APP_PIE - ) - if( DEFINED ${__var} ) - if( ${__var} MATCHES " ") - set( __toolchain_config "${__toolchain_config}set( ${__var} \"${${__var}}\" CACHE INTERNAL \"\" )\n" ) - else() - set( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \"\" )\n" ) - endif() - endif() - endforeach() - file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake" "${__toolchain_config}" ) - unset( __toolchain_config ) -endif() - - -# force cmake to produce / instead of \ in build commands for Ninja generator -if( CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_HOST_WIN32 ) - # it is a bad hack after all - # CMake generates Ninja makefiles with UNIX paths only if it thinks that we are going to build with MinGW - set( CMAKE_COMPILER_IS_MINGW TRUE ) # tell CMake that we are MinGW - set( CMAKE_CROSSCOMPILING TRUE ) # stop recursion - enable_language( C ) - enable_language( CXX ) - # unset( CMAKE_COMPILER_IS_MINGW ) # can't unset because CMake does not convert back-slashes in response files without it - unset( MINGW ) -endif() - - -# Variables controlling behavior or set by cmake toolchain: -# ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips", "arm64-v8a", "x86_64", "mips64" -# ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14,15,16,17,18,19,21 (depends on NDK version) -# ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none -# ANDROID_FORBID_SYGWIN : ON/OFF -# ANDROID_NO_UNDEFINED : ON/OFF -# ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version) -# ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF -# ANDROID_GOLD_LINKER : ON/OFF -# ANDROID_NOEXECSTACK : ON/OFF -# ANDROID_RELRO : ON/OFF -# ANDROID_FORCE_ARM_BUILD : ON/OFF -# ANDROID_STL_FORCE_FEATURES : ON/OFF -# ANDROID_LIBM_PATH : path to libm.so (set to something like $(TOP)/out/target/product//obj/lib/libm.so) to workaround unresolved `sincos` -# Can be set only at the first run: -# ANDROID_NDK : path to your NDK install -# NDK_CCACHE : path to your ccache executable -# ANDROID_TOOLCHAIN_NAME : the NDK name of compiler toolchain -# ANDROID_NDK_HOST_X64 : try to use x86_64 toolchain (default for x64 host systems) -# ANDROID_NDK_LAYOUT : the inner NDK structure (RELEASE, LINARO, ANDROID) -# LIBRARY_OUTPUT_PATH_ROOT : -# ANDROID_STANDALONE_TOOLCHAIN -# -# Primary read-only variables: -# ANDROID : always TRUE -# ARMEABI : TRUE for arm v6 and older devices -# ARMEABI_V6 : TRUE for arm v6 -# ARMEABI_V7A : TRUE for arm v7a -# ARM64_V8A : TRUE for arm64-v8a -# NEON : TRUE if NEON unit is enabled -# VFPV3 : TRUE if VFP version 3 is enabled -# X86 : TRUE if configured for x86 -# X86_64 : TRUE if configured for x86_64 -# MIPS : TRUE if configured for mips -# MIPS64 : TRUE if configured for mips64 -# BUILD_WITH_ANDROID_NDK : TRUE if NDK is used -# BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used -# ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform -# ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86", "mips", "arm64-v8a", "x86_64", "mips64" depending on ANDROID_ABI -# ANDROID_NDK_RELEASE : from r5 to r10d; set only for NDK -# ANDROID_NDK_RELEASE_NUM : numeric ANDROID_NDK_RELEASE version (1000*major+minor) -# ANDROID_ARCH_NAME : "arm", "x86", "mips", "arm64", "x86_64", "mips64" depending on ANDROID_ABI -# ANDROID_SYSROOT : path to the compiler sysroot -# TOOL_OS_SUFFIX : "" or ".exe" depending on host platform -# ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used -# -# Secondary (less stable) read-only variables: -# ANDROID_COMPILER_VERSION : GCC version used (not Clang version) -# ANDROID_CLANG_VERSION : version of clang compiler if clang is used -# ANDROID_CXX_FLAGS : C/C++ compiler flags required by Android platform -# ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI -# ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux" -# ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK) -# ANDROID_CLANG_TOOLCHAIN_ROOT : path to clang tools -# ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK -# ANDROID_STL_INCLUDE_DIRS : stl include paths -# ANDROID_RTTI : if rtti is enabled by the runtime -# ANDROID_EXCEPTIONS : if exceptions are enabled by the runtime -# ANDROID_GCC_TOOLCHAIN_NAME : read-only, differs from ANDROID_TOOLCHAIN_NAME only if clang is used -# -# Defaults: -# ANDROID_DEFAULT_NDK_API_LEVEL -# ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH} -# ANDROID_NDK_SEARCH_PATHS -# ANDROID_SUPPORTED_ABIS_${ARCH} -# ANDROID_SUPPORTED_NDK_VERSIONS diff --git a/unity/native_src_il2cpp/cmake/android.windows.toolchain.cmake b/unity/native_src_il2cpp/cmake/android.windows.toolchain.cmake deleted file mode 100644 index df8299f556..0000000000 --- a/unity/native_src_il2cpp/cmake/android.windows.toolchain.cmake +++ /dev/null @@ -1,607 +0,0 @@ -cmake_minimum_required(VERSION 3.6) - -macro(Highlight_Error error_msg) - message("==================") - message("Error: ${error_msg}") - message("==================") - message(FATAL_ERROR "") -endmacro() - -if(NOT DEFINED ENV{ANDROID_NDK}) - Highlight_Error("not defined environment variable %ANDROID_NDK%") -else() - set(ANDROID_NDK $ENV{ANDROID_NDK}) -endif() -file(TO_CMAKE_PATH "${ANDROID_NDK}" ANDROID_NDK) - -if(ANDROID_TOOLCHAIN_NAME AND NOT ANDROID_TOOLCHAIN) - if(ANDROID_TOOLCHAIN_NAME MATCHES "-clang([0-9].[0-9])?$") - set(ANDROID_TOOLCHAIN clang) - elseif(ANDROID_TOOLCHAIN_NAME MATCHES "-[0-9].[0-9]$") - set(ANDROID_TOOLCHAIN gcc) - endif() -endif() - -if(ANDROID_ABI STREQUAL "armeabi-v7a with NEON") - set(ANDROID_ABI armeabi-v7a) - set(ANDROID_ARM_NEON TRUE) -elseif(ANDROID_TOOLCHAIN_NAME AND NOT ANDROID_ABI) - if(ANDROID_TOOLCHAIN_NAME MATCHES "^arm-linux-androideabi-") - set(ANDROID_ABI armeabi-v7a) - elseif(ANDROID_TOOLCHAIN_NAME MATCHES "^aarch64-linux-android-") - set(ANDROID_ABI arm64-v8a) - elseif(ANDROID_TOOLCHAIN_NAME MATCHES "^x86-") - set(ANDROID_ABI x86) - elseif(ANDROID_TOOLCHAIN_NAME MATCHES "^x86_64-") - set(ANDROID_ABI x86_64) - elseif(ANDROID_TOOLCHAIN_NAME MATCHES "^mipsel-linux-android-") - set(ANDROID_ABI mips) - elseif(ANDROID_TOOLCHAIN_NAME MATCHES "^mips64el-linux-android-") - set(ANDROID_ABI mips64) - endif() -endif() -if(ANDROID_NATIVE_API_LEVEL AND NOT ANDROID_PLATFORM) - if(ANDROID_NATIVE_API_LEVEL MATCHES "^android-[0-9]+$") - set(ANDROID_PLATFORM ${ANDROID_NATIVE_API_LEVEL}) - elseif(ANDROID_NATIVE_API_LEVEL MATCHES "^[0-9]+$") - set(ANDROID_PLATFORM android-${ANDROID_NATIVE_API_LEVEL}) - endif() -endif() -if(DEFINED ANDROID_APP_PIE AND NOT DEFINED ANDROID_PIE) - set(ANDROID_PIE "${ANDROID_APP_PIE}") -endif() -if(ANDROID_STL_FORCE_FEATURES AND NOT DEFINED ANDROID_CPP_FEATURES) - set(ANDROID_CPP_FEATURES "rtti exceptions") -endif() -if(DEFINED ANDROID_NO_UNDEFINED AND NOT DEFINED ANDROID_ALLOW_UNDEFINED_SYMBOLS) - if(ANDROID_NO_UNDEFINED) - set(ANDROID_ALLOW_UNDEFINED_SYMBOLS FALSE) - else() - set(ANDROID_ALLOW_UNDEFINED_SYMBOLS TRUE) - endif() -endif() -if(DEFINED ANDROID_SO_UNDEFINED AND NOT DEFINED ANDROID_ALLOW_UNDEFINED_SYMBOLS) - set(ANDROID_ALLOW_UNDEFINED_SYMBOLS "${ANDROID_SO_UNDEFINED}") -endif() -if(DEFINED ANDROID_FORCE_ARM_BUILD AND NOT ANDROID_ARM_MODE) - if(ANDROID_FORCE_ARM_BUILD) - set(ANDROID_ARM_MODE arm) - else() - set(ANDROID_ARM_MODE thumb) - endif() -endif() -if(DEFINED ANDROID_NOEXECSTACK AND NOT DEFINED ANDROID_DISABLE_NO_EXECUTE) - if(ANDROID_NOEXECSTACK) - set(ANDROID_DISABLE_NO_EXECUTE FALSE) - else() - set(ANDROID_DISABLE_NO_EXECUTE TRUE) - endif() -endif() -if(DEFINED ANDROID_RELRO AND NOT DEFINED ANDROID_DISABLE_RELRO) - if(ANDROID_RELRO) - set(ANDROID_DISABLE_RELRO FALSE) - else() - set(ANDROID_DISABLE_RELRO TRUE) - endif() -endif() -if(NDK_CCACHE AND NOT ANDROID_CCACHE) - set(ANDROID_CCACHE "${NDK_CCACHE}") -endif() - -# Default values for configurable variables. -if(NOT ANDROID_TOOLCHAIN) - set(ANDROID_TOOLCHAIN clang) -endif() -if(NOT ANDROID_ABI) - set(ANDROID_ABI armeabi-v7a) -endif() -if(ANDROID_PLATFORM MATCHES "^android-([0-8]|10|11)$") - set(ANDROID_PLATFORM android-9) -elseif(ANDROID_PLATFORM STREQUAL android-20) - set(ANDROID_PLATFORM android-19) -elseif(NOT ANDROID_PLATFORM) - set(ANDROID_PLATFORM android-9) -endif() -string(REPLACE "android-" "" ANDROID_PLATFORM_LEVEL ${ANDROID_PLATFORM}) -if(ANDROID_ABI MATCHES "64(-v8a)?$" AND ANDROID_PLATFORM_LEVEL LESS 21) - set(ANDROID_PLATFORM android-21) - set(ANDROID_PLATFORM_LEVEL 21) -endif() -if(NOT ANDROID_STL) - set(ANDROID_STL gnustl_static) -endif() -if(NOT DEFINED ANDROID_PIE) - if(ANDROID_PLATFORM_LEVEL LESS 16) - set(ANDROID_PIE FALSE) - else() - set(ANDROID_PIE TRUE) - endif() -endif() -if(NOT ANDROID_ARM_MODE) - set(ANDROID_ARM_MODE thumb) -endif() - -# Export configurable variables for the try_compile() command. -set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES - ANDROID_TOOLCHAIN - ANDROID_ABI - ANDROID_PLATFORM - ANDROID_STL - ANDROID_PIE - ANDROID_CPP_FEATURES - ANDROID_ALLOW_UNDEFINED_SYMBOLS - ANDROID_ARM_MODE - ANDROID_ARM_NEON - ANDROID_DISABLE_NO_EXECUTE - ANDROID_DISABLE_RELRO - ANDROID_DISABLE_FORMAT_STRING_CHECKS - ANDROID_CCACHE) - -# Standard cross-compiling stuff. -set(ANDROID TRUE) -set(CMAKE_SYSTEM_NAME Android) -set(CMAKE_SYSTEM_VERSION ${ANDROID_PLATFORM_LEVEL}) -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) - -# ABI. -set(CMAKE_ANDROID_ARCH_ABI ${ANDROID_ABI}) -if(ANDROID_ABI MATCHES "^armeabi(-v7a)?$") - set(ANDROID_SYSROOT_ABI arm) - set(ANDROID_TOOLCHAIN_NAME arm-linux-androideabi) - set(ANDROID_TOOLCHAIN_ROOT ${ANDROID_TOOLCHAIN_NAME}) - if(ANDROID_ABI STREQUAL armeabi) - set(CMAKE_SYSTEM_PROCESSOR armv5te) - set(ANDROID_LLVM_TRIPLE armv5te-none-linux-androideabi) - elseif(ANDROID_ABI STREQUAL armeabi-v7a) - set(CMAKE_SYSTEM_PROCESSOR armv7-a) - set(ANDROID_LLVM_TRIPLE armv7-none-linux-androideabi) - endif() -elseif(ANDROID_ABI STREQUAL arm64-v8a) - set(ANDROID_SYSROOT_ABI arm64) - set(CMAKE_SYSTEM_PROCESSOR aarch64) - set(ANDROID_TOOLCHAIN_NAME aarch64-linux-android) - set(ANDROID_TOOLCHAIN_ROOT ${ANDROID_TOOLCHAIN_NAME}) - set(ANDROID_LLVM_TRIPLE aarch64-none-linux-android) -elseif(ANDROID_ABI STREQUAL x86) - set(ANDROID_SYSROOT_ABI x86) - set(CMAKE_SYSTEM_PROCESSOR i686) - set(ANDROID_TOOLCHAIN_NAME i686-linux-android) - set(ANDROID_TOOLCHAIN_ROOT ${ANDROID_ABI}) - set(ANDROID_LLVM_TRIPLE i686-none-linux-android) -elseif(ANDROID_ABI STREQUAL x86_64) - set(ANDROID_SYSROOT_ABI x86_64) - set(CMAKE_SYSTEM_PROCESSOR x86_64) - set(ANDROID_TOOLCHAIN_NAME x86_64-linux-android) - set(ANDROID_TOOLCHAIN_ROOT ${ANDROID_ABI}) - set(ANDROID_LLVM_TRIPLE x86_64-none-linux-android) -elseif(ANDROID_ABI STREQUAL mips) - set(ANDROID_SYSROOT_ABI mips) - set(CMAKE_SYSTEM_PROCESSOR mips) - set(ANDROID_TOOLCHAIN_NAME mipsel-linux-android) - set(ANDROID_TOOLCHAIN_ROOT ${ANDROID_TOOLCHAIN_NAME}) - set(ANDROID_LLVM_TRIPLE mipsel-none-linux-android) -elseif(ANDROID_ABI STREQUAL mips64) - set(ANDROID_SYSROOT_ABI mips64) - set(CMAKE_SYSTEM_PROCESSOR mips64) - set(ANDROID_TOOLCHAIN_NAME mips64el-linux-android) - set(ANDROID_TOOLCHAIN_ROOT ${ANDROID_TOOLCHAIN_NAME}) - set(ANDROID_LLVM_TRIPLE mips64el-none-linux-android) -else() - message(FATAL_ERROR "Invalid Android ABI: ${ANDROID_ABI}.") -endif() - -# STL. -set(ANDROID_STL_STATIC_LIBRARIES) -set(ANDROID_STL_SHARED_LIBRARIES) -if(ANDROID_STL STREQUAL system) - set(ANDROID_STL_STATIC_LIBRARIES - supc++) -elseif(ANDROID_STL STREQUAL stlport_static) - set(ANDROID_STL_STATIC_LIBRARIES - stlport_static) -elseif(ANDROID_STL STREQUAL stlport_shared) - set(ANDROID_STL_SHARED_LIBRARIES - stlport_shared) -elseif(ANDROID_STL STREQUAL gnustl_static) - set(ANDROID_STL_STATIC_LIBRARIES - gnustl_static) -elseif(ANDROID_STL STREQUAL gnustl_shared) - set(ANDROID_STL_STATIC_LIBRARIES - supc++) - set(ANDROID_STL_SHARED_LIBRARIES - gnustl_shared) -elseif(ANDROID_STL STREQUAL c++_static) - set(ANDROID_STL_STATIC_LIBRARIES - c++_static - c++abi - unwind - android_support) -elseif(ANDROID_STL STREQUAL c++_shared) - set(ANDROID_STL_STATIC_LIBRARIES - unwind) - set(ANDROID_STL_SHARED_LIBRARIES - c++_shared) -elseif(ANDROID_STL STREQUAL none) -else() - message(FATAL_ERROR "Invalid Android STL: ${ANDROID_STL}.") -endif() - -# Sysroot. -set(CMAKE_SYSROOT "${ANDROID_NDK}/platforms/${ANDROID_PLATFORM}/arch-${ANDROID_SYSROOT_ABI}") - -# Toolchain. -if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) - set(ANDROID_HOST_TAG linux-x86_64) -elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) - set(ANDROID_HOST_TAG darwin-x86_64) -elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) - set(ANDROID_HOST_TAG windows-x86_64) -endif() -set(ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_ROOT}-4.9/prebuilt/${ANDROID_HOST_TAG}") -set(ANDROID_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-") -if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) - set(ANDROID_TOOLCHAIN_SUFFIX .exe) -endif() -if(ANDROID_TOOLCHAIN STREQUAL clang) - set(ANDROID_LLVM_TOOLCHAIN_PREFIX "${ANDROID_NDK}/toolchains/llvm-3.6/prebuilt/${ANDROID_HOST_TAG}/bin/") - set(ANDROID_C_COMPILER "${ANDROID_LLVM_TOOLCHAIN_PREFIX}clang${ANDROID_TOOLCHAIN_SUFFIX}") - set(ANDROID_CXX_COMPILER "${ANDROID_LLVM_TOOLCHAIN_PREFIX}clang++${ANDROID_TOOLCHAIN_SUFFIX}") - # Clang can fail to compile if CMake doesn't correctly supply the target and - # external toolchain, but to do so, CMake needs to already know that the - # compiler is clang. Tell CMake that the compiler is really clang, but don't - # use CMakeForceCompiler, since we still want compile checks. We only want - # to skip the compiler ID detection step. - set(CMAKE_C_COMPILER_ID_RUN TRUE) - set(CMAKE_CXX_COMPILER_ID_RUN TRUE) - set(CMAKE_C_COMPILER_ID Clang) - set(CMAKE_CXX_COMPILER_ID Clang) - set(CMAKE_C_COMPILER_TARGET ${ANDROID_LLVM_TRIPLE}) - set(CMAKE_CXX_COMPILER_TARGET ${ANDROID_LLVM_TRIPLE}) - set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN "${ANDROID_TOOLCHAIN_ROOT}") - set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${ANDROID_TOOLCHAIN_ROOT}") -elseif(ANDROID_TOOLCHAIN STREQUAL gcc) - set(ANDROID_C_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}gcc${ANDROID_TOOLCHAIN_SUFFIX}") - set(ANDROID_CXX_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}g++${ANDROID_TOOLCHAIN_SUFFIX}") -else() - message(FATAL_ERROR "Invalid Android toolchain: ${ANDROID_TOOLCHAIN}.") -endif() - -if(NOT IS_DIRECTORY "${ANDROID_NDK}/platforms/${ANDROID_PLATFORM}") - message("${ANDROID_NDK}/platforms/${ANDROID_PLATFORM}") - message(FATAL_ERROR "Invalid Android platform: ${ANDROID_PLATFORM}.") -elseif(NOT IS_DIRECTORY "${CMAKE_SYSROOT}") - message(FATAL_ERROR "Invalid Android sysroot: ${CMAKE_SYSROOT}.") -endif() - -set(ANDROID_COMPILER_FLAGS) -set(ANDROID_COMPILER_FLAGS_CXX) -set(ANDROID_COMPILER_FLAGS_DEBUG) -set(ANDROID_COMPILER_FLAGS_RELEASE) -set(ANDROID_LINKER_FLAGS) -set(ANDROID_LINKER_FLAGS_EXE) - -# Generic flags. -list(APPEND ANDROID_COMPILER_FLAGS - -g - -DANDROID - -ffunction-sections - -funwind-tables - -fstack-protector-strong - -no-canonical-prefixes) -list(APPEND ANDROID_COMPILER_FLAGS_CXX - -fno-exceptions - -fno-rtti) -list(APPEND ANDROID_LINKER_FLAGS - -Wl,--build-id - -Wl,--warn-shared-textrel - -Wl,--fatal-warnings) -list(APPEND ANDROID_LINKER_FLAGS_EXE - -Wl,--gc-sections - -Wl,-z,nocopyreloc) - -# Debug and release flags. -list(APPEND ANDROID_COMPILER_FLAGS_DEBUG - -O0) -if(ANDROID_ABI MATCHES "^armeabi") - list(APPEND ANDROID_COMPILER_FLAGS_RELEASE - -Os) -else() - list(APPEND ANDROID_COMPILER_FLAGS_RELEASE - -O2) -endif() -list(APPEND ANDROID_COMPILER_FLAGS_RELEASE - -DNDEBUG) -if(ANDROID_TOOLCHAIN STREQUAL clang) - list(APPEND ANDROID_COMPILER_FLAGS_DEBUG - -fno-limit-debug-info) -endif() - -# Toolchain and ABI specific flags. -if(ANDROID_ABI STREQUAL armeabi) - list(APPEND ANDROID_COMPILER_FLAGS - -march=armv5te - -mtune=xscale - -msoft-float) -endif() -if(ANDROID_ABI STREQUAL armeabi-v7a) - list(APPEND ANDROID_COMPILER_FLAGS - -march=armv7-a - -mfloat-abi=softfp - -mfpu=vfpv3-d16) - list(APPEND ANDROID_LINKER_FLAGS - -Wl,--fix-cortex-a8) -endif() -if(ANDROID_ABI MATCHES "^armeabi" AND ANDROID_TOOLCHAIN STREQUAL clang) - # Disable integrated-as for better compatibility. - list(APPEND ANDROID_COMPILER_FLAGS - -fno-integrated-as) -endif() -if(ANDROID_ABI STREQUAL mips AND ANDROID_TOOLCHAIN STREQUAL clang) - list(APPEND ANDROID_COMPILER_FLAGS - -mips32) -endif() - -# STL specific flags. -if(ANDROID_STL STREQUAL system) - set(ANDROID_STL_PREFIX gnu-libstdc++/4.9) - set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES - "${ANDROID_NDK}/sources/cxx-stl/system/include") -elseif(ANDROID_STL MATCHES "^stlport_") - set(ANDROID_STL_PREFIX stlport) - set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES - "${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/stlport" - "${ANDROID_NDK}/sources/cxx-stl/gabi++/include") -elseif(ANDROID_STL MATCHES "^gnustl_") - set(ANDROID_STL_PREFIX gnu-libstdc++/4.9) - set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES - "${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/include" - "${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/include" - "${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/include/backward") -elseif(ANDROID_STL MATCHES "^c\\+\\+_") - set(ANDROID_STL_PREFIX llvm-libc++) - if(ANDROID_ABI MATCHES "^armeabi") - list(APPEND ANDROID_LINKER_FLAGS - -Wl,--exclude-libs,libunwind.a) - else() - list(REMOVE_ITEM ANDROID_STL_STATIC_LIBRARIES - unwind) - endif() - list(APPEND ANDROID_COMPILER_FLAGS_CXX - -std=c++11) - if(ANDROID_TOOLCHAIN STREQUAL gcc) - list(APPEND ANDROID_COMPILER_FLAGS_CXX - -fno-strict-aliasing) - endif() - set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES - "${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/include" - "${ANDROID_NDK}/sources/android/support/include" - "${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}abi/include") -endif() -set(ANDROID_CXX_STANDARD_LIBRARIES) -foreach(library ${ANDROID_STL_STATIC_LIBRARIES}) - list(APPEND ANDROID_CXX_STANDARD_LIBRARIES - "${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/lib${library}.a") -endforeach() -foreach(library ${ANDROID_STL_SHARED_LIBRARIES}) - list(APPEND ANDROID_CXX_STANDARD_LIBRARIES - "${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/lib${library}.so") -endforeach() -if(ANDROID_ABI STREQUAL armeabi AND NOT ANDROID_STL MATCHES "^(none|system)$") - list(APPEND ANDROID_CXX_STANDARD_LIBRARIES - -latomic) -endif() -set(CMAKE_C_STANDARD_LIBRARIES_INIT "-lm") -set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}") -if(ANDROID_CXX_STANDARD_LIBRARIES) - string(REPLACE ";" "\" \"" ANDROID_CXX_STANDARD_LIBRARIES "\"${ANDROID_CXX_STANDARD_LIBRARIES}\"") - set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_CXX_STANDARD_LIBRARIES_INIT} ${ANDROID_CXX_STANDARD_LIBRARIES}") -endif() - -# Configuration specific flags. -if(ANDROID_PIE) - set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) - list(APPEND ANDROID_LINKER_FLAGS_EXE - -pie - -fPIE) -endif() -if(ANDROID_CPP_FEATURES) - separate_arguments(ANDROID_CPP_FEATURES) - foreach(feature ${ANDROID_CPP_FEATURES}) - if(NOT ${feature} MATCHES "^(rtti|exceptions)$") - message(FATAL_ERROR "Invalid Android C++ feature: ${feature}.") - endif() - list(APPEND ANDROID_COMPILER_FLAGS_CXX - -f${feature}) - endforeach() - string(REPLACE ";" " " ANDROID_CPP_FEATURES "${ANDROID_CPP_FEATURES}") -endif() -if(NOT ANDROID_ALLOW_UNDEFINED_SYMBOLS) - list(APPEND ANDROID_LINKER_FLAGS - -Wl,--no-undefined) -endif() -if(ANDROID_ABI MATCHES "armeabi") - if(ANDROID_ARM_MODE STREQUAL thumb) - list(APPEND ANDROID_COMPILER_FLAGS - -mthumb) - elseif(ANDROID_ARM_MODE STREQUAL arm) - list(APPEND ANDROID_COMPILER_FLAGS - -marm) - else() - message(FATAL_ERROR "Invalid Android ARM mode: ${ANDROID_ARM_MODE}.") - endif() - if(ANDROID_ABI STREQUAL armeabi-v7a AND ANDROID_ARM_NEON) - list(APPEND ANDROID_COMPILER_FLAGS - -mfpu=neon) - endif() -endif() -if(ANDROID_DISABLE_NO_EXECUTE) - list(APPEND ANDROID_COMPILER_FLAGS - -Wa,--execstack) - list(APPEND ANDROID_LINKER_FLAGS - -Wl,-z,execstack) -else() - list(APPEND ANDROID_COMPILER_FLAGS - -Wa,--noexecstack) - list(APPEND ANDROID_LINKER_FLAGS - -Wl,-z,noexecstack) -endif() -if(ANDROID_TOOLCHAIN STREQUAL clang) - # CMake automatically forwards all compiler flags to the linker, - # and clang doesn't like having -Wa flags being used for linking. - # To prevent CMake from doing this would require meddling with - # the CMAKE__COMPILE_OBJECT rules, which would get quite messy. - list(APPEND ANDROID_LINKER_FLAGS - -Qunused-arguments) -endif() -if(ANDROID_DISABLE_RELRO) - list(APPEND ANDROID_LINKER_FLAGS - -Wl,-z,norelro -Wl,-z,lazy) -else() - list(APPEND ANDROID_LINKER_FLAGS - -Wl,-z,relro -Wl,-z,now) -endif() -if(ANDROID_DISABLE_FORMAT_STRING_CHECKS) - list(APPEND ANDROID_COMPILER_FLAGS - -Wno-error=format-security) -else() - list(APPEND ANDROID_COMPILER_FLAGS - -Wformat -Werror=format-security) -endif() - -# Convert these lists into strings. -string(REPLACE ";" " " ANDROID_COMPILER_FLAGS "${ANDROID_COMPILER_FLAGS}") -string(REPLACE ";" " " ANDROID_COMPILER_FLAGS_CXX "${ANDROID_COMPILER_FLAGS_CXX}") -string(REPLACE ";" " " ANDROID_COMPILER_FLAGS_DEBUG "${ANDROID_COMPILER_FLAGS_DEBUG}") -string(REPLACE ";" " " ANDROID_COMPILER_FLAGS_RELEASE "${ANDROID_COMPILER_FLAGS_RELEASE}") -string(REPLACE ";" " " ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}") -string(REPLACE ";" " " ANDROID_LINKER_FLAGS_EXE "${ANDROID_LINKER_FLAGS_EXE}") - -if(ANDROID_CCACHE) - set(CMAKE_C_COMPILER_LAUNCHER "${ANDROID_CCACHE}") - set(CMAKE_CXX_COMPILER_LAUNCHER "${ANDROID_CCACHE}") -endif() -set(CMAKE_C_COMPILER "${ANDROID_C_COMPILER}") -set(CMAKE_CXX_COMPILER "${ANDROID_CXX_COMPILER}") -set(_CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_PREFIX}") - -# Set or retrieve the cached flags. -# This is necessary in case the user sets/changes flags in subsequent -# configures. If we included the Android flags in here, they would get -# overwritten. -set(CMAKE_C_FLAGS "" - CACHE STRING "Flags used by the compiler during all build types.") -set(CMAKE_CXX_FLAGS "" - CACHE STRING "Flags used by the compiler during all build types.") -set(CMAKE_C_FLAGS_DEBUG "" - CACHE STRING "Flags used by the compiler during debug builds.") -set(CMAKE_CXX_FLAGS_DEBUG "" - CACHE STRING "Flags used by the compiler during debug builds.") -set(CMAKE_C_FLAGS_RELEASE "" - CACHE STRING "Flags used by the compiler during release builds.") -set(CMAKE_CXX_FLAGS_RELEASE "" - CACHE STRING "Flags used by the compiler during release builds.") -set(CMAKE_MODULE_LINKER_FLAGS "" - CACHE STRING "Flags used by the linker during the creation of modules.") -set(CMAKE_SHARED_LINKER_FLAGS "" - CACHE STRING "Flags used by the linker during the creation of dll's.") -set(CMAKE_EXE_LINKER_FLAGS "" - CACHE STRING "Flags used by the linker.") - -set(CMAKE_C_FLAGS "${ANDROID_COMPILER_FLAGS} ${CMAKE_C_FLAGS}") -set(CMAKE_CXX_FLAGS "${ANDROID_COMPILER_FLAGS} ${ANDROID_COMPILER_FLAGS_CXX} ${CMAKE_CXX_FLAGS}") -set(CMAKE_C_FLAGS_DEBUG "${ANDROID_COMPILER_FLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}") -set(CMAKE_CXX_FLAGS_DEBUG "${ANDROID_COMPILER_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}") -set(CMAKE_C_FLAGS_RELEASE "${ANDROID_COMPILER_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}") -set(CMAKE_CXX_FLAGS_RELEASE "${ANDROID_COMPILER_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}") -set(CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}") -set(CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}") -set(CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${ANDROID_LINKER_FLAGS_EXE} ${CMAKE_EXE_LINKER_FLAGS}") - -if(CMAKE_C_FLAGS) - message("CMAKE_C_FLAGS = ${CMAKE_C_FlAGS}") -endif() -if(CMAKE_CXX_FLAGS) - message("CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}") -endif() -if(CMAKE_C_FLAGS_DEBUG) - message("CMAKE_C_FLAGS_DEBUG = ${CMAKE_C_FLAGS_DEBUG}") -endif() -if(CMAKE_CXX_FLAGS_DEBUG) - message("CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}") -endif() -if(CMAKE_SHARED_LINKER_FLAGS) - message("CMAKE_SHARED_LINKDER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}") -endif() -if(CMAKE_MODULE_LINKER_FLAGS) - message("CMAKE_MODULE_LINKER_FLAGS = ${CMAKE_MODULE_LINKER_FLAGS}") -endif() -if(CMAKE_EXE_LINKER_FLAGS) - message("CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}") -endif() - -# Compatibility for read-only variables. -# Read-only variables for compatibility with the other toolchain file. -# We'll keep these around for the existing projects that still use them. -# TODO: All of the variables here have equivalents in our standard set of -# configurable variables, so we can remove these once most of our users migrate -# to those variables. -set(ANDROID_NATIVE_API_LEVEL ${ANDROID_PLATFORM_LEVEL}) -if(ANDROID_ALLOW_UNDEFINED_SYMBOLS) - set(ANDROID_SO_UNDEFINED TRUE) -else() - set(ANDROID_NO_UNDEFINED TRUE) -endif() -set(ANDROID_FUNCTION_LEVEL_LINKING TRUE) -set(ANDROID_GOLD_LINKER TRUE) -if(NOT ANDROID_DISABLE_NO_EXECUTE) - set(ANDROID_NOEXECSTACK TRUE) -endif() -if(NOT ANDROID_DISABLE_RELRO) - set(ANDROID_RELRO TRUE) -endif() -if(ANDROID_ARM_MODE STREQUAL arm) - set(ANDROID_FORCE_ARM_BUILD TRUE) -endif() -if(ANDROID_CPP_FEATURES MATCHES "rtti" - AND ANDROID_CPP_FEATURES MATCHES "exceptions") - set(ANDROID_STL_FORCE_FEATURES TRUE) -endif() -if(ANDROID_CCACHE) - set(NDK_CCACHE "${ANDROID_CCACHE}") -endif() -if(ANDROID_TOOLCHAIN STREQUAL clang) - set(ANDROID_TOOLCHAIN_NAME ${ANDROID_TOOLCHAIN_NAME}-clang) -else() - set(ANDROID_TOOLCHAIN_NAME ${ANDROID_TOOLCHAIN_NAME}-4.9) -endif() -set(ANDROID_NDK_HOST_X64 TRUE) -set(ANDROID_NDK_LAYOUT RELEASE) -if(ANDROID_ABI STREQUAL armeabi) - set(ARMEABI TRUE) -elseif(ANDROID_ABI STREQUAL armeabi-v7a) - set(ARMEABI_V7A TRUE) - if(ANDROID_ARM_NEON) - set(NEON TRUE) - endif() -elseif(ANDROID_ABI STREQUAL arm64-v8a) - set(ARM64_V8A TRUE) -elseif(ANDROID_ABI STREQUAL x86) - set(X86 TRUE) -elseif(ANDROID_ABI STREQUAL x86_64) - set(X86_64 TRUE) -elseif(ANDROID_ABI STREQUAL mips) - set(MIPS TRUE) -elseif(ANDROID_ABI STREQUAL MIPS64) - set(MIPS64 TRUE) -endif() -set(ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_HOST_TAG}) -set(ANDROID_NDK_ABI_NAME ${ANDROID_ABI}) -set(ANDROID_ARCH_NAME ${ANDROID_SYSROOT_ABI}) -set(ANDROID_SYSROOT "${CMAKE_SYSROOT}") -set(TOOL_OS_SUFFIX ${ANDROID_TOOLCHAIN_SUFFIX}) -if(ANDROID_TOOLCHAIN STREQUAL clang) - set(ANDROID_COMPILER_IS_CLANG TRUE) -endif() diff --git a/unity/native_src_il2cpp/cmake/iOS.cmake b/unity/native_src_il2cpp/cmake/iOS.cmake deleted file mode 100644 index d0a6c40732..0000000000 --- a/unity/native_src_il2cpp/cmake/iOS.cmake +++ /dev/null @@ -1,213 +0,0 @@ -# This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake -# files which are included with CMake 2.8.4 -# It has been altered for iOS development - -# Options: -# -# IOS_PLATFORM = OS (default) or SIMULATOR -# This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders -# OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch. -# SIMULATOR - used to build for the Simulator platforms, which have an x86 arch. -# -# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder -# By default this location is automatcially chosen based on the IOS_PLATFORM value above. -# If set manually, it will override the default location and force the user of a particular Developer Platform -# -# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder -# By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value. -# In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path. -# If set manually, this will force the use of a specific SDK version - -# Macros: -# -# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE) -# A convenience macro for setting xcode specific properties on targets -# example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1") -# -# find_host_package (PROGRAM ARGS) -# A macro used to find executable programs on the host system, not within the iOS environment. -# Thanks to the android-cmake project for providing the command - -# Standard settings -set (CMAKE_SYSTEM_NAME Darwin) -set (CMAKE_SYSTEM_VERSION 1) -set (UNIX True) -set (APPLE True) -set (IOS True) - -# Required as of cmake 2.8.10 -set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE) - -# Determine the cmake host system version so we know where to find the iOS SDKs -find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin) -if (CMAKE_UNAME) - exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION) - string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}") -endif (CMAKE_UNAME) - -# Force the compilers to gcc for iOS -#include (CMakeForceCompiler) -#CMAKE_FORCE_C_COMPILER (/usr/bin/clang Apple) -#CMAKE_FORCE_CXX_COMPILER (/usr/bin/clang++ Apple) -#set(CMAKE_AR ar CACHE FILEPATH "" FORCE) - -# Skip the platform compiler checks for cross compiling -set (CMAKE_CXX_COMPILER_WORKS TRUE) -set (CMAKE_C_COMPILER_WORKS TRUE) - -# All iOS/Darwin specific settings - some may be redundant -set (CMAKE_SHARED_LIBRARY_PREFIX "lib") -set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib") -set (CMAKE_SHARED_MODULE_PREFIX "lib") -set (CMAKE_SHARED_MODULE_SUFFIX ".so") -set (CMAKE_MODULE_EXISTS 1) -set (CMAKE_DL_LIBS "") - -set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ") -set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ") -set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") -set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") - -# Hidden visibilty is required for cxx on iOS -set (CMAKE_C_FLAGS_INIT "") -set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden -isysroot ${CMAKE_OSX_SYSROOT}") - -set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") -set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") - -set (CMAKE_PLATFORM_HAS_INSTALLNAME 1) -set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names") -set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names") -set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,") -set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,") -set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a") - -# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree -# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache -# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun) -# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex -if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) - find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool) -endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) - -# Setup iOS platform unless specified manually with IOS_PLATFORM -if (NOT DEFINED IOS_PLATFORM) - set (IOS_PLATFORM "OS") -endif (NOT DEFINED IOS_PLATFORM) -set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform") - -# Check the platform selection and setup for developer root -if (${IOS_PLATFORM} STREQUAL "OS") - set (IOS_PLATFORM_LOCATION "iPhoneOS.platform") - - # This causes the installers to properly locate the output libraries - set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos") -elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") - set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") - - # This causes the installers to properly locate the output libraries - set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") -else (${IOS_PLATFORM} STREQUAL "OS") - message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR") -endif (${IOS_PLATFORM} STREQUAL "OS") - -# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT -# Note Xcode 4.3 changed the installation location, choose the most recent one available -set (XCODE_POST_43_ROOT "/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") -set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") -if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) - if (EXISTS ${XCODE_POST_43_ROOT}) - set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT}) - elseif(EXISTS ${XCODE_PRE_43_ROOT}) - set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT}) - endif (EXISTS ${XCODE_POST_43_ROOT}) -endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) -set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform") - -# Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT -if (NOT DEFINED CMAKE_IOS_SDK_ROOT) - file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*") - if (_CMAKE_IOS_SDKS) - list (SORT _CMAKE_IOS_SDKS) - list (REVERSE _CMAKE_IOS_SDKS) - list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT) - else (_CMAKE_IOS_SDKS) - message (FATAL_ERROR "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.") - endif (_CMAKE_IOS_SDKS) - message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}") -endif (NOT DEFINED CMAKE_IOS_SDK_ROOT) -set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK") - -# Set the sysroot default to the most recent SDK -set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support") - -# set the architecture for iOS -# NOTE: Currently both ARCHS_STANDARD_32_BIT and ARCHS_UNIVERSAL_IPHONE_OS set armv7 only, so set both manually -if (${IOS_PLATFORM} STREQUAL "OS") - set (IOS_ARCH armv7) -else (${IOS_PLATFORM} STREQUAL "OS") - set (IOS_ARCH i386) -endif (${IOS_PLATFORM} STREQUAL "OS") - -set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS") - -# Set the find root to the iOS developer roots and to user defined paths -set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root") - -# default to searching for frameworks first -set (CMAKE_FIND_FRAMEWORK FIRST) - -# set up the default search directories for frameworks -set (CMAKE_SYSTEM_FRAMEWORK_PATH - ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks - ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks - ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks -) - -# only search the iOS sdks, not the remainder of the host filesystem -#set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) -#set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -#set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - - -# This little macro lets you set any XCode specific property -macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE) - set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE}) -endmacro (set_xcode_property) - - -# This macro lets you find executable programs on the host system -macro (find_host_package) - set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) - set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) - set (IOS FALSE) - - find_package(${ARGN}) - - set (IOS TRUE) - set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) - set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) - set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -endmacro (find_host_package) - -macro(ADD_FRAMEWORK fwname frameworks) - find_library(FRAMEWORK_${fwname} - NAMES ${fwname} - ) - if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND) - MESSAGE(ERROR ": Framework ${fwname} not found") - else() - list(APPEND ${frameworks} ${FRAMEWORK_${fwname}}) - MESSAGE(STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}") - endif() -endmacro(ADD_FRAMEWORK) - -# http://stackoverflow.com/questions/14171740/cmake-with-ios-toolchain-cant-find-threads -# http://public.kitware.com/Bug/view.php?id=12288 -# Fix for try_compile -SET(CMAKE_MACOSX_BUNDLE YES) -SET(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer") -SET(MACOSX_BUNDLE_GUI_IDENTIFIER "org.racing") -# http://stackoverflow.com/questions/11198878/how-do-you-specify-a-universal-ios-application-when-building-through-cmake -SET(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2") diff --git a/unity/native_src_il2cpp/cmake/ios.toolchain.cmake b/unity/native_src_il2cpp/cmake/ios.toolchain.cmake deleted file mode 100644 index 0e01fe1ee7..0000000000 --- a/unity/native_src_il2cpp/cmake/ios.toolchain.cmake +++ /dev/null @@ -1,672 +0,0 @@ -# This file is part of the ios-cmake project. It was retrieved from -# https://github.com/cristeab/ios-cmake.git, which is a fork of -# https://code.google.com/p/ios-cmake/. Which in turn is based off of -# the Platform/Darwin.cmake and Platform/UnixPaths.cmake files which -# are included with CMake 2.8.4 -# -# The ios-cmake project is licensed under the new BSD license. -# -# Copyright (c) 2014, Bogdan Cristea and LTE Engineering Software, -# Kitware, Inc., Insight Software Consortium. All rights reserved. -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -# This file is based off of the Platform/Darwin.cmake and -# Platform/UnixPaths.cmake files which are included with CMake 2.8.4 -# It has been altered for iOS development. -# -# Updated by Alex Stewart (alexs.mac@gmail.com) -# -# ***************************************************************************** -# Now maintained by Alexander Widerberg (widerbergaren [at] gmail.com) -# under the BSD-3-Clause license -# https://github.com/leetal/ios-cmake -# ***************************************************************************** -# -# INFORMATION / HELP -# -# The following arguments control the behaviour of this toolchain: -# -# PLATFORM: (default "OS") -# OS = Build for iPhoneOS. -# OS64 = Build for arm64 iphoneOS. -# OS64COMBINED = Build for arm64 x86_64 iphoneOS. Combined into FAT STATIC lib (supported on 3.14+ of CMakewith "-G Xcode" argument ONLY) -# SIMULATOR = Build for x86 i386 iphoneOS Simulator. -# SIMULATOR64 = Build for x86_64 iphoneOS Simulator. -# TVOS = Build for arm64 tvOS. -# TVOSCOMBINED = Build for arm64 x86_64 tvOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY) -# SIMULATOR_TVOS = Build for x86_64 tvOS Simulator. -# WATCHOS = Build for armv7k arm64_32 for watchOS. -# WATCHOSCOMBINED = Build for armv7k arm64_32 x86_64 watchOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY) -# SIMULATOR_WATCHOS = Build for x86_64 for watchOS Simulator. -# -# CMAKE_OSX_SYSROOT: Path to the SDK to use. By default this is -# automatically determined from PLATFORM and xcodebuild, but -# can also be manually specified (although this should not be required). -# -# CMAKE_DEVELOPER_ROOT: Path to the Developer directory for the platform -# being compiled for. By default this is automatically determined from -# CMAKE_OSX_SYSROOT, but can also be manually specified (although this should -# not be required). -# -# DEPLOYMENT_TARGET: Minimum SDK version to target. Default 2.0 on watchOS and 9.0 on tvOS+iOS -# -# ENABLE_BITCODE: (1|0) Enables or disables bitcode support. Default 1 (true) -# -# ENABLE_ARC: (1|0) Enables or disables ARC support. Default 1 (true, ARC enabled by default) -# -# ENABLE_VISIBILITY: (1|0) Enables or disables symbol visibility support. Default 0 (false, visibility hidden by default) -# -# ENABLE_STRICT_TRY_COMPILE: (1|0) Enables or disables strict try_compile() on all Check* directives (will run linker -# to actually check if linking is possible). Default 0 (false, will set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY) -# -# ARCHS: (armv7 armv7s armv7k arm64 arm64_32 i386 x86_64) If specified, will override the default architectures for the given PLATFORM -# OS = armv7 armv7s arm64 (if applicable) -# OS64 = arm64 (if applicable) -# SIMULATOR = i386 -# SIMULATOR64 = x86_64 -# TVOS = arm64 -# SIMULATOR_TVOS = x86_64 (i386 has since long been deprecated) -# WATCHOS = armv7k arm64_32 (if applicable) -# SIMULATOR_WATCHOS = x86_64 (i386 has since long been deprecated) -# -# This toolchain defines the following variables for use externally: -# -# XCODE_VERSION: Version number (not including Build version) of Xcode detected. -# SDK_VERSION: Version of SDK being used. -# CMAKE_OSX_ARCHITECTURES: Architectures being compiled for (generated from PLATFORM). -# -# This toolchain defines the following macros for use externally: -# -# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE XCODE_VARIANT) -# A convenience macro for setting xcode specific properties on targets. -# Available variants are: All, Release, RelWithDebInfo, Debug, MinSizeRel -# example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1" "all"). -# -# find_host_package (PROGRAM ARGS) -# A macro used to find executable programs on the host system, not within the -# environment. Thanks to the android-cmake project for providing the -# command. -# -# ******************************** DEPRECATIONS ******************************* -# -# IOS_DEPLOYMENT_TARGET: (Deprecated) Alias to DEPLOYMENT_TARGET -# CMAKE_IOS_DEVELOPER_ROOT: (Deprecated) Alias to CMAKE_DEVELOPER_ROOT -# IOS_PLATFORM: (Deprecated) Alias to PLATFORM -# IOS_ARCH: (Deprecated) Alias to ARCHS -# -# ***************************************************************************** -# - -# Fix for PThread library not in path -set(CMAKE_THREAD_LIBS_INIT "-lpthread") -set(CMAKE_HAVE_THREADS_LIBRARY 1) -set(CMAKE_USE_WIN32_THREADS_INIT 0) -set(CMAKE_USE_PTHREADS_INIT 1) - -# Cache what generator is used -set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE) - -if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14") - set(MODERN_CMAKE YES) - message(STATUS "Merging integrated CMake 3.14+ iOS,tvOS,watchOS,macOS toolchain(s) with this toolchain!") -endif() - -# Get the Xcode version being used. -execute_process(COMMAND xcodebuild -version - OUTPUT_VARIABLE XCODE_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) -string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}") -string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}") -message(STATUS "Building with Xcode version: ${XCODE_VERSION}") - -######## ALIASES (DEPRECATION WARNINGS) - -if(DEFINED IOS_PLATFORM) - set(PLATFORM ${IOS_PLATFORM}) - message(DEPRECATION "IOS_PLATFORM argument is DEPRECATED. Consider using the new PLATFORM argument instead.") -endif() - -if(DEFINED IOS_DEPLOYMENT_TARGET) - set(DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET}) - message(DEPRECATION "IOS_DEPLOYMENT_TARGET argument is DEPRECATED. Consider using the new DEPLOYMENT_TARGET argument instead.") -endif() - -if(DEFINED CMAKE_IOS_DEVELOPER_ROOT) - set(CMAKE_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT}) - message(DEPRECATION "CMAKE_IOS_DEVELOPER_ROOT argument is DEPRECATED. Consider using the new CMAKE_DEVELOPER_ROOT argument instead.") -endif() - -if(DEFINED IOS_ARCH) - set(ARCHS ${IOS_ARCH}) - message(DEPRECATION "IOS_ARCH argument is DEPRECATED. Consider using the new ARCHS argument instead.") -endif() - -######## END ALIASES - -# Unset the FORCE on cache variables if in try_compile() -set(FORCE_CACHE FORCE) -get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) -if(_CMAKE_IN_TRY_COMPILE) - unset(FORCE_CACHE) -endif() - -# Default to building for iPhoneOS if not specified otherwise, and we cannot -# determine the platform from the CMAKE_OSX_ARCHITECTURES variable. The use -# of CMAKE_OSX_ARCHITECTURES is such that try_compile() projects can correctly -# determine the value of PLATFORM from the root project, as -# CMAKE_OSX_ARCHITECTURES is propagated to them by CMake. -if(NOT DEFINED PLATFORM) - if (CMAKE_OSX_ARCHITECTURES) - if(CMAKE_OSX_ARCHITECTURES MATCHES ".*arm.*" AND CMAKE_OSX_SYSROOT MATCHES ".*iphoneos.*") - set(PLATFORM "OS") - elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*") - set(PLATFORM "SIMULATOR") - elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*") - set(PLATFORM "SIMULATOR64") - elseif(CMAKE_OSX_ARCHITECTURES MATCHES "arm64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvos.*") - set(PLATFORM "TVOS") - elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvsimulator.*") - set(PLATFORM "SIMULATOR_TVOS") - elseif(CMAKE_OSX_ARCHITECTURES MATCHES ".*armv7k.*" AND CMAKE_OSX_SYSROOT MATCHES ".*watchos.*") - set(PLATFORM "WATCHOS") - elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*watchsimulator.*") - set(PLATFORM "SIMULATOR_WATCHOS") - endif() - endif() - if (NOT PLATFORM) - set(PLATFORM "OS") - endif() -endif() - -set(PLATFORM_INT "${PLATFORM}" CACHE STRING "Type of platform for which the build targets.") - -# Handle the case where we are targeting iOS and a version above 10.3.4 (32-bit support dropped officially) -if(PLATFORM_INT STREQUAL "OS" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4) - set(PLATFORM_INT "OS64") - message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.") -elseif(PLATFORM_INT STREQUAL "SIMULATOR" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4) - set(PLATFORM_INT "SIMULATOR64") - message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.") -endif() - -# Determine the platform name and architectures for use in xcodebuild commands -# from the specified PLATFORM name. -if(PLATFORM_INT STREQUAL "OS") - set(SDK_NAME iphoneos) - if(NOT ARCHS) - set(ARCHS armv7 armv7s arm64) - endif() -elseif(PLATFORM_INT STREQUAL "OS64") - set(SDK_NAME iphoneos) - if(NOT ARCHS) - if (XCODE_VERSION VERSION_GREATER 10.0) - set(ARCHS arm64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example - else() - set(ARCHS arm64) - endif() - endif() -elseif(PLATFORM_INT STREQUAL "OS64COMBINED") - set(SDK_NAME iphoneos) - if(MODERN_CMAKE) - if(NOT ARCHS) - if (XCODE_VERSION VERSION_GREATER 10.0) - set(ARCHS arm64 x86_64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example - else() - set(ARCHS arm64 x86_64) - endif() - endif() - else() - message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the OS64COMBINED setting work") - endif() -elseif(PLATFORM_INT STREQUAL "SIMULATOR") - set(SDK_NAME iphonesimulator) - if(NOT ARCHS) - set(ARCHS i386) - endif() - message(DEPRECATION "SIMULATOR IS DEPRECATED. Consider using SIMULATOR64 instead.") -elseif(PLATFORM_INT STREQUAL "SIMULATOR64") - set(SDK_NAME iphonesimulator) - if(NOT ARCHS) - set(ARCHS x86_64) - endif() -elseif(PLATFORM_INT STREQUAL "TVOS") - set(SDK_NAME appletvos) - if(NOT ARCHS) - set(ARCHS arm64) - endif() -elseif (PLATFORM_INT STREQUAL "TVOSCOMBINED") - set(SDK_NAME appletvos) - if(MODERN_CMAKE) - if(NOT ARCHS) - set(ARCHS arm64 x86_64) - endif() - else() - message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the TVOSCOMBINED setting work") - endif() -elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS") - set(SDK_NAME appletvsimulator) - if(NOT ARCHS) - set(ARCHS x86_64) - endif() -elseif(PLATFORM_INT STREQUAL "WATCHOS") - set(SDK_NAME watchos) - if(NOT ARCHS) - if (XCODE_VERSION VERSION_GREATER 10.0) - set(ARCHS armv7k arm64_32) - else() - set(ARCHS armv7k) - endif() - endif() -elseif(PLATFORM_INT STREQUAL "WATCHOSCOMBINED") - set(SDK_NAME watchos) - if(MODERN_CMAKE) - if(NOT ARCHS) - if (XCODE_VERSION VERSION_GREATER 10.0) - set(ARCHS armv7k arm64_32 i386) - else() - set(ARCHS armv7k i386) - endif() - endif() - else() - message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the WATCHOSCOMBINED setting work") - endif() -elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") - set(SDK_NAME watchsimulator) - if(NOT ARCHS) - set(ARCHS i386) - endif() -else() - message(FATAL_ERROR "Invalid PLATFORM: ${PLATFORM_INT}") -endif() -message(STATUS "Configuring ${SDK_NAME} build for platform: ${PLATFORM_INT}, architecture(s): ${ARCHS}") - -if(MODERN_CMAKE AND PLATFORM_INT MATCHES ".*COMBINED" AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode") - message(FATAL_ERROR "The COMBINED options only work with Xcode generator, -G Xcode") -endif() - -# If user did not specify the SDK root to use, then query xcodebuild for it. -execute_process(COMMAND xcodebuild -version -sdk ${SDK_NAME} Path - OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_INT - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) -if (NOT DEFINED CMAKE_OSX_SYSROOT_INT AND NOT DEFINED CMAKE_OSX_SYSROOT) - message(SEND_ERROR "Please make sure that Xcode is installed and that the toolchain" - "is pointing to the correct path. Please run:" - "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer" - "and see if that fixes the problem for you.") - message(FATAL_ERROR "Invalid CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT} " - "does not exist.") -elseif(DEFINED CMAKE_OSX_SYSROOT) - message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT} for platform: ${PLATFORM_INT} when checking compatibility") -elseif(DEFINED CMAKE_OSX_SYSROOT_INT) - message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT_INT} for platform: ${PLATFORM_INT}") - set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT_INT}" CACHE INTERNAL "") -endif() - -# Set Xcode property for SDKROOT as well if Xcode generator is used -if(USED_CMAKE_GENERATOR MATCHES "Xcode") - set(CMAKE_OSX_SYSROOT "${SDK_NAME}" CACHE INTERNAL "") - if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM) - set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM 123456789A CACHE INTERNAL "") - endif() -endif() - -# Specify minimum version of deployment target. -if(NOT DEFINED DEPLOYMENT_TARGET) - if (PLATFORM_INT STREQUAL "WATCHOS" OR PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") - # Unless specified, SDK version 2.0 is used by default as minimum target version (watchOS). - set(DEPLOYMENT_TARGET "2.0" - CACHE STRING "Minimum SDK version to build for." ) - else() - # Unless specified, SDK version 9.0 is used by default as minimum target version (iOS, tvOS). - set(DEPLOYMENT_TARGET "9.0" - CACHE STRING "Minimum SDK version to build for." ) - endif() - message(STATUS "Using the default min-version since DEPLOYMENT_TARGET not provided!") -endif() -# Use bitcode or not -if(NOT DEFINED ENABLE_BITCODE AND NOT ARCHS MATCHES "((^|;|, )(i386|x86_64))+") - # Unless specified, enable bitcode support by default - message(STATUS "Enabling bitcode support by default. ENABLE_BITCODE not provided!") - set(ENABLE_BITCODE TRUE) -elseif(NOT DEFINED ENABLE_BITCODE) - message(STATUS "Disabling bitcode support by default on simulators. ENABLE_BITCODE not provided for override!") - set(ENABLE_BITCODE FALSE) -endif() -set(ENABLE_BITCODE_INT ${ENABLE_BITCODE} CACHE BOOL "Whether or not to enable bitcode" ${FORCE_CACHE}) -# Use ARC or not -if(NOT DEFINED ENABLE_ARC) - # Unless specified, enable ARC support by default - set(ENABLE_ARC TRUE) - message(STATUS "Enabling ARC support by default. ENABLE_ARC not provided!") -endif() -set(ENABLE_ARC_INT ${ENABLE_ARC} CACHE BOOL "Whether or not to enable ARC" ${FORCE_CACHE}) -# Use hidden visibility or not -if(NOT DEFINED ENABLE_VISIBILITY) - # Unless specified, disable symbols visibility by default - set(ENABLE_VISIBILITY FALSE) - message(STATUS "Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!") -endif() -set(ENABLE_VISIBILITY_INT ${ENABLE_VISIBILITY} CACHE BOOL "Whether or not to hide symbols (-fvisibility=hidden)" ${FORCE_CACHE}) -# Set strict compiler checks or not -if(NOT DEFINED ENABLE_STRICT_TRY_COMPILE) - # Unless specified, disable strict try_compile() - set(ENABLE_STRICT_TRY_COMPILE FALSE) - message(STATUS "Using NON-strict compiler checks by default. ENABLE_STRICT_TRY_COMPILE not provided!") -endif() -set(ENABLE_STRICT_TRY_COMPILE_INT ${ENABLE_STRICT_TRY_COMPILE} CACHE BOOL "Whether or not to use strict compiler checks" ${FORCE_CACHE}) -# Get the SDK version information. -execute_process(COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion - OUTPUT_VARIABLE SDK_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - -# Find the Developer root for the specific iOS platform being compiled for -# from CMAKE_OSX_SYSROOT. Should be ../../ from SDK specified in -# CMAKE_OSX_SYSROOT. There does not appear to be a direct way to obtain -# this information from xcrun or xcodebuild. -if (NOT DEFINED CMAKE_DEVELOPER_ROOT AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode") - get_filename_component(PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT} PATH) - get_filename_component(CMAKE_DEVELOPER_ROOT ${PLATFORM_SDK_DIR} PATH) - - if (NOT DEFINED CMAKE_DEVELOPER_ROOT) - message(FATAL_ERROR "Invalid CMAKE_DEVELOPER_ROOT: " - "${CMAKE_DEVELOPER_ROOT} does not exist.") - endif() -endif() -# Find the C & C++ compilers for the specified SDK. -if(NOT CMAKE_C_COMPILER) - execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang - OUTPUT_VARIABLE CMAKE_C_COMPILER - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}") -endif() -if(NOT CMAKE_CXX_COMPILER) - execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang++ - OUTPUT_VARIABLE CMAKE_CXX_COMPILER - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - message(STATUS "Using CXX compiler: ${CMAKE_CXX_COMPILER}") -endif() -# Find (Apple's) libtool. -execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find libtool - OUTPUT_VARIABLE BUILD_LIBTOOL - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) -message(STATUS "Using libtool: ${BUILD_LIBTOOL}") -# Configure libtool to be used instead of ar + ranlib to build static libraries. -# This is required on Xcode 7+, but should also work on previous versions of -# Xcode. -set(CMAKE_C_CREATE_STATIC_LIBRARY - "${BUILD_LIBTOOL} -static -o ") -set(CMAKE_CXX_CREATE_STATIC_LIBRARY - "${BUILD_LIBTOOL} -static -o ") -# Find the toolchain's provided install_name_tool if none is found on the host -if(NOT CMAKE_INSTALL_NAME_TOOL) - execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find install_name_tool - OUTPUT_VARIABLE CMAKE_INSTALL_NAME_TOOL_INT - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - set(CMAKE_INSTALL_NAME_TOOL ${CMAKE_INSTALL_NAME_TOOL_INT} CACHE STRING "" ${FORCE_CACHE}) - message(STATUS "Using install_name_tool: ${CMAKE_INSTALL_NAME_TOOL}") -endif() -# Get the version of Darwin (OS X) of the host. -execute_process(COMMAND uname -r - OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) -# CMake 3.14+ support building for iOS, watchOS and tvOS out of the box. -if(MODERN_CMAKE) - if(SDK_NAME MATCHES "iphone") - set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" ${FORCE_CACHE}) - elseif(SDK_NAME MATCHES "appletv") - set(CMAKE_SYSTEM_NAME tvOS CACHE INTERNAL "" ${FORCE_CACHE}) - elseif(SDK_NAME MATCHES "watch") - set(CMAKE_SYSTEM_NAME watchOS CACHE INTERNAL "" ${FORCE_CACHE}) - endif() - - # Provide flags for a combined FAT library build on newer CMake versions - if(PLATFORM_INT MATCHES ".*COMBINED") - set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO CACHE INTERNAL "" ${FORCE_CACHE}) - set(CMAKE_IOS_INSTALL_COMBINED YES CACHE INTERNAL "" ${FORCE_CACHE}) - message(STATUS "Will combine built (static) artifacts into FAT lib...") - endif() -else() - # Legacy code path prior to CMake 3.14 - set(CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL "" ${FORCE_CACHE}) -endif() -# Standard settings. -set(CMAKE_SYSTEM_VERSION ${SDK_VERSION} CACHE INTERNAL "") -set(UNIX TRUE CACHE BOOL "") -set(APPLE TRUE CACHE BOOL "") -set(IOS TRUE CACHE BOOL "") -set(CMAKE_AR ar CACHE FILEPATH "" FORCE) -set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE) -set(CMAKE_STRIP strip CACHE FILEPATH "" FORCE) -# Set the architectures for which to build. -set(CMAKE_OSX_ARCHITECTURES ${ARCHS} CACHE STRING "Build architecture for iOS") -# Change the type of target generated for try_compile() so it'll work when cross-compiling, weak compiler checks -if(ENABLE_STRICT_TRY_COMPILE_INT) - message(STATUS "Using strict compiler checks (default in CMake).") -else() - set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) -endif() -# All iOS/Darwin specific settings - some may be redundant. -set(CMAKE_SHARED_LIBRARY_PREFIX "lib") -set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib") -set(CMAKE_SHARED_MODULE_PREFIX "lib") -set(CMAKE_SHARED_MODULE_SUFFIX ".so") -set(CMAKE_C_COMPILER_ABI ELF) -set(CMAKE_CXX_COMPILER_ABI ELF) -set(CMAKE_C_HAS_ISYSROOT 1) -set(CMAKE_CXX_HAS_ISYSROOT 1) -set(CMAKE_MODULE_EXISTS 1) -set(CMAKE_DL_LIBS "") -set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ") -set(CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ") -set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") -set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") - -if(ARCHS MATCHES "((^|;|, )(arm64|arm64e|x86_64))+") - set(CMAKE_C_SIZEOF_DATA_PTR 8) - set(CMAKE_CXX_SIZEOF_DATA_PTR 8) - if(ARCHS MATCHES "((^|;|, )(arm64|arm64e))+") - set(CMAKE_SYSTEM_PROCESSOR "aarch64") - else() - set(CMAKE_SYSTEM_PROCESSOR "x86_64") - endif() - message(STATUS "Using a data_ptr size of 8") -else() - set(CMAKE_C_SIZEOF_DATA_PTR 4) - set(CMAKE_CXX_SIZEOF_DATA_PTR 4) - set(CMAKE_SYSTEM_PROCESSOR "arm") - message(STATUS "Using a data_ptr size of 4") -endif() - -message(STATUS "Building for minimum ${SDK_NAME} version: ${DEPLOYMENT_TARGET}" - " (SDK version: ${SDK_VERSION})") -# Note that only Xcode 7+ supports the newer more specific: -# -m${SDK_NAME}-version-min flags, older versions of Xcode use: -# -m(ios/ios-simulator)-version-min instead. -if(PLATFORM_INT STREQUAL "OS" OR PLATFORM_INT STREQUAL "OS64") - if(XCODE_VERSION VERSION_LESS 7.0) - set(SDK_NAME_VERSION_FLAGS - "-mios-version-min=${DEPLOYMENT_TARGET}") - else() - # Xcode 7.0+ uses flags we can build directly from SDK_NAME. - set(SDK_NAME_VERSION_FLAGS - "-m${SDK_NAME}-version-min=${DEPLOYMENT_TARGET}") - endif() -elseif(PLATFORM_INT STREQUAL "TVOS") - set(SDK_NAME_VERSION_FLAGS - "-mtvos-version-min=${DEPLOYMENT_TARGET}") -elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS") - set(SDK_NAME_VERSION_FLAGS - "-mtvos-simulator-version-min=${DEPLOYMENT_TARGET}") -elseif(PLATFORM_INT STREQUAL "WATCHOS") - set(SDK_NAME_VERSION_FLAGS - "-mwatchos-version-min=${DEPLOYMENT_TARGET}") -elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") - set(SDK_NAME_VERSION_FLAGS - "-mwatchos-simulator-version-min=${DEPLOYMENT_TARGET}") -else() - # SIMULATOR or SIMULATOR64 both use -mios-simulator-version-min. - set(SDK_NAME_VERSION_FLAGS - "-mios-simulator-version-min=${DEPLOYMENT_TARGET}") -endif() -message(STATUS "Version flags set to: ${SDK_NAME_VERSION_FLAGS}") -set(CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} CACHE STRING - "Set CMake deployment target" ${FORCE_CACHE}) - -if(ENABLE_BITCODE_INT) - set(BITCODE "-fembed-bitcode") - set(CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE bitcode CACHE INTERNAL "") - message(STATUS "Enabling bitcode support.") -else() - set(BITCODE "") - set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE NO CACHE INTERNAL "") - message(STATUS "Disabling bitcode support.") -endif() - -if(ENABLE_ARC_INT) - set(FOBJC_ARC "-fobjc-arc") - set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES CACHE INTERNAL "") - message(STATUS "Enabling ARC support.") -else() - set(FOBJC_ARC "-fno-objc-arc") - set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC NO CACHE INTERNAL "") - message(STATUS "Disabling ARC support.") -endif() - -if(NOT ENABLE_VISIBILITY_INT) - set(VISIBILITY "-fvisibility=hidden") - set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES CACHE INTERNAL "") - message(STATUS "Hiding symbols (-fvisibility=hidden).") -else() - set(VISIBILITY "") - set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN NO CACHE INTERNAL "") -endif() - -#Check if Xcode generator is used, since that will handle these flags automagically -if(USED_CMAKE_GENERATOR MATCHES "Xcode") - message(STATUS "Not setting any manual command-line buildflags, since Xcode is selected as generator.") -else() - set(CMAKE_C_FLAGS - "${SDK_NAME_VERSION_FLAGS} ${BITCODE} -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_C_FLAGS}") - # Hidden visibilty is required for C++ on iOS. - set(CMAKE_CXX_FLAGS - "${SDK_NAME_VERSION_FLAGS} ${BITCODE} ${VISIBILITY} -fvisibility-inlines-hidden -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_CXX_FLAGS}") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g ${CMAKE_CXX_FLAGS_DEBUG}") - set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG -Os -ffast-math ${CMAKE_CXX_FLAGS_MINSIZEREL}") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG -O2 -g -ffast-math ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -ffast-math ${CMAKE_CXX_FLAGS_RELEASE}") - set(CMAKE_C_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") - set(CMAKE_CXX_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") - - # In order to ensure that the updated compiler flags are used in try_compile() - # tests, we have to forcibly set them in the CMake cache, not merely set them - # in the local scope. - list(APPEND VARS_TO_FORCE_IN_CACHE - CMAKE_C_FLAGS - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS_MINSIZEREL - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_LINK_FLAGS - CMAKE_CXX_LINK_FLAGS) - foreach(VAR_TO_FORCE ${VARS_TO_FORCE_IN_CACHE}) - set(${VAR_TO_FORCE} "${${VAR_TO_FORCE}}" CACHE STRING "") - endforeach() -endif() - -set(CMAKE_PLATFORM_HAS_INSTALLNAME 1) -set(CMAKE_SHARED_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks") -set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names") -set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -Wl,-headerpad_max_install_names") -set(CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,") -set(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,") -set(CMAKE_FIND_LIBRARY_SUFFIXES ".tbd" ".dylib" ".so" ".a") -set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name") - -# Set the find root to the iOS developer roots and to user defined paths. -set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT_INT} ${CMAKE_PREFIX_PATH} CACHE STRING "Root path that will be prepended - to all search paths") -# Default to searching for frameworks first. -set(CMAKE_FIND_FRAMEWORK FIRST) -# Set up the default search directories for frameworks. -set(CMAKE_FRAMEWORK_PATH - ${CMAKE_DEVELOPER_ROOT}/Library/PrivateFrameworks - ${CMAKE_OSX_SYSROOT_INT}/System/Library/Frameworks - ${CMAKE_FRAMEWORK_PATH} CACHE STRING "Frameworks search paths" ${FORCE_CACHE}) - -# By default, search both the specified iOS SDK and the remainder of the host filesystem. -if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH CACHE STRING "" ${FORCE_CACHE}) -endif() -if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY CACHE STRING "" ${FORCE_CACHE}) -endif() -if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) - set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE STRING "" ${FORCE_CACHE}) -endif() -if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) - set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY CACHE STRING "" ${FORCE_CACHE}) -endif() - -# -# Some helper-macros below to simplify and beautify the CMakeFile -# - -# This little macro lets you set any Xcode specific property. -macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE XCODE_RELVERSION) - set(XCODE_RELVERSION_I "${XCODE_RELVERSION}") - if(XCODE_RELVERSION_I STREQUAL "All") - set_property(TARGET ${TARGET} PROPERTY - XCODE_ATTRIBUTE_${XCODE_PROPERTY} "${XCODE_VALUE}") - else() - set_property(TARGET ${TARGET} PROPERTY - XCODE_ATTRIBUTE_${XCODE_PROPERTY}[variant=${XCODE_RELVERSION_I}] "${XCODE_VALUE}") - endif() -endmacro(set_xcode_property) -# This macro lets you find executable programs on the host system. -macro(find_host_package) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) - set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) - set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) - set(IOS FALSE) - find_package(${ARGN}) - set(IOS TRUE) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) - set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) - set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) -endmacro(find_host_package)