|
| 1 | +Subject: [PATCH] mac cmake |
| 2 | +--- |
| 3 | +Index: composeApp/build.gradle.kts |
| 4 | +IDEA additional info: |
| 5 | +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP |
| 6 | +<+>UTF-8 |
| 7 | +=================================================================== |
| 8 | +diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts |
| 9 | +--- a/composeApp/build.gradle.kts (revision dd6004d75563bc12b389f706ce3dad6275e41ce3) |
| 10 | ++++ b/composeApp/build.gradle.kts (date 1771140321233) |
| 11 | +@@ -22,7 +22,7 @@ |
| 12 | + jvmTarget.set(JvmTarget.JVM_21) |
| 13 | + } |
| 14 | + } |
| 15 | +- |
| 16 | ++ |
| 17 | + listOf( |
| 18 | + iosX64(), |
| 19 | + iosArm64(), |
| 20 | +@@ -33,12 +33,12 @@ |
| 21 | + isStatic = true |
| 22 | + } |
| 23 | + } |
| 24 | +- |
| 25 | ++ |
| 26 | + jvm("desktop") |
| 27 | +- |
| 28 | ++ |
| 29 | + sourceSets { |
| 30 | + val desktopMain by getting |
| 31 | +- |
| 32 | ++ |
| 33 | + androidMain.dependencies { |
| 34 | + implementation(compose.preview) |
| 35 | + implementation(libs.androidx.activity.compose) |
| 36 | +@@ -272,10 +272,17 @@ |
| 37 | + val generator = cmakeGenerator.get() |
| 38 | + val options = cmakeOptions.get() |
| 39 | + |
| 40 | ++ val cmakePath = findCMake() |
| 41 | ++ println("Using CMake: $cmakePath") |
| 42 | ++ |
| 43 | ++ // Get the current JVM path used by Gradle |
| 44 | ++ val javaHome = System.getProperty("java.home") |
| 45 | ++ |
| 46 | + // 1. Configure CMake |
| 47 | + execOps.exec { |
| 48 | + workingDir = workDir |
| 49 | +- commandLine("cmake", "-S", ".", "-B", "build-$platform", "-G", generator) |
| 50 | ++ environment("JAVA_HOME", javaHome) |
| 51 | ++ commandLine(cmakePath, "-S", ".", "-B", "build-$platform", "-G", generator) |
| 52 | + args(options) |
| 53 | + isIgnoreExitValue = false |
| 54 | + } |
| 55 | +@@ -283,10 +290,23 @@ |
| 56 | + // 2. Build CMake |
| 57 | + execOps.exec { |
| 58 | + workingDir = workDir |
| 59 | +- commandLine("cmake", "--build", "build-$platform", "--config", "Release") |
| 60 | ++ environment("JAVA_HOME", javaHome) |
| 61 | ++ commandLine(cmakePath, "--build", "build-$platform", "--config", "Release") |
| 62 | + isIgnoreExitValue = false |
| 63 | + } |
| 64 | + } |
| 65 | ++ |
| 66 | ++ private fun findCMake(): String { |
| 67 | ++ val candidates = listOf( |
| 68 | ++ "/opt/homebrew/bin/cmake", // macOS Apple Silicon |
| 69 | ++ "/usr/local/bin/cmake", // macOS Intel |
| 70 | ++ "/usr/bin/cmake" // Linux / macOS default |
| 71 | ++ ) |
| 72 | ++ for (path in candidates) { |
| 73 | ++ if (File(path).exists()) return path |
| 74 | ++ } |
| 75 | ++ return "cmake" // Fallback to command from PATH |
| 76 | ++ } |
| 77 | + } |
| 78 | + // 捕获 Configuration Phase 的变量,供 Execution Phase 使用,避免 configuration cache 问题 |
| 79 | + val rootDirVal = rootDir |
| 80 | +@@ -405,10 +425,10 @@ |
| 81 | + |
| 82 | + // 如果库不存在,则添加构建任务依赖 |
| 83 | + if (!libFile.exists() && currentPlatform.isNotEmpty()) { |
| 84 | +- println("原生库不存在,配置构建任务依赖...") |
| 85 | +- dependsOn("buildNativeLibFor$currentPlatform") |
| 86 | ++ println("原生库不存在,配置构建任务依赖...") |
| 87 | ++ dependsOn("buildNativeLibFor$currentPlatform") |
| 88 | + } else { |
| 89 | +- println("原生库已存在 (配置阶段检查)") |
| 90 | ++ println("原生库已存在 (配置阶段检查)") |
| 91 | + } |
| 92 | + // 捕获需要的路径字符串,供 doLast 使用 |
| 93 | + val cppLibsDirStr = cppLibsDirVal |
0 commit comments