diff --git a/scripts/native-pack-tool/source/base/default.ts b/scripts/native-pack-tool/source/base/default.ts index bdbb75ecf99..3f9899653dc 100644 --- a/scripts/native-pack-tool/source/base/default.ts +++ b/scripts/native-pack-tool/source/base/default.ts @@ -368,6 +368,11 @@ export abstract class NativePackTool { return /^[0-9a-zA-Z_-]+$/.test(this.params.projectName) ? this.params.projectName : 'CocosGame'; } + protected getExcutableNameOrDefault(): string { + const en = this.params.executableName; + return en ? en : this.projectNameASCII(); + } + protected async excuteTemplateTask(tasks: CocosProjectTasks) { if (tasks.appendFile) { await Promise.all(tasks.appendFile.map((task) => { diff --git a/scripts/native-pack-tool/source/platforms/ios.ts b/scripts/native-pack-tool/source/platforms/ios.ts index 41400ced239..a2f69b5f2e5 100644 --- a/scripts/native-pack-tool/source/platforms/ios.ts +++ b/scripts/native-pack-tool/source/platforms/ios.ts @@ -225,7 +225,7 @@ export class IOSPackTool extends MacOSPackTool { } readBundleId(): string | null { - const prjName = this.params.projectName!; + const prjName = this.getExcutableNameOrDefault(); const cmakeTmpDir = fs.readdirSync(ps.join(this.paths.nativePrjDir, 'CMakeFiles')) .filter((x) => x.startsWith(prjName))[0]; diff --git a/scripts/native-pack-tool/source/platforms/windows.ts b/scripts/native-pack-tool/source/platforms/windows.ts index 6f5d1792032..7c7b1435215 100644 --- a/scripts/native-pack-tool/source/platforms/windows.ts +++ b/scripts/native-pack-tool/source/platforms/windows.ts @@ -137,22 +137,8 @@ export class WindowsPackTool extends NativePackTool { async run(): Promise { const executableDir = ps.join(this.paths.nativePrjDir, this.params.debug ? 'Debug' : 'Release') - let executableFile: string; - let targetFile: string; - if (this.params.executableName) { - executableFile = ps.join(executableDir, this.params.executableName + '.exe'); - targetFile = this.params.executableName; - } else { - if (/^[0-9a-zA-Z_-]+$/.test(this.params.projectName)) { - executableFile = ps.join(executableDir, this.params.projectName + '.exe'); - targetFile = this.params.projectName; - } else { - const executableFiles = ['CocosGame', this.params.projectName].map(x => ps.join(executableDir, x + '.exe')).filter(x => fs.existsSync(x)); - executableFile = executableFiles[0]; - targetFile = 'CocosGame'; - } - } - + const targetFile = this.getExcutableNameOrDefault(); + const executableFile = ps.join(executableDir, targetFile + '.exe'); if (!executableFile || !fs.existsSync(executableFile)) { throw new Error(`[windows run] '${targetFile}' is not found within ' + ${executableDir}!`); } diff --git a/templates/cmake/common.cmake b/templates/cmake/common.cmake index 5d5e733f9c0..3f506978b8a 100644 --- a/templates/cmake/common.cmake +++ b/templates/cmake/common.cmake @@ -133,7 +133,7 @@ macro(cc_common_after_target target_name) endif() target_compile_definitions(${target_name} PRIVATE - GAME_NAME="${APP_NAME}" + GAME_NAME="${CC_EXECUTABLE_NAME}" ) if(XXTEAKEY) target_compile_definitions(${target_name} PRIVATE