From 6c9d3df4d74180d397f4ffcdb0fd29751e18fa07 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Tue, 12 Sep 2000 05:37:54 -0400 Subject: [PATCH] NEW: class to collect all the flags from parent directories --- Source/cmCollectFlags.cxx | 109 ++++++++++++++++++++++++++++++++++++++ Source/cmCollectFlags.h | 96 +++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+) create mode 100644 Source/cmCollectFlags.cxx create mode 100644 Source/cmCollectFlags.h diff --git a/Source/cmCollectFlags.cxx b/Source/cmCollectFlags.cxx new file mode 100644 index 000000000..c936718f0 --- /dev/null +++ b/Source/cmCollectFlags.cxx @@ -0,0 +1,109 @@ +#include "cmCollectFlags.h" +#include "cmSystemTools.h" +#include +#include +#include + +cmCollectFlags::cmCollectFlags() +{ +} + +cmCollectFlags::~cmCollectFlags() +{ +} + +void cmCollectFlags::Print() +{ + std::ostream_iterator out(std::cout, "\n"); + std::cout << "m_IncludeDirectories " << std::endl; + std::copy(m_IncludeDirectories.begin(), m_IncludeDirectories.end(), out); + std::cout << "m_linkdirectories " << std::endl; + std::copy(m_LinkDirectories.begin(), m_LinkDirectories.end(), out); + std::cout << "m_LinkLibraries " << std::endl; + std::copy(m_LinkLibraries.begin(), m_LinkLibraries.end(), out); + std::cout << "m_LinkLibrariesWin32 " << std::endl; + std::copy(m_LinkLibrariesWin32.begin(), m_LinkLibrariesWin32.end(), out); + std::cout << "m_LinkLibrariesUnix " << std::endl; + std::copy(m_LinkLibrariesUnix.begin(), m_LinkLibrariesUnix.end(), out); +} + +void cmCollectFlags::SetSourceHomeDirectory(const char* dir) +{ + m_SourceHomeDirectory = dir; + cmSystemTools::ConvertToUnixSlashes(m_SourceHomeDirectory); +} + +void cmCollectFlags::SetStartDirectory(const char* dir) +{ + m_StartDirectory = dir; + cmSystemTools::ConvertToUnixSlashes(m_StartDirectory); +} + + +void cmCollectFlags::ParseDirectories() +{ + this->ParseDirectory(m_StartDirectory.c_str()); +} + + +void cmCollectFlags::ParseFile(const char* filename) +{ + std::ifstream fin(filename); + if(!fin) + { + std::cerr << "error can not open file " << filename << std::endl; + return; + } + char inbuffer[2048]; + while ( fin.getline(inbuffer, 2047 ) ) + { + std::string line = inbuffer; + if(line.find("INCLUDE_DIRECTORIES") != std::string::npos) + { + cmSystemTools::ReadList(m_IncludeDirectories, fin); + } + if(line.find("LINK_DIRECTORIES") != std::string::npos) + { + cmSystemTools::ReadList(m_LinkDirectories, fin); + } + if(line.find("LINK_LIBRARIES") != std::string::npos) + { + cmSystemTools::ReadList(m_LinkLibraries, fin); + } + if(line.find("WIN32_LIBRARIES") != std::string::npos) + { + cmSystemTools::ReadList(m_LinkLibrariesWin32, fin); + } + if(line.find("UNIX_LIBRARIES") != std::string::npos) + { + cmSystemTools::ReadList(m_LinkLibrariesUnix, fin); + } + } +} + + + +// Go until directory == m_cmHomeDirectory +// 1. fix slashes +// 2. peal off /dir until home found, go no higher +void cmCollectFlags::ParseDirectory(const char* dir) +{ + std::string listsFile = dir; + listsFile += "/CMakeLists.txt"; + if(cmSystemTools::FileExists(listsFile.c_str())) + { + this->ParseFile(listsFile.c_str()); + } + if(m_SourceHomeDirectory == dir) + { + return; + } + + std::string dotdotDir = dir; + std::string::size_type pos = dotdotDir.rfind('/'); + if(pos != std::string::npos) + { + dotdotDir = dotdotDir.substr(0, pos); + this->ParseDirectory(dotdotDir.c_str()); + } +} diff --git a/Source/cmCollectFlags.h b/Source/cmCollectFlags.h new file mode 100644 index 000000000..8f037da96 --- /dev/null +++ b/Source/cmCollectFlags.h @@ -0,0 +1,96 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +/** + * cmCollectFlags - collect flags from CMakeLists.txt files. + */ +#ifndef cmCollectFlags_h +#define cmCollectFlags_h + +#include +#include + +class cmCollectFlags +{ +public: + cmCollectFlags(); + ~cmCollectFlags (); + /** + * Set the home directory for the source code. + */ + void SetSourceHomeDirectory(const char* dir); + /** + * Set the start directory to look for flags + */ + void SetStartDirectory(const char* dir); + /** + * Parse the directory and all of it's parents for config + * information + */ + void ParseDirectories(); + /** + * Print to standard out + */ + void Print(); + + + std::vector& GetIncludeDirectories() + { + return m_IncludeDirectories; + } + + std::vector& GetLinkDirectories() + { + return m_LinkDirectories; + } + + std::vector& GetLinkLibraries() + { + return m_LinkLibraries; + } + + std::vector& GetLinkLibrariesWin32() + { + return m_LinkLibrariesWin32; + } + + std::vector& GetLinkLibrariesUnix() + { + return m_LinkLibrariesUnix; + } + +private: + /** + * Look for CMakeLists.txt files to parse in dir, + * then in dir's parents, until the SourceHome directory + * is found. + */ + void ParseDirectory(const char* dir); + /** + * Parse a file for includes links and libs + */ + void ParseFile(const char* dir); + + + std::string m_SourceHomeDirectory; // source code top level dir + std::string m_StartDirectory; // source code sub directory + std::vector m_IncludeDirectories; + std::vector m_LinkDirectories; + std::vector m_LinkLibraries; + std::vector m_LinkLibrariesWin32; + std::vector m_LinkLibrariesUnix; +}; + +#endif