瀏覽代碼

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.
Brad King 3 年之前
父節點
當前提交
31ee3cd49d

+ 16 - 0
Source/cmCoreTryCompile.cxx

@@ -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 - 0
Tests/RunCMake/try_compile/BinDirEmpty-result.txt

@@ -0,0 +1 @@
+1

+ 4 - 0
Tests/RunCMake/try_compile/BinDirEmpty-stderr.txt

@@ -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 - 0
Tests/RunCMake/try_compile/BinDirEmpty.cmake

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

+ 1 - 0
Tests/RunCMake/try_compile/BinDirRelative-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
Tests/RunCMake/try_compile/BinDirRelative-stderr.txt

@@ -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 - 0
Tests/RunCMake/try_compile/BinDirRelative.cmake

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

+ 2 - 0
Tests/RunCMake/try_compile/RunCMakeTest.cmake

@@ -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 - 0
Tests/RunCMake/try_run/BinDirEmpty-result.txt

@@ -0,0 +1 @@
+1

+ 4 - 0
Tests/RunCMake/try_run/BinDirEmpty-stderr.txt

@@ -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 - 0
Tests/RunCMake/try_run/BinDirEmpty.cmake

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

+ 1 - 0
Tests/RunCMake/try_run/BinDirRelative-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
Tests/RunCMake/try_run/BinDirRelative-stderr.txt

@@ -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 - 0
Tests/RunCMake/try_run/BinDirRelative.cmake

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

+ 2 - 0
Tests/RunCMake/try_run/RunCMakeTest.cmake

@@ -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)$")