diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2000-09-12 09:30:35 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2000-09-12 09:30:35 (GMT) |
commit | aa3ca2b432ab346c28ea7c758cbbf57ca346e139 (patch) | |
tree | dec236eb51e746ae123edb3e9c01a5595381e12f | |
parent | e2ad65d3c27177b8f3ee3c9b81382ea883a3bfbd (diff) | |
download | CMake-aa3ca2b432ab346c28ea7c758cbbf57ca346e139.zip CMake-aa3ca2b432ab346c28ea7c758cbbf57ca346e139.tar.gz CMake-aa3ca2b432ab346c28ea7c758cbbf57ca346e139.tar.bz2 |
ENH: CMake and configure now use SUBDIRS in CMakeLists.txt to find all the directories of the system.
38 files changed, 716 insertions, 916 deletions
diff --git a/CMakeMaster.make.in b/CMakeMaster.make.in index 51aad8f..8d477c9 100644 --- a/CMakeMaster.make.in +++ b/CMakeMaster.make.in @@ -4,14 +4,14 @@ #------------------------------------------------------------------------------ # Include all variable settings -@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_OBJ_DIR@/CMake/CMakeVariables.make@MAKEQUOTE@ +@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_CONFIG_DIR@/CMake/CMakeVariables.make@MAKEQUOTE@ #------------------------------------------------------------------------------ # Include user-editable defines. -@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_OBJ_DIR@/CMakeLocal.make@MAKEQUOTE@ +@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_CONFIG_DIR@/CMakeLocal.make@MAKEQUOTE@ #------------------------------------------------------------------------------ # Include General Build Rules -@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_OBJ_DIR@/CMake/CMakeRules.make@MAKEQUOTE@ +@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_CONFIG_DIR@/CMake/CMakeRules.make@MAKEQUOTE@ diff --git a/CMakeRules.make.in b/CMakeRules.make.in index 91341f7..af10d2e 100644 --- a/CMakeRules.make.in +++ b/CMakeRules.make.in @@ -1,5 +1,5 @@ -# include simple rules for building .o files -@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_OBJ_DIR@/CMake/CMakeSimpleRules.make@MAKEQUOTE@ +# include simple rules for building .o files from source files +@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_CONFIG_DIR@/CMake/CMakeSimpleRules.make@MAKEQUOTE@ # # Makefile for @@ -10,18 +10,18 @@ all: CMakeTargets.make ${OBJ_SUB_DIRS} ${EXECUTABLES} ${SUBDIR_BUILD} ${BUILD_LI #------------------------------------------------------------------------------ -${CMAKE}: @fullSrcDir@/CMake/Source/*.cxx @fullSrcDir@/CMake/Source/*.h - cd @CMAKE_OBJ_DIR@/CMake/Source; ${MAKE} CMakeBuildTargets +${CMAKE}: ${topdir}/CMake/Source/*.cxx ${topdir}/CMake/Source/*.h + cd ${CMAKE_CONFIG_DIR}/CMake/Source; ${MAKE} CMakeBuildTargets depend: ${CMAKE} - ${CMAKE} ${srcdir}/CMakeLists.txt -S${srcdir} -I${srcdir} ${INCLUDE_FLAGS} + ${MAKE} -${MAKEFLAGS} CMakeTargets.make clean: ${SUBDIR_CLEAN} rm -f ${SRC_OBJ} ${EXECUTABLES} CMakeTargets.make: ${CMAKE} ${srcdir}/CMakeLists.txt - ${CMAKE} ${srcdir}/CMakeLists.txt -S${srcdir} -I${srcdir} ${INCLUDE_FLAGS} + ${CMAKE} ${srcdir}/CMakeLists.txt -S${srcdir} -H${topdir} -B${CMAKE_CONFIG_DIR} #------------------------------------------------------------------------------ # rules for the normal library diff --git a/CMakeTargets.make.in b/CMakeTargets.make.in new file mode 100644 index 0000000..a9405ec --- /dev/null +++ b/CMakeTargets.make.in @@ -0,0 +1,5 @@ +#empty file used by configure to generate initial targets.make files +#if you find this as a make error, then the autoconf system is not +#working, send for help on the insight mailing list... + + diff --git a/CMakeVariables.make.in b/CMakeVariables.make.in index 07a6f1a..a2b5eeb 100644 --- a/CMakeVariables.make.in +++ b/CMakeVariables.make.in @@ -1,11 +1,39 @@ + +# ***** BEGIN VARIBLES THAT CAN BE OVERRIDDEN IN CMakeLocal.make.in ************** +# CMakeLocal.make.in should be in the directory where you run configure +# in, which need not be the source directory + +# use this to add targets to the default all +# so they are built when make is run by default +LOCAL_BUILD_TARGETS = + +# use this flag to add -L and -l options to the link line +LOCAL_LINK_FLAGS = + +# use this flag to add -I flags to the compile line +LOCAL_INCLUDE_FLAGS = + +# use this flag to add compiler options like -g -O, etc +# for the "C" compiler, for gcc these default to -g -O2 +USER_CFLAGS = @CFLAGS@ + +# use this flag to add compiler options like -g -O, etc +# for the "C++" compiler, for gcc these default to -g -O2 +USER_CXXFLAGS = @CXXFLAGS@ + +# ***** END VARIBLES THAT CAN BE OVERRIDDEN IN CMakeLocal.make.in ************** + + +# This is the path to the top of the Source tree topdir = @fullSrcDir@ -CONFIG_DIR = @CMAKE_OBJ_DIR@ +# This is the directory configure was run in +# where the binaries will be placed +CMAKE_CONFIG_DIR = @CMAKE_CONFIG_DIR@ +# the standard shell for make SHELL = /bin/sh -CMAKE_OBJ_DIR = ${CONFIG_DIR} - RANLIB = @RANLIB@ CC = @CC@ CFLAGS = @ITK_SHLIB_CFLAGS@ @ANSI_CFLAGS@ @@ -82,31 +110,21 @@ LIB_INSTALL_DIR = $(INSTALL_ROOT)$(exec_prefix)/lib BIN_INSTALL_DIR = $(INSTALL_ROOT)$(exec_prefix)/bin # set up the path to the rulesgen program -CMAKE = @CMAKE_OBJ_DIR@/CMake/Source/CMakeBuildTargets +CMAKE = @CMAKE_CONFIG_DIR@/CMake/Source/CMakeBuildTargets KIT_OBJ = ${SRC_OBJ} ${EXTRA_KIT_OBJ} -# ***** BEGIN VARIBLES THAT CAN BE OVERRIDDEN IN CMakeLocal.make.in ************** -LOCAL_BUILD_TARGETS = -LOCAL_LINK_FLAGS = -USER_CFLAGS = @CFLAGS@ -USER_CXXFLAGS = @CXXFLAGS@ - -# ***** END VARIBLES THAT CAN BE OVERRIDDEN IN CMakeLocal.make.in ************** - - -# compile line flags -INCLUDE_FLAGS = -I. \ - -I${CONFIG_DIR}/Code/Insight3DParty/vxl \ - -I${CONFIG_DIR} \ - -I${topdir}/Code/Common \ - -I${topdir}/Code/Insight3DParty/vxl +# C++ compile flags, INCLUDE_FLAGS is set in CMakeTargets.make which +# is generated by CMakeBuildTargets, see CMake/Source CXX_FLAGS = ${CPPFLAGS} ${USER_CXXFLAGS} ${CXXFLAGS} \ ${KIT_FLAGS} ${INCLUDE_FLAGS} -CC_FLAGS = ${CPPFLAGS} ${USER_CFLAGS} ${CFLAGS} +# C compile flags, INCLUDE_FLAGS is set in CMakeTargets.make which +# is generated by CMakeBuildTargets, see CMake/Source + +CC_FLAGS = ${CPPFLAGS} ${USER_CFLAGS} ${CFLAGS} ${INCLUDE_FLAGS} diff --git a/MakefileTemplate.in b/MakefileTemplate.in index 0ce54fe..c02dc9a 100644 --- a/MakefileTemplate.in +++ b/MakefileTemplate.in @@ -1,4 +1,4 @@ srcdir = @srcdir@ VPATH = @srcdir@ -@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_OBJ_DIR@/CMake/CMakeMaster.make@MAKEQUOTE@ +@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_CONFIG_DIR@/CMake/CMakeMaster.make@MAKEQUOTE@ @@ -32,9 +32,11 @@ CMakeBuildTargets -> Unix program to read CMakeLists.txt and generate CMakeT makefile fragments: CMakeMaster.make -> main file to be included by makefiles CMakeVariables.make -> all make varibles are set in this file -CMakeRules.make -> All build rules are here +CMakeRules.make -> All build rules are here (except Simple Rules) +CMakeSimpleRules.make -> simple build rules for .o to .cxx, this is separate to be able +to build CMakeBuildTargets itself. CMakeLocal.make -> Place for hand configuration -CMakeTargets.make -> generated rules for make style build +CMakeTargets.make -> generated rules for make style build in each directory MakefileTemplate.make -> master makefile template used by configure to generate Makefiles Unix install: @@ -50,7 +52,6 @@ make TODO: -Fix cmUnixMakefile.cxx and cmDSPMakefile.cxx -to read libraries and -I stuff from a config file - +configure stuff for windows should be a copy configure file +read in depend regular expression from a file diff --git a/Source/CMakeBuildTargets.cxx b/Source/CMakeBuildTargets.cxx index 06aebe8..0da1410 100644 --- a/Source/CMakeBuildTargets.cxx +++ b/Source/CMakeBuildTargets.cxx @@ -16,15 +16,20 @@ main(int ac, char** av) for(int i =2; i < ac; i++) { std::string arg = av[i]; - if(arg.find("-I",0) != std::string::npos) + if(arg.find("-S",0) != std::string::npos) { std::string path = arg.substr(2); - md.AddSearchPath(path.c_str()); + mf->SetCurrentDirectory(path.c_str()); } - if(arg.find("-S",0) != std::string::npos) + if(arg.find("-B",0) != std::string::npos) { std::string path = arg.substr(2); - mf->SetCurrentDirectory(path.c_str()); + mf->SetOutputHomeDirectory(path.c_str()); + } + if(arg.find("-H",0) != std::string::npos) + { + std::string path = arg.substr(2); + mf->SetHomeDirectory(path.c_str()); } } } diff --git a/Source/CMakeSetup.cxx b/Source/CMakeSetup.cxx deleted file mode 100644 index f01bcee..0000000 --- a/Source/CMakeSetup.cxx +++ /dev/null @@ -1,48 +0,0 @@ -#include "cmDSWBuilder.h" -#include "cmDSPBuilder.h" -#include <iostream> - -void SetArgs(cmPCBuilder& builder, int ac, char** av) -{ - for(int i =2; i < ac; i++) - { - std::string arg = av[i]; - if(arg.find("-H",0) != std::string::npos) - { - std::string path = arg.substr(2); - builder.SetHomeDirectory(path.c_str()); - } - if(arg.find("-D",0) != std::string::npos) - { - std::string path = arg.substr(2); - builder.SetCurrentDirectory(path.c_str()); - } - } -} - -main(int ac, char** av) -{ - if(ac < 3) - { - std::cerr << "Usage: " << av[0] << - " Makefile.in -[DSP|DSW] -Hinsighthome -Dcurrentdir ..." << std::endl; - return -1; - } - std::string arg = av[2]; - if(arg.find("-DSP", 0) != std::string::npos) - { - cmDSPBuilder builder; - builder.SetInputMakefilePath(av[1]); - SetArgs(builder, ac, av); - builder.CreateDSPFile(); - } - else - { - cmDSWBuilder builder; - builder.SetInputMakefilePath(av[1]); - SetArgs(builder, ac, av); - builder.CreateDSWFile(); - } - return 0; -} - diff --git a/Source/CMakeSetup.dsw b/Source/CMakeSetup.dsw index e04ca61..353ff46 100644 --- a/Source/CMakeSetup.dsw +++ b/Source/CMakeSetup.dsw @@ -12,9 +12,6 @@ Package=<5> Package=<4>
{{{
Begin Project Dependency
- Project_Dep_Name pcbuilderCMD
- End Project Dependency
- Begin Project Dependency
Project_Dep_Name CMakeSetupCMD
End Project Dependency
}}}
diff --git a/Source/CMakeSetupCMD.cxx b/Source/CMakeSetupCMD.cxx index 46b2033..4ffd20c 100644 --- a/Source/CMakeSetupCMD.cxx +++ b/Source/CMakeSetupCMD.cxx @@ -1,8 +1,8 @@ -#include "cmDSWBuilder.h" -#include "cmDSPBuilder.h" +#include "cmDSWMakefile.h" +#include "cmDSPMakefile.h" #include <iostream> -void SetArgs(cmPCBuilder& builder, int ac, char** av) +void SetArgs(cmMakefile& builder, int ac, char** av) { for(int i =3; i < ac; i++) { @@ -16,7 +16,7 @@ void SetArgs(cmPCBuilder& builder, int ac, char** av) { std::string path = arg.substr(2); std::cerr << "set makefile dir " << path.c_str() << std::endl; - builder.SetMakefileDirectory(path.c_str()); + builder.SetCurrentDirectory(path.c_str()); } if(arg.find("-O",0) != std::string::npos) { @@ -45,17 +45,17 @@ main(int ac, char** av) std::string arg = av[2]; if(arg.find("-DSP", 0) != std::string::npos) { - cmDSPBuilder builder; + cmDSPMakefile builder; SetArgs(builder, ac, av); - builder.SetInputMakefilePath(av[1]); - builder.CreateDSPFile(); + builder.ReadMakefile(av[1]); + builder.OutputDSPFile(); } else { - cmDSWBuilder builder; + cmDSWMakefile builder; SetArgs(builder, ac, av); - builder.SetInputMakefilePath(av[1]); - builder.CreateDSWFile(); + builder.ReadMakefile(av[1]); + builder.OutputDSWFile(); } return 0; } diff --git a/Source/CMakeSetupCMD.dsp b/Source/CMakeSetupCMD.dsp index 9af6147..99992c9 100644 --- a/Source/CMakeSetupCMD.dsp +++ b/Source/CMakeSetupCMD.dsp @@ -99,6 +99,10 @@ SOURCE=.\cmClassFile.cxx # End Source File
# Begin Source File
+SOURCE=.\cmCollectFlags.cxx
+# End Source File
+# Begin Source File
+
SOURCE=.\cmDirectory.cxx
# End Source File
# Begin Source File
diff --git a/Source/MFCDialog/CMakeDialog.cpp b/Source/MFCDialog/CMakeDialog.cpp deleted file mode 100644 index 373ad47..0000000 --- a/Source/MFCDialog/CMakeDialog.cpp +++ /dev/null @@ -1,327 +0,0 @@ -// CMakeSetupDialogDlg.cpp : implementation file -// - -#include "stdafx.h" -#include "pcbuilder.h" -#include "CMakeSetupDialog.h" -#include "../itkDSWBuilder.h" -#include "../itkVC60Configure.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CAboutDlg dialog used for App About - -class CAboutDlg : public CDialog -{ -public: - CAboutDlg(); - -// Dialog Data - //{{AFX_DATA(CAboutDlg) - enum { IDD = IDD_ABOUTBOX }; - //}}AFX_DATA - - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CAboutDlg) -protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - //{{AFX_MSG(CAboutDlg) - //}}AFX_MSG - DECLARE_MESSAGE_MAP() - }; - -CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) -{ - //{{AFX_DATA_INIT(CAboutDlg) - //}}AFX_DATA_INIT -} - -void CAboutDlg::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CAboutDlg) - //}}AFX_DATA_MAP -} - -BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) - //{{AFX_MSG_MAP(CAboutDlg) - // No message handlers - //}}AFX_MSG_MAP - END_MESSAGE_MAP(); - - -///////////////////////////////////////////////////////////////////////////// -// CMakeSetupDialog dialog - -CMakeSetupDialog::CMakeSetupDialog(CWnd* pParent /*=NULL*/) - : CDialog(CMakeSetupDialog::IDD, pParent) -{ - //{{AFX_DATA_INIT(CMakeSetupDialog) - m_WhereITK = _T(""); - m_WhereBuildITK = _T(""); - //}}AFX_DATA_INIT - // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 - m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); - m_WhereITK = _T(""); - this->LoadFromRegistry(); -} - -void CMakeSetupDialog::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CMakeSetupDialog) - DDX_Text(pDX, IDC_WhereITK, m_WhereITK); - DDX_Text(pDX, IDC_WhereITK2, m_WhereBuildITK); - //}}AFX_DATA_MAP -} - -BEGIN_MESSAGE_MAP(CMakeSetupDialog, CDialog) - //{{AFX_MSG_MAP(CMakeSetupDialog) - ON_WM_SYSCOMMAND() - ON_WM_PAINT() - ON_WM_QUERYDRAGICON() - ON_EN_CHANGE(IDC_WhereITK, OnChangeEdit1) - ON_BN_CLICKED(IDC_BUTTON2, OnBrowse) - ON_BN_CLICKED(IDC_BUTTON3, OnButton3) - //}}AFX_MSG_MAP - END_MESSAGE_MAP(); - - -///////////////////////////////////////////////////////////////////////////// -// CMakeSetupDialog message handlers - -BOOL CMakeSetupDialog::OnInitDialog() -{ - CDialog::OnInitDialog(); - - // Add "About..." menu item to system menu. - - // IDM_ABOUTBOX must be in the system command range. - ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); - ASSERT(IDM_ABOUTBOX < 0xF000); - - CMenu* pSysMenu = GetSystemMenu(FALSE); - if (pSysMenu != NULL) - { - CString strAboutMenu; - strAboutMenu.LoadString(IDS_ABOUTBOX); - if (!strAboutMenu.IsEmpty()) - { - pSysMenu->AppendMenu(MF_SEPARATOR); - pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); - } - } - - // Set the icon for this dialog. The framework does this automatically - // when the application's main window is not a dialog - SetIcon(m_hIcon, TRUE); // Set big icon - SetIcon(m_hIcon, FALSE); // Set small icon - - // TODO: Add extra initialization here - - return TRUE; // return TRUE unless you set the focus to a control -} - -void CMakeSetupDialog::OnSysCommand(UINT nID, LPARAM lParam) -{ - if ((nID & 0xFFF0) == IDM_ABOUTBOX) - { - CAboutDlg dlgAbout; - dlgAbout.DoModal(); - } - else - { - CDialog::OnSysCommand(nID, lParam); - } -} - -// If you add a minimize button to your dialog, you will need the code below -// to draw the icon. For MFC applications using the document/view model, -// this is automatically done for you by the framework. - -void CMakeSetupDialog::OnPaint() -{ - if (IsIconic()) - { - CPaintDC dc(this); // device context for painting - - SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); - - // Center icon in client rectangle - int cxIcon = GetSystemMetrics(SM_CXICON); - int cyIcon = GetSystemMetrics(SM_CYICON); - CRect rect; - GetClientRect(&rect); - int x = (rect.Width() - cxIcon + 1) / 2; - int y = (rect.Height() - cyIcon + 1) / 2; - - // Draw the icon - dc.DrawIcon(x, y, m_hIcon); - } - else - { - CDialog::OnPaint(); - } -} - -// The system calls this to obtain the cursor to display while the user drags -// the minimized window. -HCURSOR CMakeSetupDialog::OnQueryDragIcon() -{ - return (HCURSOR) m_hIcon; -} - -void CMakeSetupDialog::OnChangeEdit1() -{ - // TODO: If this is a RICHEDIT control, the control will not - // send this notification unless you override the CDialog::OnInitDialog() - // function and call CRichEditCtrl().SetEventMask() - // with the ENM_CHANGE flag ORed into the mask. - - // TODO: Add your control notification handler code here - -} - -void CMakeSetupDialog::OnBrowse() -{ - this->UpdateData(); - Browse(m_WhereITK, "Enter Path to Insight Source"); - this->UpdateData(false); -} - -bool CMakeSetupDialog::Browse(CString &result, const char *title) -{ -// don't know what to do with initial right now... - char szPathName[4096]; - BROWSEINFO bi; - - bi.hwndOwner = m_hWnd; - bi.pidlRoot = NULL; - bi.pszDisplayName = (LPTSTR)szPathName; - bi.lpszTitle = title; - bi.ulFlags = BIF_BROWSEINCLUDEFILES ; - bi.lpfn = NULL; - - LPITEMIDLIST pidl = SHBrowseForFolder(&bi); - - bool bSuccess = (bool)SHGetPathFromIDList(pidl, szPathName); - if(bSuccess) - { - result = szPathName; - } - - return bSuccess; -} - -void CMakeSetupDialog::OnOK() -{ - // get all the info from the screen - this->UpdateData(); - - // configure the system for VC60 - itkVC60Configure config; - config.SetWhereITK(m_WhereITK); - config.SetWhereBuildITK(m_WhereBuildITK); - config.Configure(); - - itkDSWBuilder builder; - // Set the ITK home directory - builder.SetHomeDirectory(m_WhereITK); - // Set the Makefile.in file - CString makefileIn = m_WhereITK; - makefileIn += "/Makefile.in"; - builder.SetInputMakefilePath(makefileIn); - // Set the output directory - builder.SetOutputDirectory(m_WhereBuildITK); - // set the directory which contains the Makefile.in - builder.SetMakefileDirectory(m_WhereITK); - // Create the master DSW file and all children dsp files for ITK - builder.CreateDSWFile(); - CDialog::OnOK(); - this->SaveToRegistry(); -} - -void CMakeSetupDialog::OnButton3() -{ - this->UpdateData(); - Browse(m_WhereBuildITK, "Enter Path to Insight Build"); - this->UpdateData(false); -} - -void CMakeSetupDialog::SaveToRegistry() -{ - HKEY hKey; - DWORD dwDummy; - - if(RegCreateKeyEx(HKEY_CURRENT_USER, - _T("Software\\Kitware\\ITK PCBuilder\\Settings"), - 0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, - NULL, &hKey, &dwDummy) != ERROR_SUCCESS) - { - return; - } - else - { - RegSetValueEx(hKey, _T("WhereITK"), 0, REG_SZ, - (CONST BYTE *)(const char *)m_WhereITK, - m_WhereITK.GetLength()); - RegSetValueEx(hKey, _T("WhereBuildITK"), 0, REG_SZ, - (CONST BYTE *)(const char *)m_WhereBuildITK, - m_WhereBuildITK.GetLength()); - - } - RegCloseKey(hKey); -} - - -void CMakeSetupDialog::ReadRegistryValue(HKEY hKey, - CString *val, - char *key, - char *adefault) -{ - DWORD dwType, dwSize; - char *pb; - - dwType = REG_SZ; - pb = val->GetBuffer(MAX_PATH); - dwSize = MAX_PATH; - if(RegQueryValueEx(hKey,_T(key), NULL, &dwType, - (BYTE *)pb, &dwSize) != ERROR_SUCCESS) - { - val->ReleaseBuffer(); - *val = _T(adefault); - } - else - { - val->ReleaseBuffer(); - } -} - - -void CMakeSetupDialog::LoadFromRegistry() -{ - HKEY hKey; - if(RegOpenKeyEx(HKEY_CURRENT_USER, - _T("Software\\Kitware\\ITK PCBuilder\\Settings"), - 0, KEY_READ, &hKey) != ERROR_SUCCESS) - { - return; - } - else - { - // save some values - this->ReadRegistryValue(hKey, &(m_WhereITK),"WhereITK","C:\\Insight"); - this->ReadRegistryValue(hKey, &(m_WhereBuildITK),"WhereBuildITK", - "C:\\vtkbin"); - } - RegCloseKey(hKey); -} diff --git a/Source/MFCDialog/CMakeSetup.dsp b/Source/MFCDialog/CMakeSetup.dsp index 9864a7c..3e59357 100644 --- a/Source/MFCDialog/CMakeSetup.dsp +++ b/Source/MFCDialog/CMakeSetup.dsp @@ -108,6 +108,10 @@ SOURCE=..\cmClassFile.cxx # End Source File
# Begin Source File
+SOURCE=..\cmCollectFlags.cxx
+# End Source File
+# Begin Source File
+
SOURCE=..\cmDirectory.cxx
# End Source File
# Begin Source File
@@ -232,9 +236,5 @@ SOURCE=.\res\CMakeSetupDialog.ico SOURCE=.\res\CMakeSetupDialog.rc2
# End Source File
# End Group
-# Begin Source File
-
-SOURCE=.\ReadMe.txt
-# End Source File
# End Target
# End Project
diff --git a/Source/MFCDialog/CMakeSetupDialog.cpp b/Source/MFCDialog/CMakeSetupDialog.cpp index 32b8027..f3dc17b 100644 --- a/Source/MFCDialog/CMakeSetupDialog.cpp +++ b/Source/MFCDialog/CMakeSetupDialog.cpp @@ -4,7 +4,7 @@ #include "stdafx.h" #include "CMakeSetup.h" #include "CMakeSetupDialog.h" -#include "../cmDSWBuilder.h" +#include "../cmDSWMakefile.h" #include "../itkVC60Configure.h" #ifdef _DEBUG @@ -232,19 +232,19 @@ void CMakeSetupDialog::OnOK() config.SetWhereBuild(m_WhereBuild); config.Configure(); - cmDSWBuilder builder; + cmDSWMakefile builder; // Set the ITK home directory builder.SetHomeDirectory(m_WhereSource); // Set the CMakeLists.txt file CString makefileIn = m_WhereSource; makefileIn += "/CMakeLists.txt"; - builder.SetInputMakefilePath(makefileIn); + builder.ReadMakefile(makefileIn); // Set the output directory builder.SetOutputDirectory(m_WhereBuild); // set the directory which contains the CMakeLists.txt - builder.SetMakefileDirectory(m_WhereSource); + builder.SetCurrentDirectory(m_WhereSource); // Create the master DSW file and all children dsp files for ITK - builder.CreateDSWFile(); + builder.OutputDSWFile(); CDialog::OnOK(); this->SaveToRegistry(); } diff --git a/Source/Makefile.in b/Source/Makefile.in index 0a51b1a..b9d5ca0 100644 --- a/Source/Makefile.in +++ b/Source/Makefile.in @@ -6,8 +6,8 @@ VPATH = @srcdir@ # This will cause an infinite loop as it will add the # rule for changing into this directory -@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_OBJ_DIR@/CMake/CMakeVariables.make@MAKEQUOTE@ -@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_OBJ_DIR@/CMake/CMakeSimpleRules.make@MAKEQUOTE@ +@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_CONFIG_DIR@/CMake/CMakeVariables.make@MAKEQUOTE@ +@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_CONFIG_DIR@/CMake/CMakeSimpleRules.make@MAKEQUOTE@ OBJS = \ cmClassFile.o \ @@ -16,12 +16,16 @@ cmMakefile.o \ cmUnixMakefile.o \ cmMakeDepend.o \ cmRegularExpression.o \ -CMakeBuildTargets.o +cmSystemTools.o \ +CMakeBuildTargets.o \ +cmCollectFlags.o -cmDirectory.o : cmDirectory.h cmDirectory.cxx -cmClassFile.o : cmClassFile.h cmClassFile.cxx -cmMakefile.o : cmMakefile.h cmMakefile.cxx cmClassFile.h +cmCollectFlags.o : cmCollectFlags.h cmCollectFlags.cxx cmSystemTools.h +cmSystemTools.o : cmSystemTools.h cmSystemTools.cxx cmSystemTools.h +cmDirectory.o : cmDirectory.h cmDirectory.cxx cmSystemTools.h +cmClassFile.o : cmClassFile.h cmClassFile.cxx cmSystemTools.h +cmMakefile.o : cmMakefile.h cmMakefile.cxx cmClassFile.h cmSystemTools.h cmUnixMakefile.o : cmUnixMakefile.h cmUnixMakefile.cxx cmMakefile.h cmClassFile.h cmMakeDepend.o : cmMakeDepend.h cmMakeDepend.cxx cmMakefile.h cmClassFile.h cmRegularExpression.h cmRegularExpression.o : cmRegularExpression.h cmRegularExpression.cxx diff --git a/Source/cmClassFile.cxx b/Source/cmClassFile.cxx index f953bbb..6c219ed 100644 --- a/Source/cmClassFile.cxx +++ b/Source/cmClassFile.cxx @@ -2,23 +2,10 @@ #pragma warning ( disable : 4786 ) #endif #include "cmClassFile.h" -#include <sys/stat.h> +#include "cmSystemTools.h" #include <iostream> -// Helper function to hide the use of system stat function -bool cmFileExists(const char* filename) -{ - struct stat fs; - if (stat(filename, &fs) != 0) - { - return false; - } - else - { - return true; - } -} // Set the name of the class and the full path to the file. // The class must be found in dir and end in name.cxx, name.txx, @@ -37,7 +24,7 @@ void cmClassFile::SetName(const char* name, const char* dir) pathname += m_ClassName; std::string hname = pathname; hname += ".cxx"; - if(cmFileExists(hname.c_str())) + if(cmSystemTools::FileExists(hname.c_str())) { m_HeaderFileOnly = false; m_FullPath = hname; @@ -46,7 +33,7 @@ void cmClassFile::SetName(const char* name, const char* dir) hname = pathname; hname += ".c"; - if(cmFileExists(hname.c_str())) + if(cmSystemTools::FileExists(hname.c_str())) { m_HeaderFileOnly = false; m_FullPath = hname; @@ -54,13 +41,19 @@ void cmClassFile::SetName(const char* name, const char* dir) } hname = pathname; hname += ".txx"; - if(cmFileExists(hname.c_str())) + if(cmSystemTools::FileExists(hname.c_str())) { m_HeaderFileOnly = false; m_FullPath = hname; return; } - std::cerr << "file seems to be a header only " << hname << " " << m_ClassName.c_str() << std::endl; + hname = pathname; + hname += ".h"; + if(!cmSystemTools::FileExists(hname.c_str())) + { + std::cerr << "ERROR, can not find file " << hname; + std::cerr << "Tried .txx .cxx .c " << std::endl; + } } diff --git a/Source/cmClassFile.h b/Source/cmClassFile.h index f9e2f40..a8ad7b3 100644 --- a/Source/cmClassFile.h +++ b/Source/cmClassFile.h @@ -22,19 +22,25 @@ #include <string> #include <vector> -// helper function returns true if a file exits -bool cmFileExists(const char* filename); struct cmClassFile { - // Set the name of the file + /** + * Set the name of the file, given the directory + * the file should be in. Extensions are tried on + * the name in the directory to find the actual file. + */ void SetName(const char* name, const char* dir); + /** + * print the structure to cout + */ void Print(); - bool m_AbstractClass; - bool m_HeaderFileOnly; - std::string m_FullPath; - std::string m_ClassName; + bool m_AbstractClass; // is this an abstract class + bool m_HeaderFileOnly; // is this file only a header file + std::string m_FullPath; // full path to the file + std::string m_ClassName; // class name + // list of files that this file depends on std::vector<std::string> m_Depends; }; diff --git a/Source/cmDSPBuilder.cxx b/Source/cmDSPBuilder.cxx deleted file mode 100644 index b732d96..0000000 --- a/Source/cmDSPBuilder.cxx +++ /dev/null @@ -1,31 +0,0 @@ -#ifdef _MSC_VER -#pragma warning ( disable : 4786 ) -#endif -#include "cmDSPBuilder.h" -#include "cmDSPMakefile.h" - -cmDSPBuilder::~cmDSPBuilder() -{ - delete m_Makefile; -} - -cmDSPBuilder::cmDSPBuilder() -{ - m_Makefile = new cmDSPMakefile; -} - -cmMakefile* cmDSPBuilder::GetMakefile() -{ - return m_Makefile; -} - - -void cmDSPBuilder::CreateDSPFile() -{ - m_Makefile->OutputDSPFile(); -} - -std::vector<std::string> cmDSPBuilder::GetCreatedProjectNames() -{ - return m_Makefile->GetCreatedProjectNames(); -} diff --git a/Source/cmDSPBuilder.h b/Source/cmDSPBuilder.h deleted file mode 100644 index 94d314b..0000000 --- a/Source/cmDSPBuilder.h +++ /dev/null @@ -1,40 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile$ - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) 2000 National Library of Medicine - All rights reserved. - - See COPYRIGHT.txt for copyright details. - -=========================================================================*/ -/** - * cmDSPBuilder is a Facade class for cmDSWMakefile - */ - -#ifndef __cmDSPBuilder_h -#define __cmDSPBuilder_h -#include "cmPCBuilder.h" -#include <vector> -#include <string> -class cmDSPMakefile; - -class cmDSPBuilder : public cmPCBuilder -{ -public: - cmDSPBuilder(); - ~cmDSPBuilder(); - void CreateDSPFile(); - std::vector<std::string> GetCreatedProjectNames(); - virtual cmMakefile* GetMakefile(); -protected: - cmDSPMakefile* m_Makefile; -}; - -#endif - diff --git a/Source/cmDSPMakefile.cxx b/Source/cmDSPMakefile.cxx index f140f5e..34625cd 100644 --- a/Source/cmDSPMakefile.cxx +++ b/Source/cmDSPMakefile.cxx @@ -1,8 +1,11 @@ #include "cmDSPMakefile.h" #include "cmSystemTools.h" +#include "cmCollectFlags.h" #include <iostream> #include <fstream> +#define WIN32_LEAN_AND_MEAN #include <windows.h> +#undef GetCurrentDirectory static void Die(const char* message) { @@ -13,28 +16,49 @@ static void Die(const char* message) void cmDSPMakefile::OutputDSPFile() { - m_IncludeOptions = "/STACK:10000000 "; - m_IncludeOptions = "/I \""; - m_IncludeOptions += this->GetHomeDirectory(); - m_IncludeOptions += "/Code/Common\" "; - m_IncludeOptions += "/I \""; - m_IncludeOptions += this->GetHomeDirectory(); - m_IncludeOptions += "/Code/Insight3DParty/vxl\" "; - // Add the Build directory vcl to the -I path for config.h type stuff - m_IncludeOptions += "/I \""; - m_IncludeOptions += this->GetOutputHomeDirectory(); - m_IncludeOptions += "/Code/Insight3DParty/vxl\" "; - // Add the Build directory to the -I path for config.h type stuff - m_IncludeOptions += "/I \""; - m_IncludeOptions += this->GetOutputHomeDirectory(); - m_IncludeOptions += "\" "; - m_DebugLibraryOptions = " ITKCommon.lib ITKNumerics.lib "; - m_DebugLibraryOptions += " /LIBPATH:\""; - m_DebugLibraryOptions += this->GetOutputHomeDirectory(); - m_DebugLibraryOptions += "/Code/Common/Debug\" "; - m_DebugLibraryOptions += " /LIBPATH:\""; - m_DebugLibraryOptions += this->GetOutputHomeDirectory(); - m_DebugLibraryOptions += "/Code/Insight3DParty/vxl/Debug\" "; + std::vector<std::string>& includes = m_BuildFlags.GetIncludeDirectories(); + std::vector<std::string>::iterator i; + for(i = includes.begin(); i != includes.end(); ++i) + { + std::string include = *i; + cmSystemTools::ReplaceString(include, "${CMAKE_CONFIG_DIR}", + this->GetOutputHomeDirectory() ); + cmSystemTools::ReplaceString(include, "${srcdir}", + this->GetHomeDirectory() ); + m_IncludeOptions += "/I \""; + m_IncludeOptions += include; + m_IncludeOptions += "\" "; + } + std::vector<std::string>& libs = m_BuildFlags.GetLinkLibraries(); + for(i = libs.begin(); i != libs.end(); ++i) + { + m_DebugLibraryOptions += " "; + m_DebugLibraryOptions += *i; + m_DebugLibraryOptions += ".lib "; + } + std::vector<std::string>& libswin32 = m_BuildFlags.GetLinkLibrariesWin32(); + for(i = libswin32.begin(); i != libswin32.end(); ++i) + { + m_DebugLibraryOptions += " "; + m_DebugLibraryOptions += *i; + m_DebugLibraryOptions += ".lib "; + } + std::vector<std::string>& libdirs = m_BuildFlags.GetLinkDirectories(); + for(i = libdirs.begin(); i != libdirs.end(); ++i) + { + m_DebugLibraryOptions += " /LIBPATH:\""; + m_DebugLibraryOptions += *i; + cmSystemTools::ReplaceString(m_DebugLibraryOptions, "${CMAKE_CONFIG_DIR}", + this->GetOutputHomeDirectory() ); + if(i->find("Debug") == std::string::npos) + { + if(i->find("Release") == std::string::npos) + { + m_DebugLibraryOptions += "/Debug\" "; + } + } + } + m_DebugLibraryOptions += "/STACK:10000000 "; m_ReleaseLibraryOptions = m_DebugLibraryOptions; cmSystemTools::ReplaceString(m_ReleaseLibraryOptions, "Debug", "Release"); // If the output directory is not the m_cmHomeDirectory @@ -123,7 +147,6 @@ void cmDSPMakefile::WriteDSPBuildRule(std::ostream& fout) { std::string dspname = *(m_CreatedProjectNames.end()-1); dspname += ".dsp"; -#undef GetCurrentDirectory std::string makefileIn = this->GetCurrentDirectory(); makefileIn += "/"; makefileIn += "CMakeLists.txt"; diff --git a/Source/cmDSPWriter.cxx b/Source/cmDSPWriter.cxx index f140f5e..34625cd 100644 --- a/Source/cmDSPWriter.cxx +++ b/Source/cmDSPWriter.cxx @@ -1,8 +1,11 @@ #include "cmDSPMakefile.h" #include "cmSystemTools.h" +#include "cmCollectFlags.h" #include <iostream> #include <fstream> +#define WIN32_LEAN_AND_MEAN #include <windows.h> +#undef GetCurrentDirectory static void Die(const char* message) { @@ -13,28 +16,49 @@ static void Die(const char* message) void cmDSPMakefile::OutputDSPFile() { - m_IncludeOptions = "/STACK:10000000 "; - m_IncludeOptions = "/I \""; - m_IncludeOptions += this->GetHomeDirectory(); - m_IncludeOptions += "/Code/Common\" "; - m_IncludeOptions += "/I \""; - m_IncludeOptions += this->GetHomeDirectory(); - m_IncludeOptions += "/Code/Insight3DParty/vxl\" "; - // Add the Build directory vcl to the -I path for config.h type stuff - m_IncludeOptions += "/I \""; - m_IncludeOptions += this->GetOutputHomeDirectory(); - m_IncludeOptions += "/Code/Insight3DParty/vxl\" "; - // Add the Build directory to the -I path for config.h type stuff - m_IncludeOptions += "/I \""; - m_IncludeOptions += this->GetOutputHomeDirectory(); - m_IncludeOptions += "\" "; - m_DebugLibraryOptions = " ITKCommon.lib ITKNumerics.lib "; - m_DebugLibraryOptions += " /LIBPATH:\""; - m_DebugLibraryOptions += this->GetOutputHomeDirectory(); - m_DebugLibraryOptions += "/Code/Common/Debug\" "; - m_DebugLibraryOptions += " /LIBPATH:\""; - m_DebugLibraryOptions += this->GetOutputHomeDirectory(); - m_DebugLibraryOptions += "/Code/Insight3DParty/vxl/Debug\" "; + std::vector<std::string>& includes = m_BuildFlags.GetIncludeDirectories(); + std::vector<std::string>::iterator i; + for(i = includes.begin(); i != includes.end(); ++i) + { + std::string include = *i; + cmSystemTools::ReplaceString(include, "${CMAKE_CONFIG_DIR}", + this->GetOutputHomeDirectory() ); + cmSystemTools::ReplaceString(include, "${srcdir}", + this->GetHomeDirectory() ); + m_IncludeOptions += "/I \""; + m_IncludeOptions += include; + m_IncludeOptions += "\" "; + } + std::vector<std::string>& libs = m_BuildFlags.GetLinkLibraries(); + for(i = libs.begin(); i != libs.end(); ++i) + { + m_DebugLibraryOptions += " "; + m_DebugLibraryOptions += *i; + m_DebugLibraryOptions += ".lib "; + } + std::vector<std::string>& libswin32 = m_BuildFlags.GetLinkLibrariesWin32(); + for(i = libswin32.begin(); i != libswin32.end(); ++i) + { + m_DebugLibraryOptions += " "; + m_DebugLibraryOptions += *i; + m_DebugLibraryOptions += ".lib "; + } + std::vector<std::string>& libdirs = m_BuildFlags.GetLinkDirectories(); + for(i = libdirs.begin(); i != libdirs.end(); ++i) + { + m_DebugLibraryOptions += " /LIBPATH:\""; + m_DebugLibraryOptions += *i; + cmSystemTools::ReplaceString(m_DebugLibraryOptions, "${CMAKE_CONFIG_DIR}", + this->GetOutputHomeDirectory() ); + if(i->find("Debug") == std::string::npos) + { + if(i->find("Release") == std::string::npos) + { + m_DebugLibraryOptions += "/Debug\" "; + } + } + } + m_DebugLibraryOptions += "/STACK:10000000 "; m_ReleaseLibraryOptions = m_DebugLibraryOptions; cmSystemTools::ReplaceString(m_ReleaseLibraryOptions, "Debug", "Release"); // If the output directory is not the m_cmHomeDirectory @@ -123,7 +147,6 @@ void cmDSPMakefile::WriteDSPBuildRule(std::ostream& fout) { std::string dspname = *(m_CreatedProjectNames.end()-1); dspname += ".dsp"; -#undef GetCurrentDirectory std::string makefileIn = this->GetCurrentDirectory(); makefileIn += "/"; makefileIn += "CMakeLists.txt"; diff --git a/Source/cmDSWBuilder.cxx b/Source/cmDSWBuilder.cxx deleted file mode 100644 index d64db89..0000000 --- a/Source/cmDSWBuilder.cxx +++ /dev/null @@ -1,22 +0,0 @@ -#include "cmDSWBuilder.h" -#include "cmDSWMakefile.h" - -cmDSWBuilder::~cmDSWBuilder() -{ - delete m_Makefile; -} - -cmDSWBuilder::cmDSWBuilder() -{ - m_Makefile = new cmDSWMakefile; -} - -cmMakefile* cmDSWBuilder::GetMakefile() -{ - return m_Makefile; -} - -void cmDSWBuilder::CreateDSWFile() -{ - m_Makefile->OutputDSWFile(); -} diff --git a/Source/cmDSWBuilder.h b/Source/cmDSWBuilder.h deleted file mode 100644 index f44a01e..0000000 --- a/Source/cmDSWBuilder.h +++ /dev/null @@ -1,38 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile$ - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) 2000 National Library of Medicine - All rights reserved. - - See COPYRIGHT.txt for copyright details. - -=========================================================================*/ -/** - * cmDSWBuilder - */ - -#ifndef __cmDSWBuilder_h -#define __cmDSWBuilder_h - -#include "cmPCBuilder.h" -class cmDSWMakefile; - -class cmDSWBuilder : public cmPCBuilder -{ -public: - cmDSWBuilder(); - ~cmDSWBuilder(); - void CreateDSWFile(); - virtual cmMakefile* GetMakefile(); -protected: - cmDSWMakefile* m_Makefile; -}; - -#endif - diff --git a/Source/cmDSWMakefile.cxx b/Source/cmDSWMakefile.cxx index 60d09f5..271bd3e 100644 --- a/Source/cmDSWMakefile.cxx +++ b/Source/cmDSWMakefile.cxx @@ -2,12 +2,15 @@ #pragma warning ( disable : 4786 ) #endif #include "cmDSWMakefile.h" -#include "cmDSPBuilder.h" #include "cmSystemTools.h" +#include "cmDSPMakefile.h" #include <iostream> #include <fstream> #include <windows.h> +// microsoft nonsense +#undef GetCurrentDirectory +#undef SetCurrentDirectory // virtual override, ouput the makefile void cmDSWMakefile::OutputDSWFile() @@ -27,80 +30,139 @@ void cmDSWMakefile::OutputDSWFile() MessageBox(0, m_OutputDirectory.c_str(), 0, MB_OK); } } - - std::string fname; fname = m_OutputDirectory; fname += "/"; fname += this->m_LibraryName; fname += ".dsw"; std::cerr << "writting dsw file " << fname.c_str() << std::endl; - std::ofstream fout(fname.c_str()); if(!fout) { - std::cerr << "Error can not open " << fname.c_str() << " for write" << std::endl; + std::cerr << "Error can not open " + << fname.c_str() << " for write" << std::endl; return; } this->WriteDSWFile(fout); } +// ------------------------------------------------ +// Recursive function to find all the CMakeLists.txt files +// in a project. As each file is read in, any directories in +// the SUBDIR variable are also passed back to this function. +// The result is a vector of cmDSPMakefile objects, one for +// each directory with a CMakeLists.txt file +// +void cmDSWMakefile::FindAllCMakeListsFiles(const char* subdir, + std::vector<cmDSPMakefile*>& makefiles) +{ + std::string currentDir = this->GetCurrentDirectory(); + currentDir += "/"; + currentDir += subdir; + currentDir += "/"; + currentDir += "CMakeLists.txt"; + // CMakeLists.txt exits in the subdirectory + // then create a cmDSPMakefile for it + if(cmSystemTools::FileExists(currentDir.c_str())) + { + // Create a new cmDSPMakefile to read the currentDir CMakeLists.txt file + cmDSPMakefile* dsp = new cmDSPMakefile; + // add it to the vector + makefiles.push_back(dsp); + // Set up the file with the current context + dsp->SetOutputHomeDirectory(this->GetOutputDirectory()); + dsp->SetHomeDirectory(this->GetHomeDirectory()); + // set the current directory in the Source as a full + // path + std::string currentDir = this->GetCurrentDirectory(); + currentDir += "/"; + currentDir += subdir; + dsp->SetCurrentDirectory(currentDir.c_str()); + // Parse the CMakeLists.txt file + currentDir += "/CMakeLists.txt"; + dsp->ReadMakefile(currentDir.c_str()); + // Set the output directory which may be different than the source + std::string outdir = m_OutputDirectory; + outdir += "/"; + outdir += subdir; + dsp->SetOutputDirectory(outdir.c_str()); + // Create the DSP file + dsp->OutputDSPFile(); + // Look at any sub directories parsed (SUBDIRS) and + // recurse into them + const std::vector<std::string>& subdirs = dsp->GetSubDirectories(); + for(std::vector<std::string>::const_iterator i = subdirs.begin(); + i != subdirs.end(); ++i) + { + // append the subdirectory to the current directoy subdir + std::string nextDir = subdir; + nextDir += "/"; + nextDir += i->c_str(); + // recurse into nextDir + this->FindAllCMakeListsFiles(nextDir.c_str(), + makefiles); + } + } + else + { + std::cerr << "Can not find CMakeLists.txt in " << currentDir.c_str() + << std::endl; + } +} + +// Write a DSW file to the stream void cmDSWMakefile::WriteDSWFile(std::ostream& fout) { + // Write out the header for a DSW file this->WriteDSWHeader(fout); - for(std::vector<std::string>::iterator i = m_SubDirectories.begin(); - i != m_SubDirectories.end(); ++i) + // Create an array of dsp files for the project + std::vector<cmDSPMakefile*> dspfiles; + // loop over all the subdirectories for the DSW file, + // and find all sub directory projects + for(std::vector<std::string>::iterator j = m_SubDirectories.begin(); + j != m_SubDirectories.end(); ++j) { - const char* dir = (*i).c_str(); - std::vector<std::string> dspnames = this->CreateDSPFile(dir); - std::cerr << "Create dsp for " << dspnames.size() << " number of dsp files in " << dir << std::endl; + this->FindAllCMakeListsFiles(j->c_str(), dspfiles); + } + // For each DSP file created insert them into the DSW file + for(std::vector<cmDSPMakefile*>::iterator k = dspfiles.begin(); + k != dspfiles.end(); ++k) + { + // Get the directory for the dsp file, it comes + // from the source, so it has the source path which needs + // to be removed as this may be built in a different directory + // than the source + std::string dir = (*k)->GetCurrentDirectory(); + // Get the home directory with the trailing slash + std::string homedir = this->GetHomeDirectory(); + homedir += "/"; + // make the directory relative by removing the home directory part + cmSystemTools::ReplaceString(dir, homedir.c_str(), ""); + // Get the list of create dsp files from the cmDSPMakefile, more + // than one dsp could have been created per input CMakeLists.txt file + std::vector<std::string> dspnames = (*k)->GetCreatedProjectNames(); + std::cerr << "Create dsp for " + << dspnames.size() + << " number of dsp files in " << dir << std::endl; for(std::vector<std::string>::iterator si = dspnames.begin(); si != dspnames.end(); ++si) { - std::string dspname = *si; - std::cerr << "Create dsp for " << (*si).c_str() << std::endl; - if(dspname == "") - { - std::cerr << "Project name not found in " << dir << "/CMakeLists.txt" << std::endl; - std::cerr << "Skipping Project " << std::endl; - } - else - { - std::string subdir = "./"; - subdir += dir; - this->WriteProject(fout, dspname.c_str(), subdir.c_str()); - } + // Write the project into the DSW file + this->WriteProject(fout, si->c_str(), dir.c_str()); } + // delete the cmDSPMakefile object once done with it to avoid + // leaks + delete *k; } + // Write the footer for the DSW file this->WriteDSWFooter(fout); } -std::vector<std::string> cmDSWMakefile::CreateDSPFile(const char* subdir) -{ -#undef GetCurrentDirectory - std::string currentDir = this->GetCurrentDirectory(); - currentDir += "/"; - currentDir += subdir; - cmDSPBuilder dsp; - dsp.SetOutputHomeDirectory(this->GetOutputDirectory()); - dsp.SetHomeDirectory(this->GetHomeDirectory()); - dsp.SetMakefileDirectory(currentDir.c_str()); - std::string outdir = m_OutputDirectory; - outdir += "/"; - outdir += subdir; - dsp.SetOutputDirectory(outdir.c_str()); - currentDir += "/"; - currentDir += "CMakeLists.txt"; - dsp.SetInputMakefilePath(currentDir.c_str()); - dsp.CreateDSPFile(); - return dsp.GetCreatedProjectNames(); -} - void cmDSWMakefile::WriteProject(std::ostream& fout, - const char* dspname, - const char* dir) + const char* dspname, + const char* dir) { fout << "###############################################################################\n\n"; fout << "Project: \"" << dspname << "\"=" diff --git a/Source/cmDSWMakefile.h b/Source/cmDSWMakefile.h index e4036a1..6c3fc9e 100644 --- a/Source/cmDSWMakefile.h +++ b/Source/cmDSWMakefile.h @@ -24,6 +24,7 @@ #include "cmMakefile.h" #include <vector> +class cmDSPMakefile; class cmDSWMakefile : public cmMakefile @@ -31,9 +32,10 @@ class cmDSWMakefile : public cmMakefile public: virtual void OutputDSWFile(); private: + void FindAllCMakeListsFiles(const char* subdir, + std::vector<cmDSPMakefile*>&); void WriteDSWFile(std::ostream& fout); void WriteDSWHeader(std::ostream& fout); - std::vector<std::string> CreateDSPFile(const char* dir); void WriteProject(std::ostream& fout, const char* name, const char* path); void WriteDSWFooter(std::ostream& fout); diff --git a/Source/cmDSWWriter.cxx b/Source/cmDSWWriter.cxx index 60d09f5..271bd3e 100644 --- a/Source/cmDSWWriter.cxx +++ b/Source/cmDSWWriter.cxx @@ -2,12 +2,15 @@ #pragma warning ( disable : 4786 ) #endif #include "cmDSWMakefile.h" -#include "cmDSPBuilder.h" #include "cmSystemTools.h" +#include "cmDSPMakefile.h" #include <iostream> #include <fstream> #include <windows.h> +// microsoft nonsense +#undef GetCurrentDirectory +#undef SetCurrentDirectory // virtual override, ouput the makefile void cmDSWMakefile::OutputDSWFile() @@ -27,80 +30,139 @@ void cmDSWMakefile::OutputDSWFile() MessageBox(0, m_OutputDirectory.c_str(), 0, MB_OK); } } - - std::string fname; fname = m_OutputDirectory; fname += "/"; fname += this->m_LibraryName; fname += ".dsw"; std::cerr << "writting dsw file " << fname.c_str() << std::endl; - std::ofstream fout(fname.c_str()); if(!fout) { - std::cerr << "Error can not open " << fname.c_str() << " for write" << std::endl; + std::cerr << "Error can not open " + << fname.c_str() << " for write" << std::endl; return; } this->WriteDSWFile(fout); } +// ------------------------------------------------ +// Recursive function to find all the CMakeLists.txt files +// in a project. As each file is read in, any directories in +// the SUBDIR variable are also passed back to this function. +// The result is a vector of cmDSPMakefile objects, one for +// each directory with a CMakeLists.txt file +// +void cmDSWMakefile::FindAllCMakeListsFiles(const char* subdir, + std::vector<cmDSPMakefile*>& makefiles) +{ + std::string currentDir = this->GetCurrentDirectory(); + currentDir += "/"; + currentDir += subdir; + currentDir += "/"; + currentDir += "CMakeLists.txt"; + // CMakeLists.txt exits in the subdirectory + // then create a cmDSPMakefile for it + if(cmSystemTools::FileExists(currentDir.c_str())) + { + // Create a new cmDSPMakefile to read the currentDir CMakeLists.txt file + cmDSPMakefile* dsp = new cmDSPMakefile; + // add it to the vector + makefiles.push_back(dsp); + // Set up the file with the current context + dsp->SetOutputHomeDirectory(this->GetOutputDirectory()); + dsp->SetHomeDirectory(this->GetHomeDirectory()); + // set the current directory in the Source as a full + // path + std::string currentDir = this->GetCurrentDirectory(); + currentDir += "/"; + currentDir += subdir; + dsp->SetCurrentDirectory(currentDir.c_str()); + // Parse the CMakeLists.txt file + currentDir += "/CMakeLists.txt"; + dsp->ReadMakefile(currentDir.c_str()); + // Set the output directory which may be different than the source + std::string outdir = m_OutputDirectory; + outdir += "/"; + outdir += subdir; + dsp->SetOutputDirectory(outdir.c_str()); + // Create the DSP file + dsp->OutputDSPFile(); + // Look at any sub directories parsed (SUBDIRS) and + // recurse into them + const std::vector<std::string>& subdirs = dsp->GetSubDirectories(); + for(std::vector<std::string>::const_iterator i = subdirs.begin(); + i != subdirs.end(); ++i) + { + // append the subdirectory to the current directoy subdir + std::string nextDir = subdir; + nextDir += "/"; + nextDir += i->c_str(); + // recurse into nextDir + this->FindAllCMakeListsFiles(nextDir.c_str(), + makefiles); + } + } + else + { + std::cerr << "Can not find CMakeLists.txt in " << currentDir.c_str() + << std::endl; + } +} + +// Write a DSW file to the stream void cmDSWMakefile::WriteDSWFile(std::ostream& fout) { + // Write out the header for a DSW file this->WriteDSWHeader(fout); - for(std::vector<std::string>::iterator i = m_SubDirectories.begin(); - i != m_SubDirectories.end(); ++i) + // Create an array of dsp files for the project + std::vector<cmDSPMakefile*> dspfiles; + // loop over all the subdirectories for the DSW file, + // and find all sub directory projects + for(std::vector<std::string>::iterator j = m_SubDirectories.begin(); + j != m_SubDirectories.end(); ++j) { - const char* dir = (*i).c_str(); - std::vector<std::string> dspnames = this->CreateDSPFile(dir); - std::cerr << "Create dsp for " << dspnames.size() << " number of dsp files in " << dir << std::endl; + this->FindAllCMakeListsFiles(j->c_str(), dspfiles); + } + // For each DSP file created insert them into the DSW file + for(std::vector<cmDSPMakefile*>::iterator k = dspfiles.begin(); + k != dspfiles.end(); ++k) + { + // Get the directory for the dsp file, it comes + // from the source, so it has the source path which needs + // to be removed as this may be built in a different directory + // than the source + std::string dir = (*k)->GetCurrentDirectory(); + // Get the home directory with the trailing slash + std::string homedir = this->GetHomeDirectory(); + homedir += "/"; + // make the directory relative by removing the home directory part + cmSystemTools::ReplaceString(dir, homedir.c_str(), ""); + // Get the list of create dsp files from the cmDSPMakefile, more + // than one dsp could have been created per input CMakeLists.txt file + std::vector<std::string> dspnames = (*k)->GetCreatedProjectNames(); + std::cerr << "Create dsp for " + << dspnames.size() + << " number of dsp files in " << dir << std::endl; for(std::vector<std::string>::iterator si = dspnames.begin(); si != dspnames.end(); ++si) { - std::string dspname = *si; - std::cerr << "Create dsp for " << (*si).c_str() << std::endl; - if(dspname == "") - { - std::cerr << "Project name not found in " << dir << "/CMakeLists.txt" << std::endl; - std::cerr << "Skipping Project " << std::endl; - } - else - { - std::string subdir = "./"; - subdir += dir; - this->WriteProject(fout, dspname.c_str(), subdir.c_str()); - } + // Write the project into the DSW file + this->WriteProject(fout, si->c_str(), dir.c_str()); } + // delete the cmDSPMakefile object once done with it to avoid + // leaks + delete *k; } + // Write the footer for the DSW file this->WriteDSWFooter(fout); } -std::vector<std::string> cmDSWMakefile::CreateDSPFile(const char* subdir) -{ -#undef GetCurrentDirectory - std::string currentDir = this->GetCurrentDirectory(); - currentDir += "/"; - currentDir += subdir; - cmDSPBuilder dsp; - dsp.SetOutputHomeDirectory(this->GetOutputDirectory()); - dsp.SetHomeDirectory(this->GetHomeDirectory()); - dsp.SetMakefileDirectory(currentDir.c_str()); - std::string outdir = m_OutputDirectory; - outdir += "/"; - outdir += subdir; - dsp.SetOutputDirectory(outdir.c_str()); - currentDir += "/"; - currentDir += "CMakeLists.txt"; - dsp.SetInputMakefilePath(currentDir.c_str()); - dsp.CreateDSPFile(); - return dsp.GetCreatedProjectNames(); -} - void cmDSWMakefile::WriteProject(std::ostream& fout, - const char* dspname, - const char* dir) + const char* dspname, + const char* dir) { fout << "###############################################################################\n\n"; fout << "Project: \"" << dspname << "\"=" diff --git a/Source/cmDSWWriter.h b/Source/cmDSWWriter.h index e4036a1..6c3fc9e 100644 --- a/Source/cmDSWWriter.h +++ b/Source/cmDSWWriter.h @@ -24,6 +24,7 @@ #include "cmMakefile.h" #include <vector> +class cmDSPMakefile; class cmDSWMakefile : public cmMakefile @@ -31,9 +32,10 @@ class cmDSWMakefile : public cmMakefile public: virtual void OutputDSWFile(); private: + void FindAllCMakeListsFiles(const char* subdir, + std::vector<cmDSPMakefile*>&); void WriteDSWFile(std::ostream& fout); void WriteDSWHeader(std::ostream& fout); - std::vector<std::string> CreateDSPFile(const char* dir); void WriteProject(std::ostream& fout, const char* name, const char* path); void WriteDSWFooter(std::ostream& fout); diff --git a/Source/cmMakeDepend.cxx b/Source/cmMakeDepend.cxx index 4738373..ea1e6b5 100644 --- a/Source/cmMakeDepend.cxx +++ b/Source/cmMakeDepend.cxx @@ -2,23 +2,27 @@ #pragma warning ( disable : 4786 ) #endif #include "cmMakeDepend.h" +#include "cmSystemTools.h" #include <fstream> #include <iostream> #include <algorithm> #include <functional> -void cmMakeDepend::SetIncludeRegularExpression(const char* prefix) -{ - m_IncludeFileRegularExpression.compile(prefix); -} - cmMakeDepend::cmMakeDepend() { m_Verbose = false; m_IncludeFileRegularExpression.compile("^itk|^vtk|^vnl|^vcl|^f2c"); } + +// only files matching this regular expression with be considered +void cmMakeDepend::SetIncludeRegularExpression(const char* prefix) +{ + m_IncludeFileRegularExpression.compile(prefix); +} + + cmMakeDepend::~cmMakeDepend() { for(DependArray::iterator i = m_DependInformation.begin(); @@ -32,11 +36,25 @@ cmMakeDepend::~cmMakeDepend() // Set the makefile that depends will be made from. // The pointer is kept so the cmClassFile array can -// be updated with the depend information. +// be updated with the depend information in the cmMakefile. void cmMakeDepend::SetMakefile(cmMakefile* makefile) { m_Makefile = makefile; + + // Now extract any include paths from the makefile flags + cmCollectFlags& flags = m_Makefile->GetBuildFlags(); + std::vector<std::string>& includes = flags.GetIncludeDirectories(); + std::vector<std::string>::iterator j; + for(j = includes.begin(); j != includes.end(); ++j) + { + cmSystemTools::ReplaceString(*j, "${CMAKE_CONFIG_DIR}", + m_Makefile->GetOutputHomeDirectory() ); + cmSystemTools::ReplaceString(*j, "${srcdir}", + m_Makefile->GetHomeDirectory() ); + this->AddSearchPath(j->c_str()); + } + // Now create cmDependInformation objects for files in the directory int index = 0; std::vector<cmClassFile>::iterator i = makefile->m_Classes.begin(); while(i != makefile->m_Classes.end()) @@ -49,7 +67,6 @@ void cmMakeDepend::SetMakefile(cmMakefile* makefile) info->m_IncludeName = (*i).m_FullPath; m_DependInformation.push_back(info); info->m_ClassFileIndex = index; - } ++i; index++; @@ -195,6 +212,9 @@ int cmMakeDepend::FindInformation(const char* fname) } cmDependInformation* newinfo = new cmDependInformation; newinfo->m_FullPath = this->FullPath(fname); + // Add the directory where this file was found to the search path + // may have been foo/bar.h, but bar may include files from the foo + // directory without the foo prefix this->AddFileToSearchPath(newinfo->m_FullPath.c_str()); newinfo->m_IncludeName = fname; m_DependInformation.push_back(newinfo); @@ -204,13 +224,15 @@ int cmMakeDepend::FindInformation(const char* fname) // remove duplicate indices from the depend information void cmDependInformation::RemoveDuplicateIndices() { + // sort the array std::sort(m_Indices.begin(), m_Indices.end(), std::less<int>()); + // remove duplicates std::vector<int>::iterator new_end = std::unique(m_Indices.begin(), m_Indices.end()); m_Indices.erase(new_end, m_Indices.end()); } -// add the depend information from info to this +// add the depend information from info to the m_Indices varible of this class. void cmDependInformation::MergeInfo(cmDependInformation* info) { std::vector<int>::iterator i = info->m_Indices.begin(); @@ -226,19 +248,19 @@ std::string cmMakeDepend::FullPath(const char* fname) for(std::vector<std::string>::iterator i = m_IncludeDirectories.begin(); i != m_IncludeDirectories.end(); ++i) { - if(cmFileExists(fname)) + if(cmSystemTools::FileExists(fname)) { return std::string(fname); } std::string path = *i; path = path + "/"; path = path + fname; - if(cmFileExists(path.c_str())) + if(cmSystemTools::FileExists(path.c_str())) { return path; } } - std::cerr << "File not found " << fname << std::endl; + std::cerr << "Depend: File not found " << fname << std::endl; return std::string(fname); } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 38792a5..3fa59a9 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4,39 +4,11 @@ #include "cmMakefile.h" #include "cmClassFile.h" #include "cmDirectory.h" - +#include "cmSystemTools.h" #include <fstream> #include <iostream> -// remove extra spaces and the "\" character from the name -// of the class as it is in the CMakeLists.txt -inline std::string CleanUpName(const char* name) -{ - std::string className = name; - size_t i =0; - while(className[i] == ' ') - { - i++; - } - if(i) - { - className = className.substr(i, className.size()); - } - size_t pos = className.find('\\'); - if(pos != std::string::npos) - { - className = className.substr(0, pos); - } - - pos = className.find(' '); - if(pos != std::string::npos) - { - className = className.substr(0, pos); - } - return className; -} - // default is not to be building executables cmMakefile::cmMakefile() { @@ -55,7 +27,10 @@ void cmMakefile::Print() bool cmMakefile::ReadMakefile(const char* filename) { - std::cerr << "reading makefile " << filename << std::endl; + m_BuildFlags.SetSourceHomeDirectory(this->GetHomeDirectory()); + m_BuildFlags.SetStartDirectory(this->GetCurrentDirectory()); + m_BuildFlags.ParseDirectories(); + std::ifstream fin(filename); if(!fin) { @@ -106,7 +81,7 @@ bool cmMakefile::ReadMakefile(const char* filename) { if(line.find("\\") != std::string::npos) { - this->ReadSubdirs(fin); + cmSystemTools::ReadList(m_SubDirectories, fin); } } else if(line.find("EXECUTABLES") != std::string::npos) @@ -177,7 +152,7 @@ void cmMakefile::ReadClasses(std::ifstream& fin, done = true; } // remove extra spaces and \ from the class name - classname = CleanUpName(classname.c_str()); + classname = cmSystemTools::CleanUpName(classname.c_str()); // if this is not an abstract list then add new class // to the list of classes in this makefile @@ -204,6 +179,9 @@ void cmMakefile::ReadClasses(std::ifstream& fin, } } +// Find all of the files in dir as specified from this line: +// TEMPLATE_INSTANCE_DIRECTORY = dir +// Add all the files to the m_Classes array. void cmMakefile::ReadTemplateInstanceDirectory(std::string& line) { @@ -211,7 +189,7 @@ void cmMakefile::ReadTemplateInstanceDirectory(std::string& line) if(start != std::string::npos) { std::string dirname = line.substr(start+1, line.size()); - dirname = CleanUpName(dirname.c_str()); + dirname = cmSystemTools::CleanUpName(dirname.c_str()); std::string tdir = this->GetCurrentDirectory(); tdir += "/"; tdir += dirname; @@ -250,28 +228,3 @@ void cmMakefile::ReadTemplateInstanceDirectory(std::string& line) } - -// Read a list of subdirectories from the stream -void cmMakefile::ReadSubdirs(std::ifstream& fin) -{ - char inbuffer[2048]; - bool done = false; - - while (!done) - { - // read a line from the makefile - fin.getline(inbuffer, 2047); - // convert to a string class - std::string dir = inbuffer; - // if the line does not end in \ then we are at the - // end of the list - if(dir.find('\\') == std::string::npos) - { - done = true; - } - // remove extra spaces and \ from the class name - dir = CleanUpName(dir.c_str()); - m_SubDirectories.push_back(dir); - } -} - diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index d570de4..94cb988 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -14,7 +14,8 @@ =========================================================================*/ /** - * cmMakefile + * cmMakefile - used to parse and store the contents of a + * CMakeLists.txt makefile in memory. */ #ifndef cmMakefile_h #define cmMakefile_h @@ -23,6 +24,7 @@ #endif #include "cmClassFile.h" +#include "cmCollectFlags.h" #include <vector> #include <fstream> #include <iostream> @@ -82,10 +84,17 @@ public: { return m_OutputHomeDirectory.c_str(); } + cmCollectFlags& GetBuildFlags() + { + return m_BuildFlags; + } + const std::vector<std::string>& GetSubDirectories() + { + return m_SubDirectories; + } private: void ReadTemplateInstanceDirectory(std::string&); - void ReadSubdirs(std::ifstream& fin); void ReadClasses(std::ifstream& fin, bool t); friend class cmMakeDepend; // make depend needs direct access // to the m_Classes array @@ -99,7 +108,8 @@ protected: std::string m_LibraryName; // library name std::vector<cmClassFile> m_Classes; // list of classes in makefile std::vector<std::string> m_SubDirectories; // list of sub directories - std::vector<std::string> m_MakeVerbatim; // list of sub directories + std::vector<std::string> m_MakeVerbatim; // lines copied from input file + cmCollectFlags m_BuildFlags; }; diff --git a/Source/cmPCBuilder.cxx b/Source/cmPCBuilder.cxx deleted file mode 100644 index e8745c5..0000000 --- a/Source/cmPCBuilder.cxx +++ /dev/null @@ -1,46 +0,0 @@ -#include "cmPCBuilder.h" -#include "cmMakefile.h" - - -cmPCBuilder::cmPCBuilder() -{ -} - -// Delete the m_Makefile -cmPCBuilder::~cmPCBuilder() -{ -} - -// Read in the given makefile -void cmPCBuilder::SetInputMakefilePath(const char* mfile) -{ - if(!GetMakefile()->ReadMakefile(mfile)) - { - std::cerr << "Error can not open " << mfile << " for input " << std::endl; - abort(); - } -} - - -void cmPCBuilder::SetHomeDirectory(const char* dir) -{ - GetMakefile()->SetHomeDirectory(dir); -} - -void cmPCBuilder::SetMakefileDirectory(const char* dir) -{ - GetMakefile()->SetCurrentDirectory(dir); -} - - - -void cmPCBuilder::SetOutputDirectory(const char* dir) -{ - GetMakefile()->SetOutputDirectory(dir); -} - -void cmPCBuilder::SetOutputHomeDirectory(const char* dir) -{ - GetMakefile()->SetOutputHomeDirectory(dir); -} - diff --git a/Source/cmPCBuilder.h b/Source/cmPCBuilder.h deleted file mode 100644 index e541bfc..0000000 --- a/Source/cmPCBuilder.h +++ /dev/null @@ -1,43 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile$ - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) 2000 National Library of Medicine - All rights reserved. - - See COPYRIGHT.txt for copyright details. - -=========================================================================*/ -/** - * cmPCBuilder - */ - -#ifndef __cmPCBuilder_h -#define __cmPCBuilder_h -class cmMakefile; -/** - * cmPCBuilder is a supper class used for creating a build - * file for PC's. This class can parse an cm Makefile.in and - * extract the classes that need to be compiled. - */ - -class cmPCBuilder -{ -public: - cmPCBuilder(); - ~cmPCBuilder(); - virtual cmMakefile* GetMakefile() = 0; - void SetInputMakefilePath(const char*); - void SetHomeDirectory(const char*); - void SetMakefileDirectory(const char*); - void SetOutputDirectory(const char*); - void SetOutputHomeDirectory(const char*); -}; - -#endif - diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 49dc32b..b8a44c9 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1,7 +1,52 @@ #include "cmSystemTools.h" -#include <direct.h> #include "errno.h" +#include <sys/stat.h> + +#ifdef _MSC_VER #include <windows.h> +#include <direct.h> +inline int Mkdir(const char* dir) +{ + return _mkdir(dir); +} +#else +#include <sys/types.h> +#include <fcntl.h> +#include <unistd.h> +inline int Mkdir(const char* dir) +{ + return mkdir(dir, 00700); +} +#endif + +// remove extra spaces and the "\" character from the name +// of the class as it is in the CMakeLists.txt +std::string cmSystemTools::CleanUpName(const char* name) +{ + std::string className = name; + size_t i =0; + while(className[i] == ' ') + { + i++; + } + if(i) + { + className = className.substr(i, className.size()); + } + size_t pos = className.find('\\'); + if(pos != std::string::npos) + { + className = className.substr(0, pos); + } + + pos = className.find(' '); + if(pos != std::string::npos) + { + className = className.substr(0, pos); + } + return className; +} + bool cmSystemTools::MakeDirectory(const char* path) { @@ -21,10 +66,10 @@ bool cmSystemTools::MakeDirectory(const char* path) while((pos = dir.find('/', pos)) != std::string::npos) { std::string topdir = dir.substr(0, pos); - _mkdir(topdir.c_str()); + Mkdir(topdir.c_str()); pos++; } - if(_mkdir(path) != 0) + if(Mkdir(path) != 0) { // if it is some other error besides directory exists // then return false @@ -36,6 +81,9 @@ bool cmSystemTools::MakeDirectory(const char* path) return true; } + +// replace replace with with as many times as it shows up in source. +// write the result into source. void cmSystemTools::ReplaceString(std::string& source, const char* replace, const char* with) @@ -52,3 +100,57 @@ void cmSystemTools::ReplaceString(std::string& source, start = source.find(replace, start + lengthReplace ); } } + +// return true if the file exists +bool cmSystemTools::FileExists(const char* filename) +{ + struct stat fs; + if (stat(filename, &fs) != 0) + { + return false; + } + else + { + return true; + } +} + +// Read a list from a CMakeLists.txt file open stream. +// assume the stream has just read "VAR = \" +// read until there is not a "\" at the end of the line. +void cmSystemTools::ReadList(std::vector<std::string>& stringList, + std::ifstream& fin) +{ + char inbuffer[2048]; + bool done = false; + while ( !done ) + { + fin.getline(inbuffer, 2047 ); + std::string inname = inbuffer; + if(inname.find('\\') == std::string::npos) + { + done = true; + } + if(inname.size()) + { + stringList.push_back(cmSystemTools::CleanUpName(inname.c_str())); + } + } +} + + +// convert windows slashes to unix slashes \ with / +void cmSystemTools::ConvertToUnixSlashes(std::string& path) +{ + std::string::size_type pos = path.find('\\'); + while(pos != std::string::npos) + { + path[pos] = '/'; + pos = path.find('\\'); + } + // remove any trailing slash + if(path[path.size()-1] == '/') + { + path = path.substr(0, path.size()-1); + } +} diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index a7b00f7..d4745f4 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -14,23 +14,56 @@ =========================================================================*/ /** - * cmWindowsTools + * cmSystemTools - a collection of useful functions for CMake. */ -#ifndef cmWindowsTools_h -#define cmWindowsTools_h +#ifndef cmSystemTools_h +#define cmSystemTools_h #ifdef _MSC_VER #pragma warning ( disable : 4786 ) #endif #include <string> +#include <vector> +#include <fstream> class cmSystemTools { public: + /** + * Make a new directory if it is not there. This function + * can make a full path even if none of the directories existed + * prior to calling this function. + */ static bool MakeDirectory(const char* path); + /** + * Replace replace all occurances of the string in in + * souce string. + */ static void ReplaceString(std::string& source, const char* replace, const char* with); + /** + * Remove extra spaces and the trailing \ from a string. + */ + static std::string CleanUpName(const char* name); + /** + * Replace windows slashes with unix style slashes + */ + static void ConvertToUnixSlashes(std::string& path); + + /** + * Return true if a file exists + */ + static bool FileExists(const char* filename); + /** + * Read a list from a file into the array of strings. + * This function assumes that the first line of the + * list has been read. For example: NAME = \ was already + * read in. The reading stops when there are no more + * continuation characters. + */ + static void ReadList(std::vector<std::string>& stringList, + std::ifstream& fin); }; diff --git a/Source/cmUnixMakefile.cxx b/Source/cmUnixMakefile.cxx index 90c887b..83f215c 100644 --- a/Source/cmUnixMakefile.cxx +++ b/Source/cmUnixMakefile.cxx @@ -53,7 +53,14 @@ inline std::string FixDirectoryName(const char* dir) return s; } -// output the makefile to the named file +// This is where CMakeTargets.make is generated +// This function ouputs the following: +// 1. Include flags for the compiler +// 2. List of .o files that need to be compiled +// 3. Rules to build executables including -l and -L options +// 4. Rules to build in sub directories +// 5. The name of the library being built, if it is a library + void cmUnixMakefile::OutputMakefile(const char* file) { std::ofstream fout(file); @@ -62,8 +69,28 @@ void cmUnixMakefile::OutputMakefile(const char* file) std::cerr << "Error can not open " << file << " for write" << std::endl; return; } + // Output Include paths + fout << "INCLUDE_FLAGS = "; + std::vector<std::string>& includes = m_BuildFlags.GetIncludeDirectories(); + std::vector<std::string>::iterator i; + for(i = includes.begin(); i != includes.end(); ++i) + { + std::string include = *i; + fout << "-I" << i->c_str() << " "; + } + fout << " ${LOCAL_INCLUDE_FLAGS} "; + fout << "\n"; + // see if there are files to compile in this makefile + // These are used for both libraries and executables if(m_Classes.size() ) { + // Ouput Library name if there are SRC_OBJS + if(strlen(this->GetLibraryName()) > 0) + { + fout << "ME = " << this->GetLibraryName() << "\n\n"; + fout << "BUILD_LIB_FILE = lib${ME}${ITK_LIB_EXT}\n\n"; + } + // Output SRC_OBJ list for all the classes to be compiled fout << "SRC_OBJ = \\\n"; for(int i = 0; i < m_Classes.size(); i++) { @@ -82,20 +109,41 @@ void cmUnixMakefile::OutputMakefile(const char* file) } fout << "\n"; } - if(strlen(this->GetLibraryName()) > 0) - { - fout << "ME = " << this->GetLibraryName() << "\n\n"; - fout << "BUILD_LIB_FILE = lib${ME}${ITK_LIB_EXT}\n\n"; - } - + // Ouput user make text embeded in the input file for(int i =0; i < m_MakeVerbatim.size(); i++) { fout << m_MakeVerbatim[i] << "\n"; } fout << "\n\n"; + // Output rules for building executables if( m_Executables ) { + // collect all the flags needed for linking libraries + std::string linkLibs; + std::vector<std::string>::iterator j; + std::vector<std::string>& libdirs = m_BuildFlags.GetLinkDirectories(); + for(j = libdirs.begin(); j != libdirs.end(); ++j) + { + linkLibs += "-L"; + linkLibs += *j; + linkLibs += " "; + } + std::vector<std::string>& libs = m_BuildFlags.GetLinkLibraries(); + for(j = libs.begin(); j != libs.end(); ++j) + { + linkLibs += "-l"; + linkLibs += *j; + linkLibs += " "; + } + std::vector<std::string>& libsUnix = m_BuildFlags.GetLinkLibrariesUnix(); + for(j = libsUnix.begin(); j != libsUnix.end(); ++j) + { + linkLibs += *j; + linkLibs += " "; + } + linkLibs += " ${LOCAL_LINK_FLAGS} "; + // Now create rules for all of the executables to be built for(int i = 0; i < m_Classes.size(); i++) { if(!m_Classes[i].m_AbstractClass && !m_Classes[i].m_HeaderFileOnly) @@ -103,10 +151,13 @@ void cmUnixMakefile::OutputMakefile(const char* file) std::string DotO = m_Classes[i].m_ClassName; DotO += ".o"; fout << m_Classes[i].m_ClassName << ": " << DotO << "\n"; - fout << "\t ${CXX} ${CXX_FLAGS} " << DotO.c_str() << " -o $@ -L${CMAKE_OBJ_DIR}/Code/Common -lITKCommon \\\n" - << "\t-L${CMAKE_OBJ_DIR}/Code/Insight3DParty/vxl -lITKNumerics -lm ${DL_LIBS}\n\n"; + fout << "\t${CXX} ${CXX_FLAGS} " + << DotO.c_str() << " " + << linkLibs.c_str() + << " -o $@ ""\n\n"; } } + // ouput the list of executables fout << "EXECUTABLES = \\\n"; for(int i = 0; i < m_Classes.size(); i++) { @@ -122,7 +173,7 @@ void cmUnixMakefile::OutputMakefile(const char* file) } fout << "\n"; } - + // Output Sub directory build rules if( m_SubDirectories.size() ) { fout << "SUBDIR_BUILD = \\\n"; diff --git a/Source/cmUnixMakefile.h b/Source/cmUnixMakefile.h index 67c0911..220a07d 100644 --- a/Source/cmUnixMakefile.h +++ b/Source/cmUnixMakefile.h @@ -25,7 +25,9 @@ class cmUnixMakefile : public cmMakefile { public: - // Write the makefile to the named file + /** + * Write the makefile to the named file + */ void OutputMakefile(const char* file); protected: void OutputDepends(std::ostream&); diff --git a/Source/cmWindowsConfigure.h b/Source/cmWindowsConfigure.h index 662e07d..e0a7413 100644 --- a/Source/cmWindowsConfigure.h +++ b/Source/cmWindowsConfigure.h @@ -26,10 +26,16 @@ class cmWindowsConfigure { public: + /** + * Set the path to the top level of the source directory + */ void SetWhereSource(const char* dir) { m_WhereSource = dir; } + /** + * Set the path to the top level of the build directory + */ void SetWhereBuild(const char* dir) { m_WhereBuild = dir; diff --git a/Source/itkVC60Configure.h b/Source/itkVC60Configure.h index b86b0ea..a30c71e 100644 --- a/Source/itkVC60Configure.h +++ b/Source/itkVC60Configure.h @@ -25,8 +25,17 @@ class itkVC60Configure : public cmWindowsConfigure { public: + /** + * implement configure from parent + */ virtual void Configure(); + /** + * create the main itk configure file + */ virtual void GenerateITKConfigHeader(); + /** + * Create the vnl configure file + */ virtual void GenerateVNLConfigHeader(); protected: void CopyFileTo(const char* source, |