Procházet zdrojové kódy

ENH: add the unix makefile generator as an option from the windows GUI, this builds with mingw, cygwin, and combinations of make cl, bcc32

Bill Hoffman před 22 roky
rodič
revize
a413160fec

+ 10 - 0
Modules/CMakeCCompiler.cmake.in

@@ -3,4 +3,14 @@ SET(CMAKE_AR "@CMAKE_AR@")
 SET(CMAKE_RANLIB "@CMAKE_RANLIB@")
 SET(CMAKE_COMPILER_IS_GNUCC @CMAKE_COMPILER_IS_GNUCC@)
 SET(CMAKE_C_COMPILER_LOADED 1)
+SET(CMAKE_COMPILER_IS_MINGW @CMAKE_COMPILER_IS_MINGW@)
+SET(CMAKE_COMPILER_IS_CYGWIN @CMAKE_COMPILER_IS_CYGWIN@)
+IF(CMAKE_COMPILER_IS_CYGWIN)
+  SET(CYGWIN 1)
+  SET(UNIX 1)
+ENDIF(CMAKE_COMPILER_IS_CYGWIN)
+
+IF(CMAKE_COMPILER_IS_MINGW)
+  SET(MINGW 1)
+ENDIF(CMAKE_COMPILER_IS_MINGW)
 

+ 7 - 0
Modules/CMakeDetermineCCompiler.cmake

@@ -59,6 +59,13 @@ IF(NOT CMAKE_COMPILER_RETURN)
       "Determining if the C compiler is GNU failed with "
       "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
   ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
+  IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_MINGW.*" )
+    SET(CMAKE_COMPILER_IS_MINGW 1)
+  ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_MINGW.*" )
+  IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
+    SET(CMAKE_COMPILER_IS_CYGWIN 1)
+  ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
+
 ENDIF(NOT CMAKE_COMPILER_RETURN)
 
 

+ 2 - 2
Modules/CMakeSystemSpecificInformation.cmake

@@ -57,9 +57,9 @@ ENDIF(EXISTS ${CMAKE_SYSTEM_INFO_FILE})
 IF(CMAKE_C_COMPILER)
   GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_C_COMPILER} NAME_WE)
   # since the gnu compiler has several names force gcc
-  IF(CMAKE_COMPILER_IS_GNUGCC)
+  IF(CMAKE_COMPILER_IS_GNUCC)
      SET(CMAKE_BASE_NAME gcc)
-  ENDIF(CMAKE_COMPILER_IS_GNUGCC)
+  ENDIF(CMAKE_COMPILER_IS_GNUCC)
   SET(CMAKE_SYSTEM_AND_C_COMPILER_INFO_FILE 
       ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake)
   INCLUDE(${CMAKE_SYSTEM_AND_C_COMPILER_INFO_FILE} OPTIONAL)

+ 1 - 1
Modules/CMakeTestCCompiler.cmake

@@ -1,6 +1,6 @@
 # This file is used by EnableLanguage in cmGlobalGenerator to
 # determine that that selected C compiler can actually compile
-# and like the most basic of programs.   If not, a fatel error
+# and link the most basic of programs.   If not, a fatel error
 # is set and cmake stops processing commands and will not generate
 # any makefiles or projects.
 IF(NOT CMAKE_C_COMPILER_WORKS)

+ 1 - 1
Modules/CMakeTestCXXCompiler.cmake

@@ -1,6 +1,6 @@
 # This file is used by EnableLanguage in cmGlobalGenerator to
 # determine that that selected C++ compiler can actually compile
-# and like the most basic of programs.   If not, a fatel error
+# and link the most basic of programs.   If not, a fatel error
 # is set and cmake stops processing commands and will not generate
 # any makefiles or projects.
 IF(NOT CMAKE_CXX_COMPILER_WORKS)

+ 6 - 0
Modules/CMakeTestGNU.c

@@ -1,3 +1,9 @@
 #ifdef __GNUC__
 void THIS_IS_GNU();
 #endif
+#ifdef __MINGW32__
+void THIS_IS_MINGW();
+#endif
+#ifdef __CYGWIN__
+void THIS_IS_CYGWIN();
+#endif

+ 1 - 2
Modules/Platform/Windows-bcc32.cmake

@@ -14,9 +14,8 @@ SET(CMAKE_LIBRARY_PATH_FLAG "-L")
 SET(CMAKE_LINK_LIBRARY_FLAG "")
 SET(CMAKE_SHARED_BUILD_CXX_FLAGS "-tWR")
 SET(CMAKE_SHARED_BUILD_C_FLAGS "-tWR")
+SET(BORLAND 1)
 
-SET(CMAKE_START_TEMP_FILE "@&&|\n")
-SET(CMAKE_END_TEMP_FILE "\n|")
 # uncomment these out to debug makefiles
 #SET(CMAKE_START_TEMP_FILE "")
 #SET(CMAKE_END_TEMP_FILE "")

+ 1 - 8
Modules/Platform/Windows-cl.cmake

@@ -1,13 +1,6 @@
 SET(CMAKE_LIBRARY_PATH_FLAG "-LIBPATH:")
 SET(CMAKE_LINK_LIBRARY_FLAG "")
-
-SET(CMAKE_START_TEMP_FILE "@<<\n")
-SET(CMAKE_END_TEMP_FILE "\n<<")
-# uncomment these out to debug makefiles
-#SET(CMAKE_START_TEMP_FILE "")
-#SET(CMAKE_END_TEMP_FILE "")
-#SET(CMAKE_VERBOSE_MAKEFILE 1)
-
+SET(WIN32 1)
 # create a shared C++ library
 SET(CMAKE_CXX_CREATE_SHARED_LIBRARY 
  "link /nologo ${CMAKE_START_TEMP_FILE}  /out:<TARGET> /dll  <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}")

+ 22 - 0
Modules/Platform/Windows.cmake

@@ -4,3 +4,25 @@ SET(CMAKE_SHARED_LIBRARY_PREFIX "")          # lib
 SET(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")          # .so
 SET(CMAKE_LINK_LIBRARY_SUFFIX ".lib")
 SET(CMAKE_DL_LIBS "")
+
+# for borland make long command lines are redirected to a file
+# with the following syntax, see Windows-bcc32.cmake for use
+IF(CMAKE_GENERATOR MATCHES "Borland")
+  SET(CMAKE_START_TEMP_FILE "@&&|\n")
+  SET(CMAKE_END_TEMP_FILE "\n|")
+ENDIF(CMAKE_GENERATOR MATCHES "Borland")
+
+# for nmake make long command lines are redirected to a file
+# with the following syntax, see Windows-bcc32.cmake for use
+IF(CMAKE_GENERATOR MATCHES "NMake")
+  SET(CMAKE_START_TEMP_FILE "@<<\n")
+  SET(CMAKE_END_TEMP_FILE "\n<<")
+ENDIF(CMAKE_GENERATOR MATCHES "NMake")
+
+# uncomment these out to debug nmake and borland makefiles
+#SET(CMAKE_START_TEMP_FILE "")
+#SET(CMAKE_END_TEMP_FILE "")
+#SET(CMAKE_VERBOSE_MAKEFILE 1)
+
+  
+

+ 25 - 20
Source/CMakeLists.txt

@@ -65,22 +65,25 @@ ENDIF (APPLE)
 IF (WIN32)
   IF(NOT UNIX)
     SET(SRCS ${SRCS}
-                    cmGlobalBorlandMakefileGenerator.cxx
-                    cmGlobalNMakeMakefileGenerator.cxx
-                    cmGlobalVisualStudio6Generator.cxx
-                    cmLocalVisualStudio6Generator.cxx
-                    cmGlobalVisualStudio71Generator.cxx
-                    cmGlobalVisualStudio7Generator.cxx
-                    cmLocalVisualStudio7Generator.cxx
-                    cmGlobalBorlandMakefileGenerator.h
-                    cmGlobalNMakeMakefileGenerator.h
-                    cmGlobalVisualStudio6Generator.h
-                    cmLocalVisualStudio6Generator.h
-                    cmGlobalVisualStudio7Generator.h
-                    cmLocalVisualStudio7Generator.h
-		    cmWin32ProcessExecution.cxx
-		    cmWin32ProcessExecution.h
-                    )
+      cmGlobalBorlandMakefileGenerator.cxx
+      cmGlobalNMakeMakefileGenerator.cxx
+      cmGlobalVisualStudio6Generator.cxx
+      cmLocalVisualStudio6Generator.cxx
+      cmGlobalBorlandMakefileGenerator.h
+      cmGlobalNMakeMakefileGenerator.h
+      cmGlobalVisualStudio6Generator.h
+      cmLocalVisualStudio6Generator.h
+      cmWin32ProcessExecution.cxx
+      cmWin32ProcessExecution.h
+      )
+    IF(NOT MINGW)
+      SET(SRCS ${SRCS}
+        cmGlobalVisualStudio7Generator.h
+        cmLocalVisualStudio7Generator.h
+        cmGlobalVisualStudio71Generator.cxx
+        cmGlobalVisualStudio7Generator.cxx
+        cmLocalVisualStudio7Generator.cxx)
+    ENDIF(NOT MINGW)
   ENDIF(NOT UNIX)
 ENDIF (WIN32)
 
@@ -95,10 +98,12 @@ LINK_DIRECTORIES(${CMake_BINARY_DIR}/Source)
 IF (WIN32)
   IF(NOT UNIX)
     IF( NOT BORLAND )
-      LINK_LIBRARIES( rpcrt4.lib )
-      ADD_EXECUTABLE(cmw9xcom cmw9xcom.cxx)
-      TARGET_LINK_LIBRARIES(cmw9xcom CMakeLib)
-      SUBDIRS(MFCDialog)
+      IF(NOT MINGW )
+        LINK_LIBRARIES( rpcrt4.lib )
+        ADD_EXECUTABLE(cmw9xcom cmw9xcom.cxx)
+        TARGET_LINK_LIBRARIES(cmw9xcom CMakeLib)
+        SUBDIRS(MFCDialog)
+      ENDIF(NOT MINGW )
     ENDIF( NOT BORLAND )
   ENDIF(NOT UNIX)
 ENDIF (WIN32)

+ 1 - 1
Source/CTest/Curl/telnet.c

@@ -1105,7 +1105,7 @@ CURLcode Curl_telnet(struct connectdata *conn)
         ssize_t bytes_written;
         char *buffer = buf;
               
-        if(!ReadFile(stdin_handle, buf, 255, &(DWORD)nread, NULL)) {
+        if(!ReadFile(stdin_handle, buf, 255, ((DWORD*)&nread), NULL)) {
           keepon = FALSE;
           break;
         }

+ 1 - 1
Source/cmDynamicLoader.cxx

@@ -266,7 +266,7 @@ cmDynamicLoader::GetSymbolAddress(cmLibHandle lib, const char* sym)
   delete [] wsym;
   void* result = ret;
 #else
-  void* result = GetProcAddress(lib, sym);
+  void* result = (void*)GetProcAddress(lib, sym);
 #endif
   // Hack to cast pointer-to-data to pointer-to-function.
   return *reinterpret_cast<cmDynamicLoaderFunction*>(&result);

+ 1 - 0
Source/cmGlobalBorlandMakefileGenerator.cxx

@@ -21,6 +21,7 @@
 cmGlobalBorlandMakefileGenerator::cmGlobalBorlandMakefileGenerator()
 {
   m_FindMakeProgramFile = "CMakeBorlandFindMake.cmake";
+  m_ForceUnixPaths = false;
 }
 
 void cmGlobalBorlandMakefileGenerator::EnableLanguage(const char* l,

+ 2 - 1
Source/cmGlobalGenerator.cxx

@@ -28,7 +28,8 @@ int cmGlobalGenerator::s_TryCompileTimeout = 0;
 
 cmGlobalGenerator::cmGlobalGenerator()
 {
-// do nothing duh
+  // by default use the native paths
+  m_ForceUnixPaths = false;
 }
 
 cmGlobalGenerator::~cmGlobalGenerator()

+ 2 - 0
Source/cmGlobalGenerator.h

@@ -104,7 +104,9 @@ public:
   void GetLocalGenerators(std::vector<cmLocalGenerator *>&g) { g = m_LocalGenerators;}
   static int s_TryCompileTimeout;
   
+  bool GetForceUnixPaths() {return m_ForceUnixPaths;}
 protected:
+  bool m_ForceUnixPaths;
   cmStdString m_FindMakeProgramFile;
   cmStdString m_ConfiguredFilesPath;
   cmake *m_CMakeInstance;

+ 1 - 0
Source/cmGlobalNMakeMakefileGenerator.cxx

@@ -22,6 +22,7 @@
 cmGlobalNMakeMakefileGenerator::cmGlobalNMakeMakefileGenerator()
 {
   m_FindMakeProgramFile = "CMakeNMakeFindMake.cmake";
+  m_ForceUnixPaths = false;
 }
 
 void cmGlobalNMakeMakefileGenerator::EnableLanguage(const char* l,

+ 2 - 0
Source/cmGlobalUnixMakefileGenerator.cxx

@@ -22,6 +22,8 @@
 
 cmGlobalUnixMakefileGenerator::cmGlobalUnixMakefileGenerator()
 {
+  // This type of makefile always requires unix style paths
+  m_ForceUnixPaths = true;
   m_FindMakeProgramFile = "CMakeUnixFindMake.cmake";
 }
 

+ 1 - 1
Source/cmLocalUnixMakefileGenerator.cxx

@@ -2117,7 +2117,7 @@ cmLocalUnixMakefileGenerator::ConvertToOutputForExisting(const char* p)
       {
       if(!cmSystemTools::GetShortPath(ret.c_str(), ret))
         {
-        ret = p;
+        ret = cmSystemTools::ConvertToOutputPath(p);
         }
       }
     }

+ 15 - 0
Source/cmSystemTools.cxx

@@ -48,6 +48,7 @@ bool cmSystemTools::s_DisableRunCommandOutput = false;
 bool cmSystemTools::s_ErrorOccured = false;
 bool cmSystemTools::s_FatalErrorOccured = false;
 bool cmSystemTools::s_DisableMessages = false;
+bool cmSystemTools::s_ForceUnixPaths = false;
 
 std::string cmSystemTools::s_Windows9xComspecSubstitute = "command.com";
 void cmSystemTools::SetWindows9xComspecSubstitute(const char* str)
@@ -1032,3 +1033,17 @@ bool cmSystemTools::Split(const char* s, std::vector<cmStdString>& l)
     }
   return true;
 }
+
+std::string cmSystemTools::ConvertToOutputPath(const char* path)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+  if(s_ForceUnixPaths)
+    {
+    return cmSystemTools::ConvertToUnixOutputPath(path);
+    }
+  return cmSystemTools::ConvertToWindowsOutputPath(path);
+#else
+  return cmSystemTools::ConvertToUnixOutputPath(path);
+#endif
+}
+

+ 7 - 1
Source/cmSystemTools.h

@@ -235,8 +235,14 @@ public:
   /** Split a string on its newlines into multiple lines.  Returns
       false only if the last line stored had no newline.  */
   static bool Split(const char* s, std::vector<cmStdString>& l);  
-
+  static void SetForceUnixPaths(bool v)
+    {
+      s_ForceUnixPaths = v;
+    }
+  static std::string ConvertToOutputPath(const char* path);
+  
 private:
+  static bool s_ForceUnixPaths;
   static bool s_RunCommandHideConsole;
   static bool s_ErrorOccured;
   static bool s_FatalErrorOccured;

+ 19 - 7
Source/cmWin32ProcessExecution.cxx

@@ -291,16 +291,17 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
 {
   PROCESS_INFORMATION piProcInfo;
   STARTUPINFO siStartInfo;
-  char *s1,*s2, *s3 = " /c ";
+  char *s1=0,*s2=0, *s3 = " /c ";
   int i;
   int x;
   if (i = GetEnvironmentVariable("COMSPEC",NULL,0)) 
     {
     char *comshell;
 
-    s1 = (char *)_alloca(i);
+    s1 = (char *)malloc(i);
     if (!(x = GetEnvironmentVariable("COMSPEC", s1, i)))
       {
+      free(s1);
       return x;
       }
 
@@ -317,7 +318,7 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
       {
       /* NT/2000 and not using command.com. */
       x = i + (int)strlen(s3) + (int)strlen(cmdstring) + 1;
-      s2 = (char *)_alloca(x);
+      s2 = (char *)malloc(x);
       ZeroMemory(s2, x);
       //sprintf(s2, "%s%s%s", s1, s3, cmdstring);
       sprintf(s2, "%s", cmdstring);
@@ -366,15 +367,20 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
             << "Can not locate '" << modulepath
             << "' which is needed "
             "for popen to work with your shell "
-            "or platform." << std::endl;
+            "or platform." << std::endl;    
+          free(s1);
+          free(s2);
           return FALSE;
           }
         }
       x = i + (int)strlen(s3) + (int)strlen(cmdstring) + 1 +
         (int)strlen(modulepath) + 
         (int)strlen(szConsoleSpawn) + 1;
-
-      s2 = (char *)_alloca(x);
+      if(s2)
+        {
+        free(s2);
+        }
+      s2 = (char *)malloc(x);
       ZeroMemory(s2, x);
       sprintf(
         s2,
@@ -396,7 +402,9 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
   else 
     {
     std::cout << "Cannot locate a COMSPEC environment variable to "
-              << "use as the shell" << std::endl;
+              << "use as the shell" << std::endl; 
+    free(s2);
+    free(s1);
     return FALSE;
     }
   
@@ -429,11 +437,15 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
     /* Return process handle */
     *hProcess = piProcInfo.hProcess;
     //std::cout << "Process created..." << std::endl;
+    free(s2);
+    free(s1);
     return TRUE;
     }
   output += "CreateProcessError ";
   output += s2;
   output += "\n";
+  free(s2);
+  free(s1);
   return FALSE;
 }
 

+ 18 - 1
Source/cmake.cxx

@@ -26,10 +26,13 @@
 // include the generator
 #if defined(_WIN32) && !defined(__CYGWIN__)
 #include "cmGlobalVisualStudio6Generator.h"
+#if !defined(__MINGW32__)
 #include "cmGlobalVisualStudio7Generator.h"
 #include "cmGlobalVisualStudio71Generator.h"
+#endif
 #include "cmGlobalBorlandMakefileGenerator.h"
 #include "cmGlobalNMakeMakefileGenerator.h"
+#include "cmGlobalUnixMakefileGenerator.h"
 #include "cmWin32ProcessExecution.h"
 #else
 #include "cmGlobalUnixMakefileGenerator.h"
@@ -795,6 +798,10 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
 
   // set the new
   m_GlobalGenerator = gg;
+  // set the global flag for unix style paths on cmSystemTools as 
+  // soon as the generator is set.  This allows gmake to be used
+  // on windows.
+  cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
   // Save the environment variables CXX and CC
   m_CXXEnvironment = getenv("CXX");
   m_CCEnvironment = getenv("CC");    
@@ -877,6 +884,10 @@ int cmake::Configure()
     if(genName)
       {
       m_GlobalGenerator = this->CreateGlobalGenerator(genName);
+      // set the global flag for unix style paths on cmSystemTools as 
+      // soon as the generator is set.  This allows gmake to be used
+      // on windows.
+      cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
       }
     else
       {
@@ -1065,6 +1076,10 @@ int cmake::LocalGenerate()
   if(genName)
     {
     m_GlobalGenerator = this->CreateGlobalGenerator(genName);
+    // set the global flag for unix style paths on cmSystemTools as 
+    // soon as the generator is set.  This allows gmake to be used
+    // on windows.
+    cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
     }
   else
     {
@@ -1151,10 +1166,12 @@ void cmake::AddDefaultGenerators()
 #if defined(_WIN32) && !defined(__CYGWIN__)
   m_Generators[cmGlobalVisualStudio6Generator::GetActualName()] =
     &cmGlobalVisualStudio6Generator::New;
+#if !defined(__MINGW32__)
   m_Generators[cmGlobalVisualStudio7Generator::GetActualName()] =
     &cmGlobalVisualStudio7Generator::New;
   m_Generators[cmGlobalVisualStudio71Generator::GetActualName()] =
     &cmGlobalVisualStudio71Generator::New;
+#endif
   m_Generators[cmGlobalBorlandMakefileGenerator::GetActualName()] =
     &cmGlobalBorlandMakefileGenerator::New;
   m_Generators[cmGlobalNMakeMakefileGenerator::GetActualName()] =
@@ -1164,9 +1181,9 @@ void cmake::AddDefaultGenerators()
   m_Generators[cmGlobalCodeWarriorGenerator::GetActualName()] =
     &cmGlobalCodeWarriorGenerator::New;
 # endif
+#endif
   m_Generators[cmGlobalUnixMakefileGenerator::GetActualName()] =
     &cmGlobalUnixMakefileGenerator::New;
-#endif
 }
 
 int cmake::LoadCache()

+ 1 - 1
Source/kwsys/SystemTools.cxx

@@ -38,7 +38,7 @@
 #include <sys/wait.h>
 #endif
 
-#if defined(_WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__))
+#if defined(_WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__))
 #include <string.h>
 #include <windows.h>
 #include <direct.h>