Skip to content

Commit e3741ee

Browse files
simplify cmake usage
1 parent b27b931 commit e3741ee

File tree

2 files changed

+2
-80
lines changed

2 files changed

+2
-80
lines changed

Modules/@babylonjs/react-native/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ In your app workspace, add a reference to BabylonReactNative project by adding t
2929
to your app `xcworkspace/content.xcworkspacedata` file.
3030

3131
#### CMake
32-
iOS NPM needs CMake 3.26+ to be present to generate Xcode project. If CMake is not in the default path (or an older version that can't be upgraded) a local version can be set and used with this variable:
33-
34-
```
35-
export BABYLON_CMAKE_PATH=/path/to/a/more/recent/cmake
36-
```
37-
3832
To disable post install CMake generation, set this variable before running `npm install`:
3933
```
4034
export BABYLON_NO_CMAKE_POSTINSTALL=1

Modules/@babylonjs/react-native/postinstall.js

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,9 @@
11
const os = require("os");
2-
const { spawn } = require('child_process');
32

43
function iosCMake() {
5-
const { spawn, spawnSync } = require('child_process');
6-
const fs = require('fs');
7-
const path = require('path');
4+
const { spawn } = require('child_process');
85

9-
// Determine cmake path in order of preference
10-
let cmakePath = process.env.BABYLON_CMAKE_PATH;
11-
12-
if (!cmakePath) {
13-
// Check if cmake-runtime package is installed
14-
try {
15-
// Try multiple ways to find cmake-runtime
16-
const possiblePaths = [
17-
path.join(__dirname, 'node_modules', 'cmake-runtime', 'bin', 'cmake'),
18-
path.join(process.cwd(), 'node_modules', 'cmake-runtime', 'bin', 'cmake'),
19-
path.join(__dirname, '..', 'node_modules', 'cmake-runtime', 'bin', 'cmake'),
20-
path.join(__dirname, '..', '..', 'node_modules', 'cmake-runtime', 'bin', 'cmake')
21-
];
22-
23-
for (const possiblePath of possiblePaths) {
24-
if (fs.existsSync(possiblePath)) {
25-
cmakePath = possiblePath;
26-
break;
27-
}
28-
}
29-
30-
// If not found by path, try require.resolve as fallback
31-
if (!cmakePath) {
32-
try {
33-
const cmakeRuntimePath = require.resolve('cmake-runtime/cmake');
34-
if (fs.existsSync(cmakeRuntimePath)) {
35-
cmakePath = cmakeRuntimePath;
36-
}
37-
} catch (e) {
38-
// cmake-runtime not resolvable
39-
console.warn(`cmake-runtime not resolvable.`);
40-
}
41-
}
42-
} catch (e) {
43-
// cmake-runtime not installed, continue to default
44-
console.warn(`CMake not found in installed packages.`);
45-
}
46-
}
47-
48-
if (!cmakePath) {
49-
cmakePath = 'cmake';
50-
}
51-
52-
// Check if cmake exists and get version
53-
const versionResult = spawnSync(cmakePath, ['--version'], { encoding: 'utf8' });
54-
55-
if (versionResult.error) {
56-
console.error('CMake is not installed or not found in PATH');
57-
process.exit(1);
58-
}
59-
60-
// Parse version from output (format: "cmake version 3.26.0")
61-
const versionMatch = versionResult.stdout.match(/cmake version (\d+)\.(\d+)\.(\d+)/);
62-
if (!versionMatch) {
63-
console.error('Unable to parse CMake version');
64-
process.exit(1);
65-
}
66-
67-
const majorVersion = parseInt(versionMatch[1]);
68-
const minorVersion = parseInt(versionMatch[2]);
69-
70-
// Check if version is >= 3.26
71-
if (majorVersion < 3 || (majorVersion === 3 && minorVersion < 26)) {
72-
console.error(`CMake version ${majorVersion}.${minorVersion} is not supported. Please upgrade to version 3.26 or higher.`);
73-
process.exit(1);
74-
}
75-
76-
console.log(`Using CMake version ${majorVersion}.${minorVersion}.${versionMatch[3]} from ${cmakePath}`);
77-
78-
const cmake = spawn(cmakePath, [
6+
const cmake = spawn('npx cmake', [
797
'-S', 'ios',
808
'-B', 'Build/iOS',
819
'-G', 'Xcode',

0 commit comments

Comments
 (0)