Pārlūkot izejas kodu

ENH: make relative paths optional and default off, and add a test for them

Bill Hoffman 21 gadi atpakaļ
vecāks
revīzija
d0cea4c7bb

+ 11 - 0
Source/CMakeLists.txt

@@ -322,6 +322,17 @@ IF(BUILD_TESTING)
       --build-exe-dir "${CMake_BINARY_DIR}/Tests/ComplexOneConfig/bin"
       --test-command complex)
 
+    ADD_TEST(complexRelativePaths  ${CMAKE_CTEST_COMMAND}
+      --build-and-test
+      "${CMake_SOURCE_DIR}/Tests/Complex"
+      "${CMake_BINARY_DIR}/Tests/ComplexRelativePaths"
+      --build-generator ${CMAKE_GENERATOR}
+      --build-project complex
+      --build-makeprogram ${MAKEPROGRAM}
+      --build-exe-dir "${CMake_BINARY_DIR}/Tests/ComplexRelativePaths/bin" 
+      --build-options -DCMAKE_USE_RELATIVE_PATHS:BOOL=ON
+      --test-command complex)
+
   ENDIF(NOT COMPILER_IS_COMO)
 
   ADD_TEST(Example ${CMAKE_CTEST_COMMAND}

+ 1 - 1
Source/cmLocalGenerator.cxx

@@ -354,7 +354,7 @@ std::string cmLocalGenerator::GetFullTargetName(const char* n,
 
 std::string cmLocalGenerator::ConvertToRelativeOutputPath(const char* p)
 {
-  if ( m_Makefile->GetDefinition("CMAKE_NO_RELATIVE_PATHS") )
+  if ( !m_Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS") )
     {
     return cmSystemTools::ConvertToOutputPath(p);
     }

+ 7 - 5
Source/cmLocalUnixMakefileGenerator.cxx

@@ -32,6 +32,7 @@ cmLocalUnixMakefileGenerator::cmLocalUnixMakefileGenerator()
   m_MakefileVariableSize = 0;
   m_IgnoreLibPrefix = false;
   m_PassMakeflags = false;
+  m_UseRelativePaths = false;
 }
 
 cmLocalUnixMakefileGenerator::~cmLocalUnixMakefileGenerator()
@@ -41,6 +42,7 @@ cmLocalUnixMakefileGenerator::~cmLocalUnixMakefileGenerator()
 
 void cmLocalUnixMakefileGenerator::Generate(bool fromTheTop)
 {
+  m_UseRelativePaths = m_Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
   // suppoirt override in output directories
   if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
     {
@@ -700,12 +702,12 @@ void cmLocalUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
     if(emitted.insert(libpath).second)
       {
       std::string fullLibPath;
-      if(!m_WindowsShell)
+      if(!m_WindowsShell && m_UseRelativePaths)
         {
         fullLibPath = "\"`cd ";
         }
       fullLibPath += libpath;
-      if(!m_WindowsShell)
+      if(!m_WindowsShell && m_UseRelativePaths)
         {
         fullLibPath += ";pwd`\"";
         }
@@ -1076,16 +1078,16 @@ void cmLocalUnixMakefileGenerator::OutputLibraryRule(std::ostream& fout,
 
   std::string outpath;
   std::string outdir = this->ConvertToRelativeOutputPath(m_LibraryOutputPath.c_str());
-  if(!m_WindowsShell && outdir.size())
+  if(!m_WindowsShell && m_UseRelativePaths && outdir.size())
     {
     outpath =  "\"`cd ";
     }
   outpath += outdir;
-  if(!m_WindowsShell && outdir.size())
+  if(!m_WindowsShell && m_UseRelativePaths && outdir.size())
     {
     outpath += ";pwd`\"/";
     }
-  if(outdir.size() == 0 && !m_WindowsShell)
+  if(outdir.size() == 0 && m_UseRelativePaths && !m_WindowsShell)
     {
     outpath = "\"`pwd`\"/";
     }

+ 1 - 0
Source/cmLocalUnixMakefileGenerator.h

@@ -246,6 +246,7 @@ protected:
   std::string m_ExecutableOutputPath;
   std::string m_LibraryOutputPath;
   bool m_WindowsShell;
+  bool m_UseRelativePaths;
   bool m_PassMakeflags;
 private:
 };

+ 11 - 0
Source/cmake.cxx

@@ -1085,6 +1085,17 @@ int cmake::Configure()
                                   "Single output directory for building all executables.",
                                   cmCacheManager::PATH);
     }  
+  if(!m_CacheManager->GetCacheValue("CMAKE_USE_RELATIVE_PATHS"))
+    {
+    m_CacheManager->AddCacheEntry("CMAKE_USE_RELATIVE_PATHS", false,
+                                  "If true, cmake will use relative paths in makefiles and projects.");
+    cmCacheManager::CacheIterator it =
+      m_CacheManager->GetCacheIterator("CMAKE_USE_RELATIVE_PATHS");
+    if ( !it.PropertyExists("ADVANCED") )
+      {
+      it.SetProperty("ADVANCED", "1");
+      }
+    }  
   
   if(cmSystemTools::GetFatalErrorOccured() &&
      (!this->m_CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") ||