diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index c43ae25bb0..9a511b1a31 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -480,17 +480,18 @@ elseif(ANDROID) cocos/platform/android/FileUtils-android.h cocos/platform/android/View.cpp cocos/platform/android/View.h - cocos/platform/android/jni/JniHelper.cpp - cocos/platform/android/jni/JniHelper.h - cocos/platform/android/jni/JniImp.cpp - cocos/platform/android/jni/JniImp.h - cocos/platform/android/jni/JniCocosActivity.cpp - cocos/platform/android/jni/JniCocosActivity.h - cocos/platform/android/jni/JniCocosTouchHandler.cpp - cocos/platform/android/jni/JniCocosKeyCodeHandler.cpp - cocos/platform/android/jni/JniCocosSurfaceView.cpp - cocos/platform/android/jni/JniCocosOrientationHelper.cpp - + ) + set(CC_JNI_SRC_FILES + ${CWD}/cocos/platform/android/jni/JniCocosActivity.cpp + ${CWD}/cocos/platform/android/jni/JniCocosActivity.h + ${CWD}/cocos/platform/android/jni/JniCocosTouchHandler.cpp + ${CWD}/cocos/platform/android/jni/JniCocosKeyCodeHandler.cpp + ${CWD}/cocos/platform/android/jni/JniCocosSurfaceView.cpp + ${CWD}/cocos/platform/android/jni/JniCocosOrientationHelper.cpp + ${CWD}/cocos/platform/android/jni/JniHelper.cpp + ${CWD}/cocos/platform/android/jni/JniHelper.h + ${CWD}/cocos/platform/android/jni/JniImp.cpp + ${CWD}/cocos/platform/android/jni/JniImp.h ) elseif(APPLE) cocos_source_files( @@ -1099,19 +1100,19 @@ if(USE_MIDDLEWARE) cocos/editor-support/dragonbones/core/BaseObject.cpp cocos/editor-support/dragonbones/core/BaseObject.h cocos/editor-support/dragonbones/core/DragonBones.cpp - cocos/editor-support/dragonbones/core/DragonBones.h + cocos/editor-support/dragonbones/core/DragonBones.h cocos/editor-support/dragonbones/event/EventObject.cpp cocos/editor-support/dragonbones/event/EventObject.h - cocos/editor-support/dragonbones/event/IEventDispatcher.h + cocos/editor-support/dragonbones/event/IEventDispatcher.h cocos/editor-support/dragonbones/factory/BaseFactory.cpp - cocos/editor-support/dragonbones/factory/BaseFactory.h + cocos/editor-support/dragonbones/factory/BaseFactory.h cocos/editor-support/dragonbones/geom/ColorTransform.h cocos/editor-support/dragonbones/geom/Matrix.h cocos/editor-support/dragonbones/geom/Point.cpp cocos/editor-support/dragonbones/geom/Point.h cocos/editor-support/dragonbones/geom/Rectangle.h cocos/editor-support/dragonbones/geom/Transform.cpp - cocos/editor-support/dragonbones/geom/Transform.h + cocos/editor-support/dragonbones/geom/Transform.h cocos/editor-support/dragonbones/model/AnimationConfig.cpp cocos/editor-support/dragonbones/model/AnimationConfig.h cocos/editor-support/dragonbones/model/AnimationData.cpp @@ -1139,7 +1140,7 @@ if(USE_MIDDLEWARE) cocos/editor-support/dragonbones/parser/DataParser.cpp cocos/editor-support/dragonbones/parser/DataParser.h cocos/editor-support/dragonbones/parser/JSONDataParser.cpp - cocos/editor-support/dragonbones/parser/JSONDataParser.h + cocos/editor-support/dragonbones/parser/JSONDataParser.h cocos/editor-support/dragonbones-creator-support/ArmatureCache.cpp cocos/editor-support/dragonbones-creator-support/ArmatureCache.h cocos/editor-support/dragonbones-creator-support/ArmatureCacheMgr.cpp @@ -1443,6 +1444,19 @@ list(APPEND COCOS2D_SOURCE_LIST ${CC_EXTERNAL_SROUCES}) add_library(cocos2d ${COCOS2D_SOURCE_LIST}) +if(ANDROID) + add_library(cocos2d_jni STATIC ${CC_JNI_SRC_FILES}) + target_include_directories(cocos2d_jni PUBLIC + ${CWD} + ${CWD}/cocos + ) + target_link_libraries(cocos2d_jni PUBLIC + android_platform + android + log + ) +endif() + # setup default flags target_compile_definitions(cocos2d PUBLIC $,USE_VIDEO=1,USE_VIDEO=0> diff --git a/native/templates/android/build/build.gradle b/native/templates/android/build/build.gradle new file mode 100644 index 0000000000..5bb1044f2f --- /dev/null +++ b/native/templates/android/build/build.gradle @@ -0,0 +1,17 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + + repositories { + google() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:4.1.0' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +apply from: "${NATIVE_DIR}/build.gradle" diff --git a/native/templates/template-link/platforms/android/gradle.properties b/native/templates/android/build/gradle.properties similarity index 94% rename from native/templates/template-link/platforms/android/gradle.properties rename to native/templates/android/build/gradle.properties index b93e641d3e..a9271cc992 100644 --- a/native/templates/template-link/platforms/android/gradle.properties +++ b/native/templates/android/build/gradle.properties @@ -33,6 +33,15 @@ PROP_BUILD_TOOLS_VERSION=30.0.2 PROP_NDK_PATH= +# Cocos Engine Path +COCOS_ENGINE_PATH= + +# Res path +RES_PATH= + +# Application ID +APPLICATION_ID= + # List of CPU Archtexture to build that application with # Available architextures (armeabi-v7a | arm64-v8a | x86) # To build for multiple architexture, use the `:` between them diff --git a/native/templates/template-link/platforms/android/gradle/wrapper/gradle-wrapper.jar b/native/templates/android/build/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from native/templates/template-link/platforms/android/gradle/wrapper/gradle-wrapper.jar rename to native/templates/android/build/gradle/wrapper/gradle-wrapper.jar diff --git a/native/templates/template-link/platforms/android/gradle/wrapper/gradle-wrapper.properties b/native/templates/android/build/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from native/templates/template-link/platforms/android/gradle/wrapper/gradle-wrapper.properties rename to native/templates/android/build/gradle/wrapper/gradle-wrapper.properties diff --git a/native/templates/template-link/platforms/android/gradlew b/native/templates/android/build/gradlew similarity index 100% rename from native/templates/template-link/platforms/android/gradlew rename to native/templates/android/build/gradlew diff --git a/native/templates/template-link/platforms/android/gradlew.bat b/native/templates/android/build/gradlew.bat similarity index 100% rename from native/templates/template-link/platforms/android/gradlew.bat rename to native/templates/android/build/gradlew.bat diff --git a/native/templates/android/build/settings.gradle b/native/templates/android/build/settings.gradle new file mode 100644 index 0000000000..0f5312cc15 --- /dev/null +++ b/native/templates/android/build/settings.gradle @@ -0,0 +1,4 @@ +include ':libcocos',':instantapp',':CocosGame' +project(':libcocos').projectDir = new File('${COCOS_ROOT}/cocos/platform/android/libcocos2dx') +project(':instantapp').projectDir = new File('${NATIVE_DIR}/instantapp') +project(':CocosGame').projectDir = new File('${NATIVE_DIR}/app') diff --git a/native/templates/template-link/platforms/android/.gitignore b/native/templates/android/template/.gitignore similarity index 100% rename from native/templates/template-link/platforms/android/.gitignore rename to native/templates/android/template/.gitignore diff --git a/native/templates/android/template/CMakeLists.txt b/native/templates/android/template/CMakeLists.txt new file mode 100755 index 0000000000..7b02af51f8 --- /dev/null +++ b/native/templates/android/template/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.8) + +option(APP_NAME "Project Name" "CocosGame") +project(${APP_NAME} CXX) + +include(${CMAKE_CURRENT_LIST_DIR}/../common/CMakeLists.txt) + + +set(LIB_NAME cocos) +set(PROJ_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}) + +set(PROJ_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/Game.h + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/Game.cpp + ${CMAKE_CURRENT_LIST_DIR}/jni/main.cpp +) + + +if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/jsb_module_register.cpp) + file(COPY "${COCOS_X_PATH}/cocos/bindings/manual/jsb_module_register.cpp" + DESTINATION ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/) +endif() + +list(APPEND PROJ_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/jsb_module_register.cpp +) + +add_library(${LIB_NAME} SHARED ${PROJ_SOURCES}) + +target_link_libraries(${LIB_NAME} + "-Wl,--whole-archive" cocos2d_jni "-Wl,--no-whole-archive" + cocos2d +) + +target_include_directories(${LIB_NAME} PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes +) diff --git a/native/templates/template-link/platforms/android/app/.gitignore b/native/templates/android/template/app/.gitignore similarity index 100% rename from native/templates/template-link/platforms/android/app/.gitignore rename to native/templates/android/template/app/.gitignore diff --git a/native/templates/template-link/platforms/android/app/AndroidManifest.xml b/native/templates/android/template/app/AndroidManifest.xml similarity index 100% rename from native/templates/template-link/platforms/android/app/AndroidManifest.xml rename to native/templates/android/template/app/AndroidManifest.xml diff --git a/native/templates/template-link/platforms/android/app/build.gradle b/native/templates/android/template/app/build.gradle similarity index 81% rename from native/templates/template-link/platforms/android/app/build.gradle rename to native/templates/android/template/app/build.gradle index 8207f5fccd..a4536fe2cf 100644 --- a/native/templates/template-link/platforms/android/app/build.gradle +++ b/native/templates/android/template/app/build.gradle @@ -2,13 +2,17 @@ import org.apache.tools.ant.taskdefs.condition.Os apply plugin: 'com.android.application' +RES_PATH = RES_PATH.replace("\\", "/") +COCOS_ENGINE_PATH = COCOS_ENGINE_PATH.replace("\\", "/") + +buildDir = "${RES_PATH}/proj/build/$project.name" android { compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() buildToolsVersion PROP_BUILD_TOOLS_VERSION ndkPath PROP_NDK_PATH defaultConfig { - applicationId "com.cocos.helloworld" + applicationId APPLICATION_ID minSdkVersion PROP_MIN_SDK_VERSION targetSdkVersion PROP_TARGET_SDK_VERSION versionCode 1 @@ -17,7 +21,7 @@ android { externalNativeBuild { cmake { targets "cocos" - arguments "-DRES_DIR=${projectDir.absolutePath.replace("\\", "/")}/../..", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE" + arguments "-DRES_DIR=${RES_PATH}", "-DCOCOS_X_PATH=${COCOS_ENGINE_PATH}", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DANDROID_LD=lld" cppFlags "-frtti -fexceptions -fsigned-char" } ndk { abiFilters PROP_APP_ABI.split(':') } @@ -38,7 +42,8 @@ android { externalNativeBuild { cmake { - path "${COCOS_PROJ_COMMON}/CMakeLists.txt" + path "../CMakeLists.txt" + buildStagingDirectory "${RES_PATH}/proj/build" } } @@ -78,7 +83,7 @@ android { android.applicationVariants.all { variant -> def outputDir ="${projectDir}/assets" - def sourceDir = "${projectDir}/../../assets" + def sourceDir = "${RES_PATH}/assets" // assert file("${sourceDir}/res").exists() @@ -100,6 +105,6 @@ android.applicationVariants.all { variant -> dependencies { implementation fileTree(dir: '../libs', include: ['*.jar','*.aar']) implementation fileTree(dir: 'libs', include: ['*.jar','*.aar']) - implementation fileTree(dir: "${COCOS_ROOT}/cocos/platform/android/java/libs", include: ['*.jar']) + implementation fileTree(dir: "${COCOS_ENGINE_PATH}/cocos/platform/android/java/libs", include: ['*.jar']) implementation project(':libcocos') } diff --git a/native/templates/template-link/platforms/android/app/proguard-rules.pro b/native/templates/android/template/app/proguard-rules.pro similarity index 100% rename from native/templates/template-link/platforms/android/app/proguard-rules.pro rename to native/templates/android/template/app/proguard-rules.pro diff --git a/native/templates/template-link/platforms/android/app/src/com/cocos/game/AppActivity.java b/native/templates/android/template/app/src/com/cocos/game/AppActivity.java similarity index 100% rename from native/templates/template-link/platforms/android/app/src/com/cocos/game/AppActivity.java rename to native/templates/android/template/app/src/com/cocos/game/AppActivity.java diff --git a/native/templates/template-link/platforms/android/build-cfg.json b/native/templates/android/template/build-cfg.json similarity index 100% rename from native/templates/template-link/platforms/android/build-cfg.json rename to native/templates/android/template/build-cfg.json diff --git a/native/templates/template-link/platforms/android/build.gradle b/native/templates/android/template/build.gradle similarity index 99% rename from native/templates/template-link/platforms/android/build.gradle rename to native/templates/android/template/build.gradle index 66225541dd..4b53b887e1 100644 --- a/native/templates/template-link/platforms/android/build.gradle +++ b/native/templates/android/template/build.gradle @@ -9,7 +9,6 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.1.0' - // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/native/templates/template-link/platforms/android/instantapp/AndroidManifest.xml b/native/templates/android/template/instantapp/AndroidManifest.xml similarity index 100% rename from native/templates/template-link/platforms/android/instantapp/AndroidManifest.xml rename to native/templates/android/template/instantapp/AndroidManifest.xml diff --git a/native/templates/template-link/platforms/android/instantapp/build.gradle b/native/templates/android/template/instantapp/build.gradle similarity index 81% rename from native/templates/template-link/platforms/android/instantapp/build.gradle rename to native/templates/android/template/instantapp/build.gradle index afd204db94..2d9075dff1 100644 --- a/native/templates/template-link/platforms/android/instantapp/build.gradle +++ b/native/templates/android/template/instantapp/build.gradle @@ -2,6 +2,10 @@ import org.apache.tools.ant.taskdefs.condition.Os apply plugin: 'com.android.application' +RES_PATH = RES_PATH.replace("\\", "/") +COCOS_ENGINE_PATH = COCOS_ENGINE_PATH.replace("\\", "/") +buildDir = "${RES_PATH}/proj/build/$project.name" + android { compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() buildToolsVersion PROP_BUILD_TOOLS_VERSION @@ -17,7 +21,7 @@ android { externalNativeBuild { cmake { targets "cocos" - arguments "-DRES_DIR=${projectDir.absolutePath.replace("\\", "/")}/../..", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE" + arguments "-DRES_DIR=${RES_PATH}", "-DCOCOS_X_PATH=${COCOS_ENGINE_PATH}","-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DANDROID_LD=lld" cppFlags "-frtti -fexceptions -fsigned-char -DANDROID_INSTANT=1" } ndk { abiFilters PROP_APP_ABI.split(':') } @@ -34,7 +38,8 @@ android { externalNativeBuild { cmake { - path "${COCOS_PROJ_COMMON}/CMakeLists.txt" + path "../CMakeLists.txt" + buildStagingDirectory "${RES_PATH}/proj/build" } } @@ -74,7 +79,7 @@ android { android.applicationVariants.all { variant -> def outputDir ="${projectDir}/assets" - def sourceDir = "${projectDir}/../../assets" + def sourceDir = "${RES_PATH}/assets" // assert file("${sourceDir}/res").exists() @@ -91,12 +96,11 @@ android.applicationVariants.all { variant -> } tasks.getByName("pre${targetName}Build").dependsOn copyTaskName - } dependencies { implementation fileTree(dir: '../libs', include: ['*.jar','*.aar']) implementation fileTree(dir: 'libs', include: ['*.jar','*.aar']) - implementation fileTree(dir: "/Users/wzm/cocos_creator/cocos2d-x-lite-3d/cocos/platform/android/java/libs", include: ['*.jar']) + implementation fileTree(dir: "${COCOS_ENGINE_PATH}/cocos/platform/android/java/libs", include: ['*.jar']) implementation project(':libcocos') } diff --git a/native/templates/template-link/platforms/android/instantapp/proguard-rules.pro b/native/templates/android/template/instantapp/proguard-rules.pro similarity index 100% rename from native/templates/template-link/platforms/android/instantapp/proguard-rules.pro rename to native/templates/android/template/instantapp/proguard-rules.pro diff --git a/native/templates/template-link/platforms/android/instantapp/src/com/cocos/game/InstantActivity.java b/native/templates/android/template/instantapp/src/com/cocos/game/InstantActivity.java similarity index 100% rename from native/templates/template-link/platforms/android/instantapp/src/com/cocos/game/InstantActivity.java rename to native/templates/android/template/instantapp/src/com/cocos/game/InstantActivity.java diff --git a/native/templates/template-link/platforms/android/jni/main.cpp b/native/templates/android/template/jni/main.cpp similarity index 100% rename from native/templates/template-link/platforms/android/jni/main.cpp rename to native/templates/android/template/jni/main.cpp diff --git a/native/templates/template-link/platforms/android/res/mipmap-hdpi/ic_launcher.png b/native/templates/android/template/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from native/templates/template-link/platforms/android/res/mipmap-hdpi/ic_launcher.png rename to native/templates/android/template/res/mipmap-hdpi/ic_launcher.png diff --git a/native/templates/template-link/platforms/android/res/mipmap-mdpi/ic_launcher.png b/native/templates/android/template/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from native/templates/template-link/platforms/android/res/mipmap-mdpi/ic_launcher.png rename to native/templates/android/template/res/mipmap-mdpi/ic_launcher.png diff --git a/native/templates/template-link/platforms/android/res/mipmap-xhdpi/ic_launcher.png b/native/templates/android/template/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from native/templates/template-link/platforms/android/res/mipmap-xhdpi/ic_launcher.png rename to native/templates/android/template/res/mipmap-xhdpi/ic_launcher.png diff --git a/native/templates/template-link/platforms/android/res/mipmap-xxhdpi/ic_launcher.png b/native/templates/android/template/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from native/templates/template-link/platforms/android/res/mipmap-xxhdpi/ic_launcher.png rename to native/templates/android/template/res/mipmap-xxhdpi/ic_launcher.png diff --git a/native/templates/android/template/res/values/strings.xml b/native/templates/android/template/res/values/strings.xml new file mode 100644 index 0000000000..1043872e78 --- /dev/null +++ b/native/templates/android/template/res/values/strings.xml @@ -0,0 +1,3 @@ + + CocosGame + diff --git a/native/templates/template-link/platforms/android/src/com/cocos/game/SDKWrapper.java b/native/templates/android/template/src/com/cocos/game/SDKWrapper.java similarity index 100% rename from native/templates/template-link/platforms/android/src/com/cocos/game/SDKWrapper.java rename to native/templates/android/template/src/com/cocos/game/SDKWrapper.java diff --git a/native/templates/template-link/platforms/android/src/com/cocos/game/service/SDKClass.java b/native/templates/android/template/src/com/cocos/game/service/SDKClass.java similarity index 100% rename from native/templates/template-link/platforms/android/src/com/cocos/game/service/SDKClass.java rename to native/templates/android/template/src/com/cocos/game/service/SDKClass.java diff --git a/native/templates/template-link/platforms/android/src/com/cocos/game/service/SDKInterface.java b/native/templates/android/template/src/com/cocos/game/service/SDKInterface.java similarity index 100% rename from native/templates/template-link/platforms/android/src/com/cocos/game/service/SDKInterface.java rename to native/templates/android/template/src/com/cocos/game/service/SDKInterface.java diff --git a/native/templates/template-link/cocos-project-template.json b/native/templates/cocos-project-template.json similarity index 59% rename from native/templates/template-link/cocos-project-template.json rename to native/templates/cocos-project-template.json index 93e51aa9b3..b4868f8a34 100755 --- a/native/templates/template-link/cocos-project-template.json +++ b/native/templates/cocos-project-template.json @@ -1,24 +1,17 @@ { - "doDefault": { - "exclude_from_template": [ - "cocos-project-template.json", - "platforms", - "common" - ] - }, "doAddNativeSupport": { "appendFile": [{ "from": "cocos/bindings/manual/jsb_module_register.cpp", "to": "${COMMON_DIR}/Classes/jsb_module_register.cpp" }], "projectReplaceProjectName": { - "srcProjectName": "HelloJavascript", + "srcProjectName": "CocosGame", "files": [ "proj/main.cpp", "proj/settings.gradle", - "proj/res/values/strings.xml", + "${NATIVE_DIR}/res/values/strings.xml", "proj/main.m", - "${COMMON_DIR}/CMakeLists.txt" + "${NATIVE_DIR}/CMakeLists.txt" ] }, "appendXEngine": { @@ -28,39 +21,44 @@ "projectReplacePackageName": { "srcPackageName": "com.cocos.helloworld", "files": [ - "proj/app/build.gradle", - "proj/app/AndroidManifest.xml", - "proj/instantapp/build.gradle", - "proj/instantapp/AndroidManifest.xml" + "${NATIVE_DIR}/app/build.gradle", + "${NATIVE_DIR}/app/AndroidManifest.xml", + "${NATIVE_DIR}/instantapp/build.gradle", + "${NATIVE_DIR}/instantapp/AndroidManifest.xml" ] }, "projectReplaceMacBundleid": { "srcBundleId": "com.cocos.helloworld.mac", "files": [ - "${COMMON_DIR}/CMakeLists.txt" + "${NATIVE_DIR}/CMakeLists.txt" ] }, "projectReplaceIosBundleid": { "srcBundleId": "com.cocos.helloworld.ios", "files": [ - "${COMMON_DIR}/CMakeLists.txt" + "${NATIVE_DIR}/CMakeLists.txt" ] }, "projectReplaceCocosRoot": { "pattern":"\\$\\{COCOS_ROOT\\}", "files": [ - {"file": "${COMMON_DIR}/CMakeLists.txt", "default":"${CMAKE_CURRENT_LIST_DIR}/cocos2d-x", "needFix":true}, + {"file": "${NATIVE_DIR}/CMakeLists.txt", "default":"${CMAKE_CURRENT_LIST_DIR}/cocos2d-x", "needFix":true}, {"file": "proj/settings.gradle", "default":"${COMMON_DIR}/cocos2d-x", "needFix":true}, - {"file": "proj/app/build.gradle", "default":"${COMMON_DIR}/cocos2d-x", "needFix":true}, - {"file": "proj/instantapp/build.gradle", "default":"${COMMON_DIR}/cocos2d-x", "needFix":true}, "proj/build-cfg.json" ] }, + "projectReplaceTemplatePath": { + "pattern":"\\$\\{NATIVE_DIR\\}", + "files": [ + "proj/settings.gradle", + "proj/build.gradle" + ] + }, "projectReplaceProjectCommon" : { "pattern":"\\$\\{COCOS_PROJ_COMMON\\}", "files":[ - "proj/app/build.gradle", - "proj/instantapp/build.gradle" + "${NATIVE_DIR}/app/build.gradle", + "${NATIVE_DIR}/instantapp/build.gradle" ] } } diff --git a/native/templates/common/CMakeLists.txt b/native/templates/common/CMakeLists.txt new file mode 100755 index 0000000000..f909226021 --- /dev/null +++ b/native/templates/common/CMakeLists.txt @@ -0,0 +1,63 @@ +enable_language(C ASM) + + +set(DEVELOPMENT_TEAM "" CACHE STRING "APPLE Developtment Team") +set(RES_DIR "" CACHE STRING "Resource path") +set(COCOS_X_PATH "" CACHE STRING "Path to cocos2d-x-lite/") + +set(CMAKE_CXX_STANDARD 14) +option(USE_SE_V8 "USE V8 JavaScript Engine" ON) +option(USE_V8_DEBUGGER "Enable Chrome Remote inspector" ON) +option(USE_SOCKET "Enable WebSocket & SocketIO" ON) +option(USE_AUDIO "Enable Audio" ON) #Enable AudioEngine +option(USE_EDIT_BOX "Enable EditBox" ON) +option(USE_SE_JSC "USE JavaScriptCore on MacOSX/iOS" OFF) +option(USE_VIDEO "Enable VideoPlayer Component" ON) +option(USE_WEBVIEW "Enable WebView Component" ON) +option(USE_MIDDLEWARE "Enable Middleware" ON) +option(USE_DRAGONBONES "Enable Dragonbones" ON) +option(USE_SPINE "Enable Spine" ON) +option(USE_WEBSOCKET_SERVER "Enable WebSocket Server" OFF) + + +if(NOT RES_DIR) + message(FATAL_ERROR "RES_DIR is not set!") +endif() + +include(${RES_DIR}/proj/cfg.cmake) + +if(NOT COCOS_X_PATH) + message(FATAL_ERROR "COCOS_X_PATH is not set!") +endif() + + +set(TARGET_OSX_VERSION "10.10") +set(TARGET_IOS_VERSION "9.0") + +include(${COCOS_X_PATH}/CMakeLists.txt) + +set(ASSET_FILES) +macro(include_resources ARG_RES_ROOT) + foreach(res ${ARG_RES_ROOT}) + set(res_list) + if(NOT EXISTS ${res}) + continue() + endif() + + if(IS_DIRECTORY ${res}) + file(GLOB_RECURSE res_list "${res}/*") + else() + set(res_list ${res}) + endif() + foreach(res ${res_list}) + get_filename_component(res_abs ${res} ABSOLUTE) + file(RELATIVE_PATH res_rel ${ARG_RES_ROOT} ${res_abs}) + get_filename_component(res_dir ${res_rel} PATH) + set_source_files_properties(${res_abs} PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources/${res_dir}/" + HEADER_FILE_ONLY 1 + ) + list(APPEND ASSET_FILES ${res_abs}) + endforeach() + endforeach() +endmacro() \ No newline at end of file diff --git a/native/templates/template-link/common/Classes/Game.cpp b/native/templates/common/Classes/Game.cpp similarity index 100% rename from native/templates/template-link/common/Classes/Game.cpp rename to native/templates/common/Classes/Game.cpp diff --git a/native/templates/template-link/common/Classes/Game.h b/native/templates/common/Classes/Game.h similarity index 100% rename from native/templates/template-link/common/Classes/Game.h rename to native/templates/common/Classes/Game.h diff --git a/native/templates/template-link/platforms/ios/AppDelegate.h b/native/templates/ios/AppDelegate.h similarity index 100% rename from native/templates/template-link/platforms/ios/AppDelegate.h rename to native/templates/ios/AppDelegate.h diff --git a/native/templates/template-link/platforms/ios/AppDelegate.mm b/native/templates/ios/AppDelegate.mm similarity index 100% rename from native/templates/template-link/platforms/ios/AppDelegate.mm rename to native/templates/ios/AppDelegate.mm diff --git a/native/templates/template-link/platforms/ios/Base.lproj/LaunchScreen.storyboard b/native/templates/ios/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from native/templates/template-link/platforms/ios/Base.lproj/LaunchScreen.storyboard rename to native/templates/ios/Base.lproj/LaunchScreen.storyboard diff --git a/native/templates/template-link/platforms/ios/Base.lproj/Localizable.strings b/native/templates/ios/Base.lproj/Localizable.strings similarity index 100% rename from native/templates/template-link/platforms/ios/Base.lproj/Localizable.strings rename to native/templates/ios/Base.lproj/Localizable.strings diff --git a/native/templates/ios/CMakeLists.txt b/native/templates/ios/CMakeLists.txt new file mode 100755 index 0000000000..39e8372487 --- /dev/null +++ b/native/templates/ios/CMakeLists.txt @@ -0,0 +1,73 @@ +cmake_minimum_required(VERSION 3.8) +set(CMAKE_SYSTEM_NAME iOS) +set(APP_NAME "CocosGame" CACHE STRING "Project Name") +project(${APP_NAME} CXX) + +include(${CMAKE_CURRENT_LIST_DIR}/../common/CMakeLists.txt) + +set(LIB_NAME ${APP_NAME}-mobile) + +set(UI_RESOURCES) +set(PROJ_SOURCES) +set(PROJ_EXTRA_SOURCE) +set(PROJ_COMMON_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/Game.h + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/Game.cpp +) + +if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/jsb_module_register.cpp) + file(COPY "${COCOS_X_PATH}/cocos/bindings/manual/jsb_module_register.cpp" + DESTINATION ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/) +endif() +list(APPEND PROJ_COMMON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/jsb_module_register.cpp) + +set(UI_RESOURCES + ${CMAKE_CURRENT_LIST_DIR}/LaunchScreenBackground.png + ${CMAKE_CURRENT_LIST_DIR}/Images.xcassets + ${CMAKE_CURRENT_LIST_DIR}/Base.lproj/Localizable.strings + ${CMAKE_CURRENT_LIST_DIR}/Base.lproj/LaunchScreen.storyboard +) + +list(APPEND PROJ_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/AppDelegate.mm + ${CMAKE_CURRENT_LIST_DIR}/AppDelegate.h + ${CMAKE_CURRENT_LIST_DIR}/SDKWrapper.m + ${CMAKE_CURRENT_LIST_DIR}/SDKWrapper.h + ${CMAKE_CURRENT_LIST_DIR}/service/SDKDelegate.h + ${CMAKE_CURRENT_LIST_DIR}/main.m + ${CMAKE_CURRENT_LIST_DIR}/ViewController.mm + ${CMAKE_CURRENT_LIST_DIR}/ViewController.h + ${UI_RESOURCES} +) + +include_resources(${RES_DIR}/assets) + +add_executable(${LIB_NAME} ${PROJ_SOURCES} ${ASSET_FILES} ${PROJ_EXTRA_SOURCE} ${PROJ_COMMON_SOURCES}) +source_group(TREE ${RES_DIR}/assets PREFIX "Resources" FILES ${ASSET_FILES}) +source_group(TREE ${CMAKE_CURRENT_LIST_DIR} PREFIX "Source Files" FILES ${PROJ_SOURCES}) +source_group(TREE ${CMAKE_CURRENT_LIST_DIR}/../common PREFIX "Source Files" FILES ${PROJ_COMMON_SOURCES}) + +target_link_libraries(${LIB_NAME} cocos2d) +target_include_directories(${LIB_NAME} PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes + ${CMAKE_CURRENT_LIST_DIR}/service +) + +set(EXECUTABLE_NAME ${LIB_NAME}) # referenced in Info.plist +set(PRODUCT_NAME ${APP_NAME}) + +set_target_properties(${LIB_NAME} PROPERTIES + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/Info.plist" + MACOSX_BUNDLE 1 + RESOURCE "${UI_RESOURCES}" + OSX_ARCHITECTURES "arm64;x86_64" + MACOSX_DEPLOYMENT_TARGET ${TARGET_IOS_VERSION} + XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "${DEVELOPMENT_TEAM}" + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer" + XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon" + XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_LAUNCHSTORYBOARD_NAME "LaunchScreen" + XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${TARGET_IOS_VERSION} + XCODE_ATTRIBUTE_ENABLE_BITCODE NO + XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH YES + IOS_INSTALL_COMBINED YES +) \ No newline at end of file diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Contents.json b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Contents.json rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Contents.json diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-20.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-20.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-20.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-20.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-20@2x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-20@2x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-20@2x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-20@2x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-20@3x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-20@3x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-20@3x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-20@3x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-29.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-29.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-29.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-29.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-29@2x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-29@2x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-29@2x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-29@2x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-29@3x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-29@3x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-29@3x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-29@3x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-40.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-40.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-40.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-40.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-40@2x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-40@2x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-40@2x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-40@2x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-40@3x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-40@3x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-40@3x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-40@3x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-50.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-50.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-50.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-50.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-50@2x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-50@2x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-50@2x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-50@2x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-57.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-57.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-57.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-57.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-57@2x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-57@2x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-57@2x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-57@2x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-72.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-72.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-72.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-72.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-72@2x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-72@2x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-72@2x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-72@2x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-76.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-76.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-76.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-76.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-76@2x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-76@2x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-76@2x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-76@2x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-83.5@2x.png b/native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-83.5@2x.png similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/AppIcon.appiconset/Icon-83.5@2x.png rename to native/templates/ios/Images.xcassets/AppIcon.appiconset/Icon-83.5@2x.png diff --git a/native/templates/template-link/platforms/ios/Images.xcassets/Contents.json b/native/templates/ios/Images.xcassets/Contents.json similarity index 100% rename from native/templates/template-link/platforms/ios/Images.xcassets/Contents.json rename to native/templates/ios/Images.xcassets/Contents.json diff --git a/native/templates/template-link/platforms/ios/Info.plist b/native/templates/ios/Info.plist similarity index 100% rename from native/templates/template-link/platforms/ios/Info.plist rename to native/templates/ios/Info.plist diff --git a/native/templates/template-link/platforms/ios/LaunchScreenBackground.png b/native/templates/ios/LaunchScreenBackground.png similarity index 100% rename from native/templates/template-link/platforms/ios/LaunchScreenBackground.png rename to native/templates/ios/LaunchScreenBackground.png diff --git a/native/templates/template-link/platforms/ios/Prefix.pch b/native/templates/ios/Prefix.pch similarity index 100% rename from native/templates/template-link/platforms/ios/Prefix.pch rename to native/templates/ios/Prefix.pch diff --git a/native/templates/template-link/platforms/ios/SDKWrapper.h b/native/templates/ios/SDKWrapper.h similarity index 100% rename from native/templates/template-link/platforms/ios/SDKWrapper.h rename to native/templates/ios/SDKWrapper.h diff --git a/native/templates/template-link/platforms/ios/SDKWrapper.m b/native/templates/ios/SDKWrapper.m similarity index 100% rename from native/templates/template-link/platforms/ios/SDKWrapper.m rename to native/templates/ios/SDKWrapper.m diff --git a/native/templates/template-link/platforms/ios/ViewController.h b/native/templates/ios/ViewController.h similarity index 100% rename from native/templates/template-link/platforms/ios/ViewController.h rename to native/templates/ios/ViewController.h diff --git a/native/templates/template-link/platforms/ios/ViewController.mm b/native/templates/ios/ViewController.mm similarity index 100% rename from native/templates/template-link/platforms/ios/ViewController.mm rename to native/templates/ios/ViewController.mm diff --git a/native/templates/template-link/platforms/ios/main.m b/native/templates/ios/main.m similarity index 100% rename from native/templates/template-link/platforms/ios/main.m rename to native/templates/ios/main.m diff --git a/native/templates/template-link/platforms/ios/service/SDKDelegate.h b/native/templates/ios/service/SDKDelegate.h similarity index 100% rename from native/templates/template-link/platforms/ios/service/SDKDelegate.h rename to native/templates/ios/service/SDKDelegate.h diff --git a/native/templates/template-link/platforms/ios/zh-Hans.lproj/Localizable.strings b/native/templates/ios/zh-Hans.lproj/Localizable.strings similarity index 100% rename from native/templates/template-link/platforms/ios/zh-Hans.lproj/Localizable.strings rename to native/templates/ios/zh-Hans.lproj/Localizable.strings diff --git a/native/templates/template-link/platforms/mac/AppDelegate.h b/native/templates/mac/AppDelegate.h similarity index 100% rename from native/templates/template-link/platforms/mac/AppDelegate.h rename to native/templates/mac/AppDelegate.h diff --git a/native/templates/template-link/platforms/mac/AppDelegate.mm b/native/templates/mac/AppDelegate.mm similarity index 100% rename from native/templates/template-link/platforms/mac/AppDelegate.mm rename to native/templates/mac/AppDelegate.mm diff --git a/native/templates/template-link/platforms/mac/Assets.xcassets/AppIcon.appiconset/Contents.json b/native/templates/mac/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from native/templates/template-link/platforms/mac/Assets.xcassets/AppIcon.appiconset/Contents.json rename to native/templates/mac/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/native/templates/template-link/platforms/mac/Assets.xcassets/Contents.json b/native/templates/mac/Assets.xcassets/Contents.json similarity index 100% rename from native/templates/template-link/platforms/mac/Assets.xcassets/Contents.json rename to native/templates/mac/Assets.xcassets/Contents.json diff --git a/native/templates/mac/CMakeLists.txt b/native/templates/mac/CMakeLists.txt new file mode 100644 index 0000000000..23154e64f4 --- /dev/null +++ b/native/templates/mac/CMakeLists.txt @@ -0,0 +1,71 @@ +cmake_minimum_required(VERSION 3.8) + +set(APP_NAME "CocosGame" CACHE STRING "Project Name") +project(${APP_NAME} CXX) + +include(${CMAKE_CURRENT_LIST_DIR}/../common/CMakeLists.txt) + +set(CMAKE_OSX_DEPLOYMENT_TARGET ${TARGET_OSX_VERSION}) + +set(LIB_NAME ${APP_NAME}-desktop) + +set(UI_RESOURCES) +set(PROJ_SOURCES) +set(PROJ_EXTRA_SOURCE) +set(PROJ_COMMON_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/Game.h + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/Game.cpp +) + +if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/jsb_module_register.cpp) + file(COPY "${COCOS_X_PATH}/cocos/bindings/manual/jsb_module_register.cpp" + DESTINATION ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/) +endif() +list(APPEND PROJ_COMMON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/jsb_module_register.cpp) + + +set(UI_RESOURCES + ${CMAKE_CURRENT_LIST_DIR}/Assets.xcassets + ${CMAKE_CURRENT_LIST_DIR}/Icon.icns +) +list(APPEND PROJ_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/main.m + ${CMAKE_CURRENT_LIST_DIR}/ViewController.mm + ${CMAKE_CURRENT_LIST_DIR}/ViewController.h + ${CMAKE_CURRENT_LIST_DIR}/AppDelegate.mm + ${CMAKE_CURRENT_LIST_DIR}/AppDelegate.h + ${UI_RESOURCES} +) + +include_resources(${RES_DIR}/assets) + +add_executable(${LIB_NAME} ${PROJ_SOURCES} ${ASSET_FILES} ${PROJ_EXTRA_SOURCE} ${PROJ_COMMON_SOURCES}) +source_group(TREE ${RES_DIR}/assets PREFIX "Resources" FILES ${ASSET_FILES}) +source_group(TREE ${CMAKE_CURRENT_LIST_DIR} PREFIX "Source Files" FILES ${PROJ_SOURCES}) +source_group(TREE ${CMAKE_CURRENT_LIST_DIR}/../common PREFIX "Source Files" FILES ${PROJ_COMMON_SOURCES}) + +target_link_libraries(${LIB_NAME} cocos2d) +target_include_directories(${LIB_NAME} PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes +) + +set(EXECUTABLE_NAME ${LIB_NAME}) # referenced in Info.plist +set(PRODUCT_NAME ${APP_NAME}) +# set(MACOSX_BUNDLE_GUI_IDENTIFIER org.cocos2dx.hellojavascript.mac) +set_target_properties(${LIB_NAME} PROPERTIES + MACOSX_DEPLOYMENT_TARGET ${TARGET_OSX_VERSION} + OSX_ARCHITECTURES "x86_64;arm64" + XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH YES + XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon" + XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_LAUNCHSTORYBOARD_NAME "LaunchScreen" + MACOSX_BUNDLE 1 + RESOURCE "${UI_RESOURCES}" + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/Info.plist" +) +get_property(gles2_loc TARGET GLESv2 PROPERTY IMPORTED_LOCATION) +get_property(egl_loc TARGET EGL PROPERTY IMPORTED_LOCATION) +add_custom_command(TARGET ${LIB_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory $/../Frameworks + COMMAND ${CMAKE_COMMAND} -E copy ${gles2_loc} $/../Frameworks + COMMAND ${CMAKE_COMMAND} -E copy ${egl_loc} $/../Frameworks +) diff --git a/native/templates/template-link/platforms/mac/Icon.icns b/native/templates/mac/Icon.icns similarity index 100% rename from native/templates/template-link/platforms/mac/Icon.icns rename to native/templates/mac/Icon.icns diff --git a/native/templates/template-link/platforms/mac/Info.plist b/native/templates/mac/Info.plist similarity index 100% rename from native/templates/template-link/platforms/mac/Info.plist rename to native/templates/mac/Info.plist diff --git a/native/templates/template-link/platforms/mac/Prefix.pch b/native/templates/mac/Prefix.pch similarity index 100% rename from native/templates/template-link/platforms/mac/Prefix.pch rename to native/templates/mac/Prefix.pch diff --git a/native/templates/template-link/platforms/mac/UserConfigMac.debug.xcconfig b/native/templates/mac/UserConfigMac.debug.xcconfig similarity index 100% rename from native/templates/template-link/platforms/mac/UserConfigMac.debug.xcconfig rename to native/templates/mac/UserConfigMac.debug.xcconfig diff --git a/native/templates/template-link/platforms/mac/UserConfigMac.release.xcconfig b/native/templates/mac/UserConfigMac.release.xcconfig similarity index 100% rename from native/templates/template-link/platforms/mac/UserConfigMac.release.xcconfig rename to native/templates/mac/UserConfigMac.release.xcconfig diff --git a/native/templates/template-link/platforms/mac/ViewController.h b/native/templates/mac/ViewController.h similarity index 100% rename from native/templates/template-link/platforms/mac/ViewController.h rename to native/templates/mac/ViewController.h diff --git a/native/templates/template-link/platforms/mac/ViewController.mm b/native/templates/mac/ViewController.mm similarity index 100% rename from native/templates/template-link/platforms/mac/ViewController.mm rename to native/templates/mac/ViewController.mm diff --git a/native/templates/template-link/platforms/mac/gfx_tests.entitlements b/native/templates/mac/gfx_tests.entitlements similarity index 100% rename from native/templates/template-link/platforms/mac/gfx_tests.entitlements rename to native/templates/mac/gfx_tests.entitlements diff --git a/native/templates/template-link/platforms/mac/main.m b/native/templates/mac/main.m similarity index 100% rename from native/templates/template-link/platforms/mac/main.m rename to native/templates/mac/main.m diff --git a/native/templates/template-link/project.json b/native/templates/project.json similarity index 100% rename from native/templates/template-link/project.json rename to native/templates/project.json diff --git a/native/templates/template-link/common/CMakeLists.txt b/native/templates/template-link/common/CMakeLists.txt deleted file mode 100644 index 587ca86f67..0000000000 --- a/native/templates/template-link/common/CMakeLists.txt +++ /dev/null @@ -1,270 +0,0 @@ -cmake_minimum_required(VERSION 3.8) - -set(APP_NAME HelloJavascript) -project(${APP_NAME} CXX) - -enable_language(C ASM) - -set(CMAKE_CXX_STANDARD 14) -option(USE_SE_V8 "USE V8 JavaScript Engine" ON) -option(USE_V8_DEBUGGER "Enable Chrome Remote inspector" ON) -option(USE_SOCKET "Enable WebSocket & SocketIO" ON) -option(USE_AUDIO "Enable Audio" ON) #Enable AudioEngine -option(USE_EDIT_BOX "Enable EditBox" ON) -option(USE_SE_JSC "USE JavaScriptCore on MacOSX/iOS" OFF) -option(USE_VIDEO "Enable VideoPlayer Component" ON) -option(USE_WEBVIEW "Enable WebView Component" ON) -option(USE_MIDDLEWARE "Enable Middleware" ON) -option(USE_DRAGONBONES "Enable Dragonbones" ON) -option(USE_SPINE "Enable Spine" ON) -option(USE_WEBSOCKET_SERVER "Enable WebSocket Server" OFF) - -if(USE_SE_JSC AND APPLE) - set(USE_SE_V8 OFF) - set(USE_V8_DEBUGGER OFF) -endif() - -set(DEVELOPMENT_TEAM "" CACHE STRING "APPLE Developtment Team") -set(RES_DIR "" CACHE STRING "Resource path") - -set(TARGET_IOS_VERSION "9.0") -set(TARGET_OSX_VERSION "10.10") - -if(RES_DIR) - include(${RES_DIR}/proj/cfg.cmake) -endif() - -set(cocosdir "${COCOS_ROOT}") -if(NOT cocosdir) - message(FATAL_ERROR "COCOS_ROOT is not set!") -endif() -include(${cocosdir}/CMakeLists.txt) - - -if(ANDROID) - set(LIB_NAME cocos) - set(PLATFORM_DIR_NAME "android") -elseif(MACOSX) - set(LIB_NAME ${APP_NAME}-desktop) - set(PLATFORM_DIR_NAME "mac") -elseif(IOS) - set(LIB_NAME ${APP_NAME}-mobile) - set(PLATFORM_DIR_NAME "ios") - if(CMAKE_OSX_SYSROOT STREQUAL "iphonesimulator") - set(LIB_NAME ${LIB_NAME}-sim) - endif() -elseif(WINDOWS) - set(LIB_NAME ${APP_NAME}) - set(PLATFORM_DIR_NAME "windows") -endif() - -if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../${PLATFORM_DIR_NAME}) - set(PROJ_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../${PLATFORM_DIR_NAME}/proj) -else() - if(WINDOWS) - set(PROJ_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../platforms/win32) ## FIXME - else() - set(PROJ_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../platforms/${PLATFORM_DIR_NAME}) - endif() -endif() -set(GAME_RES_ROOT ${CMAKE_CURRENT_LIST_DIR}/../${PLATFORM_DIR_NAME}) - -if(RES_DIR) - set(GAME_RES_ROOT ${RES_DIR}/assets) - set(PROJ_SRC_DIR ${RES_DIR}/proj) - message(STATUS "Use resource diretory ${RES_DIR}") -endif() - -set(UI_RESOURCES) -set(PROJ_SOURCES) -set(PROJ_EXTRA_SOURCE) -set(PROJ_COMMON_SOURCES - Classes/Game.h - Classes/Game.cpp -) - -if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/Classes/jsb_module_register.cpp) - file(COPY "${cocosdir}/cocos/bindings/manual/jsb_module_register.cpp" - DESTINATION ${CMAKE_CURRENT_LIST_DIR}/Classes/) -endif() -list(APPEND PROJ_COMMON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/Classes/jsb_module_register.cpp) - - -if(WINDOWS) - set(UI_RESOURCES - ${PROJ_SRC_DIR}/game.rc - ) - list(APPEND PROJ_SOURCES - ${PROJ_SRC_DIR}/AppDelegate.h - ${PROJ_SRC_DIR}/AppDelegate.cpp - ${PROJ_SRC_DIR}/main.h - ${PROJ_SRC_DIR}/main.cpp - ${PROJ_SRC_DIR}/resource.h - ${UI_RESOURCES} - ) -elseif(MACOSX) - set(UI_RESOURCES - ${PROJ_SRC_DIR}/Assets.xcassets - ${PROJ_SRC_DIR}/Icon.icns - ) - list(APPEND PROJ_SOURCES - ${PROJ_SRC_DIR}/main.m - ${PROJ_SRC_DIR}/ViewController.mm - ${PROJ_SRC_DIR}/ViewController.h - ${PROJ_SRC_DIR}/AppDelegate.mm - ${PROJ_SRC_DIR}/AppDelegate.h - ${UI_RESOURCES} - ) -elseif(IOS) - - set(UI_RESOURCES - ${PROJ_SRC_DIR}/LaunchScreenBackground.png - ${PROJ_SRC_DIR}/Images.xcassets - ${PROJ_SRC_DIR}/Base.lproj/Localizable.strings - ${PROJ_SRC_DIR}/Base.lproj/LaunchScreen.storyboard - ) - - list(APPEND PROJ_SOURCES - ${PROJ_SRC_DIR}/AppDelegate.mm - ${PROJ_SRC_DIR}/AppDelegate.h - ${PROJ_SRC_DIR}/SDKWrapper.m - ${PROJ_SRC_DIR}/SDKWrapper.h - ${PROJ_SRC_DIR}/service/SDKDelegate.h - ${PROJ_SRC_DIR}/main.m - ${PROJ_SRC_DIR}/ViewController.mm - ${PROJ_SRC_DIR}/ViewController.h - ${UI_RESOURCES} - ) -elseif(ANDROID) - list(APPEND PROJ_SOURCES - ${PROJ_SRC_DIR}/jni/main.cpp - ) -endif() - -set(asset_files) -foreach(res ${GAME_RES_ROOT}) - set(res_list) - if(NOT EXISTS ${res}) - continue() - endif() - - if(IS_DIRECTORY ${res}) - file(GLOB_RECURSE res_list "${res}/*") - else() - set(res_list ${res}) - endif() - foreach(res ${res_list}) - get_filename_component(res_abs ${res} ABSOLUTE) - file(RELATIVE_PATH res_rel ${GAME_RES_ROOT} ${res_abs}) - get_filename_component(res_dir ${res_rel} PATH) - set_source_files_properties(${res_abs} PROPERTIES - MACOSX_PACKAGE_LOCATION "Resources/${res_dir}/" - HEADER_FILE_ONLY 1 - ) - list(APPEND asset_files ${res_abs}) - endforeach() -endforeach() - -if(ANDROID) - add_library(${LIB_NAME} SHARED ${PROJ_SOURCES} ${PROJ_EXTRA_SOURCE} ${PROJ_COMMON_SOURCES}) - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u ANativeActivity_onCreate") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosActivity_onCreateNative") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosActivity_onSurfaceCreateNative") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosActivity_onStartNative") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosActivity_onPauseNative") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosActivity_onResumeNative") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosActivity_onStopNative") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosActivity_onLowMemoryNative") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosActivity_onWindowFocusChangedNative") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosActivity_onSurfaceChangedNative") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosActivity_onSurfaceDestroyNative") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosTouchHandler_handleActionDown") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosTouchHandler_handleActionUp") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosTouchHandler_handleActionMove") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosTouchHandler_handleActionCancel") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosKeyCodeHandler_handleKeyDown") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosKeyCodeHandler_handleKeyUp") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosSurfaceView_nativeOnSizeChanged") - set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -u Java_com_cocos_lib_CocosOrientationHelper_nativeOnOrientationChanged") -elseif(APPLE OR MSVC) - add_executable(${LIB_NAME} ${PROJ_SOURCES} ${asset_files} ${PROJ_EXTRA_SOURCE} ${PROJ_COMMON_SOURCES}) - source_group(TREE ${GAME_RES_ROOT} PREFIX "Resources" FILES ${asset_files}) -else() - add_executable(${LIB_NAME} ${PROJ_SOURCES} ${PROJ_EXTRA_SOURCE} ${PROJ_COMMON_SOURCES}) -endif() - -target_link_libraries(${LIB_NAME} cocos2d) -target_include_directories(${LIB_NAME} PRIVATE - Classes -) - -source_group(TREE ${PROJ_SRC_DIR} PREFIX "Source Files" FILES ${PROJ_SOURCES}) -source_group(TREE ${CMAKE_CURRENT_LIST_DIR} PREFIX "Source Files" FILES ${PROJ_COMMON_SOURCES}) - -if(APPLE) - set_target_properties(${LIB_NAME} PROPERTIES MACOSX_BUNDLE 1) - set_target_properties(${LIB_NAME} PROPERTIES RESOURCE "${UI_RESOURCES}") - set(EXECUTABLE_NAME ${LIB_NAME}) # referenced in Info.plist - set(PRODUCT_NAME ${APP_NAME}) - if(MACOSX) - set(CMAKE_OSX_DEPLOYMENT_TARGET ${TARGET_OSX_VERSION}) - set(MACOSX_BUNDLE_GUI_IDENTIFIER org.cocos2dx.hellojavascript.mac) - set_target_properties(${LIB_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${PROJ_SRC_DIR}/Info.plist") - set_target_properties(${LIB_NAME} PROPERTIES - MACOSX_DEPLOYMENT_TARGET ${TARGET_OSX_VERSION} - ) - get_property(gles2_loc TARGET GLESv2 PROPERTY IMPORTED_LOCATION) - get_property(egl_loc TARGET EGL PROPERTY IMPORTED_LOCATION) - add_custom_command(TARGET ${LIB_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory $/../Frameworks - COMMAND ${CMAKE_COMMAND} -E copy ${gles2_loc} $/../Frameworks - COMMAND ${CMAKE_COMMAND} -E copy ${egl_loc} $/../Frameworks - ) - elseif(IOS) - set(MACOSX_BUNDLE_GUI_IDENTIFIER org.cocos2dx.hellojavascript.ios) - - target_include_directories(${LIB_NAME} PRIVATE ${PROJ_SRC_DIR}/service ) - - set_target_properties(${LIB_NAME} PROPERTIES - MACOSX_BUNDLE_INFO_PLIST "${PROJ_SRC_DIR}/Info.plist" - IOS_INSTALL_COMBINED YES - OSX_ARCHITECTURES "arm64;x86_64" - ) - set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "${DEVELOPMENT_TEAM}") - set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer") - set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon") - set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_LAUNCHSTORYBOARD_NAME "LaunchScreen") - set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${TARGET_IOS_VERSION}) - set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_ENABLE_BITCODE "NO") - set_property(TARGET ${LIB_NAME} PROPERTY XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "YES") - endif() - -elseif(WINDOWS) - set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${LIB_NAME}) - if(EXISTS ${GAME_RES_ROOT}/jsb-adapter) - set(bin_dir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) - add_custom_target(copy_resource ALL - COMMAND ${CMAKE_COMMAND} -E echo "Copying resources to ${bin_dir}" - COMMAND ${CMAKE_COMMAND} -E make_directory ${bin_dir}/Resources - COMMAND robocopy "${GAME_RES_ROOT}/" "${bin_dir}/Resources/" /MIR || (exit 0) - COMMAND ${CMAKE_COMMAND} -E echo "Copying resources done!" - ) - add_dependencies(${LIB_NAME} copy_resource) - set_target_properties(copy_resource PROPERTIES FOLDER Utils) - endif() - - target_include_directories(${LIB_NAME} PRIVATE - ${GAME_RES_ROOT}/proj - ) - - if(MSVC) - foreach(item ${WIN32_DLLS}) - get_filename_component(filename ${item} NAME) - get_filename_component(abs ${item} ABSOLUTE) - add_custom_command(TARGET ${LIB_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${abs} $/${filename} - ) - endforeach() - target_link_options(${LIB_NAME} PRIVATE /SUBSYSTEM:WINDOWS) - endif() -endif() diff --git a/native/templates/template-link/platforms/android/res/values/strings.xml b/native/templates/template-link/platforms/android/res/values/strings.xml deleted file mode 100644 index 2403f5dc60..0000000000 --- a/native/templates/template-link/platforms/android/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - HelloJavascript - \ No newline at end of file diff --git a/native/templates/template-link/platforms/android/settings.gradle b/native/templates/template-link/platforms/android/settings.gradle deleted file mode 100644 index b8c531e786..0000000000 --- a/native/templates/template-link/platforms/android/settings.gradle +++ /dev/null @@ -1,4 +0,0 @@ -include ':libcocos', ':instantapp' -project(':libcocos').projectDir = new File('${COCOS_ROOT}/cocos/platform/android/libcocos2dx') -include ':HelloJavascript' -project(':HelloJavascript').projectDir = new File(settingsDir, 'app') diff --git a/native/templates/template-link/platforms/mac/CMakeLists.txt b/native/templates/template-link/platforms/mac/CMakeLists.txt deleted file mode 100644 index f115bd314c..0000000000 --- a/native/templates/template-link/platforms/mac/CMakeLists.txt +++ /dev/null @@ -1,115 +0,0 @@ -macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE) - set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} - ${XCODE_VALUE}) -endmacro (set_xcode_property) - -message(STATUS "App: ${APP_NAME}...") - -# --------------------------------------------------------------------- -# set include files - -set(INCLUDE_FILES - ${GFX_EXTERNAL_PATH}/khronos - ${COCOS_SRC_PATH}/renderer/core - ${COCOS_SRC_PATH}/renderer/gfx-metal - ./GFXTest -) - -include_directories( ${INCLUDE_FILES} ) - -# --------------------------------------------------------------------- - -file(GLOB_RECURSE HEADER_FILES *.h) -file(GLOB_RECURSE SOURCE_CPP_FILES *.cpp *.cc) -file(GLOB_RECURSE SOURCE_C_FILES *.c) -file(GLOB_RECURSE SOURCE_MM_FILES *.m *.mm) - -set(APP_UI_RES - ${CMAKE_CURRENT_LIST_DIR}/../Resources/uv_checker_01.jpg - ${CMAKE_CURRENT_LIST_DIR}/Base.lproj/Main.storyboard - ${CMAKE_CURRENT_LIST_DIR}/Assets.xcassets/Contents.json - ${CMAKE_CURRENT_LIST_DIR}/Assets.xcassets/AppIcon.appiconset/Contents.json -) - -set(ALL_FILES - ${HEADER_FILES} - ${SOURCE_CPP_FILES} - ${SOURCE_C_FILES} - ${SOURCE_MM_FILES} - ${GFX_TESTCASE_HEADER} - ${GFX_TESTCASE_SOURCE} - ${APP_UI_RES} - ${CC_PLATFORM_SOURCES} - ${CC_BASE_HEADERS} - ${CC_BASE_SOURCES} - ${CC_MATH_HEADERS} - ${CC_MATH_SOURCES} - ${CC_EXTERNAL_SROUCES} - ${cc_common_res} - ${COCOS_SRC_PATH}/cocos2d.h - ${COCOS_SRC_PATH}/cocos2d.cpp - ) - -if(COCOS_UNICODE) - add_definitions("-DUNICODE -D_UNICODE") -endif() - -add_executable(${APP_NAME} MACOSX_BUNDLE ${ALL_FILES}) - -set_target_properties(${APP_NAME} PROPERTIES RESOURCE "${APP_UI_RES}") -set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/Info.plist") - -# Locate system libraries on macOS -find_library(APPKIT_LIBRARY AppKit) -find_library(METAL_LIBRARY Metal) -find_library(METALKIT_LIBRARY MetalKit) -list(APPEND PLATFORM_SPECIFIC_LIBS - ${APPKIT_LIBRARY} - ${METAL_LIBRARY} - ${METAL_KIT} -) - -target_link_libraries(${APP_NAME} - ${PLATFORM_SPECIFIC_LIBS} - Core - GFXMetal - ${CC_EXTERNAL_LIBS} - z -) - -target_include_directories(${APP_NAME} PUBLIC - ${PROJECT_SOURCE_DIR} - ${COCOS_SRC_PATH}/platform - ${COCOS_EXTERNAL_PATH}/sources - ${CC_EXTERNAL_INCLUDES} - ${CC_EXTERNAL_INCLUDES}/v8 -) - -if(MACOSX) - target_include_directories(${APP_NAME} PRIVATE - ##FIXME: bad dependency - ${COCOS_SRC_PATH}/platform/ios - ) -endif() - -source_group(TREE ${COCOS_SRC_PATH}/platform PREFIX "Header Files/platform" FILES ${CC_PLATFORM_SOURCES}) -source_group(TREE ${COCOS_SRC_PATH}/base PREFIX "Header Files/base" FILES ${CC_BASE_HEADERS}) -source_group(TREE ${COCOS_SRC_PATH}/base PREFIX "Source Files/base" FILES ${CC_BASE_SOURCES}) -source_group(TREE ${COCOS_SRC_PATH}/math PREFIX "Header Files/math" FILES ${CC_MATH_HEADERS}) -source_group(TREE ${COCOS_SRC_PATH}/math PREFIX "Source Files/math" FILES ${CC_MATH_SOURCES}) -source_group(TREE ${COCOS_EXTERNAL_PATH}/sources PREFIX "Header Files/external" FILES ${CC_EXTERNAL_SROUCES}) - -# setup default flags -target_compile_definitions(${APP_NAME} PUBLIC - $<$>:USE_VIDEO=0> - $<$>:USE_WEB_VIEW=0> - $<$>:USE_AUDIO=0> - $<$>:USE_SOCKET=0> - $<$>:USE_MIDDLEWARE=0> - $<$>:USE_SPINE=0> - $<$>:USE_DRAGONBONES=0> - $<$:USE_GFX_RENDERER=1> - $<$>:USE_V8_DEBUGGER=0> -) - -message(STATUS "${APP_NAME} configuration completed.") diff --git a/native/templates/template-link/platforms/win32/AppDelegate.cpp b/native/templates/win32/AppDelegate.cpp similarity index 100% rename from native/templates/template-link/platforms/win32/AppDelegate.cpp rename to native/templates/win32/AppDelegate.cpp diff --git a/native/templates/template-link/platforms/win32/AppDelegate.h b/native/templates/win32/AppDelegate.h similarity index 100% rename from native/templates/template-link/platforms/win32/AppDelegate.h rename to native/templates/win32/AppDelegate.h diff --git a/native/templates/win32/CMakeLists.txt b/native/templates/win32/CMakeLists.txt new file mode 100755 index 0000000000..7b77d2d238 --- /dev/null +++ b/native/templates/win32/CMakeLists.txt @@ -0,0 +1,77 @@ +cmake_minimum_required(VERSION 3.8) + +set(CMAKE_GENERATOR_PLATFORM win32) +set(APP_NAME "CocosGame" CACHE STRING "Project Name") +project(${APP_NAME} CXX) + +include(${CMAKE_CURRENT_LIST_DIR}/../common/CMakeLists.txt) + +set(LIB_NAME ${APP_NAME}) + +set(UI_RESOURCES) +set(PROJ_SOURCES) +set(PROJ_COMMON_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/Game.h + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/Game.cpp +) + +if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/jsb_module_register.cpp) + file(COPY "${COCOS_X_PATH}/cocos/bindings/manual/jsb_module_register.cpp" + DESTINATION ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/) +endif() +list(APPEND PROJ_COMMON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/../common/Classes/jsb_module_register.cpp) + +set(UI_RESOURCES + ${CMAKE_CURRENT_LIST_DIR}/game.rc +) +list(APPEND PROJ_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/AppDelegate.h + ${CMAKE_CURRENT_LIST_DIR}/AppDelegate.cpp + ${CMAKE_CURRENT_LIST_DIR}/main.h + ${CMAKE_CURRENT_LIST_DIR}/main.cpp + ${CMAKE_CURRENT_LIST_DIR}/resource.h + ${UI_RESOURCES} +) + +include_resources(${RES_DIR}/assets) + +add_executable(${LIB_NAME} + ${PROJ_SOURCES} + ${PROJ_COMMON_SOURCES} + ${ASSET_FILES} +) +source_group(TREE ${RES_DIR}/assets PREFIX "Resources" FILES ${ASSET_FILES}) +source_group(TREE ${CMAKE_CURRENT_LIST_DIR} PREFIX "Source Files" FILES ${PROJ_SOURCES}) +source_group(TREE ${CMAKE_CURRENT_LIST_DIR}/../common PREFIX "Source Files" FILES ${PROJ_COMMON_SOURCES}) + + +target_link_libraries(${LIB_NAME} cocos2d) +target_include_directories(${LIB_NAME} PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/../common/Classes + ${RES_DIR}/assets/proj +) + +set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${LIB_NAME}) + +if(EXISTS ${RES_DIR}/assets/jsb-adapter) + set(bin_dir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) + add_custom_target(copy_resource ALL + COMMAND ${CMAKE_COMMAND} -E echo "Copying resources to ${bin_dir}" + COMMAND ${CMAKE_COMMAND} -E make_directory ${bin_dir}/Resources + COMMAND robocopy "${RES_DIR}/assets/" "${bin_dir}/Resources/" /MIR || (exit 0) + COMMAND ${CMAKE_COMMAND} -E echo "Copying resources done!" + ) + add_dependencies(${LIB_NAME} copy_resource) + set_target_properties(copy_resource PROPERTIES FOLDER Utils) +endif() + +if(MSVC) + foreach(item ${WIN32_DLLS}) + get_filename_component(filename ${item} NAME) + get_filename_component(abs ${item} ABSOLUTE) + add_custom_command(TARGET ${LIB_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${abs} $/${filename} + ) + endforeach() + target_link_options(${LIB_NAME} PRIVATE /SUBSYSTEM:WINDOWS) +endif() \ No newline at end of file diff --git a/native/templates/template-link/platforms/win32/build-cfg.json b/native/templates/win32/build-cfg.json similarity index 100% rename from native/templates/template-link/platforms/win32/build-cfg.json rename to native/templates/win32/build-cfg.json diff --git a/native/templates/template-link/platforms/win32/game.rc b/native/templates/win32/game.rc similarity index 100% rename from native/templates/template-link/platforms/win32/game.rc rename to native/templates/win32/game.rc diff --git a/native/templates/template-link/platforms/win32/main.cpp b/native/templates/win32/main.cpp similarity index 100% rename from native/templates/template-link/platforms/win32/main.cpp rename to native/templates/win32/main.cpp diff --git a/native/templates/template-link/platforms/win32/main.h b/native/templates/win32/main.h similarity index 100% rename from native/templates/template-link/platforms/win32/main.h rename to native/templates/win32/main.h diff --git a/native/templates/template-link/platforms/win32/res/game.ico b/native/templates/win32/res/game.ico similarity index 100% rename from native/templates/template-link/platforms/win32/res/game.ico rename to native/templates/win32/res/game.ico diff --git a/native/templates/template-link/platforms/win32/resource.h b/native/templates/win32/resource.h similarity index 100% rename from native/templates/template-link/platforms/win32/resource.h rename to native/templates/win32/resource.h diff --git a/native/tools/travis-scripts/run-script.sh b/native/tools/travis-scripts/run-script.sh index 84b232c68f..6135e090b6 100755 --- a/native/tools/travis-scripts/run-script.sh +++ b/native/tools/travis-scripts/run-script.sh @@ -6,6 +6,8 @@ COCOS2DX_ROOT="$DIR"/../.. COCOS_CLI=$COCOS2DX_ROOT/tools/cocos-console/bin/cocos_cli.js TOJS_ROOT=$COCOS2DX_ROOT/tools/tojs +NATIVE_DIR=$COCOS2DX_ROOT/templates/android-template + if [ -z "$NDK_ROOT" ]; then export NDK_ROOT=$HOME/bin/android-ndk fi @@ -27,7 +29,7 @@ generate_bindings_glue_codes() { echo "Create auto-generated jsbinding glue codes." pushd $TOJS_ROOT - python -V + python -V python ./genbindings.py rm userconf.ini popd @@ -55,16 +57,25 @@ function setup_linux_andorid_sdk() function build_android() { echo "Compiling Android ... " - cd $COCOS2DX_ROOT/templates/template-link/platforms/android - sed -i "s@\${COCOS_ROOT}@$COCOS2DX_ROOT@g" app/build.gradle - sed -i "s@\${COCOS_ROOT}@$COCOS2DX_ROOT@g" instantapp/build.gradle - sed -i "s@RES_DIR@UNUSE_RES_DIR@g" app/build.gradle - sed -i "s@RES_DIR@UNUSE_RES_DIR@g" instantapp/build.gradle - sed -i "s@\${COCOS_ROOT}@$COCOS2DX_ROOT@g" ../../common/CMakeLists.txt + + cd $COCOS2DX_ROOT/templates/ + if [ ! -d android-template ]; then + cp -r android/template android-template + fi + cd $COCOS2DX_ROOT/templates/android/build + mkdir -p build-android/proj + touch build-android/proj/cfg.cmake + mkdir -p build-android/assets + + ASSET_DIR=$COCOS2DX_ROOT/templates/android/build/build-android/ + + sed -i "s@\${NATIVE_DIR}@$NATIVE_DIR@g" settings.gradle sed -i "s@\${COCOS_ROOT}@$COCOS2DX_ROOT@g" settings.gradle - sed -i "s@\${COCOS_PROJ_COMMON}@$COCOS2DX_ROOT/templates/template-link/common@g" app/build.gradle - sed -i "s@\${COCOS_PROJ_COMMON}@$COCOS2DX_ROOT/templates/template-link/common@g" instantapp/build.gradle - sed -i "s/^RELEASE_/#RELEASE_/g" gradle.properties + sed -i "s@\${NATIVE_DIR}@$NATIVE_DIR@g" build.gradle + sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDORID_NDK@g" gradle.properties + sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties + sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties + sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$COCOS2DX_ROOT@g" gradle.properties #echo "Compile Android - ndk-build ..." #./gradlew assembleDebug --quiet @@ -106,20 +117,24 @@ function mac_download_cmake() function build_macosx() { - NUM_OF_CORES=`getconf _NPROCESSORS_ONLN` + NUM_OF_CORES=`getconf _NPROCESSORS_ONLN` echo "Compiling MacOSX ... " - cd $COCOS2DX_ROOT/templates/template-link/platforms/mac - mkdir build-mac + cd $COCOS2DX_ROOT/templates/mac + mkdir -p build-mac/proj + touch build-mac/proj/cfg.cmake + mkdir build-mac/assets + + RES_DIR=$COCOS2DX_ROOT/templates/mac/build-mac cd build-mac - cmake ../../../common -GXcode -DCOCOS_ROOT=$COCOS2DX_ROOT -DCC_USE_METAL=ON -DCMAKE_OSX_ARCHITECTURES=x86_64 - cmake --build . --config Release -- -quiet -jobs $NUM_OF_CORES + cmake ../ -GXcode -DCC_USE_METAL=ON -DCMAKE_OSX_ARCHITECTURES=x86_64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT + cmake --build . --config Release -- -quiet -jobs $NUM_OF_CORES -arch x86_64 echo "Compile MacOSX X86_64 Release Done!" cd .. mkdir build-mac-apple-silicon cd build-mac-apple-silicon - cmake ../../../common -GXcode -DCOCOS_ROOT=$COCOS2DX_ROOT -DCC_USE_METAL=ON -DCC_USE_GLES3=OFF -DCMAKE_OSX_ARCHITECTURES=arm64 - cmake --build . --config Release -- -quiet -jobs $NUM_OF_CORES + cmake ../ -GXcode -DCC_USE_METAL=ON -DCC_USE_GLES3=OFF -DCMAKE_OSX_ARCHITECTURES=arm64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT + cmake --build . --config Release -- -quiet -jobs $NUM_OF_CORES -arch arm64 echo "Compile MacOSX ARM64 Release Done!" } @@ -128,13 +143,18 @@ function build_ios() NUM_OF_CORES=`getconf _NPROCESSORS_ONLN` echo "Compiling iOS ... " - cd $COCOS2DX_ROOT/templates/template-link/platforms/ios - mkdir build-ios + cd $COCOS2DX_ROOT/templates/ios + mkdir -p build-ios/proj + touch build-ios/proj/cfg.cmake + mkdir build-ios/assets cd build-ios - cmake ../../../common -GXcode -DCOCOS_ROOT=$COCOS2DX_ROOT -DCMAKE_SYSTEM_NAME=iOS \ + RES_DIR=$COCOS2DX_ROOT/templates/ios/build-ios + cmake ../ -GXcode -DCMAKE_SYSTEM_NAME=iOS \ -DCMAKE_OSX_SYSROOT=iphonesimulator \ -DCMAKE_OSX_ARCHITECTURES=x86_64 \ - -DCC_USE_METAL=ON + -DCC_USE_METAL=ON \ + -DRES_DIR=$RES_DIR \ + -DCOCOS_X_PATH=$COCOS2DX_ROOT cmake --build . --config Debug -- -quiet -jobs $NUM_OF_CORES -allowProvisioningUpdates echo "Compile iOS Done!" } @@ -142,10 +162,13 @@ function build_ios() function build_windows() { echo "Compiling Win32 ... " - cd $COCOS2DX_ROOT/templates/template-link/platforms/win32 - mkdir build-win32 + cd $COCOS2DX_ROOT/templates/win32 + mkdir -p build-win32/proj + touch build-win32/proj/cfg.cmake + mkdir build-win32/assets cd build-win32 - cmake ../../../common -G"Visual Studio 15 2017" -DCOCOS_ROOT=$COCOS2DX_ROOT + RES_DIR=$COCOS2DX_ROOT/templates/win32/build-win32 + cmake ../ -G"Visual Studio 15 2017" -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT cmake --build . --config Debug echo "Compile Win32 Debug Done!" cmake --build . --config Release