--- projectM-2.0.0-Source.orig/CMakeLists.txt	2009-12-01 07:38:42.000000000 +0100
+++ projectM-2.0.0-Source/CMakeLists.txt	2014-09-02 18:13:37.650948971 +0200
@@ -18,6 +18,7 @@
 
 cmake_policy(SET CMP0005 OLD)
 
+ADD_DEFINITIONS(-fPIC)
 
 set( CMAKE_MODULE_PATH    ${CMAKE_MODULE_PATH}
                           ${CMAKE_CURRENT_SOURCE_DIR}/cmake )
@@ -100,15 +101,6 @@
 ADD_DEFINITIONS(-DUSE_FBO)
 endif(USE_FBO)
 
-if(USE_FTGL)
-ADD_DEFINITIONS(-DUSE_FTGL)
-
-find_package( Freetype2 REQUIRED)
-include_directories( ${FREETYPE2_INCLUDE_DIR} )
-
-endif(USE_FTGL)
-
-
 if(COMMAND cmake_policy)
        cmake_policy(SET CMP0003 NEW)
 endif(COMMAND cmake_policy)
@@ -138,58 +130,54 @@
 
 add_subdirectory(Renderer)
 
-#ADD_DEFINITIONS(-DCMAKE_INSTALL_PREFIX="\\\"${CMAKE_INSTALL_PREFIX}\\\"") 
-
 FIND_PACKAGE(OpenGL)
 
 INCLUDE(FindPkgConfig.cmake)
 
-pkg_search_module (FTGL ftgl)
-
-#set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH};/opt/local/include;/Developer/SDKs/MACOSX10.5.sdk/usr/X11/include)
-#set(CMAKE_LIBRARY_PATH /opt/local/lib;/Developer/SDKs/MACOSX10.5.sdk;/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/)
-
 IF(USE_FTGL)
-	if (FTGL_FOUND)
+        pkg_check_modules (FREETYPE freetype2)
+        if(FREETYPE_FOUND)
+                include(FindPackageHandleStandardArgs)
+                find_package_handle_standard_args(FREETYPE DEFAULT_MSG FREETYPE_INCLUDE_DIRS FREETYPE_LIBRARIES FREETYPE_LIBRARY_DIRS)
+                set(FREETYPE2_INCLUDE_DIR ${FREETYPE_INCLUDE_DIRS})
+                include_directories(${FREETYPE_INCLUDE_DIRS} ${FREETYPE_INCLUDE_DIRS}/include/freetype2)
+        endif()
+        message(STATUS "FREETYPE2_INCLUDE_DIR: ${FREETYPE2_INCLUDE_DIR}")
+
+	pkg_check_modules (FTGL ftgl)
+	if(FTGL_FOUND)
+		include(FindPackageHandleStandardArgs)
+		find_package_handle_standard_args(FTGL DEFAULT_MSG FTGL_INCLUDE_DIRS FTGL_LIBRARIES FTGL_LIBRARY_DIRS)
+		ADD_DEFINITIONS(-DUSE_FTGL)
+
 		MESSAGE(STATUS "[projectM] FTGL font support was detected and enabled.")
 	else (FTGL_FOUND)
-		MESSAGE(STATUS 
-	"[projectM] Warning! FTGL has been enabled but not detected. Your compilation will probably break. Turn off FTGL support by setting USE_FTGL to false, or visit http://ftgl.wiki.sourceforge.net/ for help on installing FTGL.")
+		MESSAGE(FATAL_ERROR "[projectM] Warning! FTGL has been enabled but not detected. Your compilation will probably break. Turn off FTGL support by setting USE_FTGL to false, or visit http://ftgl.wiki.sourceforge.net/ for help on installing FTGL.")
 	endif (FTGL_FOUND)
 	
-	ADD_DEFINITIONS(-DUSE_FTGL)
-	
 	set (FTGL_INCUDE_DIRS ${FTGL_INCLUDE_DIRS} ${CMAKE_INCLUDE_PATH} ${OPENGL_INCLUDE_DIR})
-	set (FTGL_LINK_DIRS ${FTGL_LIBRARY_DIRS} )
+	set (FTGL_LINK_DIRS ${FTGL_LIBRARIES} )
+	set (FTGL_LINK_LIBS -L${FTGL_LIBRARY_DIRS} ${FTGL_LIBRARIES} -L${FREETYPE_LIBRARY_DIRS} ${FREETYPE_LIBRARIES})
 	set (FTGL_LINK_TARGETS ftgl freetype)
 	
-ELSE (USE_FTGL)
-	IF (FTGL_FOUND)
-		MESSAGE(STATUS "[projectM] Warning: FTGL font support was detected but NOT enabled. You can enable it by setting USE_FTGL=true")
-	ELSE (FTGL_FOUND)
-		MESSAGE(STATUS "[projectM] Warning: FTGL font support was not detected. Visit http://ftgl.wiki.sourceforge.net/ for help on installing FTGL.")
-	ENDIF(FTGL_FOUND)
-	
-	# todo: change this because its obscure and probably not being used
-	set (FTGL_INCLUDE_DIRS "/opt/local/include")
-	set (FTGL_LINK_DIRS )
-	set (FTGL_LINK_TARGETS )
 ENDIF(USE_FTGL)
 
-
 IF(USE_OPENMP)
 	SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp ")
 	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp ")
 ENDIF(USE_OPENMP)
 
 INCLUDE_DIRECTORIES(${projectM_SOURCE_DIR} ${FTGL_INCLUDE_DIRS} ${Renderer_SOURCE_DIR} ${PRESET_FACTORY_SOURCES})
-LINK_DIRECTORIES(${FTGL_LINK_DIRS} ${Renderer_BINARY_DIR} ${PRESET_FACTORY_BINARY_DIR})
+LINK_DIRECTORIES(${Renderer_BINARY_DIR} ${PRESET_FACTORY_BINARY_DIR})
 
 if(BUILD_PROJECTM_STATIC)
-		TARGET_LINK_LIBRARIES(projectM ${GLEW_LINK_TARGETS} m ${FTGL_LINK_TARGETS} ${OPENGL_LIBRARIES} ${IMAGE_LINK_TARGETS} ${CG_LINK_TARGETS} ${PRESET_FACTORY_LINK_TARGETS})
+message(STATUS "OPENGL_LIBRARIES: ${OPENGL_LIBRARIES}")
+	set(OPENGL_LIBRARIES "-lGLEW -lGLU -lGL -lm -ldl -ldrm -lXdamage -lX11-xcb -lxcb-glx -lxcb-dri2 -lxcb-dri3 -lxcb-present -lxcb-sync -lxshmfence -lXxf86vm -lXfixes -lXext -lX11 -lpthread -lxcb -lXau -lXdmcp")
+message(STATUS "OPENGL_LIBRARIES: ${OPENGL_LIBRARIES}")
+	TARGET_LINK_LIBRARIES(projectM Renderer ${PRESET_FACTORY_LINK_TARGETS} ${GLEW_LINK_TARGETS} m ${FTGL_LINK_LIBS} ${OPENGL_LIBRARIES}  ${IMAGE_LINK_TARGETS} ${CG_LINK_TARGETS})
 else(BUILD_PROJECTM_STATIC)
 
-TARGET_LINK_LIBRARIES(projectM ${GLEW_LINK_TARGETS} m ${FTGL_LINK_TARGETS} ${OPENGL_LIBRARIES}  ${IMAGE_LINK_TARGETS} ${CG_LINK_TARGETS} ${PRESET_FACTORY_LINK_TARGETS})
+	TARGET_LINK_LIBRARIES(projectM Renderer ${PRESET_FACTORY_LINK_TARGETS} ${GLEW_LINK_TARGETS} m dl ${FTGL_LINK_LIBS} ${OPENGL_LIBRARIES}  ${IMAGE_LINK_TARGETS} ${CG_LINK_TARGETS})
 
 endif(BUILD_PROJECTM_STATIC)
