try_compile: Fail earlier when bindir is not an absolute path

If the bindir is not an absolute path, other errors occur later.
Fail early with a clear error in this case.
This commit is contained in:
Brad King
2022-06-15 14:30:35 -04:00
parent 5fc4e121a1
commit 31ee3cd49d
15 changed files with 48 additions and 0 deletions

View File

@@ -391,6 +391,22 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
}
}
if (!this->BinaryDirectory.empty()) {
if (!cmSystemTools::FileIsFullPath(this->BinaryDirectory)) {
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("<bindir> is not an absolute path:\n '",
this->BinaryDirectory, "'"));
// Do not try to clean up the ill-specified directory.
this->BinaryDirectory.clear();
return -1;
}
} else {
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"No <bindir> specified.");
return -1;
}
if (didCopyFile && copyFile.empty()) {
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"COPY_FILE must be followed by a file path");

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,4 @@
^CMake Error at BinDirEmpty.cmake:[0-9]+ \(try_compile\):
No <bindir> specified.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1 @@
try_compile(resultVar "" ${CMAKE_CURRENT_SOURCE_DIR}/src.c)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,6 @@
^CMake Error at BinDirRelative.cmake:[0-9]+ \(try_compile\):
<bindir> is not an absolute path:
'bin_dir_relative'
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1 @@
try_compile(resultVar bin_dir_relative ${CMAKE_CURRENT_SOURCE_DIR}/src.c)

View File

@@ -15,6 +15,8 @@ run_cmake(BadSources1)
run_cmake(BadSources2)
run_cmake(NonSourceCopyFile)
run_cmake(NonSourceCompileDefinitions)
run_cmake(BinDirEmpty)
run_cmake(BinDirRelative)
run_cmake(EnvConfig)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,4 @@
^CMake Error at BinDirEmpty.cmake:[0-9]+ \(try_run\):
No <bindir> specified.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1 @@
try_run(runResultVar compileResultVar "" ${CMAKE_CURRENT_SOURCE_DIR}/src.c)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,6 @@
^CMake Error at BinDirRelative.cmake:[0-9]+ \(try_run\):
<bindir> is not an absolute path:
'bin_dir_relative'
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1 @@
try_run(runResultVar compileResultVar bin_dir_relative ${CMAKE_CURRENT_SOURCE_DIR}/src.c)

View File

@@ -1,6 +1,8 @@
include(RunCMake)
run_cmake(BadLinkLibraries)
run_cmake(BinDirEmpty)
run_cmake(BinDirRelative)
if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND
CMAKE_C_COMPILER_ID MATCHES "^(MSVC|GNU|LCC|Clang|AppleClang)$")