瀏覽代碼

- Fixing to compile
- Refactoring Exception and other files that call it
- Updating the CMakeList.txt to find libs more easily

Panagiotis Christopoulos Charitos 14 年之前
父節點
當前提交
9af971e84a

+ 69 - 14
CMakeLists.txt

@@ -1,7 +1,29 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
 
 PROJECT(ANKI_PROJ)
 
+#
+# Macros
+#
+MACRO(ANKI_ADD_LIB INCDIR LIBDIR ONEINCFILE)
+	IF(NOT EXISTS ${INCDIR})
+		MESSAGE(FATAL_ERROR "Directory does not exist: " ${INCDIR})
+	ENDIF()
+	
+	IF(NOT EXISTS ${LIBDIR})
+		MESSAGE(FATAL_ERROR "Directory does not exist: " ${LIBDIR})
+	ENDIF()
+	
+	IF(NOT EXISTS ${ONEINCFILE})
+		MESSAGE(FATAL_ERROR "File not found: " ${ONEINCFILE})
+	ELSE()
+		MESSAGE("Found: " ${ONEINCFILE})
+	ENDIF()
+	
+	INCLUDE_DIRECTORIES(${INCDIR})
+	LINK_DIRECTORIES(${LIBDIR})
+ENDMACRO()
+
 #
 # Install
 #
@@ -11,7 +33,7 @@ SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Library install pa
 #
 # SVN
 #
-FIND_PACKAGE(Subversion)
+FIND_PACKAGE(Subversion 1.6 REQUIRED)
 IF(Subversion_FOUND)
 	Subversion_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} ER)
 	ADD_DEFINITIONS("-DANKI_REVISION=${ER_WC_REVISION}")
@@ -42,6 +64,47 @@ ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxyfile
 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating API documentation with Doxygen" VERBATIM)
 ENDIF()
 
+#
+# Libraries
+#
+FIND_PACKAGE(PNG 1.2 REQUIRED)
+FIND_PACKAGE(JPEG 62 REQUIRED)
+FIND_PACKAGE(Freetype 2.4.4 REQUIRED)
+
+
+#
+# Freetype
+#
+SET(FREETYPE_INCLUDE_DIR "/usr/include/freetype2" CACHE PATH "The directory that contains the Freetype headers")
+SET(FREETYPE_LIBRARY_DIR "/usr/lib" CACHE PATH "The directory that contains the libfreetype.so")
+
+ANKI_ADD_LIB(${FREETYPE_INCLUDE_DIR} ${FREETYPE_LIBRARY_DIR} ${FREETYPE_INCLUDE_DIR}/freetype/freetype.h)
+
+#
+# Python
+#
+SET(PYTHON_VER 2.7)
+SET(PYTHON_INCLUDE_DIR "/usr/include/python${PYTHON_VER}" CACHE PATH "The directory that contains the Python.h and the other headers")
+SET(PYTHON_LIBRARY_DIR "/usr/lib" CACHE PATH "The directory that contains the libpython${PYTHON_VER}.so")
+
+ANKI_ADD_LIB(${PYTHON_INCLUDE_DIR} ${PYTHON_LIBRARY_DIR} ${PYTHON_INCLUDE_DIR}/Python.h)
+
+#
+# Bullet (Because FIND_PACKAGE(Bullet) sucks)
+#
+SET(BULLET_INCLUDE_DIR "${ANKI_PROJ_SOURCE_DIR}/extern/include/" CACHE PATH "The directory that contains the bullet directory with the header files")
+SET(BULLET_LIBRARY_DIR "${ANKI_PROJ_SOURCE_DIR}/extern/lib64/" CACHE PATH "The directory that contains the Bullet (static) libraries")
+
+ANKI_ADD_LIB(${BULLET_INCLUDE_DIR}/bullet ${BULLET_LIBRARY_DIR} ${BULLET_INCLUDE_DIR}/bullet/btBulletCollisionCommon.h)
+
+#
+# GLEW
+#
+SET(GLEW_INCLUDE_DIR "${ANKI_PROJ_SOURCE_DIR}/extern/include/" CACHE PATH "The directory that contains the GL directory with the header files")
+SET(GLEW_LIBRARY_DIR "${ANKI_PROJ_SOURCE_DIR}/extern/lib64/" CACHE PATH "The directory that contains the GLEW (static) libraries")
+
+ANKI_ADD_LIB(${GLEW_INCLUDE_DIR} ${GLEW_LIBRARY_DIR} ${GLEW_INCLUDE_DIR}/GL/glew.h)
+
 #
 # Defines & flags
 #
@@ -67,21 +130,13 @@ ELSE()
 ENDIF()
 
 
-INCLUDE_DIRECTORIES("${ANKI_PROJ_SOURCE_DIR}/extern/include")
-INCLUDE_DIRECTORIES("${ANKI_PROJ_SOURCE_DIR}/extern/include/bullet") # Because bullet wants it
-INCLUDE_DIRECTORIES("/usr/include/python2.6")
-INCLUDE_DIRECTORIES("/usr/include/freetype2")
-INCLUDE_DIRECTORIES(.)
+#INCLUDE_DIRECTORIES("${ANKI_PROJ_SOURCE_DIR}/extern/include")
+#INCLUDE_DIRECTORIES("/usr/include/python2.6")
+#INCLUDE_DIRECTORIES("/usr/include/freetype2")
+INCLUDE_DIRECTORIES(${ANKI_PROJ_SOURCE_DIR})
 
 LINK_DIRECTORIES(${ANKI_PROJ_SOURCE_DIR}/extern/lib64)
 
-# Lib dependencies
-FIND_PACKAGE(Boost 1.46 REQUIRED)
-FIND_PACKAGE(PNG 1.2 REQUIRED)
-FIND_PACKAGE(JPEG 62 REQUIRED)
-FIND_PACKAGE(Freetype 2.4.4 REQUIRED)
-FIND_PACKAGE(PythonLibs 2.6 REQUIRED)
-
 #
 # libanki
 #

+ 3 - 2
anki/misc/Parser.h

@@ -21,10 +21,11 @@ namespace parser {
 
 #define PARSER_EXCEPTION_EXPECTED(x) \
 	PARSER_EXCEPTION("Expected " + x + " and not " + \
-		scanner.getCrntToken().getInfoStr())
+		scanner.getCrntToken().getInfoString())
 
 #define PARSER_EXCEPTION_UNEXPECTED() \
-	PARSER_EXCEPTION("Unexpected token " + scanner.getCrntToken().getInfoStr())
+	PARSER_EXCEPTION("Unexpected token " + \
+	scanner.getCrntToken().getInfoString())
 
 
 /// This template func is used for a common operation of parsing arrays of

+ 4 - 4
anki/misc/Parser.inl.h

@@ -130,9 +130,9 @@ void parseNumber(scanner::Scanner& scanner, bool sign, Type& out)
 			out = static_cast<Type>(l);
 		}
 	}
-	catch(std::exception& e)
+	catch(const std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Error", e);
+		throw ANKI_EXCEPTION("Error") << e;
 	}
 }
 
@@ -169,9 +169,9 @@ void parseMathVector(scanner::Scanner& scanner, Type& out)
 			throw PARSER_EXCEPTION_EXPECTED("}");
 		}
 	}
-	catch(std::exception& e)
+	catch(const std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Error", e);
+		throw ANKI_EXCEPTION("Error") << e;
 	}
 }
 

+ 7 - 7
anki/renderer/Bl.cpp

@@ -41,10 +41,10 @@ void Bl::init(const RendererInitializer& initializer)
 		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
 			GL_TEXTURE_2D, blurFai.getGlId(), 0);
 	}
-	catch(std::exception& e)
+	catch(const std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot create horizontal blur "
-			"post-processing stage FBO: ", e);
+		throw ANKI_EXCEPTION("Cannot create horizontal blur "
+			"post-processing stage FBO") << e;
 	}
 
 	hBlurSProg.load(ShaderProgram::createSrcCodeToCache(
@@ -61,8 +61,8 @@ void Bl::init(const RendererInitializer& initializer)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot create vertical blur "
-			"post-processing stage FBO", e);
+		throw ANKI_EXCEPTION("Cannot create vertical blur "
+			"post-processing stage FBO") << e;
 	}
 
 	vBlurSProg.load(ShaderProgram::createSrcCodeToCache(
@@ -79,8 +79,8 @@ void Bl::init(const RendererInitializer& initializer)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot create side blur "
-			"post-processing stage FBO", e);
+		throw ANKI_EXCEPTION("Cannot create side blur "
+			"post-processing stage FBO") << e;
 	}
 
 	sideBlurMap.load("engine-rsrc/side-blur.png");

+ 1 - 1
anki/renderer/Dbg.cpp

@@ -226,7 +226,7 @@ void Dbg::init(const RendererInitializer& initializer)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot create debug FBO", e);
+		throw ANKI_EXCEPTION("Cannot create debug FBO") << e;
 	}
 
 	//

+ 2 - 2
anki/renderer/Hdr.cpp

@@ -54,8 +54,8 @@ void Hdr::initFbo(Fbo& fbo, Texture& fai)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot create deferred shading post-processing "
-			"stage HDR passes FBO", e);
+		throw ANKI_EXCEPTION("Cannot create deferred shading "
+			"post-processing stage HDR passes FBO") << e;
 	}
 }
 

+ 4 - 4
anki/renderer/Is.cpp

@@ -64,8 +64,8 @@ void Is::initFbo()
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot create deferred shading illumination "
-			"stage FBO", e);
+		throw ANKI_EXCEPTION("Cannot create deferred shading illumination "
+			"stage FBO") << e;
 	}
 }
 
@@ -98,8 +98,8 @@ void Is::initCopy()
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot create deferred shading "
-			"illumination stage additional FBO", e);
+		throw ANKI_EXCEPTION("Cannot create deferred shading "
+			"illumination stage additional FBO") << e;
 	}
 }
 

+ 1 - 1
anki/renderer/MainRenderer.cpp

@@ -109,7 +109,7 @@ void MainRenderer::initGl()
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("OpenGL initialization failed", e);
+		throw ANKI_EXCEPTION("OpenGL initialization failed") << e;
 	}
 }
 

+ 2 - 2
anki/renderer/Ms.cpp

@@ -74,8 +74,8 @@ void Ms::init(const RendererInitializer& initializer)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot create deferred "
-			"shading material stage FBO", e);
+		throw ANKI_EXCEPTION("Cannot create deferred "
+			"shading material stage FBO") << e;
 	}
 
 	ez.init(initializer);

+ 4 - 4
anki/renderer/Pps.cpp

@@ -53,8 +53,8 @@ void Pps::init(const RendererInitializer& initializer)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot create pre-pass "
-			"post-processing stage FBO", e);
+		throw ANKI_EXCEPTION("Cannot create pre-pass "
+			"post-processing stage FBO") << e;
 	}
 
 	// SProg
@@ -86,8 +86,8 @@ void Pps::init(const RendererInitializer& initializer)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot create post-pass "
-			"post-processing stage FBO", e);
+		throw ANKI_EXCEPTION("Cannot create post-pass "
+			"post-processing stage FBO") << e;
 	}
 
 	// SProg

+ 2 - 2
anki/renderer/Sm.cpp

@@ -94,8 +94,8 @@ void Sm::initLevel(uint resolution, float distance, bool bilinear, Level& level)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot create shadowmapping "
-			"FBO", e);
+		throw ANKI_EXCEPTION("Cannot create shadowmapping "
+			"FBO") << e;
 	}
 }
 

+ 2 - 2
anki/renderer/Ssao.cpp

@@ -41,8 +41,8 @@ void Ssao::createFbo(Fbo& fbo, Texture& fai)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot create deferred shading post-processing "
-			"stage SSAO blur FBO", e);
+		throw ANKI_EXCEPTION("Cannot create deferred shading post-processing "
+			"stage SSAO blur FBO") << e;
 	}
 }
 

+ 2 - 2
anki/resource/Image.cpp

@@ -455,7 +455,7 @@ void Image::load(const char* filename)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("File \"" + filename + "\": ", e);
+		throw ANKI_EXCEPTION("File \"" + filename + "\"") << e;
 	}
 }
 
@@ -498,7 +498,7 @@ void Image::load(const char* filename)
 #define DDSCAPS2_CUBEMAP_NEGATIVEZ  0x00008000
 #define DDSCAPS2_VOLUME             0x00200000
 
-static int toInt(const char* x)
+static uint toInt(const char* x)
 {
 	return x[3] | (x[2] << 8) | (x[1] << 16) | (x[0] << 24);
 }

+ 1 - 1
anki/resource/LightRsrc.cpp

@@ -216,7 +216,7 @@ void LightRsrc::load(const char* filename)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Material \"" + filename + "\": ", e);
+		throw ANKI_EXCEPTION("Material \"" + filename + "\"") << e;
 	}
 }
 

+ 1 - 1
anki/resource/Material.cpp

@@ -65,7 +65,7 @@ void Material::load(const char* filename)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("File \"" + filename + "\" failed", e);
+		throw ANKI_EXCEPTION("File \"" + filename + "\" failed") << e;
 	}
 }
 

+ 1 - 1
anki/resource/Mesh.cpp

@@ -36,7 +36,7 @@ void Mesh::load(const char* filename)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Mesh \"" + filename + "\"", e);
+		throw ANKI_EXCEPTION("Mesh \"" + filename + "\"") << e;
 	}
 }
 

+ 1 - 1
anki/resource/MeshData.cpp

@@ -125,7 +125,7 @@ void MeshData::load(const char* filename)
 	}
 	catch(Exception& e)
 	{
-		throw ANKI_EXCEPTION_R("File \"" + filename + "\"", e);
+		throw ANKI_EXCEPTION("File \"" + filename + "\"") << e;
 	}
 }
 

+ 1 - 1
anki/resource/Model.cpp

@@ -57,7 +57,7 @@ void Model::load(const char* filename)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Model \"" + filename + "\"", e);
+		throw ANKI_EXCEPTION("Model \"" + filename + "\"") << e;
 	}
 }
 

+ 6 - 6
anki/resource/ResourceManager.inl.h

@@ -19,10 +19,10 @@ void ResourceManager<Type>::allocAndLoadRsrc(
 	{
 		newInstance = new Type();
 	}
-	catch(std::exception& e)
+	catch(const std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Constructor failed for \"" + filename +
-			"\"", e);
+		throw ANKI_EXCEPTION("Constructor failed for \"" + filename +
+			"\"") << e;
 	}
 
 	// Load
@@ -32,7 +32,7 @@ void ResourceManager<Type>::allocAndLoadRsrc(
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Cannot load \"" + filename + "\"", e);
+		throw ANKI_EXCEPTION("Cannot load \"" + filename + "\"") << e;
 	}
 }
 
@@ -69,8 +69,8 @@ typename ResourceManager<Type>::Hook& ResourceManager<Type>::load(
 				delete hook;
 			}
 
-			throw ANKI_EXCEPTION_R("Cannot load \"" +
-				filename + "\"", e);
+			throw ANKI_EXCEPTION("Cannot load \"" +
+				filename + "\"") << e;
 		}
 
 		hooks.push_back(hook);

+ 1 - 1
anki/resource/ShaderProgramPrePreprocessor.cpp

@@ -245,7 +245,7 @@ void ShaderProgramPrePreprocessor::parseFile(const char* filename)
 	}
 	catch(Exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Started from \"" + filename + "\"", e);
+		throw ANKI_EXCEPTION("Started from \"" + filename + "\"") << e;
 	}
 }
 

+ 1 - 1
anki/resource/Skeleton.cpp

@@ -108,7 +108,7 @@ void Skeleton::load(const char* filename)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Skeleton \"" + filename + "\"", e);
+		throw ANKI_EXCEPTION("Skeleton \"" + filename + "\"") << e;
 	}
 }
 

+ 1 - 1
anki/resource/Skin.cpp

@@ -93,7 +93,7 @@ void Skin::load(const char* filename)
 	  }
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("Skin \"" + filename + "\"", e);
+		throw ANKI_EXCEPTION("Skin \"" + filename + "\"") << e;
 	}
 }
 

+ 1 - 1
anki/resource/Texture.cpp

@@ -54,7 +54,7 @@ void Texture::load(const char* filename)
 	}
 	catch(std::exception& e)
 	{
-		throw ANKI_EXCEPTION_R("File \"" + filename + "\"", e);
+		throw ANKI_EXCEPTION("File \"" + filename + "\"") << e;
 	}
 }
 

+ 5 - 5
anki/util/Exception.cpp

@@ -16,12 +16,12 @@ std::string Exception::synthErr(const char* error, const char* file,
 
 
 //==============================================================================
-Exception::Exception(const char* err, const std::exception& e,
-	const char* file, int line, const char* func)
+Exception Exception::operator<<(const std::exception& e) const
 {
-	std::stringstream ss;
-	ss << synthErr(error, file, line, func) << ". From here:\n" << e.what();
-	err = ss.str();
+	Exception out(*this);
+	out.err += "\nFrom: ";
+	out.err += e.what();
+	return out;
 }
 
 

+ 6 - 11
anki/util/Exception.h

@@ -14,10 +14,10 @@ class Exception: public std::exception
 {
 public:
 	/// Constructor
-	Exception(const char* err, const char* file = "unknown",
+	Exception(const char* error, const char* file = "unknown",
 		int line = -1, const char* func = "unknown")
 	{
-		synthErr(err, file, line, func);
+		err = synthErr(error, file, line, func);
 	}
 
 	/// Copy constructor
@@ -25,15 +25,13 @@ public:
 		: err(e.err)
 	{}
 
-	/// For re-throws
-	Exception(const char* err, const std::exception& e,
-		const char* file = "unknown",
-		int line = -1, const char* func = "unknown");
-
 	/// Destructor. Do nothing
 	~Exception() throw()
 	{}
 
+	/// For re-throws
+	Exception operator<<(const std::exception& e) const;
+
 	/// Implements std::exception::what()
 	const char* what() const throw()
 	{
@@ -43,7 +41,7 @@ public:
 private:
 	std::string err;
 
-	/// XXX
+	/// Synthesize the error string
 	std::string synthErr(const char* error, const char* file,
 		int line, const char* func);
 };
@@ -59,8 +57,5 @@ private:
 #define ANKI_EXCEPTION(x) Exception((std::string() + x).c_str(), \
 	__FILE__, __LINE__, __func__)
 
-#define ANKI_EXCEPTION_R(x, e) Exception((std::string() + x).c_str(), e, \
-	__FILE__, __LINE__, __func__)
-
 
 #endif