mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-04 04:40:56 -06:00
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:
@@ -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");
|
||||
|
||||
1
Tests/RunCMake/try_compile/BinDirEmpty-result.txt
Normal file
1
Tests/RunCMake/try_compile/BinDirEmpty-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
4
Tests/RunCMake/try_compile/BinDirEmpty-stderr.txt
Normal file
4
Tests/RunCMake/try_compile/BinDirEmpty-stderr.txt
Normal 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\)$
|
||||
1
Tests/RunCMake/try_compile/BinDirEmpty.cmake
Normal file
1
Tests/RunCMake/try_compile/BinDirEmpty.cmake
Normal file
@@ -0,0 +1 @@
|
||||
try_compile(resultVar "" ${CMAKE_CURRENT_SOURCE_DIR}/src.c)
|
||||
1
Tests/RunCMake/try_compile/BinDirRelative-result.txt
Normal file
1
Tests/RunCMake/try_compile/BinDirRelative-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
6
Tests/RunCMake/try_compile/BinDirRelative-stderr.txt
Normal file
6
Tests/RunCMake/try_compile/BinDirRelative-stderr.txt
Normal 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\)$
|
||||
1
Tests/RunCMake/try_compile/BinDirRelative.cmake
Normal file
1
Tests/RunCMake/try_compile/BinDirRelative.cmake
Normal file
@@ -0,0 +1 @@
|
||||
try_compile(resultVar bin_dir_relative ${CMAKE_CURRENT_SOURCE_DIR}/src.c)
|
||||
@@ -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)
|
||||
|
||||
|
||||
1
Tests/RunCMake/try_run/BinDirEmpty-result.txt
Normal file
1
Tests/RunCMake/try_run/BinDirEmpty-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
4
Tests/RunCMake/try_run/BinDirEmpty-stderr.txt
Normal file
4
Tests/RunCMake/try_run/BinDirEmpty-stderr.txt
Normal 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\)$
|
||||
1
Tests/RunCMake/try_run/BinDirEmpty.cmake
Normal file
1
Tests/RunCMake/try_run/BinDirEmpty.cmake
Normal file
@@ -0,0 +1 @@
|
||||
try_run(runResultVar compileResultVar "" ${CMAKE_CURRENT_SOURCE_DIR}/src.c)
|
||||
1
Tests/RunCMake/try_run/BinDirRelative-result.txt
Normal file
1
Tests/RunCMake/try_run/BinDirRelative-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
6
Tests/RunCMake/try_run/BinDirRelative-stderr.txt
Normal file
6
Tests/RunCMake/try_run/BinDirRelative-stderr.txt
Normal 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\)$
|
||||
1
Tests/RunCMake/try_run/BinDirRelative.cmake
Normal file
1
Tests/RunCMake/try_run/BinDirRelative.cmake
Normal file
@@ -0,0 +1 @@
|
||||
try_run(runResultVar compileResultVar bin_dir_relative ${CMAKE_CURRENT_SOURCE_DIR}/src.c)
|
||||
@@ -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)$")
|
||||
|
||||
Reference in New Issue
Block a user