-# Find gengetopt
-FIND_PATH(CLITK_GENGETOPT gengetopt)
-IF (CLITK_GENGETOPT STREQUAL "CLITK_GENGETOPT-NOTFOUND")
- MESSAGE("gengetopt not found, please install it (see http://www.gnu.org/software/gengetopt/gengetopt.html)")
-ENDIF (CLITK_GENGETOPT STREQUAL "CLITK_GENGETOPT-NOTFOUND")
+# Find gengetopt, will create a target exe if not found
+SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
+FIND_PACKAGE(Gengetopt)
+#=========================================================
+
+#=========================================================
+# Find libstatgrab is installed, add clitkMemoryUsage.cxx in the library
+FIND_LIBRARY(LIBSTATGRAB NAMES statgrab PATHS)
+IF (${LIBSTATGRAB} MATCHES "LIBSTATGRAB-NOTFOUND")
+# MESSAGE("Install libstatgrab (http://www.i-scream.org/libstatgrab/) for memory usage information")
+ SET(CLITK_MEMORY_INFO OFF)
+ELSE (${LIBSTATGRAB} MATCHES "LIBSTATGRAB-NOTFOUND")
+ SET(CLITK_MEMORY_INFO ON)
+ENDIF (${LIBSTATGRAB} MATCHES "LIBSTATGRAB-NOTFOUND")
+#=========================================================
+
+#=========================================================
+# If the user choose to build documentation, then search for Doxygen executables.
+OPTION(BUILD_DOXYGEN "Build Doxygen Documentation" OFF)
+IF(BUILD_DOXYGEN)
+ FIND_PACKAGE(Doxygen)
+ ADD_SUBDIRECTORY(Doxygen)
+ENDIF(BUILD_DOXYGEN)