diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..1b2434a3f77ee3755966fc8bb6d3ad844b209cef
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,41 @@
+project(qhull)
+cmake_minimum_required(VERSION 2.6)
+
+
+set(QHULL_VERSION "2010.1.next")
+
+if(INCLUDE_INSTALL_DIR)
+else()
+set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include)
+endif()
+if(LIB_INSTALL_DIR)
+else()
+set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
+endif()
+if(BIN_INSTALL_DIR)
+else()
+set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
+endif()
+if(DOC_INSTALL_DIR)
+else()
+set(DOC_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/doc/packages/qhull)
+endif()
+
+message(STATUS)
+message(STATUS "========== qhull Build Information ==========")
+message(STATUS "Build Version: ${QHULL_VERSION}")
+message(STATUS "Install Prefix (CMAKE_INSTALL_PREFIX): ${CMAKE_INSTALL_PREFIX}")
+message(STATUS "Binary Directory (BIN_INSTALL_DIR): ${BIN_INSTALL_DIR}")
+message(STATUS "Library Directory (LIB_INSTALL_DIR): ${LIB_INSTALL_DIR}")
+message(STATUS "Include Directory (INCLUDE_INSTALL_DIR): ${INCLUDE_INSTALL_DIR}")
+message(STATUS "Documentation Directory (DOC_INSTALL_DIR): ${DOC_INSTALL_DIR}")
+message(STATUS)
+message(STATUS "To change any of these options, override them using -D{OPTION_NAME} on the commandline.")
+message(STATUS "To build and install qhull, run \"make\" and \"make install\"")
+message(STATUS)
+
+
+add_subdirectory(src)
+
+
+install(DIRECTORY html/ DESTINATION ${DOC_INSTALL_DIR})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 61c978e3831c27a2feb12b4c5cef39aa4120db1f..e1b244d3279d120c0a0010e8c3b1270c9c0289a0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,9 +1,73 @@
-project(qhull)
-cmake_minimum_required(VERSION 2.4)
-if(COMMAND cmake_policy)
-  cmake_policy(SET CMP0003 NEW)
-endif(COMMAND cmake_policy)
+project(qhull_lib)
 
-add_subdirectory(src)
+# Order object files by frequency of execution.  Small files at end.
+set(
+    qhull_src
+        rboxlib.c
+        user.c
+        global.c
+        stat.c
+        io.c
+        geom2.c
+        poly2.c
+        merge.c
+        libqhull.c
+        geom.c
+        poly.c
+        qset.c
+        mem.c
+        usermem.c
+        userprintf.c
+        random.c
+)
 
-install(DIRECTORY html DESTINATION share/doc/qhull)
+file(GLOB qhull_hdr *.h)
+
+add_library(qhull SHARED ${qhull_src})
+target_link_libraries(qhull m)
+if(UNIX)
+	if(APPLE)
+		set_target_properties(qhull PROPERTIES 
+			INSTALL_NAME_DIR "${LIB_INSTALL_DIR}")
+	else(APPLE)
+		set_target_properties(qhull PROPERTIES 
+			INSTALL_RPATH "${LIB_INSTALL_DIR}"
+			INSTALL_RPATH_USE_LINK_PATH TRUE
+			BUILD_WITH_INSTALL_RPATH FALSE)
+	endif(APPLE)
+endif(UNIX)
+add_library(qhullstatic STATIC ${qhull_src})
+set_property(TARGET qhullstatic PROPERTY OUTPUT_NAME "qhull")
+
+set(qhullcmd_SOURCES  unix.c)
+set(rbox_SOURCES  rbox.c)
+set(qconvex_SOURCES  qconvex.c)
+set(qdelaunay_SOURCES  qdelaun.c)
+set(qvoronoi_SOURCES  qvoronoi.c)
+set(qhalf_SOURCES  qhalf.c)
+
+
+add_executable(qhullcmd ${qhullcmd_SOURCES})
+target_link_libraries(qhullcmd qhull)
+set_property(TARGET qhullcmd PROPERTY OUTPUT_NAME "qhull")
+
+add_executable(rbox ${rbox_SOURCES})
+target_link_libraries(rbox qhull)
+
+add_executable(qconvex ${qconvex_SOURCES})
+target_link_libraries(qconvex qhull)
+
+add_executable(qdelaunay ${qdelaunay_SOURCES})
+target_link_libraries(qdelaunay qhull)
+
+add_executable(qvoronoi ${qvoronoi_SOURCES})
+target_link_libraries(qvoronoi qhull)
+
+add_executable(qhalf ${qhalf_SOURCES})
+target_link_libraries(qhalf qhull)
+
+install(TARGETS qhull qhullstatic qhullcmd rbox qconvex qdelaunay qvoronoi qhalf
+	RUNTIME DESTINATION ${BIN_INSTALL_DIR} 
+	LIBRARY DESTINATION ${LIB_INSTALL_DIR}
+	ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
+install(FILES libqhull.h DESTINATION ${INCLUDE_INSTALL_DIR})
diff --git a/src/libqhull/CMakeLists.txt b/src/libqhull/CMakeLists.txt
index 45e246ed3b1875f2b40a2e06ef559b02b601922b..e1b244d3279d120c0a0010e8c3b1270c9c0289a0 100644
--- a/src/libqhull/CMakeLists.txt
+++ b/src/libqhull/CMakeLists.txt
@@ -28,10 +28,10 @@ target_link_libraries(qhull m)
 if(UNIX)
 	if(APPLE)
 		set_target_properties(qhull PROPERTIES 
-			INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
+			INSTALL_NAME_DIR "${LIB_INSTALL_DIR}")
 	else(APPLE)
 		set_target_properties(qhull PROPERTIES 
-			INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
+			INSTALL_RPATH "${LIB_INSTALL_DIR}"
 			INSTALL_RPATH_USE_LINK_PATH TRUE
 			BUILD_WITH_INSTALL_RPATH FALSE)
 	endif(APPLE)
@@ -67,7 +67,7 @@ add_executable(qhalf ${qhalf_SOURCES})
 target_link_libraries(qhalf qhull)
 
 install(TARGETS qhull qhullstatic qhullcmd rbox qconvex qdelaunay qvoronoi qhalf
-	RUNTIME DESTINATION bin
-	LIBRARY DESTINATION lib
-	ARCHIVE DESTINATION lib)
-install(FILES libqhull.h DESTINATION include)
+	RUNTIME DESTINATION ${BIN_INSTALL_DIR} 
+	LIBRARY DESTINATION ${LIB_INSTALL_DIR}
+	ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
+install(FILES libqhull.h DESTINATION ${INCLUDE_INSTALL_DIR})
diff --git a/src/libqhull/global.c b/src/libqhull/global.c
index d4fefc40db0bb7914370af027add0f99d7a589de..3373cc0e04e92d800ab56c9b92c8c58cc7fa0b86 100644
--- a/src/libqhull/global.c
+++ b/src/libqhull/global.c
@@ -614,7 +614,7 @@ void qh_initflags(char *command) {
   if (command <= &qh qhull_command[0] || command > &qh qhull_command[0] + sizeof(qh qhull_command)) {
     if (command != &qh qhull_command[0]) {
       *qh qhull_command= '\0';
-      strncat( qh qhull_command, command, sizeof( qh qhull_command));
+      strncat(qh qhull_command, command, sizeof(qh qhull_command)-strlen(qh qhull_command)-1);
     }
     while (*s && !isspace(*s))  /* skip program name */
       s++;
diff --git a/src/libqhull/rboxlib.c b/src/libqhull/rboxlib.c
index ab7278e80a568309ccc01fb6fb912218cdb40112..5c84ab84926f584c7da13c14b2950127e7c601c2 100644
--- a/src/libqhull/rboxlib.c
+++ b/src/libqhull/rboxlib.c
@@ -124,7 +124,7 @@ int qh_rboxpoints(FILE* fout, FILE* ferr, char* rbox_command) {
   }
 
   *command= '\0';
-  strncat(command, rbox_command, sizeof(command));
+  strncat(command, rbox_command, sizeof(command)-strlen(command)-1);
 
   while (*s && !isspace(*s))  /* skip program name */
     s++;