]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMMain.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMMain.cpp
index 71f60f6b84513eabe5ad63dce70c3ec48441242c..8d69741da2b3d46229e93248e4ae5943355ad256 100644 (file)
@@ -38,6 +38,7 @@
 #include <cstdlib>
 #include <iostream>
 #include <string>
+#include <vector>
 #include <cstdio>
 #include <fstream>
 
@@ -175,11 +176,13 @@ bool modelCDMMain::OpenProject(
   std::string pathBuild = "";
 
   //check if Makefile file exists
-  std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "Makefile";
-  FILE* pFile;
 #ifdef _WIN32
+  std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "CMakeCache.txt";
+  FILE* pFile;
   errno_t errorOpen = fopen_s(&pFile, pathMakefile.c_str(), "r");
 #else
+  std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "Makefile";
+  FILE* pFile;
   pFile = fopen(pathMakefile.c_str(), "r");
   bool errorOpen = (pFile == NULL);
 #endif
@@ -191,9 +194,29 @@ bool modelCDMMain::OpenProject(
       readFile.open(pathMakefile.c_str());
       std::string word;
 
+      
+#ifdef _WIN32
+         while(!isBinary && !readFile.eof())
+        {
+            getline(readFile, word, '\n');
+                       std::vector<std::string> words;
+                       CDMUtilities::splitter::split(words,word,"=",CDMUtilities::splitter::no_empties);
+                       if(words.size() && words[0] == "CMAKE_HOME_DIRECTORY:INTERNAL")
+            {
+                         pathBuild = pathFixed;
+              pathFixed = CDMUtilities::fixPath(words[1]);
+                         for (int i = 0; i < (int)(pathFixed.size()); i++)
+                {
+                  if (pathFixed[i]=='/')
+                                         pathFixed[i]='\\';
+                }
+              isBinary = true;
+            }
+        }
+#else
       while(!isBinary && readFile >> word)
         {
-          if(word == "CMAKE_SOURCE_DIR")
+            if(word == "CMAKE_SOURCE_DIR")
             {
               readFile >> word;
               readFile.ignore();
@@ -202,7 +225,8 @@ bool modelCDMMain::OpenProject(
               pathFixed = CDMUtilities::fixPath(word);
               isBinary = true;
             }
-        }
+           }
+#endif
       readFile.close();
     }
 
@@ -267,7 +291,7 @@ bool modelCDMMain::OpenProject(
     }
   else
     {
-      result = new std::string("No source folder found. Please make sure to select either the project's build or source folder.");
+      result = new std::string("No source folder found. Please make sure to select either the project's build or source folder. " + pathBuild + pathFixed);
       return false;
     }