diff --git a/Source/CMakeLib.dsp b/Source/CMakeLib.dsp index ee8ffc6dd2..d55cb3ca61 100644 --- a/Source/CMakeLib.dsp +++ b/Source/CMakeLib.dsp @@ -85,6 +85,10 @@ LIB32=link.exe -lib # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File +SOURCE=.\cmake.cxx +# End Source File +# Begin Source File + SOURCE=.\cmCableClassSet.cxx # End Source File # Begin Source File diff --git a/Source/MFCDialog/CMakeSetup.dsp b/Source/MFCDialog/CMakeSetup.dsp index 13bb7ba0c3..0d97adffcd 100644 --- a/Source/MFCDialog/CMakeSetup.dsp +++ b/Source/MFCDialog/CMakeSetup.dsp @@ -70,8 +70,8 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FD /GZ /c -# SUBTRACT CPP /YX /Yc /Yu +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FD /GZ /c +# SUBTRACT CPP /O /YX /Yc /Yu # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL" diff --git a/Source/MFCDialog/CMakeSetupDialog.cpp b/Source/MFCDialog/CMakeSetupDialog.cpp index 804496e2af..8a1f64b80b 100644 --- a/Source/MFCDialog/CMakeSetupDialog.cpp +++ b/Source/MFCDialog/CMakeSetupDialog.cpp @@ -8,6 +8,7 @@ #include "../cmMSProjectGenerator.h" #include "../cmCacheManager.h" #include "../cmMakefile.h" +#include "../cmake.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE @@ -75,6 +76,13 @@ CMakeSetupDialog::CMakeSetupDialog(CWnd* pParent /*=NULL*/) // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_BuildPathChanged = false; + // Find the path to the cmake.exe executable + char fname[1024]; + ::GetModuleFileName(NULL,fname,1023); + // extract just the path part + m_PathToExecutable = cmSystemTools::GetProgramPath(fname).c_str(); + // add the cmake.exe to the path + m_PathToExecutable += "/cmake.exe"; } void CMakeSetupDialog::DoDataExchange(CDataExchange* pDX) @@ -412,8 +420,9 @@ void CMakeSetupDialog::OnBuildProjects() return; } } + // set the wait cursor ::SetCursor(LoadCursor(NULL, IDC_WAIT)); - // get all the info from the screen + // get all the info from the dialog this->UpdateData(); if(!m_BuildPathChanged) { @@ -423,34 +432,32 @@ void CMakeSetupDialog::OnBuildProjects() } // Make sure we are working from the cache on disk this->LoadCacheFromDiskToGUI(); - -// duh - // Create a makefile object - cmMakefile makefile; - makefile.SetMakefileGenerator(new cmMSProjectGenerator); - makefile.GetMakefileGenerator()->ComputeSystemInfo(); - makefile.SetHomeDirectory(m_WhereSource); - makefile.SetStartOutputDirectory(m_WhereBuild); - makefile.SetHomeOutputDirectory(m_WhereBuild); - makefile.SetStartDirectory(m_WhereSource); - makefile.MakeStartDirectoriesCurrent(); - CString makefileIn = m_WhereSource; - makefileIn += "/CMakeLists.txt"; - makefile.ReadListFile(makefileIn); - // Generate the project files - makefile.GenerateMakefile(); - // Save the cache - cmCacheManager::GetInstance()->SaveCache(&makefile); -// end duh - + // create a cmake object + cmake make; + // create the arguments for the cmake object + std::vector args; + args.push_back((const char*)m_PathToExecutable); + std::string arg; + arg = "-H"; + arg += m_WhereSource; + args.push_back(arg); + arg = "-B"; + arg += m_WhereBuild; + args.push_back(arg); + // run the generate process + if(make.Generate(args) != 0) + { + cmSystemTools::Error( + "Error in generation process, project files may be invalid"); + } // update the GUI with any new values in the caused by the // generation process this->LoadCacheFromDiskToGUI(); - cmCacheManager::GetInstance()->DefineCache(&makefile); // save source and build paths to registry this->SaveToRegistry(); - // path is not up-to-date + // path is up-to-date now m_BuildPathChanged = false; + // put the cursor back ::SetCursor(LoadCursor(NULL, IDC_ARROW)); } @@ -460,7 +467,8 @@ void CMakeSetupDialog::OnBuildProjects() // callback for combo box menu where build selection void CMakeSetupDialog::OnSelendokWhereBuild() { - m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(), m_WhereBuild); + m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(), + m_WhereBuild); this->UpdateData(FALSE); this->OnChangeWhereBuild(); } @@ -468,7 +476,8 @@ void CMakeSetupDialog::OnSelendokWhereBuild() // callback for combo box menu where source selection void CMakeSetupDialog::OnSelendokWhereSource() { - m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(), m_WhereSource); + m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(), + m_WhereSource); this->UpdateData(FALSE); this->OnChangeWhereSource(); } @@ -557,7 +566,8 @@ void CMakeSetupDialog::FillCacheManagerFromCacheGUI() { CPropertyItem* item = *i; cmCacheManager::CacheEntry *entry = - cmCacheManager::GetInstance()->GetCacheEntry((const char*)item->m_propName); + cmCacheManager::GetInstance()->GetCacheEntry( + (const char*)item->m_propName); if (entry) { entry->m_Value = item->m_curValue; @@ -573,27 +583,6 @@ void CMakeSetupDialog::LoadCacheFromDiskToGUI() if(m_WhereBuild != "") { cmCacheManager::GetInstance()->LoadCache(m_WhereBuild); - - // Find our own exectuable. - char fname[1024]; - ::GetModuleFileName(NULL,fname,1023); - std::string root = cmSystemTools::GetProgramPath(fname); - std::string::size_type slashPos = root.rfind("/"); - if(slashPos != std::string::npos) - { - root = root.substr(0, slashPos); - } - cmCacheManager::GetInstance()->AddCacheEntry - ("CMAKE_ROOT", root.c_str(), - "Path to CMake installation.", cmCacheManager::INTERNAL); - std::string cMakeCMD = "\""+cmSystemTools::GetProgramPath(fname); - cMakeCMD += "/cmake.exe\""; - - // Save the value in the cache - cmCacheManager::GetInstance()->AddCacheEntry("CMAKE_COMMAND", - cMakeCMD.c_str(), - "Path to CMake executable.", - cmCacheManager::INTERNAL); this->FillCacheGUIFromCacheManager(); } } diff --git a/Source/MFCDialog/CMakeSetupDialog.h b/Source/MFCDialog/CMakeSetupDialog.h index b1140a68d7..aea794d96b 100644 --- a/Source/MFCDialog/CMakeSetupDialog.h +++ b/Source/MFCDialog/CMakeSetupDialog.h @@ -58,6 +58,7 @@ protected: HICON m_hIcon; CString m_RegistryKey; + CString m_PathToExecutable; // Generated message map functions //{{AFX_MSG(CMakeSetupDialog) virtual BOOL OnInitDialog(); diff --git a/Source/Makefile.in b/Source/Makefile.in index 43c308a48d..61a2fb6254 100644 --- a/Source/Makefile.in +++ b/Source/Makefile.in @@ -15,6 +15,7 @@ all: cmake OBJS = \ cmake.o \ +cmakemain.o \ cmMakeDepend.o \ cmMakefile.o \ cmMakefileGenerator.o \ @@ -34,6 +35,7 @@ DEPENDS = $(srcdir)/*.h cmConfigure.h cmCollectFlags.o : $(DEPENDS) cmake.o : $(DEPENDS) +cmakemain.o : $(DEPENDS) cmMakeDepend.o : $(DEPENDS) cmMakefile.o : $(DEPENDS) cmMakefileGenerator.o : $(DEPENDS) @@ -50,7 +52,6 @@ cmCableClassSet.o: $(DEPENDS) cmSourceGroup.o : $(DEPENDS) - cmake: ${OBJS} ${CXX} ${OBJS} ${CXXFLAGS} -o cmake diff --git a/Source/cmMSProjectGenerator.cxx b/Source/cmMSProjectGenerator.cxx index ee71f8df23..12e2733d21 100644 --- a/Source/cmMSProjectGenerator.cxx +++ b/Source/cmMSProjectGenerator.cxx @@ -78,6 +78,12 @@ void cmMSProjectGenerator::SetLocal(bool local) void cmMSProjectGenerator::ComputeSystemInfo() { // now load the settings + if(!cmCacheManager::GetInstance()->GetCacheValue("CMAKE_ROOT")) + { + cmSystemTools::Error( + "CMAKE_ROOT has not been defined, bad GUI or driver program"); + return; + } std::string fpath = cmCacheManager::GetInstance()->GetCacheValue("CMAKE_ROOT"); fpath += "/Templates/CMakeWindowsSystemConfig.cmake"; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 016871967a..66df7b2d4f 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -48,17 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "cmUnixMakefileGenerator.h" #endif -int main(int ac, char** av) -{ - cmake foo; - if(ac < 2) - { - foo.Usage(av[0]); - return -1; - } - return foo.Generate(ac,av); -} - void cmake::Usage(const char* program) { std::cerr << "cmake version " << cmMakefile::GetVersion() << "\n"; @@ -67,23 +56,23 @@ void cmake::Usage(const char* program) } // Parse the args -void cmake::SetArgs(cmMakefile& builder, int ac, char** av) +void cmake::SetArgs(cmMakefile& builder, const std::vector& args) { m_Local = false; // watch for cmake and cmake srcdir invocations - if (ac <= 2) + if (args.size() <= 2) { builder.SetHomeOutputDirectory (cmSystemTools::GetCurrentWorkingDirectory().c_str()); builder.SetStartOutputDirectory (cmSystemTools::GetCurrentWorkingDirectory().c_str()); - if (ac == 2) + if (args.size() == 2) { builder.SetHomeDirectory - (cmSystemTools::CollapseFullPath(av[1]).c_str()); + (cmSystemTools::CollapseFullPath(args[1].c_str()).c_str()); builder.SetStartDirectory - (cmSystemTools::CollapseFullPath(av[1]).c_str()); + (cmSystemTools::CollapseFullPath(args[1].c_str()).c_str()); } else { @@ -94,9 +83,9 @@ void cmake::SetArgs(cmMakefile& builder, int ac, char** av) } } - for(int i =1; i < ac; i++) + for(int i =1; i < args.size(); i++) { - std::string arg = av[i]; + std::string arg = args[i]; if(arg.find("-H",0) != std::string::npos) { std::string path = arg.substr(2); @@ -137,10 +126,10 @@ void cmake::SetArgs(cmMakefile& builder, int ac, char** av) } // at the end of this CMAKE_ROOT and CMAAKE_COMMAND should be added to the cache -void cmake::AddCMakePaths(char **av) +void cmake::AddCMakePaths(const std::vector& args) { // Find our own exectuable. - std::string cMakeSelf = av[0]; + std::string cMakeSelf = args[0]; cmSystemTools::ConvertToUnixSlashes(cMakeSelf); cMakeSelf = cmSystemTools::FindProgram(cMakeSelf.c_str()); @@ -198,13 +187,13 @@ void cmake::AddCMakePaths(char **av) "Path to CMake installation.", cmCacheManager::INTERNAL); } -int cmake::Generate(int ac, char **av) +int cmake::Generate(const std::vector& args) { // Create a makefile cmMakefile mf; // extract the directory arguments - cmake::SetArgs(mf, ac, av); + cmake::SetArgs(mf, args); // create the generator #if defined(_WIN32) && !defined(__CYGWIN__) @@ -221,7 +210,7 @@ int cmake::Generate(int ac, char **av) cmCacheManager::GetInstance()->LoadCache(&mf); // setup CMAKE_ROOT and CMAKE_COMMAND - this->AddCMakePaths(av); + this->AddCMakePaths(args); // compute system info gen->ComputeSystemInfo(); @@ -233,7 +222,7 @@ int cmake::Generate(int ac, char **av) lf += "/CMakeLists.txt"; if(!mf.ReadListFile(lf.c_str())) { - this->Usage(av[0]); + this->Usage(args[0].c_str()); return -1; } mf.GenerateMakefile(); diff --git a/Source/cmake.dsp b/Source/cmake.dsp index fddb07c9fd..fe7c932cc5 100644 --- a/Source/cmake.dsp +++ b/Source/cmake.dsp @@ -50,6 +50,7 @@ BSC32=bscmake.exe LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /pdb:"cmake.pdb" /machine:I386 /out:"cmake.exe" +# SUBTRACT LINK32 /pdb:none !ELSEIF "$(CFG)" == "cmake - Win32 Debug" @@ -74,6 +75,7 @@ BSC32=bscmake.exe LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /pdb:"cmake.pdb" /debug /machine:I386 /out:"cmake.exe" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none !ENDIF @@ -86,7 +88,7 @@ LINK32=link.exe # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File -SOURCE=.\cmake.cxx +SOURCE=.\cmakemain.cxx # End Source File # End Group # Begin Group "Header Files" diff --git a/Source/cmake.h b/Source/cmake.h index fc65d3db25..ac7a80d792 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -55,20 +55,24 @@ class cmake /** * Generate the SourceFilesList from the SourceLists. This should only be - * done once to be safe. + * done once to be safe. The argument is a list of command line + * arguments. The first argument should be the name or full path + * to the command line version of cmake. For building a GUI, + * you would pass in the following arguments: + * /path/to/cmake -H/path/to/source -B/path/to/build */ - int Generate(int ac, char **av); + int Generate(const std::vector&); /** * Generate the SourceFilesList from the SourceLists. This should only be * done once to be safe. */ - void SetArgs(cmMakefile& builder, int ac, char** av); + void SetArgs(cmMakefile& builder, const std::vector&); /** * Generate CMAKE_ROOT and CMAKE_COMMAND cache entries */ - void AddCMakePaths(char **av); + void AddCMakePaths(const std::vector&); /** * constructor