mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
cmCoreTryCompile: Simplify TryCompileCode return type
The return value is only used as a boolean, so use `bool`.
This commit is contained in:
@@ -235,8 +235,8 @@ std::set<std::string> const ghs_platform_vars{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
bool cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
||||||
bool isTryRun)
|
bool isTryRun)
|
||||||
{
|
{
|
||||||
std::string const& resultVar = argv[0];
|
std::string const& resultVar = argv[0];
|
||||||
this->OutputFile.clear();
|
this->OutputFile.clear();
|
||||||
@@ -260,7 +260,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
"' and '",
|
"' and '",
|
||||||
cmState::GetTargetTypeName(cmStateEnums::STATIC_LIBRARY),
|
cmState::GetTargetTypeName(cmStateEnums::STATIC_LIBRARY),
|
||||||
"' are allowed."));
|
"' are allowed."));
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,7 +361,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
"IMPORTED LINK_LIBRARIES. Got ",
|
"IMPORTED LINK_LIBRARIES. Got ",
|
||||||
tgt->GetName(), " of type ",
|
tgt->GetName(), " of type ",
|
||||||
cmState::GetTargetTypeName(tgt->GetType()), "."));
|
cmState::GetTargetTypeName(tgt->GetType()), "."));
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
if (tgt->IsImported()) {
|
if (tgt->IsImported()) {
|
||||||
targets.emplace_back(argv[i]);
|
targets.emplace_back(argv[i]);
|
||||||
@@ -405,7 +405,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
this->BinaryDirectory, "'"));
|
this->BinaryDirectory, "'"));
|
||||||
// Do not try to clean up the ill-specified directory.
|
// Do not try to clean up the ill-specified directory.
|
||||||
this->BinaryDirectory.clear();
|
this->BinaryDirectory.clear();
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
// compute the binary dir when TRY_COMPILE is called with a src file
|
// compute the binary dir when TRY_COMPILE is called with a src file
|
||||||
// signature
|
// signature
|
||||||
@@ -415,7 +415,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
} else {
|
} else {
|
||||||
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
|
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
|
||||||
"No <bindir> specified.");
|
"No <bindir> specified.");
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->SrcFileSignature) {
|
if (this->SrcFileSignature) {
|
||||||
@@ -431,69 +431,69 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
if (didCopyFile && copyFile.empty()) {
|
if (didCopyFile && copyFile.empty()) {
|
||||||
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
|
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
|
||||||
"COPY_FILE must be followed by a file path");
|
"COPY_FILE must be followed by a file path");
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (didCopyFileError && copyFileError.empty()) {
|
if (didCopyFileError && copyFileError.empty()) {
|
||||||
this->Makefile->IssueMessage(
|
this->Makefile->IssueMessage(
|
||||||
MessageType::FATAL_ERROR,
|
MessageType::FATAL_ERROR,
|
||||||
"COPY_FILE_ERROR must be followed by a variable name");
|
"COPY_FILE_ERROR must be followed by a variable name");
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (didCopyFileError && !didCopyFile) {
|
if (didCopyFileError && !didCopyFile) {
|
||||||
this->Makefile->IssueMessage(
|
this->Makefile->IssueMessage(
|
||||||
MessageType::FATAL_ERROR,
|
MessageType::FATAL_ERROR,
|
||||||
"COPY_FILE_ERROR may be used only with COPY_FILE");
|
"COPY_FILE_ERROR may be used only with COPY_FILE");
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (didOutputVariable && outputVariable.empty()) {
|
if (didOutputVariable && outputVariable.empty()) {
|
||||||
this->Makefile->IssueMessage(
|
this->Makefile->IssueMessage(
|
||||||
MessageType::FATAL_ERROR,
|
MessageType::FATAL_ERROR,
|
||||||
"OUTPUT_VARIABLE must be followed by a variable name");
|
"OUTPUT_VARIABLE must be followed by a variable name");
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useSources && sources.empty()) {
|
if (useSources && sources.empty()) {
|
||||||
this->Makefile->IssueMessage(
|
this->Makefile->IssueMessage(
|
||||||
MessageType::FATAL_ERROR,
|
MessageType::FATAL_ERROR,
|
||||||
"SOURCES must be followed by at least one source file");
|
"SOURCES must be followed by at least one source file");
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only valid for srcfile signatures
|
// only valid for srcfile signatures
|
||||||
if (!this->SrcFileSignature) {
|
if (!this->SrcFileSignature) {
|
||||||
if (!cState.Validate(this->Makefile)) {
|
if (!cState.Validate(this->Makefile)) {
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
if (!cudaState.Validate(this->Makefile)) {
|
if (!cudaState.Validate(this->Makefile)) {
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
if (!hipState.Validate(this->Makefile)) {
|
if (!hipState.Validate(this->Makefile)) {
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
if (!cxxState.Validate(this->Makefile)) {
|
if (!cxxState.Validate(this->Makefile)) {
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
if (!objcState.Validate(this->Makefile)) {
|
if (!objcState.Validate(this->Makefile)) {
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
if (!objcxxState.Validate(this->Makefile)) {
|
if (!objcxxState.Validate(this->Makefile)) {
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!compileDefs.empty()) {
|
if (!compileDefs.empty()) {
|
||||||
this->Makefile->IssueMessage(
|
this->Makefile->IssueMessage(
|
||||||
MessageType::FATAL_ERROR,
|
MessageType::FATAL_ERROR,
|
||||||
"COMPILE_DEFINITIONS specified on a srcdir type TRY_COMPILE");
|
"COMPILE_DEFINITIONS specified on a srcdir type TRY_COMPILE");
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
if (!copyFile.empty()) {
|
if (!copyFile.empty()) {
|
||||||
this->Makefile->IssueMessage(
|
this->Makefile->IssueMessage(
|
||||||
MessageType::FATAL_ERROR,
|
MessageType::FATAL_ERROR,
|
||||||
"COPY_FILE specified on a srcdir type TRY_COMPILE");
|
"COPY_FILE specified on a srcdir type TRY_COMPILE");
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// make sure the binary directory exists
|
// make sure the binary directory exists
|
||||||
@@ -505,7 +505,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
e << "Attempt at a recursive or nested TRY_COMPILE in directory\n"
|
e << "Attempt at a recursive or nested TRY_COMPILE in directory\n"
|
||||||
<< " " << this->BinaryDirectory << "\n";
|
<< " " << this->BinaryDirectory << "\n";
|
||||||
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
|
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string outFileName = this->BinaryDirectory + "/CMakeLists.txt";
|
std::string outFileName = this->BinaryDirectory + "/CMakeLists.txt";
|
||||||
@@ -539,7 +539,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
err << cmJoin(langs, " ");
|
err << cmJoin(langs, " ");
|
||||||
err << "\nSee project() command to enable other languages.";
|
err << "\nSee project() command to enable other languages.";
|
||||||
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, err.str());
|
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, err.str());
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,7 +566,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
<< cmSystemTools::GetLastSystemError();
|
<< cmSystemTools::GetLastSystemError();
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
|
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmValue def = this->Makefile->GetDefinition("CMAKE_MODULE_PATH");
|
cmValue def = this->Makefile->GetDefinition("CMAKE_MODULE_PATH");
|
||||||
@@ -753,7 +753,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
|
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
|
||||||
"could not write export file.");
|
"could not write export file.");
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
fprintf(fout, "\ninclude(\"${CMAKE_CURRENT_LIST_DIR}/%s\")\n\n",
|
fprintf(fout, "\ninclude(\"${CMAKE_CURRENT_LIST_DIR}/%s\")\n\n",
|
||||||
fname.c_str());
|
fname.c_str());
|
||||||
@@ -1047,7 +1047,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
}
|
}
|
||||||
if (copyFileError.empty()) {
|
if (copyFileError.empty()) {
|
||||||
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, emsg.str());
|
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, emsg.str());
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
copyFileErrorMessage = emsg.str();
|
copyFileErrorMessage = emsg.str();
|
||||||
}
|
}
|
||||||
@@ -1057,7 +1057,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
this->Makefile->AddDefinition(copyFileError, copyFileErrorMessage);
|
this->Makefile->AddDefinition(copyFileError, copyFileErrorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmCoreTryCompile::CleanupFiles(std::string const& binDir)
|
void cmCoreTryCompile::CleanupFiles(std::string const& binDir)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public:
|
|||||||
* commands, such as TryRun can access the same logic without
|
* commands, such as TryRun can access the same logic without
|
||||||
* duplication.
|
* duplication.
|
||||||
*/
|
*/
|
||||||
int TryCompileCode(std::vector<std::string> const& argv, bool isTryRun);
|
bool TryCompileCode(std::vector<std::string> const& argv, bool isTryRun);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This deletes all the files created by TryCompileCode.
|
* This deletes all the files created by TryCompileCode.
|
||||||
|
|||||||
@@ -192,10 +192,10 @@ bool TryRunCommandImpl::TryRunCode(std::vector<std::string> const& argv)
|
|||||||
this->CompileResultVariable = argv[1];
|
this->CompileResultVariable = argv[1];
|
||||||
|
|
||||||
// do the try compile
|
// do the try compile
|
||||||
int res = this->TryCompileCode(tryCompile, true);
|
bool compiled = this->TryCompileCode(tryCompile, true);
|
||||||
|
|
||||||
// now try running the command if it compiled
|
// now try running the command if it compiled
|
||||||
if (!res) {
|
if (compiled) {
|
||||||
if (this->OutputFile.empty()) {
|
if (this->OutputFile.empty()) {
|
||||||
cmSystemTools::Error(this->FindErrorMessage);
|
cmSystemTools::Error(this->FindErrorMessage);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user