From 98a3eea5bd70eb1b216e178d5065b44da054b651 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Mon, 23 Jan 2012 10:11:33 +0100
Subject: [PATCH] Finishes GET_SOURCE_FILES CMake macro.

---
 GeoLib/CMakeLists.txt         |  48 +----------
 GeoLib/ProjectData.cpp        | 148 ----------------------------------
 GeoLib/ProjectData.h          |  75 -----------------
 GeoLib/SimplePolygonTree.h    |   1 -
 MathLib/CMakeLists.txt        |  97 ++++------------------
 scripts/cmake/Functions.cmake |  22 +++--
 6 files changed, 34 insertions(+), 357 deletions(-)
 delete mode 100644 GeoLib/ProjectData.cpp
 delete mode 100644 GeoLib/ProjectData.h

diff --git a/GeoLib/CMakeLists.txt b/GeoLib/CMakeLists.txt
index bde06ed7800..5f68fd5c5e7 100644
--- a/GeoLib/CMakeLists.txt
+++ b/GeoLib/CMakeLists.txt
@@ -1,49 +1,8 @@
 # Source files
-SET ( GeoLib_Files
-	AxisAlignedBoundingBox.cpp
-	BruteForceClosestPair.cpp
-	Color.cpp
-	GEOObjects.cpp
-	GeoType.cpp
-	Point.cpp
-	PointVec.cpp
-	Polygon.cpp
-	Polyline.cpp
-#	ProjectData.cpp # uses CFEMesh class
-#	SimplePolygonTree.cpp # uses FileIO/MeshIO
-	Station.cpp
-	Surface.cpp
-	Triangle.cpp
-	Raster.cpp
-	AxisAlignedBoundingBox.h
-	BruteForceClosestPair.h
-	ClosestPair.h
-	Color.h
-	GeoObject.h
-	GEOObjects.h
-	GeoType.h
-	Point.h
-	PointVec.h
-	PointWithID.h
-	Polygon.h
-	Polyline.h
-	PolylineVec.h
-#	ProjectData.h # uses CFEMesh class
-	PropertyBounds.h
-	QuadTree.h
-#	SimplePolygonTree.h # uses FileIO/MeshIO
-	Station.h
-	Surface.h
-	SurfaceVec.h
-	TemplatePoint.h
-	TemplateVec.h
-	Triangle.h
-	Raster.h
-)
-SOURCE_GROUP(GeoLib FILES ${GeoLib_Files})
+GET_SOURCE_FILES(SOURCES_GEOLIB)
 
 # Create the library
-ADD_LIBRARY(GeoLib STATIC ${GeoLib_Files})
+ADD_LIBRARY(GeoLib STATIC ${SOURCES_GEOLIB})
 
 
 include_directories(
@@ -53,8 +12,7 @@ include_directories(
 )
 
 
-target_link_libraries (
-	GeoLib
+target_link_libraries (GeoLib
 	Base
 	MathLib
 )
diff --git a/GeoLib/ProjectData.cpp b/GeoLib/ProjectData.cpp
deleted file mode 100644
index d668fd46726..00000000000
--- a/GeoLib/ProjectData.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/**
- * \file ProjectData.cpp
- * 25/08/2010 KR Initial implementation
- */
-
-#include "ProjectData.h"
-#include "StringTools.h"
-
-
-ProjectData::ProjectData()
-//: _geoObjects ()
-{}
-
-ProjectData::~ProjectData()
-{
-	delete _geoObjects;
-	for (std::map<std::string, MeshLib::CFEMesh*>::iterator it = _msh_vec.begin(); it != _msh_vec.end(); ++it)
-	{
-		delete it->second;
-	}
-	size_t nCond (_cond_vec.size());
-	for (size_t i=0; i<nCond; i++)
-	{
-		delete _cond_vec[i];
-	}
-}
-
-void ProjectData::addMesh(MeshLib::CFEMesh* mesh, std::string &name)
-{
-	isUniqueMeshName(name);
-	_msh_vec[name] = mesh;
-};
-
-const MeshLib::CFEMesh* ProjectData::getMesh(const std::string &name) const
-{
-	return _msh_vec.find(name)->second;
-}
-
-bool ProjectData::removeMesh(const std::string &name)
-{
-	delete _msh_vec[name];
-	size_t result = _msh_vec.erase(name);
-	return (result>0);
-}
-
-void ProjectData::addCondition(FEMCondition* cond)
-{
-	_cond_vec.push_back(cond);
-};
-
-void ProjectData::addConditions(std::vector<FEMCondition*> conds)
-{
-	for (size_t i=0; i<conds.size(); i++)
-		_cond_vec.push_back(conds[i]);
-};
-
-const FEMCondition* ProjectData::getCondition(const std::string &geo_name, GEOLIB::GEOTYPE type, const std::string &cond_name) const
-{
-	for (std::vector<FEMCondition*>::const_iterator it = _cond_vec.begin(); it != _cond_vec.end(); ++it)
-	{
-		if ((*it)->getAssociatedGeometryName().compare(geo_name) == 0) 
-		{
-			if ( ((*it)->getGeoName().compare(cond_name)==0) && ((*it)->getGeoType()==type) )
-				return *it;
-		}
-	}
-	std::cout << "Error in ProjectData::getCondition() - No condition found with name \"" << cond_name << "\"..." << std::endl;
-	return NULL;
-}
-
-const std::vector<FEMCondition*> ProjectData::getConditions(const std::string &geo_name, FEMCondition::CondType type) const
-{
-	std::vector<FEMCondition*> conds;
-	for (std::vector<FEMCondition*>::const_iterator it = _cond_vec.begin(); it != _cond_vec.end(); ++it)
-	{
-		if ((*it)->getAssociatedGeometryName().compare(geo_name) == 0)
-		{
-			if ( (type == FEMCondition::UNSPECIFIED) || ((*it)->getCondType() == type) )
-				conds.push_back(*it);
-		}
-	}
-	return conds;
-}
-
-bool ProjectData::removeCondition(const std::string &geo_name, GEOLIB::GEOTYPE type, const std::string &cond_name)
-{
-	for (std::vector<FEMCondition*>::iterator it = _cond_vec.begin(); it != _cond_vec.end(); ++it)
-	{
-		if ((*it)->getAssociatedGeometryName().compare(geo_name) == 0) 
-		{
-			if ( ((*it)->getGeoName().compare(cond_name)==0) && ((*it)->getGeoType()==type) )
-			{
-				delete *it;
-				_cond_vec.erase(it);
-				return true;
-			}
-		}
-	}
-	std::cout << "Error in ProjectData::getCondition() - No condition found with name \"" << cond_name << "\"..." << std::endl;
-	return false;
-}
-
-void ProjectData::removeConditions(const std::string &geo_name, FEMCondition::CondType type)
-{
-	for (std::vector<FEMCondition*>::iterator it = _cond_vec.begin(); it != _cond_vec.end();)
-	{
-		if ( ((*it)->getAssociatedGeometryName().compare(geo_name) == 0) 
-			&& ( (type == FEMCondition::UNSPECIFIED) || ((*it)->getCondType() == type) ))
-		{
-			delete *it;
-			it = _cond_vec.erase(it);
-		}
-		else ++it;
-	}
-}
-
-bool ProjectData::isUniqueMeshName(std::string &name)
-{
-	int count(0);
-	bool isUnique(false);
-	std::string cpName;
-
-	while (!isUnique)
-	{
-		isUnique = true;
-		cpName = name;
-
-		count++;
-		// If the original name already exists we start to add numbers to name for
-		// as long as it takes to make the name unique.
-		if (count>1) cpName = cpName + "-" + number2str(count);
-
-		for (std::map<std::string, MeshLib::CFEMesh*>::iterator it = _msh_vec.begin(); it != _msh_vec.end(); ++it)
-		{
-			if ( cpName.compare(it->first) == 0 ) isUnique = false;
-		}
-	}
-
-	// At this point cpName is a unique name and isUnique is true.
-	// If cpName is not the original name, "name" is changed and isUnique is set to false,
-	// indicating that a vector with the original name already exists.
-	if (count>1)
-	{
-		isUnique = false;
-		name = cpName;
-	}
-	return isUnique;
-}
diff --git a/GeoLib/ProjectData.h b/GeoLib/ProjectData.h
deleted file mode 100644
index f3887909200..00000000000
--- a/GeoLib/ProjectData.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * \file ProjectData.h
- * 25/08/2010 KR Initial implementation
- */
-
-#ifndef PROJECTDATA_H_
-#define PROJECTDATA_H_
-
-#include "GEOObjects.h"
-#include "msh_mesh.h"
-#include "FEMCondition.h"
-
-
-/**
- * The ProjectData Object contains all the data needed for a certain project, i.e. all
- * geometric data (stored in a GEOObjects-object), all the meshes, FEM Conditions (i.e.
- * Boundary Conditions, Source Terms and Initial Conditions), etc.
- * ProjectData does not administrate any of the objects, it is just a "container class" 
- * to store them all in one place.
- * For each class of object stored in this container exists an add-, get- and remove-method.
- *
- * \sa GEOModels, FEMCondition
- */
-class ProjectData
-{
-public:
-	ProjectData();
-	virtual ~ProjectData();
-
-	// Returns the GEOObjects containing all points, polylines and surfaces
-	GEOLIB::GEOObjects* getGEOObjects() { return _geoObjects; };
-
-	// Returns the GEOObjects containing all points, polylines and surfaces
-	void setGEOObjects(GEOLIB::GEOObjects* geo_objects) { _geoObjects = geo_objects; };
-
-	/// Adds a new mesh
-	virtual void addMesh(MeshLib::CFEMesh* mesh, std::string &name);
-
-	/// Returns the mesh with the given name.
-	const MeshLib::CFEMesh* getMesh(const std::string &name) const;
-
-	/// Returns all the meshes with their respective names
-	const std::map<std::string, MeshLib::CFEMesh*>& getMeshObjects() const { return _msh_vec; };
-
-	/// Removes the mesh with the given name.
-	virtual bool removeMesh(const std::string &name);
-
-	/// Adds a new FEM Condition
-	virtual void addCondition(FEMCondition* cond);
-
-	/// Adds a new FEM Condition
-	virtual void addConditions(std::vector<FEMCondition*> conds);
-
-	/// Returns the FEM Condition set on a GeoObject with the given name and type from a certain geometry.
-	const FEMCondition* getCondition(const std::string &geo_name, GEOLIB::GEOTYPE type, const std::string &cond_name) const;
-
-	/// Returns all FEM Conditions with the given type from a certain geometry.
-	const std::vector<FEMCondition*> getConditions(const std::string &geo_name, FEMCondition::CondType type = FEMCondition::UNSPECIFIED) const;
-
-	/// Removes the FEM Condition set on a GeoObject with the given name and type from a certain geometry.
-	virtual bool removeCondition(const std::string &geo_name, GEOLIB::GEOTYPE type, const std::string &cond_name);
-
-	/// Removes all FEM Conditions with the given type from a certain geometry
-	virtual void removeConditions(const std::string &geo_name, FEMCondition::CondType type = FEMCondition::UNSPECIFIED);
-
-	/// Checks if the name of the mesh is already exists, if so it generates a unique name.
-	bool isUniqueMeshName(std::string &name);
-
-private:
-	GEOLIB::GEOObjects* _geoObjects;
-	std::map<std::string, MeshLib::CFEMesh*> _msh_vec;
-	std::vector<FEMCondition*> _cond_vec;
-};
-
-#endif //PROJECTDATA_H_
diff --git a/GeoLib/SimplePolygonTree.h b/GeoLib/SimplePolygonTree.h
index 688364df5f7..44c500fc657 100644
--- a/GeoLib/SimplePolygonTree.h
+++ b/GeoLib/SimplePolygonTree.h
@@ -10,7 +10,6 @@
 
 #include "Polygon.h"
 // FileIO
-#include "MeshIO/GMSHInterface.h"
 
 namespace GEOLIB {
 
diff --git a/MathLib/CMakeLists.txt b/MathLib/CMakeLists.txt
index 37b96ef97ff..6eb716e444f 100644
--- a/MathLib/CMakeLists.txt
+++ b/MathLib/CMakeLists.txt
@@ -1,89 +1,26 @@
 #Source files grouped by a directory
-SET ( MathLib_Files
-	AnalyticalGeometry.h        
-	LinearInterpolation.h  
-	MathTools.h
-	Vector3.h
-	EarClippingTriangulation.h  
-	max.h
-        sparse.h
-	vector_io.h
-	AnalyticalGeometry.cpp        
-	LinearInterpolation.cpp  
-	MathTools.cpp
-	EarClippingTriangulation.cpp  
-)
-SOURCE_GROUP( MathLib FILES ${MathLib_Files})
-SET ( SOURCES ${SOURCES} ${MathLib_Files})
-
-SET ( MathLib_LinAlg_Files
-	LinAlg/MatrixBase.h
-	LinAlg/VectorNorms.h
-)
-SOURCE_GROUP( MathLib\\LinAlg FILES ${MathLib_LinAlg_Files})
-SET ( SOURCES ${SOURCES} ${MathLib_LinAlg_Files})
+GET_SOURCE_FILES(SOURCES_MATHLIB)
+SET ( SOURCES ${SOURCES_MATHLIB})
 
-SET ( MathLib_LinAlg_Dense_Files
-	LinAlg/Dense/Matrix.h
-)
-SOURCE_GROUP( MathLib\\LinAlg\\Dense FILES ${MathLib_LinAlg_Dense_Files})
-SET ( SOURCES ${SOURCES} ${MathLib_LinAlg_Dense_Files})
+GET_SOURCE_FILES(SOURCES_LINALG LinAlg)
+SET ( SOURCES ${SOURCES} ${SOURCES_LINALG})
 
-SET ( MathLib_LinAlg_Sparse_Files
-	LinAlg/Sparse/amuxCRS.h
-        LinAlg/Sparse/CRSMatrix.h
-        LinAlg/Sparse/CRSMatrixPThreads.h
-        LinAlg/Sparse/CRSMatrixOpenMP.h
-        LinAlg/Sparse/CRSSymMatrix.h
-        LinAlg/Sparse/SparseMatrixBase.h
-        LinAlg/Sparse/amuxCRS.cpp
-)
-SOURCE_GROUP( MathLib\\LinAlg\\Sparse FILES ${MathLib_LinAlg_Sparse_Files})
-SET ( SOURCES ${SOURCES} ${MathLib_LinAlg_Sparse_Files})
+GET_SOURCE_FILES(SOURCES_LINALG_DENSE LinAlg/Dense)
+SET ( SOURCES ${SOURCES} ${SOURCES_LINALG_DENSE})
 
-SET ( MathLib_LinAlg_Solvers_Files
-        LinAlg/Solvers/LinearSolver.h
-        LinAlg/Solvers/DirectLinearSolver.h
-        LinAlg/Solvers/DenseDirectLinearSolver.h
-        LinAlg/Solvers/GaussAlgorithm.h
-        LinAlg/Solvers/TriangularSolve.h
-        LinAlg/Solvers/IterativeLinearSolver.h
-        LinAlg/Solvers/solver.h
-        LinAlg/Solvers/BiCGStab.h
-        LinAlg/Solvers/CG.h
-        LinAlg/Solvers/GMRes.h
-        LinAlg/Solvers/BiCGStab.cpp
-        LinAlg/Solvers/CG.cpp
-        LinAlg/Solvers/CGParallel.cpp
-        LinAlg/Solvers/GMRes.cpp
-	LinAlg/Solvers/GaussAlgorithm.cpp
-        LinAlg/Solvers/TriangularSolve.cpp
-)
-SOURCE_GROUP( MathLib\\LinAlg\\Solvers FILES ${MathLib_LinAlg_Solvers_Files})
-SET ( SOURCES ${SOURCES} ${MathLib_LinAlg_Solvers_Files})
+GET_SOURCE_FILES(SOURCES_LINALG_SPARSE LinAlg/Sparse)
+SET ( SOURCES ${SOURCES} ${SOURCES_LINALG_SPARSE})
 
-SET ( MathLib_LinAlg_Preconditioner_Files
-        LinAlg/Preconditioner/generateDiagPrecond.h
-	LinAlg/Preconditioner/generateDiagPrecond.cpp
-)
-SOURCE_GROUP( MathLib\\LinAlg\\Preconditioner FILES ${MathLib_LinAlg_Preconditioner_Files})
-SET ( SOURCES ${SOURCES} ${MathLib_LinAlg_Preconditioner_Files})
+GET_SOURCE_FILES(SOURCES_LINALG_SOLVERS LinAlg/Solvers)
+SET ( SOURCES ${SOURCES} ${SOURCES_LINALG_SOLVERS})
 
-IF (METIS_FOUND)
-	FILE(GLOB MathLib_LinAlg_Sparse_NestedDissectionPermutation_HEADERS
-		LinAlg/Sparse/NestedDissectionPermutation/*.h)
+GET_SOURCE_FILES(SOURCES_LINALG_PRECOND LinAlg/Preconditioner)
+SET ( SOURCES ${SOURCES} ${SOURCES_LINALG_PRECOND})
 
-	FILE(GLOB MathLib_LinAlg_Sparse_NestedDissectionPermutation_SOURCES
-		LinAlg/Sparse/NestedDissectionPermutation/*.cpp)
 
-	SOURCE_GROUP( MathLib\\LinAlg\\Sparse\\NestedDissectionPermutation FILES
-		${MathLib_LinAlg_Sparse_NestedDissectionPermutation_HEADERS}
-		${MathLib_LinAlg_Sparse_NestedDissectionPermutation_SOURCES}
-	)
-	SET (SOURCES ${SOURCES} 
-		${MathLib_LinAlg_Sparse_NestedDissectionPermutation_HEADERS}
-		${MathLib_LinAlg_Sparse_NestedDissectionPermutation_SOURCES}
-	)
+IF (METIS_FOUND)
+	GET_SOURCE_FILES(SOURCES_LINALG_SPARSE_NESTEDDISSECTION LinAlg/Sparse/NestedDissectionPermutation)
+	SET ( SOURCES ${SOURCES} ${SOURCES_LINALG_SPARSE_NESTEDDISSECTION})
 ENDIF ()
 
 INCLUDE_DIRECTORIES (
@@ -99,9 +36,7 @@ IF(METIS_FOUND)
 ENDIF()
 
 # Create the library
-ADD_LIBRARY( MathLib STATIC 
-	${SOURCES}
-)
+ADD_LIBRARY( MathLib STATIC ${SOURCES} )
 
 SET_TARGET_PROPERTIES(MathLib PROPERTIES LINKER_LANGUAGE CXX)
 
diff --git a/scripts/cmake/Functions.cmake b/scripts/cmake/Functions.cmake
index e0e806c336b..9a61a5f6674 100644
--- a/scripts/cmake/Functions.cmake
+++ b/scripts/cmake/Functions.cmake
@@ -5,23 +5,31 @@ MACRO(GET_CURRENT_SOURCE_SUBDIRECTORY CURRENT_SOURCE_SUBDIRECTORY)
 ENDMACRO()
 
 # Returns a list of source files (*.h and *.cpp) in SOURCE_FILES and creates a Visual
-# Studio folder. A (relative) directory can be passed as second parameter (optional).
+# Studio folder. A (relative) subdirectory can be passed as second parameter (optional).
 MACRO(GET_SOURCE_FILES SOURCE_FILES)
 	
-	IF(ARGC EQUAL 2)
-		SET(DIR "${arg2}")
+	IF(${ARGC} EQUAL 2)
+		SET(DIR "${ARGV1}")
 	ELSE()
-		SET(DIR "")
+		SET(DIR ".")
 	ENDIF()
 	
 	# Get all files in the directory
-	FILE(GLOB GET_SOURCE_FILES_HEADERS ${DIR}*.h)
-	FILE(GLOB GET_SOURCE_FILES_SOURCES ${DIR}*.cpp)
+	FILE(GLOB GET_SOURCE_FILES_HEADERS ${DIR}/*.h)
+	FILE(GLOB GET_SOURCE_FILES_SOURCES ${DIR}/*.cpp)
 
 	SET(${SOURCE_FILES} ${GET_SOURCE_FILES_HEADERS} ${GET_SOURCE_FILES_SOURCES})
+
+	# Adapt DIR var to backslash syntax of SOURCE_GROUP cmd
+	IF(${ARGC} EQUAL 2)
+		STRING(REPLACE "/" "\\\\" DIR ${DIR})
+		SET(DIR "\\${DIR}")
+	ELSE()
+		SET(DIR "")
+	ENDIF()
 	
 	GET_CURRENT_SOURCE_SUBDIRECTORY(DIRECTORY)
-	SOURCE_GROUP( "${DIRECTORY}" FILES
+	SOURCE_GROUP( "${DIRECTORY}${DIR}" FILES
 		${GET_SOURCE_FILES_HEADERS}
 		${GET_SOURCE_FILES_SOURCES})
 	
-- 
GitLab