Merge topic 'emscripten-try_run'

a308ea38f3 Emscripten: Fix try_run to run the `.js` file and not the adjacent `.wasm`
ad91bc558a ci: Make node available to Emscripten tests
27cc5d58bf Tests/RunCMake/Emscripten: Add tests covering try_compile COPY_FILE

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11451
This commit is contained in:
Brad King
2025-11-26 14:59:19 +00:00
committed by Kitware Robot
11 changed files with 66 additions and 13 deletions

View File

@@ -1232,8 +1232,20 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
if ((res == 0) && arguments.CopyFileTo) {
std::string const& copyFile = *arguments.CopyFileTo;
std::string outputFile = this->OutputFile;
// Emscripten `.js` executables have an adjacent `.wasm` file with the
// actual compiled binary. Our COPY_FILE clients need the latter.
if (cmHasLiteralSuffix(outputFile, ".js")) {
std::string wasmOutput =
cmStrCat(outputFile.substr(0, outputFile.length() - 3), ".wasm");
if (cmSystemTools::FileExists(wasmOutput)) {
outputFile = std::move(wasmOutput);
}
}
cmsys::SystemTools::CopyStatus status =
cmSystemTools::CopyFileAlways(this->OutputFile, copyFile);
cmSystemTools::CopyFileAlways(outputFile, copyFile);
if (!status) {
std::string err = status.GetString();
switch (status.Path) {
@@ -1249,7 +1261,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
/* clang-format off */
err = cmStrCat(
"Cannot copy output executable\n"
" '", this->OutputFile, "'\n"
" '", outputFile, "'\n"
"to destination specified by COPY_FILE:\n"
" '", copyFile, "'\n"
"because:\n"
@@ -1388,14 +1400,6 @@ void cmCoreTryCompile::FindOutputFile(std::string const& targetName)
return;
}
if (cmHasLiteralSuffix(outputFileLocation, ".js")) {
std::string wasmOutputLocation = cmStrCat(
outputFileLocation.substr(0, outputFileLocation.length() - 3), ".wasm");
if (cmSystemTools::FileExists(wasmOutputLocation)) {
outputFileLocation = wasmOutputLocation;
}
}
this->OutputFile = cmSystemTools::CollapseFullPath(outputFileLocation);
}