From 321bd727b3015e62f0f645481c77d0bf846756bd Mon Sep 17 00:00:00 2001
From: Fons Rademakers <Fons.Rademakers@cern.ch>
Date: Tue, 7 Jun 2011 17:14:37 +0000
Subject: [PATCH] From Pere: - Added the following packages: oracle, mysql,
 odbc, gviz, fftw, pythia6,   pythia8, unuran, table - Changed the default
 values for the build options depending on platform   such that they display
 correctly with cmake-gui or ccmake - Fixed mathmore build on Windows - Make
 histfactory depending on xml option

git-svn-id: http://root.cern.ch/svn/root/trunk@39577 27541ba8-7e3a-0410-8455-c3a389f83636
---
 CMakeLists.txt                              |   1 +
 cmake/modules/FindFFTW.cmake                |  37 ++++
 cmake/modules/FindGSL.cmake                 |  15 +-
 cmake/modules/FindGraphviz.cmake            |  29 +++
 cmake/modules/FindMySQL.cmake               |  12 +-
 cmake/modules/FindODBC.cmake                |  53 +++++
 cmake/modules/FindOracle.cmake              | 181 ++++++++++++---
 cmake/modules/FindPythia6.cmake             |  33 +++
 cmake/modules/FindPythia8.cmake             |  36 +++
 cmake/modules/RootBuildOptions.cmake        |  22 +-
 cmake/modules/RootNewMacros.cmake           |  26 ++-
 cmake/modules/SearchInstalledSoftware.cmake | 103 ++++++++-
 graf2d/CMakeLists.txt                       |   3 +
 graf2d/gviz/CMakeLists.txt                  |  17 ++
 io/CMakeLists.txt                           |   7 +
 io/castor/CMakeLists.txt                    |  12 +
 io/rfio/CMakeLists.txt                      |  12 +
 math/CMakeLists.txt                         |   9 +-
 math/fftw/CMakeLists.txt                    |  12 +
 math/mathmore/CMakeLists.txt                |   7 +-
 math/unuran/CMakeLists.txt                  |  64 ++++++
 math/unuran/config.h.win.in                 | 230 ++++++++++++++++++++
 misc/CMakeLists.txt                         |   4 +-
 misc/table/CMakeLists.txt                   |  13 ++
 montecarlo/CMakeLists.txt                   |  11 +-
 montecarlo/pythia6/CMakeLists.txt           |  13 ++
 montecarlo/pythia8/CMakeLists.txt           |  13 ++
 roofit/CMakeLists.txt                       |   4 +-
 sql/CMakeLists.txt                          |  10 +
 sql/mysql/CMakeLists.txt                    |  13 ++
 sql/odbc/CMakeLists.txt                     |  13 ++
 sql/oracle/CMakeLists.txt                   |  13 ++
 32 files changed, 961 insertions(+), 67 deletions(-)
 create mode 100644 cmake/modules/FindFFTW.cmake
 create mode 100644 cmake/modules/FindGraphviz.cmake
 create mode 100644 cmake/modules/FindODBC.cmake
 create mode 100644 cmake/modules/FindPythia6.cmake
 create mode 100644 cmake/modules/FindPythia8.cmake
 create mode 100644 graf2d/gviz/CMakeLists.txt
 create mode 100644 io/castor/CMakeLists.txt
 create mode 100644 io/rfio/CMakeLists.txt
 create mode 100644 math/fftw/CMakeLists.txt
 create mode 100644 math/unuran/CMakeLists.txt
 create mode 100644 math/unuran/config.h.win.in
 create mode 100644 misc/table/CMakeLists.txt
 create mode 100644 montecarlo/pythia6/CMakeLists.txt
 create mode 100644 montecarlo/pythia8/CMakeLists.txt
 create mode 100644 sql/CMakeLists.txt
 create mode 100644 sql/mysql/CMakeLists.txt
 create mode 100644 sql/odbc/CMakeLists.txt
 create mode 100644 sql/oracle/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2cf551986f5..81f46a7eca1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -70,6 +70,7 @@ endif()
 add_subdirectory (misc)
 add_subdirectory (main)
 add_subdirectory (bindings)
+add_subdirectory (sql)
 if(tmva)
   add_subdirectory(tmva)
 endif()
diff --git a/cmake/modules/FindFFTW.cmake b/cmake/modules/FindFFTW.cmake
new file mode 100644
index 00000000000..e6a873121c5
--- /dev/null
+++ b/cmake/modules/FindFFTW.cmake
@@ -0,0 +1,37 @@
+# Find the FFTW includes and library.
+# 
+# This module defines
+# FFTW_INCLUDE_DIR, where to locate Pythia.h file
+# FFTW_LIBRARIES, the libraries to link against to use Pythia6
+# FFTW_FOUND.  If false, you cannot build anything that requires Pythia6.
+# FFTW_LIBRARY, where to find the libpythia8 library.
+
+set(PYTHIA8_FOUND 0)
+
+find_path(FFTW_INCLUDE_DIR fftw3.h
+  $ENV{FFTW_DIR}/include
+  /usr/include
+  /usr/local/include
+  /opt/include
+  /usr/apps/include
+  DOC "Specify the directory containing fftw3.h"
+)
+
+find_library(FFTW_LIBRARY NAMES libfftw3 libfftw3-3 PATHS
+  $ENV{FFTW_DIR}/lib
+  /usr/lib 
+  /usr/local/lib
+  /opt/lib
+  /sw/lib
+  DOC "Specify the fttw3 library here."
+)
+
+if(FFTW_INCLUDE_DIR AND FFTW_LIBRARY)
+  set(FFTW_FOUND 1 )
+  message(STATUS "Found fftw3 library at ${FFTW_LIBRARY}")
+endif()
+
+
+set(FFTW_LIBRARIES ${FFTW_LIBRARY})
+
+MARK_AS_ADVANCED(FFTW_FOUND FFTW_LIBRARY FFTW_INCLUDE_DIR)
diff --git a/cmake/modules/FindGSL.cmake b/cmake/modules/FindGSL.cmake
index 27e5c200939..1efca4950dc 100644
--- a/cmake/modules/FindGSL.cmake
+++ b/cmake/modules/FindGSL.cmake
@@ -11,24 +11,27 @@
 #  GSL_INCLUDE_DIRS - where to find headers
 #  GSL_LIBRARIES - full path to the libraries
 #  GSL_LIBRARY_DIRS, the directory where the PLplot library is found.
- 
-#  CMAKE_GSL_CXX_FLAGS  = Unix compiler flags for GSL, essentially "`gsl-config --cxxflags`"
-#  GSL_LINK_DIRECTORIES = link directories, useful for rpath on Unix
-#  GSL_EXE_LINKER_FLAGS = rpath on Unix
+#  GSL_CFLAGS, additional c (c++) required
  
 set( GSL_FOUND OFF )
 set( GSL_CBLAS_FOUND OFF )
- 
+
+if(GSL_INCLUDE_DIR AND GSL_LIBRARY AND GSL_CBLAS_LIBRARY)
+  set(GSL_FIND_QUIETLY 1)
+endif()
+
 # Windows, but not for Cygwin and MSys where gsl-config is available
 if( WIN32 AND NOT CYGWIN AND NOT MSYS )
   # look for headers
   find_path( GSL_INCLUDE_DIR
     NAMES gsl/gsl_cdf.h gsl/gsl_randist.h
+	PATHS $ENV{GSL_DIR}/include
     )
   if( GSL_INCLUDE_DIR )
     # look for gsl library
     find_library( GSL_LIBRARY
       NAMES gsl
+	  PATHS $ENV{GSL_DIR}/lib
     )
     if( GSL_LIBRARY )
       set( GSL_INCLUDE_DIRS ${GSL_INCLUDE_DIR} )
@@ -39,12 +42,14 @@ if( WIN32 AND NOT CYGWIN AND NOT MSYS )
     # look for gsl cblas library
     find_library( GSL_CBLAS_LIBRARY
         NAMES gslcblas
+		PATHS $ENV{GSL_DIR}/lib
       )
     if( GSL_CBLAS_LIBRARY )
       set( GSL_CBLAS_FOUND ON )
     endif( GSL_CBLAS_LIBRARY )
  
     set( GSL_LIBRARIES ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} )
+	set( GSL_CFLAGS "-DGSL_DLL")
   endif( GSL_INCLUDE_DIR )
  
   mark_as_advanced(
diff --git a/cmake/modules/FindGraphviz.cmake b/cmake/modules/FindGraphviz.cmake
new file mode 100644
index 00000000000..949707f1a96
--- /dev/null
+++ b/cmake/modules/FindGraphviz.cmake
@@ -0,0 +1,29 @@
+# Try to find Graphviz. 
+# This will define:
+# GRAPHVIZ_FOUND - system has Graphviz
+# GRAPHVIZ_INCLUDE_DIR - the Graphviz include directory
+# GRAPHVIZ_LIBRARY - Link these to use Graphviz
+# GRAPHVIZ_DEFINITIONS - Compiler switches required for using Graphviz
+
+if(GRAPHVIZ_INCLUDE_DIR AND GRAPHVIZ_CDT_LIBRARY AND GRAPHVIZ_GRAPH_LIBRARY AND GRAPHVIZ_PATHPLAN_LIBRARY)
+  set(GRAPHVIZ_FIND_QUIETLY TRUE)
+endif()
+
+
+find_path(GRAPHVIZ_INCLUDE_DIR graphviz/graph.h PATHS $ENV{GRAPHVIZ_DIR}/include)
+
+find_library(GRAPHVIZ_CDT_LIBRARY NAMES cdt PATHS $ENV{GRAPHVIZ_DIR}/lib)
+find_library(GRAPHVIZ_GVC_LIBRARY NAMES gvc PATHS $ENV{GRAPHVIZ_DIR}/lib)
+find_library(GRAPHVIZ_GRAPH_LIBRARY NAMES graph PATHS $ENV{GRAPHVIZ_DIR}/lib)
+find_library(GRAPHVIZ_PATHPLAN_LIBRARY NAMES pathplan PATHS $ENV{GRAPHVIZ_DIR}/lib)
+	
+if(GRAPHVIZ_INCLUDE_DIR AND GRAPHVIZ_CDT_LIBRARY AND GRAPHVIZ_GVC_LIBRARY AND GRAPHVIZ_GRAPH_LIBRARY AND GRAPHVIZ_PATHPLAN_LIBRARY)
+  set(GRAPHVIZ_FOUND 1)
+else()
+  set(GRAPHVIZ_FOUND 0)
+endif()
+
+if(GRAPHVIZ_FOUND AND NOT GRAPHVIZ_FIND_QUIETLY)
+  message(STATUS "Found Graphviz: ${GRAPHVIZ_CDT_LIBRARY} ${GRAPHVIZ_GVC_LIBRARY} ${GRAPHVIZ_GRAPH_LIBRARY} ${GRAPHVIZ_PATHPLAN_LIBRARY}")
+endif()
+
diff --git a/cmake/modules/FindMySQL.cmake b/cmake/modules/FindMySQL.cmake
index 97c8f25139b..fbfe9195136 100644
--- a/cmake/modules/FindMySQL.cmake
+++ b/cmake/modules/FindMySQL.cmake
@@ -1,4 +1,3 @@
-# - Find mysqlclient
 # Find the native MySQL includes and library
 #
 #  MYSQL_INCLUDE_DIR - where to find mysql.h, etc.
@@ -17,20 +16,25 @@ FIND_PATH(MYSQL_INCLUDE_DIR mysql.h
   /usr/include/mysql
   /usr/include
   /usr/mysql/include
+  $ENV{MYSQL_DIR}/include
 )
 
 SET(MYSQL_NAMES mysqlclient mysqlclient_r)
 FIND_LIBRARY(MYSQL_LIBRARY
   NAMES ${MYSQL_NAMES}
-  PATHS /usr/local/mysql/lib /usr/local/lib /usr/lib
+  PATHS /usr/local/mysql/lib /usr/local/lib /usr/lib $ENV{MYSQL_DIR}/lib $ENV{MYSQL_DIR}/lib/opt
 )
 
 IF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
   SET(MYSQL_FOUND TRUE)
-  SET( MYSQL_LIBRARIES ${MYSQL_LIBRARY} )
+  SET(MYSQL_LIBRARIES ${MYSQL_LIBRARY})
+  iF(WIN32)
+    STRING(REPLACE mysqlclient libmysql libmysql ${MYSQL_LIBRARY})
+    SET(MYSQL_LIBRARIES ${libmysql} ${MYSQL_LIBRARIES})
+  ENDIF()
 ELSE (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
   SET(MYSQL_FOUND FALSE)
-  SET( MYSQL_LIBRARIES )
+  SET(MYSQL_LIBRARIES )
 ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
 
 IF (MYSQL_FOUND)
diff --git a/cmake/modules/FindODBC.cmake b/cmake/modules/FindODBC.cmake
new file mode 100644
index 00000000000..296702f4450
--- /dev/null
+++ b/cmake/modules/FindODBC.cmake
@@ -0,0 +1,53 @@
+# Find the ODBC driver manager includes and library.
+# 
+# ODBC is an open standard for connecting to different databases in a
+# semi-vendor-independent fashion.  First you install the ODBC driver
+# manager.  Then you need a driver for each separate database you want
+# to connect to (unless a generic one works).  VTK includes neither
+# the driver manager nor the vendor-specific drivers: you have to find
+# those yourself.
+#  
+# This module defines
+# ODBC_INCLUDE_DIR where to find sql.h
+# ODBC_LIBRARIES, the libraries to link against to use ODBC
+# ODBC_FOUND.  If false, you cannot build anything that requires MySQL.
+# also defined, but not for general use is
+# ODBC_LIBRARY, where to find the ODBC driver manager library.
+
+SET( ODBC_FOUND 0 )
+
+#---For the windows platform ODBC is located automatically
+if(WIN32)
+  set(ODBC_INCLUDE_DIR "")
+  set(ODBC_LIBRARY odbc32.lib) 
+  set(ODBC_FOUND 1)
+else()
+  find_path(ODBC_INCLUDE_DIR sqlext.h
+    /usr/include
+    /usr/include/odbc
+    /usr/local/include
+    /usr/local/include/odbc
+    /usr/local/odbc/include
+	$ENV{ODBC_DIR}/include
+    DOC "Specify the directory containing sql.h."
+  )
+
+  find_library( ODBC_LIBRARY NAMES libiodbc libodbc odbc32
+    PATHS
+    /usr/lib
+    /usr/lib/odbc
+    /usr/local/lib
+    /usr/local/lib/odbc
+    /usr/local/odbc/lib
+	$ENV{ODBC_DIR}/lib
+    DOC "Specify the ODBC driver manager library here."
+  )
+  if(ODBC_LIBRARY AND ODBC_INCLUDE_DIR)
+    set( ODBC_FOUND 1 )
+  endif()
+endif()
+
+
+set(ODBC_LIBRARIES ${ODBC_LIBRARY})
+
+MARK_AS_ADVANCED( ODBC_FOUND ODBC_LIBRARY ODBC_EXTRA_LIBRARIES ODBC_INCLUDE_DIR )
diff --git a/cmake/modules/FindOracle.cmake b/cmake/modules/FindOracle.cmake
index 4ed2138da01..5d67a6a7f54 100644
--- a/cmake/modules/FindOracle.cmake
+++ b/cmake/modules/FindOracle.cmake
@@ -1,41 +1,162 @@
-# - Find Oracle / Oracle Embedded
-# Find the Oracle includes and client library
-# This module defines
-#  ORACLE_INCLUDE_DIR, where to find oracle.h
-#  ORACLE_LIBRARIES, the libraries needed to use Oracle.
-#  ORACLE_EMBEDDED_LIBRARIES, the libraries needed to use Oracle Embedded.
-#  ORACLE_FOUND, If false, do not try to use Oracle.
-#  ORACLE_EMBEDDED_FOUND, If false, do not try to use Oracle Embedded.
-
-# Copyright (c) 2008, Julia Sanchez-Simon, <hithwen@gmail.com>
-# Copyright (c) 2008, Miguel Angel Aragüez-Rey, <fizban87@gmail.com>
+# TOra: Configure Oracle libraries
 #
-# Redistribution and use is allowed according to the terms of the BSD license.
-# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+# ORACLE_FOUND - system has Oracle OCI
+# ORACLE_INCLUDE_DIR - where to find oci.h
+# ORACLE_LIBRARIES - the libraries to link against to use Oracle OCI
+#
+# copyright (c) 2007 Petr Vanek <petr@scribus.info>
+# Redistribution and use is allowed according to the terms of the GPLv2 license.
+# Mofified by Pere Mato
+
+set(ORACLE_FOUND "NO")
+
+set(ORACLE_HOME $ENV{ORACLE_DIR})
 
+IF (ORACLE_PATH_INCLUDES)
+    SET (ORACLE_INCLUDES_LOCATION ${ORACLE_PATH_INCLUDES})
+ELSE (ORACLE_PATH_INCLUDES)
+    SET (ORACLE_INCLUDES_LOCATION
+            ${ORACLE_HOME}/rdbms/public
+            ${ORACLE_HOME}/include
+            # sdk
+            ${ORACLE_HOME}/sdk/include
+            # xe on windows
+            ${ORACLE_HOME}/OCI/include
+       )
+ENDIF (ORACLE_PATH_INCLUDES)
 
-find_path(ORACLE_INCLUDE_DIR nzerror.h occiCommon.h occi.h oci8dp.h ocidef.h ociextp.h 				     ocixmldb.h orid.h oro.h nzt.h occiControl.h occiObjects.h 				     ociap.h ocidem.h oci.h odci.h ori.h ort.h occiAQ.h oci1.h  		             occiData.h  ociapr.h  ocidfn.h  ocikpr.h  oratypes.h  				     orl.h   xa.h
+IF (ORACLE_PATH_LIB)
+    SET (ORACLE_LIB_LOCATION ${ORACLE_PATH_LIB})
+ELSE (ORACLE_PATH_LIB)
+    SET (ORACLE_LIB_LOCATION
+            ${ORACLE_HOME}/lib
+            # xe on windows
+            ${ORACLE_HOME}/OCI/lib/MSVC
+        )
+ENDIF (ORACLE_PATH_LIB)
 
-   /usr/include/oracle/11.1.0.1/client
+FIND_PATH(
+    ORACLE_INCLUDE_DIR
+    oci.h
+    ${ORACLE_INCLUDES_LOCATION}
 )
 
-find_library(ORACLE_LIBRARIES NAMES occi clntsh
-   PATHS
-   /usr/lib/oracle/11.1.0.1/client/lib
-   /usr/lib/oracle/11.1.0.1/client/bin
+FIND_LIBRARY(
+    ORACLE_LIBRARY_OCCI
+    NAMES libocci occi oraocci10
+    PATHS ${ORACLE_LIB_LOCATION}
+)
+FIND_LIBRARY(
+    ORACLE_LIBRARY_CLNTSH
+    NAMES libclntsh clntsh oci
+    PATHS ${ORACLE_LIB_LOCATION}
+)
+FIND_LIBRARY(
+    ORACLE_LIBRARY_LNNZ
+    NAMES libnnz10 nnz10 libnnz11 nnz11 ociw32
+    PATHS ${ORACLE_LIB_LOCATION}
 )
 
+SET (ORACLE_LIBRARY ${ORACLE_LIBRARY_OCCI} ${ORACLE_LIBRARY_CLNTSH} ${ORACLE_LIBRARY_LNNZ})
+
+IF (ORACLE_LIBRARY)
+    SET(ORACLE_LIBRARIES ${ORACLE_LIBRARY})
+    SET(ORACLE_FOUND 1)
+ENDIF (ORACLE_LIBRARY)
+
+
+# guess OCI version
+IF (NOT DEFINED ORACLE_OCI_VERSION)
+    FIND_PROGRAM(SQLPLUS_EXECUTABLE sqlplus
+      /usr/bin/
+      /usr/local/bin
+      ${ORACLE_HOME}/bin
+    )
+    IF(SQLPLUS_EXECUTABLE)
+		EXECUTE_PROCESS(COMMAND ${ORACLE_HOME}/bin/sqlplus -version OUTPUT_VARIABLE sqlplus_out)
+		STRING(REGEX MATCH "([0-9.]+)" sqlplus_version ${sqlplus_out})
+		MESSAGE(STATUS "Found sqlplus version: ${sqlplus_version}")
+
+		# WARNING!
+		# MATCHES operator is using Cmake regular expression.
+		# so the e.g. 9.* does not expand like shell file mask
+		# but as "9 and then any sequence of characters"
+		IF (${sqlplus_version} MATCHES "8.*")
+			SET(ORACLE_OCI_VERSION "8I")
+		ELSEIF (${sqlplus_version} MATCHES "9.*")
+			SET(ORACLE_OCI_VERSION "9")
+# do not change the order of the ora10 checking!
+		ELSEIF (${sqlplus_version} MATCHES "10.2.*")
+			SET(ORACLE_OCI_VERSION "10G_R2")
+		ELSEIF (${sqlplus_version} MATCHES "10.*")
+			SET(ORACLE_OCI_VERSION "10G")
+		ELSEIF (${sqlplus_version} MATCHES "11.*")
+			SET(ORACLE_OCI_VERSION "11G")
+		ELSE (${sqlplus_version} MATCHES "8.*")
+			SET(ORACLE_OCI_VERSION "10G_R2")
+		ENDIF (${sqlplus_version} MATCHES "8.*")
+
+		MESSAGE(STATUS "Guessed ORACLE_OCI_VERSION value: ${ORACLE_OCI_VERSION}")
+	ENDIF()
+ENDIF (NOT DEFINED ORACLE_OCI_VERSION)
+
+
+IF (ORACLE_FOUND)
+    IF (NOT ORACLE_FIND_QUIETLY)
+         MESSAGE(STATUS "Found Oracle: ${ORACLE_LIBRARIES}")
+    ENDIF (NOT ORACLE_FIND_QUIETLY)
+    # there *must* be OCI version defined for internal libraries
+    IF (ORACLE_OCI_VERSION)
+        ADD_DEFINITIONS(-DOTL_ORA${ORACLE_OCI_VERSION})
+    ELSE (ORACLE_OCI_VERSION)
+        MESSAGE(FATAL_ERROR "Set -DORACLE_OCI_VERSION for your oci. [8, 8I, 9I, 10G, 10G_R2]")
+    ENDIF (ORACLE_OCI_VERSION)
+
+ELSE (ORACLE_FOUND)
+    MESSAGE(STATUS "Oracle not found.")
+    MESSAGE(STATUS "Oracle: You can specify includes: -DORACLE_PATH_INCLUDES=/usr/include/oracle/10.2.0.3/client")
+    MESSAGE(STATUS "   currently found includes: ${ORACLE_INCLUDES}")
+    MESSAGE(STATUS "Oracle: You can specify libs: -DORACLE_PATH_LIB=/usr/lib/oracle/10.2.0.3/client/lib")
+    MESSAGE(STATUS "   currently found libs: ${ORACLE_LIBRARY}")
+    IF (ORACLE_FIND_REQUIRED)
+        MESSAGE(FATAL_ERROR "Could not find Oracle library")
+    ELSE (ORACLE_FIND_REQUIRED)
+        # setup the variables for silent continue
+        SET (ORACLE_INCLUDES "")
+    ENDIF (ORACLE_FIND_REQUIRED)
+ENDIF (ORACLE_FOUND)
+
+MACRO (PREPROCESS_ORACLE_FILES INFILES INCLUDE_DIRS_IN)
+ 
+  set(SYS_INCLUDE "'sys_include=(${ORACLE_HOME}/precomp/public,/usr/include/,/usr/local/gcc3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/include,/usr/local/gcc3.2.3/lib/gcc-lib/i686-pc-linux-gnu,/usr/include/g++-3,/usr/include/c++/3.2/backward,/usr/include/c++/3.2)'")
+
+#  set(INCLUDE_DIRS "
+#      include=${ORACLE_HOME}/precomp/public
+#      include=${ORACLE_HOME}/rdbms/public
+#      include=${ORACLE_HOME}/rdbms/demo
+#      include=${ORACLE_HOME}/plsql/public
+#      include=${ORACLE_HOME}/network/public
+#  ")
+
+  set(INCLUDE_DIRS)
+
+  foreach (_current_FILE ${INCLUDE_DIRS_IN})
+    set(INCLUDE_DIRS ${INCLUDE_DIRS} include=${_current_FILE})   
+  endforeach (_current_FILE ${INCLUDE_DIRS_IN})
+
+  SET(PROCFLAGS oraca=yes code=cpp parse=partial sqlcheck=semantics ireclen=130 oreclen=130 ${INCLUDE_DIRS})
+# ${SYS_INCLUDE} ${INCLUDE_DIRS})
+ 
+
+#  MESSAGE("PROCFLAGS: ${PROCFLAGS}")
+#  MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
 
-#macro_push_required_vars()
-#set( CMAKE_REQUIRED_INCLUDES ${ORACLE_INCLUDE_DIR} )
-#macro_pop_required_vars()
 
-if(ORACLE_INCLUDE_DIR AND ORACLE_LIBRARIES)
-   set(ORACLE_FOUND TRUE)
-   message(STATUS "Found Oracle: ${ORACLE_INCLUDE_DIR}, ${ORACLE_LIBRARIES}")
-else(ORACLE_INCLUDE_DIR AND ORACLE_LIBRARIES)
-   set(ORACLE_FOUND FALSE)
-   message(STATUS "Oracle not found.")
-endif(ORACLE_INCLUDE_DIR AND ORACLE_LIBRARIES)
+  foreach (_current_FILE ${INFILES})
+    GET_FILENAME_COMPONENT(OUTFILE_NAME ${_current_FILE} NAME_WE)
+    set(OUTFILE "${OUTFILE_NAME}.cxx")
+    ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILE} 
+     COMMAND $ENV{ORACLE_HOME}/bin/proc ARGS iname=${CMAKE_CURRENT_SOURCE_DIR}/${_current_FILE} oname=${CMAKE_CURRENT_BINARY_DIR}/${OUTFILE} ${PROCFLAGS} DEPENDS ${_current_FILE})
+  endforeach (_current_FILE ${INFILES})
 
-mark_as_advanced(ORACLE_INCLUDE_DIR ORACLE_LIBRARIES)
+ENDMACRO (PREPROCESS_ORACLE_FILES)
\ No newline at end of file
diff --git a/cmake/modules/FindPythia6.cmake b/cmake/modules/FindPythia6.cmake
new file mode 100644
index 00000000000..c083ca7e76f
--- /dev/null
+++ b/cmake/modules/FindPythia6.cmake
@@ -0,0 +1,33 @@
+# Find the Pythia6 includes and library.
+# 
+# This module defines
+# PYTHIA6_LIBRARIES, the libraries to link against to use Pythia6
+# PYTHIA6_FOUND.  If false, you cannot build anything that requires Pythia6.
+# PYTHIA6_LIBRARY, where to find the libPythia6 library.
+
+set(PYTHIA6_FOUND 0)
+
+
+find_library(PYTHIA6_LIBRARY NAMES pythia6 libPythia6 PATHS
+  $ENV{PYTHIA6_DIR}/lib
+  /cern/pro/lib 
+  /opt/pythia 
+  /opt/pythia6
+  /usr/lib/pythia
+  /usr/local/lib/pythia
+  /usr/lib/pythia6
+  /usr/local/lib/pythia6
+  /usr/lib
+  /usr/local/lib
+  DOC "Specify the Pythia6 library here."
+)
+
+if(PYTHIA6_LIBRARY)
+  message(STATUS "Found Pythia8 library at ${PYTHIA6_LIBRARY}")
+  set(PYTHIA6_FOUND 1 )
+endif()
+
+
+set(PYTHIA6_LIBRARIES ${PYTHIA6_LIBRARY})
+
+MARK_AS_ADVANCED( PYTHIA6_FOUND PYTHIA6_LIBRARY)
diff --git a/cmake/modules/FindPythia8.cmake b/cmake/modules/FindPythia8.cmake
new file mode 100644
index 00000000000..9fd8562ace8
--- /dev/null
+++ b/cmake/modules/FindPythia8.cmake
@@ -0,0 +1,36 @@
+# Find the Pythia8 includes and library.
+# 
+# This module defines
+# PYTHIA8_INCLUDE_DIR, where to locate Pythia.h file
+# PYTHIA8_LIBRARIES, the libraries to link against to use Pythia6
+# PYTHIA8_FOUND.  If false, you cannot build anything that requires Pythia6.
+# PYTHIA8_LIBRARY, where to find the libpythia8 library.
+
+set(PYTHIA8_FOUND 0)
+
+find_path(PYTHIA8_INCLUDE_DIR Pythia.h
+  $ENV{PYTHIA8_DIR}/include
+  /opt/pythia8/include
+  /usr/local/include
+  /usr/include
+  /usr/include/pythia
+  DOC "Specify the directory containing Pythia.h."
+)
+
+find_library(PYTHIA8_LIBRARY NAMES libPythia8 PATHS
+  $ENV{PYTHIA8_DIR}/lib
+  /opt/pythia8/lib
+  /usr/local/lib
+  /usr/lib
+  DOC "Specify the Pythia8 library here."
+)
+
+if(PYTHIA8_INCLUDE_DIR AND PYTHIA8_LIBRARY)
+  set(PYTHIA8_FOUND 1 )
+  message(STATUS "Found Pythia8 library at ${PYTHIA8_LIBRARY}")
+endif()
+
+
+set(PYTHIA8_LIBRARIES ${PYTHIA8_LIBRARY})
+
+MARK_AS_ADVANCED( PYTHIA8_FOUND PYTHIA8_LIBRARY PYTHIA8_INCLUDE_DIR)
diff --git a/cmake/modules/RootBuildOptions.cmake b/cmake/modules/RootBuildOptions.cmake
index eac76ed69a2..1b40d8648e4 100644
--- a/cmake/modules/RootBuildOptions.cmake
+++ b/cmake/modules/RootBuildOptions.cmake
@@ -44,6 +44,17 @@ function(ROOT_WRITE_OPTIONS file)
   endforeach()
 endfunction()
 
+#---Define default values depending on platform before the options are defined----------------------
+if(WIN32)
+  set(x11_defvalue OFF)
+  set(memstat_defvalue OFF)
+  set(explicitlink_defvalue ON)
+else()
+  set(x11_defvalue ON)
+  set(memstat_defvalue ON)
+  set(explicitlink_defvalue OFF)
+endif()
+
 ROOT_BUILD_OPTION(afs OFF "AFS support, requires AFS libs and objects")                 
 ROOT_BUILD_OPTION(alien OFF "AliEn support, requires libgapiUI from ALICE")               
 ROOT_BUILD_OPTION(asimage ON "Image processing support, requires libAfterImage")             
@@ -62,7 +73,7 @@ ROOT_BUILD_OPTION(clarens OFF "Clarens RPC support, optionally used by PROOF")
 ROOT_BUILD_OPTION(cling OFF "Enable new CLING C++ interpreter")            
 ROOT_BUILD_OPTION(dcache OFF "dCache support, requires libdcap from DESY")              
 ROOT_BUILD_OPTION(exceptions ON "Turn on compiler exception handling capability")         
-ROOT_BUILD_OPTION(explicitlink OFF "Explicitly link with all dependent libraries")      
+ROOT_BUILD_OPTION(explicitlink ${explicitlink_defvalue} "Explicitly link with all dependent libraries")      
 ROOT_BUILD_OPTION(fftw3 OFF "Fast Fourier Transform support, requires libfftw3") 
 ROOT_BUILD_OPTION(fitsio OFF "Read images and data from FITS files, requires cfitsio")                
 ROOT_BUILD_OPTION(gviz OFF "Graphs visualization support, requires graphviz")                
@@ -76,7 +87,7 @@ ROOT_BUILD_OPTION(hdfs OFF "HDFS support; requires libhdfs from HDFS >= 0.19.1")
 ROOT_BUILD_OPTION(krb5 ON "Kerberos5 support, requires Kerberos libs")               
 ROOT_BUILD_OPTION(ldap ON "LDAP support, requires (Open)LDAP libs")                
 ROOT_BUILD_OPTION(mathmore OFF "Build the new libMathMore extended math library, requires GSL (vers. >= 1.8)")            
-ROOT_BUILD_OPTION(memstat ON "A memory statistics utility, helps to detect memory leaks")    
+ROOT_BUILD_OPTION(memstat ${memstat_defvalue} "A memory statistics utility, helps to detect memory leaks")    
 ROOT_BUILD_OPTION(minuit2 OFF "Build the new libMinuit2 minimizer library")            
 ROOT_BUILD_OPTION(monalisa OFF "Monalisa monitoring support, requires libapmoncpp")        
 ROOT_BUILD_OPTION(mysql OFF "MySQL support, requires libmysqlclient")              
@@ -108,18 +119,13 @@ ROOT_BUILD_OPTION(unuran OFF "UNURAN - package for generating non-uniform random
 ROOT_BUILD_OPTION(winrtdebug OFF "Link against the Windows debug runtime library")         
 ROOT_BUILD_OPTION(xft OFF "Xft support (X11 antialiased fonts)")                
 ROOT_BUILD_OPTION(xml ON "XML parser interface")
-ROOT_BUILD_OPTION(x11 ON "X11 support")
+ROOT_BUILD_OPTION(x11 ${x11_defvalue} "X11 support")
 ROOT_BUILD_OPTION(xrootd OFF "Build xrootd file server and its client (if supported)")
   
 option(fail-on-missing "Fail the configure step if a required external package is missing" OFF)
 option(minimal "Do not automatically search for support libraries" OFF)
 option(gminimal "Do not automatically search for support libraries, but include X11" OFF)
   
-if(WIN32)
-  set(x11 OFF)
-  set(memstat OFF)
-  set(explicitlink ON)
-endif()
 
 #---General Build options----------------------------------------------------------------------
 # use, i.e. don't skip the full RPATH for the build tree
diff --git a/cmake/modules/RootNewMacros.cmake b/cmake/modules/RootNewMacros.cmake
index 514647aac2b..6ca6e1f7330 100644
--- a/cmake/modules/RootNewMacros.cmake
+++ b/cmake/modules/RootNewMacros.cmake
@@ -204,20 +204,24 @@ function(ROOT_LINKER_LIBRARY library)
     #---create a list of all the object files-----------------------------
     if(CMAKE_GENERATOR MATCHES "Visual Studio")
       foreach(src1 ${lib_srcs})
-        string (REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "" src2 ${src1})
-        string (REPLACE ${CMAKE_CURRENT_BINARY_DIR} "" src3 ${src2})     
-        string (REPLACE ".." "__" src ${src3})     
-        get_filename_component(name ${src} NAME_WE)
-        set(lib_objs ${lib_objs} ${library}.dir/${CMAKE_CFG_INTDIR}/${name}.obj)
+		if(NOT src1 MATCHES "[.]h$|[.]icc$|[.]hxx$|[.]hpp$")
+          string (REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "" src2 ${src1})
+          string (REPLACE ${CMAKE_CURRENT_BINARY_DIR} "" src3 ${src2})     
+          string (REPLACE ".." "__" src ${src3})     
+          get_filename_component(name ${src} NAME_WE)
+          set(lib_objs ${lib_objs} ${library}.dir/${CMAKE_CFG_INTDIR}/${name}.obj)
+		endif()
       endforeach()
     else()
       foreach(src1 ${lib_srcs})
-        string (REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "" src2 ${src1})
-        string (REPLACE ${CMAKE_CURRENT_BINARY_DIR} "" src3 ${src2})           
-        string (REPLACE ".." "__" src ${src3})     
-        get_filename_component(name ${src} NAME_WE)
-        get_filename_component(path ${src} PATH)
-        set(lib_objs ${lib_objs} ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${library}.dir/${path}/${name}.obj)
+		if(NOT src1 MATCHES "[.]h$|[.]icc$|[.]hxx$|[.]hpp$")
+	      string (REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "" src2 ${src1})
+          string (REPLACE ${CMAKE_CURRENT_BINARY_DIR} "" src3 ${src2})           
+          string (REPLACE ".." "__" src ${src3})     
+          get_filename_component(name ${src} NAME_WE)
+          get_filename_component(path ${src} PATH)
+          set(lib_objs ${lib_objs} ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${library}.dir/${path}/${name}.obj)
+		endif()
       endforeach()
     endif()
     #---create a shared library with the .def file------------------------
diff --git a/cmake/modules/SearchInstalledSoftware.cmake b/cmake/modules/SearchInstalledSoftware.cmake
index 97e06269fe8..bf2534b3054 100644
--- a/cmake/modules/SearchInstalledSoftware.cmake
+++ b/cmake/modules/SearchInstalledSoftware.cmake
@@ -205,6 +205,20 @@ if(opengl)
   endif()
 endif()
 
+#---Check for Graphviz installation-------------------------------------------------------
+if(gviz)
+  message(STATUS "Looking for Graphviz")
+  find_package(Graphviz)
+  if(NOT GRAPHVIZ_FOUND)
+    if(fail-on-missing)
+      message(FATAL_ERROR "Graphviz package not found and gviz option required")
+    else()
+      set(gviz OFF)
+      message(STATUS "Graphviz not found. Switching off gviz option")
+    endif()
+  endif()
+endif()
+
 #---Check for Qt installation-------------------------------------------------------
 if(qt)
   message(STATUS "Looking for Qt4")
@@ -278,7 +292,7 @@ if(ssl)
 endif()
 
 #---Check for Castor-------------------------------------------------------------------
-if(castor)
+if(castor OR rfio)
   message(STATUS "Looking for Castor")
   find_package(Castor)
   if(NOT CASTOR_FOUND)
@@ -286,7 +300,92 @@ if(castor)
       message(FATAL_ERROR "Castor libraries not found and they are required (castor option enabled)")
     else()
       set(castor OFF)
-      message(STATUS "Castor not found. Switching off castor option")
+	  set(rfio OFF)
+      message(STATUS "Castor not found. Switching off castor/rfio option")
+    endif()
+  endif()
+endif()
+
+#---Check for MySQL-------------------------------------------------------------------
+if(mysql)
+  message(STATUS "Looking for MySQL")
+  find_package(MySQL)
+  if(NOT MYSQL_FOUND)
+    if(fail-on-missing)
+      message(FATAL_ERROR "MySQL libraries not found and they are required (mysql option enabled)")
+    else()
+      set(mysql OFF)
+      message(STATUS "MySQL not found. Switching off mysql option")
+    endif()
+  endif()
+endif()
+
+#---Check for Oracle-------------------------------------------------------------------
+if(oracle)
+  message(STATUS "Looking for Oracle")
+  find_package(Oracle)
+  if(NOT ORACLE_FOUND)
+    if(fail-on-missing)
+      message(FATAL_ERROR "Oracle libraries not found and they are required (orable option enabled)")
+    else()
+      set(oracle OFF)
+      message(STATUS "Oracle not found. Switching off oracle option")
+    endif()
+  endif()
+endif()
+
+#---Check for ODBC-------------------------------------------------------------------
+if(odbc)
+  message(STATUS "Looking for ODBC")
+  find_package(ODBC)
+  if(NOT ODBC_FOUND)
+    if(fail-on-missing)
+      message(FATAL_ERROR "ODBC libraries not found and they are required (odbc option enabled)")
+    else()
+      set(odbc OFF)
+      message(STATUS "ODBC not found. Switching off odbc option")
+    endif()
+  endif()
+endif()
+
+#---Check for Pythia6-------------------------------------------------------------------
+if(pythia6)
+  message(STATUS "Looking for Pythia6")
+  find_package(Pythia6)
+  if(NOT PYTHIA6_FOUND)
+    if(fail-on-missing)
+      message(FATAL_ERROR "Pythia6 libraries not found and they are required (pythia6 option enabled)")
+    else()
+      set(pythia6 OFF)
+      message(STATUS "Pythia6 not found. Switching off pythia6 option")
+    endif()
+  endif()
+endif()
+
+#---Check for Pythia8-------------------------------------------------------------------
+if(pythia8)
+  message(STATUS "Looking for Pythia8")
+  find_package(Pythia8)
+  if(NOT PYTHIA8_FOUND)
+    if(fail-on-missing)
+      message(FATAL_ERROR "Pythia8 libraries not found and they are required (pythia8 option enabled)")
+    else()
+      set(pythia8 OFF)
+      message(STATUS "Pythia8 not found. Switching off pythia8 option")
+    endif()
+  endif()
+endif()
+
+#---Check for FFTW3-------------------------------------------------------------------
+if(fftw3)
+  message(STATUS "Looking for FFTW3")
+  find_package(FFTW)
+  if(NOT FFTW_FOUND)
+    if(fail-on-missing)
+      message(FATAL_ERROR "FFTW3 libraries not found and they are required (fftw3 option enabled)")
+    else()
+      set(fftw3 OFF)
+      message(STATUS "FFTW3 not found. Switching off fftw3 option")
     endif()
   endif()
 endif()
diff --git a/graf2d/CMakeLists.txt b/graf2d/CMakeLists.txt
index c095dbbbea9..4fc3f82e599 100644
--- a/graf2d/CMakeLists.txt
+++ b/graf2d/CMakeLists.txt
@@ -17,4 +17,7 @@ add_subdirectory(asimage)     # special CMakeLists.txt
 if(qt)
   add_subdirectory(qt)
 endif()
+if(gviz)
+  add_subdirectory(gviz)
+endif()
 
diff --git a/graf2d/gviz/CMakeLists.txt b/graf2d/gviz/CMakeLists.txt
new file mode 100644
index 00000000000..a7b1eeb23e0
--- /dev/null
+++ b/graf2d/gviz/CMakeLists.txt
@@ -0,0 +1,17 @@
+############################################################################
+# CMakeLists.txt file for building ROOT graf2d/gviz package
+# @author Pere Mato, CERN
+############################################################################
+
+
+ROOT_USE_PACKAGE(hist/hist)
+ROOT_USE_PACKAGE(graf2d/graf)
+
+include_directories(${GRAPHVIZ_INCLUDE_DIR}/graphviz)
+
+ROOT_GENERATE_DICTIONARY(G__Gviz *.h LINKDEF LinkDef.h)
+ROOT_GENERATE_ROOTMAP(Gviz LINKDEF LinkDef.h DEPENDENCIES Hist Graf)
+ROOT_LINKER_LIBRARY(Gviz *.cxx G__Gviz.cxx 
+                    LIBRARIES ${GRAPHVIZ_GRAPH_LIBRARY} ${GRAPHVIZ_GVC_LIBRARY} 
+                    DEPENDENCIES Hist Graf)
+ROOT_INSTALL_HEADERS()
diff --git a/io/CMakeLists.txt b/io/CMakeLists.txt
index 8920b3f926a..9b516a93ee1 100644
--- a/io/CMakeLists.txt
+++ b/io/CMakeLists.txt
@@ -4,3 +4,10 @@ add_subdirectory(xml)
 if(xml)
   add_subdirectory(xmlparser)
 endif()
+if(castor)
+  add_subdirectory(castor)
+endif()
+if(rfio)
+  add_subdirectory(rfio)
+endif()
+
diff --git a/io/castor/CMakeLists.txt b/io/castor/CMakeLists.txt
new file mode 100644
index 00000000000..ecd7152b364
--- /dev/null
+++ b/io/castor/CMakeLists.txt
@@ -0,0 +1,12 @@
+############################################################################
+# CMakeLists.txt file for building ROOT io/castor package
+############################################################################
+
+ROOT_USE_PACKAGE(io/io)
+ROOT_USE_PACKAGE(net/net)
+include_directories(${CASTOR_INCLUDE_DIR})
+
+ROOT_GENERATE_DICTIONARY(G__CASTOR *.h LINKDEF LinkDef.h)
+ROOT_GENERATE_ROOTMAP(RCastor LINKDEF LinkDef.h DEPENDENCIES Net RIO)
+ROOT_LINKER_LIBRARY(RCastor *.cxx G__CASTOR.cxx LIBRARIES Cint Core ${CASTOR_LIBRARIES} DEPENDENCIES Net RIO)
+ROOT_INSTALL_HEADERS()
diff --git a/io/rfio/CMakeLists.txt b/io/rfio/CMakeLists.txt
new file mode 100644
index 00000000000..ecd7152b364
--- /dev/null
+++ b/io/rfio/CMakeLists.txt
@@ -0,0 +1,12 @@
+############################################################################
+# CMakeLists.txt file for building ROOT io/castor package
+############################################################################
+
+ROOT_USE_PACKAGE(io/io)
+ROOT_USE_PACKAGE(net/net)
+include_directories(${CASTOR_INCLUDE_DIR})
+
+ROOT_GENERATE_DICTIONARY(G__CASTOR *.h LINKDEF LinkDef.h)
+ROOT_GENERATE_ROOTMAP(RCastor LINKDEF LinkDef.h DEPENDENCIES Net RIO)
+ROOT_LINKER_LIBRARY(RCastor *.cxx G__CASTOR.cxx LIBRARIES Cint Core ${CASTOR_LIBRARIES} DEPENDENCIES Net RIO)
+ROOT_INSTALL_HEADERS()
diff --git a/math/CMakeLists.txt b/math/CMakeLists.txt
index 1d9d5c137f2..3078df7fac4 100644
--- a/math/CMakeLists.txt
+++ b/math/CMakeLists.txt
@@ -15,12 +15,19 @@ add_subdirectory(physics)
 add_subdirectory(mlp)
 add_subdirectory(quadp)
 add_subdirectory(foam)
-add_subdirectory(smatrix)   #special CMakeList.txt
+add_subdirectory(smatrix)
 add_subdirectory(splot)
 #add_subdirectory(mathcore/test EXCLUDE_FROM_ALL)
 add_subdirectory(genvector)
 if(tmva) 
   add_subdirectory(genetic) 
 endif()
+if(unuran)
+  add_subdirectory(unuran)
+endif()
+if(fftw3)
+  add_subdirectory(fftw)
+endif()
+
 
 
diff --git a/math/fftw/CMakeLists.txt b/math/fftw/CMakeLists.txt
new file mode 100644
index 00000000000..f09810fcadb
--- /dev/null
+++ b/math/fftw/CMakeLists.txt
@@ -0,0 +1,12 @@
+############################################################################
+# CMakeLists.txt file for building ROOT math/fftw package
+# @author Pere Mato, CERN
+############################################################################
+
+ROOT_USE_PACKAGE(math/mathcore)
+include_directories(${FFTW_INCLUDE_DIR})
+
+ROOT_GENERATE_DICTIONARY(G__FFTW *.h LINKDEF LinkDef.h)
+ROOT_GENERATE_ROOTMAP(FFTW LINKDEF LinkDef.h DEPENDENCIES )
+ROOT_LINKER_LIBRARY(FFTW *.cxx G__FFTW.cxx LIBRARIES Core ${FFTW_LIBRARIES} DEPENDENCIES )
+ROOT_INSTALL_HEADERS()
diff --git a/math/mathmore/CMakeLists.txt b/math/mathmore/CMakeLists.txt
index 4fee4e264a6..47cde289d76 100644
--- a/math/mathmore/CMakeLists.txt
+++ b/math/mathmore/CMakeLists.txt
@@ -2,8 +2,10 @@
 # CMakeLists.txt file for building ROOT math/mathmore package
 ############################################################################
 
-ROOT_USE_PACKAGE(GSL)
-add_definitions(-DUSE_ROOT_ERROR )
+ROOT_USE_PACKAGE(math/mathcore)
+
+include_directories(${GSL_INCLUDE_DIR})
+add_definitions(-DUSE_ROOT_ERROR ${GSL_CFLAGS})
 
 set(headers Math/DistFuncMathMore.h Math/SpecFuncMathMore.h Math/PdfFuncMathMore.h
             Math/Polynomial.h Math/Derivator.h Math/Interpolator.h 
@@ -12,6 +14,7 @@ set(headers Math/DistFuncMathMore.h Math/SpecFuncMathMore.h Math/PdfFuncMathMore
             Math/MCParameters.h Math/GSLMinimizer1D.h Math/Chebyshev.h 
             Math/Random.h Math/GSLRndmEngines.h Math/KelvinFunctions.h
             Math/GSLMinimizer.h Math/GSLNLSMinimizer.h Math/GSLSimAnMinimizer.h
+			Math/GSLMultiRootFinder.h 
             Math/Vavilov.h Math/VavilovAccurate.h Math/VavilovAccuratePdf.h
             Math/VavilovAccurateCdf.h Math/VavilovAccurateQuantile.h Math/VavilovFast.h )
 set(linkdefs Math/LinkDef.h Math/LinkDef_Func.h Math/LinkDef_RootFinding.h)
diff --git a/math/unuran/CMakeLists.txt b/math/unuran/CMakeLists.txt
new file mode 100644
index 00000000000..190eeda0ca3
--- /dev/null
+++ b/math/unuran/CMakeLists.txt
@@ -0,0 +1,64 @@
+############################################################################
+# CMakeLists.txt file for building ROOT math/unurun package
+############################################################################
+
+#---Define package related variables----------------------------------------------------------------- 
+set(UNR_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
+set(UNR_VERSION "1.8.0-root")
+set(UNR_TARNAME "unuran-${UNR_VERSION}")
+set(UNR_TARGZFILE ${UNR_SRCDIR}/${UNR_TARNAME}.tar.gz)
+set(UNR_TARFILE ${UNR_SRCDIR}/${UNR_TARNAME}.tar)
+set(UNR_UNTARDIR ${CMAKE_CURRENT_BINARY_DIR}/${UNR_TARNAME})
+
+#---Untar sources at configuration/generation time (needed for listing sources)
+if(NOT EXISTS ${UNR_UNTARDIR})
+  execute_process( COMMAND cmake -E tar xzf ${UNR_TARGZFILE}
+                   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} )
+endif()
+
+if(WIN32)
+  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.win.in  ${UNR_UNTARDIR}/config.h)
+else()  
+  #---Define special compiler settings for unurun-----------------------------------------------------
+  set(UNR_CC ${CMAKE_C_COMPILER})
+  if(ROOT_ARCHITECTURE MATCHES sgicc64)
+    set(UNR_CC "gcc -mabi=64")
+  elseif(ROOT_ARCHITECTURE MATCHES hpuxia64acc)
+    set(UNR_CC "cc +DD64 -Ae")  
+  elseif(ROOT_ARCHITECTURE MATCHES linuxppc64gcc)
+    set(UNR_CC "gcc -m64 -fPIC")
+  elseif(ROOT_ARCHITECTURE MATCHES linuxx8664gcc)
+    set(UNR_CC "gcc")
+    set(UNR_CFLAGS "-m64 -fPIC")
+  elseif(ROOT_ARCHITECTURE MATCHES linuxicc)
+    set(UNR_CC "icc")
+    set(UNR_CFLAGS "-m32")
+  elseif(ROOT_ARCHITECTURE MATCHES linuxx8664icc)
+    set(UNR_CC "icc")
+    set(UNR_CFLAGS "-m64")
+  endif()
+
+  #---configure unuran (required for creating the config.h used by unuran source files)----------------
+  add_custom_command(OUTPUT ${UNR_UNTARDIR}/config.h  
+                     COMMAND GNUMAKE=make ./configure CC=${UNR_CC} CFLAGS=${UNR_CFLAGS}
+                     WORKING_DIRECTORY ${UNR_UNTARDIR})
+endif()
+
+ROOT_USE_PACKAGE(hist/hist)
+
+include_directories(BEFORE ${UNR_UNTARDIR} ${UNR_UNTARDIR}/src ${UNR_UNTARDIR}/src/utils)
+add_definitions(-DHAVE_CONFIG_H)
+set(unrsources ${UNR_UNTARDIR}/src/utils/*.c
+               ${UNR_UNTARDIR}/src/methods/*.c
+               ${UNR_UNTARDIR}/src/specfunct/*.c
+               ${UNR_UNTARDIR}/src/distr/*.c
+               ${UNR_UNTARDIR}/src/distributions/*.c
+               ${UNR_UNTARDIR}/src/parser/*.c
+               ${UNR_UNTARDIR}/src/tests/*.c
+               ${UNR_UNTARDIR}/src/uniform/*.c
+               ${UNR_UNTARDIR}/src/urng/*.c )
+
+ROOT_GENERATE_DICTIONARY(G__Unuran *.h LINKDEF LinkDef.h)
+ROOT_GENERATE_ROOTMAP(Unuran LINKDEF LinkDef.h DEPENDENCIES Hist MathCore)
+ROOT_LINKER_LIBRARY(Unuran *.cxx ${unrsources} G__Unuran.cxx ${UNR_UNTARDIR}/config.h  LIBRARIES Cint Core DEPENDENCIES Hist MathCore)
+ROOT_INSTALL_HEADERS()
diff --git a/math/unuran/config.h.win.in b/math/unuran/config.h.win.in
new file mode 100644
index 00000000000..771f09c0b78
--- /dev/null
+++ b/math/unuran/config.h.win.in
@@ -0,0 +1,230 @@
+/* config.h.win transformed into input to CMake configure_file() command  */
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Define to 1 if you have the `alarm' function. */
+/* #undef HAVE_ALARM */
+
+/* Define to 1 if you have the declaration of `alarm', and to 0 if you don't.
+   */
+#define HAVE_DECL_ALARM 0
+
+/* Define to 1 if you have the declaration of `getopt', and to 0 if you don't.
+   */
+#define HAVE_DECL_GETOPT 0
+
+/* Define to 1 if you have the declaration of `HUGE_VAL', and to 0 if you
+   don't. */
+#define HAVE_DECL_HUGE_VAL 1
+
+/* Define to 1 if you have the declaration of `INFINITY', and to 0 if you
+   don't. */
+#define HAVE_DECL_INFINITY 0
+
+/* Define to 1 if you have the declaration of `isfinite', and to 0 if you
+   don't. */
+#define HAVE_DECL_ISFINITE 0
+
+/* Define to 1 if you have the declaration of `isinf', and to 0 if you don't.
+   */
+#define HAVE_DECL_ISINF 0
+
+/* Define to 1 if you have the declaration of `isnan', and to 0 if you don't.
+   */
+#define HAVE_DECL_ISNAN 0
+
+/* Define to 1 if you have the declaration of `log1p', and to 0 if you don't.
+   */
+#define HAVE_DECL_LOG1P 0
+
+/* Define to 1 if you have the declaration of `signal', and to 0 if you don't.
+   */
+#define HAVE_DECL_SIGNAL 1
+
+/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
+   don't. */
+#define HAVE_DECL_SNPRINTF 0
+
+/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
+   don't. */
+#define HAVE_DECL_VSNPRINTF 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+/* #undef HAVE_DLFCN_H */
+
+/* Define to 1 if you have the <float.h> header file. */
+#define HAVE_FLOAT_H 1
+
+/* Define to 1 if you have the `floor' function. */
+#define HAVE_FLOOR 1
+
+/* Define to 1 if you have the `gettimeofday' function. */
+/* #undef HAVE_GETTIMEOFDAY */
+
+/* Define to 1 if you have the <gsl/gsl_rng.h> header file. */
+/* #undef HAVE_GSL_GSL_RNG_H */
+
+/* Define to 1 if "x != x" is true for NaNs */
+#define HAVE_IEEE_COMPARISONS 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+/* #undef HAVE_INTTYPES_H */
+
+/* Define to 1 if you have the `gsl' library (-lgsl). */
+/* #undef HAVE_LIBGSL */
+
+/* Define to 1 if you have the `m' library (-lm). */
+#define HAVE_LIBM 1
+
+/* Define to 1 if you have the `prng' library (-lprng). */
+/* #undef HAVE_LIBPRNG */
+
+/* Define to 1 if you have the `Rmath' library (-lRmath). */
+/* #undef HAVE_LIBRMATH */
+
+/* Define to 1 if you have the `rngstreams' library (-lrngstreams). */
+/* #undef HAVE_LIBRNGSTREAMS */
+
+/* Define to 1 if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `pow' function. */
+#define HAVE_POW 1
+
+/* Define to 1 if you have the <prng.h> header file. */
+/* #undef HAVE_PRNG_H */
+
+/* Define to 1 if you have the <RngStream.h> header file. */
+/* #undef HAVE_RNGSTREAM_H */
+
+/* Define to 1 if you have the `signal' function. */
+#define HAVE_SIGNAL 1
+
+/* Define to 1 if you have the `sqrt' function. */
+#define HAVE_SQRT 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+/* #undef HAVE_STDINT_H */
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strcasecmp' function. */
+/* #undef HAVE_STRCASECMP */
+
+/* Define to 1 if you have the `strchr' function. */
+#define HAVE_STRCHR 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+/* #undef HAVE_STRINGS_H */
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strtol' function. */
+#define HAVE_STRTOL 1
+
+/* Define to 1 if you have the `strtoul' function. */
+#define HAVE_STRTOUL 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+/* #undef HAVE_SYS_TIME_H */
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+/* #undef HAVE_UNISTD_H */
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+   */
+#define LT_OBJDIR ".libs/"
+
+/* Name of package */
+#define PACKAGE "unuran"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "unuran@statmath.wu.ac.at"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "unuran"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "unuran @UNR_VERSION@"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "@UNR_TARNAME@"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "@UNR_VERSION@"
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+/* #undef TIME_WITH_SYS_TIME */
+
+/* Define to 1 if you use random number generators from GNU Scientific
+   Library. */
+/* #undef UNURAN_HAS_GSL */
+
+/* Define to 1 if you use Otmar Lendl's PRNG library. */
+/* #undef UNURAN_HAS_PRNG */
+
+/* Define to 1 if you use Pierre L'Ecuyer's RNGSTREAM library. */
+/* #undef UNURAN_HAS_RNGSTREAM */
+
+/* Define to 1 if you want to use magic cookies to validate type of a pointer
+   */
+/* #undef UNUR_COOKIES */
+
+/* Define to 1 if you want to perform additional checks against an invalid
+   NULL pointer */
+/* #undef UNUR_ENABLE_CHECKNULL */
+
+/* Define to 1 if you want to use the info routine for printing informations
+   about UNU.RAN objects */
+#define UNUR_ENABLE_INFO 1
+
+/* Define to 1 if you want to use a logfile for logging informations about
+   UNU.RAN objects */
+/* #undef UNUR_ENABLE_LOGGING */
+
+/* Define to 1 if you use RNGSTREAM as global URNG. */
+/* #undef UNUR_URNG_DEFAULT_RNGSTREAM */
+
+/* Define to 1 if you want to use deprecated code. */
+/* #undef USE_DEPRECATED_CODE */
+
+/* Define to 1 if you want to use experimental code */
+/* #undef USE_EXPERIMENTAL_CODE */
+
+/* Version number of package */
+#define VERSION "@UNR_VERSION@"
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+   calls it, or to nothing if 'inline' is not supported under any name.  */
+#ifndef __cplusplus
+#define inline __inline
+#endif
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */
+
+/* Substitute UNU.RAN functions for missing system functions */
+
+#if !HAVE_DECL_LOG1P
+#define log1p _unur_log1p
+#endif
diff --git a/misc/CMakeLists.txt b/misc/CMakeLists.txt
index 4d4911c1f70..f451e0455e0 100644
--- a/misc/CMakeLists.txt
+++ b/misc/CMakeLists.txt
@@ -4,5 +4,7 @@ endif()
 if(memstat)
   add_subdirectory(memstat)
 endif()
-
+if(table)
+  add_subdirectory(table)
+endif()
 
diff --git a/misc/table/CMakeLists.txt b/misc/table/CMakeLists.txt
new file mode 100644
index 00000000000..4000642cf81
--- /dev/null
+++ b/misc/table/CMakeLists.txt
@@ -0,0 +1,13 @@
+############################################################################
+# CMakeLists.txt file for building ROOT misc/table package
+# @author Pere Mato, CERN
+############################################################################
+
+ROOT_USE_PACKAGE(tree/tree)
+ROOT_USE_PACKAGE(io/io)
+ROOT_USE_PACKAGE(graf3d/g3d)
+
+ROOT_GENERATE_DICTIONARY(G__Table *.h LINKDEF LinkDef.h)
+ROOT_GENERATE_ROOTMAP(Table LINKDEF LinkDef.h DEPENDENCIES Tree Gpad Graf3d Graf Hist RIO MathCore)
+ROOT_LINKER_LIBRARY(Table *.cxx G__Table.cxx LIBRARIES Core Cint DEPENDENCIES Tree Gpad Graf3d Graf Hist RIO MathCore)
+ROOT_INSTALL_HEADERS()
diff --git a/montecarlo/CMakeLists.txt b/montecarlo/CMakeLists.txt
index 811673a8b30..7f89b01dded 100644
--- a/montecarlo/CMakeLists.txt
+++ b/montecarlo/CMakeLists.txt
@@ -1,2 +1,9 @@
-Add_Subdirectory(eg)  # special CMakeLists.txt
-Add_Subdirectory(vmc)
+add_subdirectory(eg)
+add_subdirectory(vmc)
+if(pythia6)
+  add_subdirectory(pythia6)
+endif()
+if(pythia8)
+  add_subdirectory(pythia8)
+endif()
+
diff --git a/montecarlo/pythia6/CMakeLists.txt b/montecarlo/pythia6/CMakeLists.txt
new file mode 100644
index 00000000000..3ed2f82ff71
--- /dev/null
+++ b/montecarlo/pythia6/CMakeLists.txt
@@ -0,0 +1,13 @@
+############################################################################
+# CMakeLists.txt file for building ROOT montecarlo/pythia6 package
+# @author Pere Mato, CERN
+############################################################################
+
+ROOT_USE_PACKAGE(montecarlo/eg)
+ROOT_USE_PACKAGE(montecarlo/vmc)
+ROOT_USE_PACKAGE(math/physics)
+
+ROOT_GENERATE_DICTIONARY(G__Pythia6 *.h  LINKDEF LinkDef.h)
+ROOT_GENERATE_ROOTMAP(EGPythia6 LINKDEF LinkDef.h DEPENDENCIES EG Graf VMC Physics )
+ROOT_LINKER_LIBRARY(EGPythia6 *.cxx G__Pythia6.cxx LIBRARIES Core ${PYTHIA6_LIBRARIES} DEPENDENCIES EG Graf VMC Physics)
+ROOT_INSTALL_HEADERS()
diff --git a/montecarlo/pythia8/CMakeLists.txt b/montecarlo/pythia8/CMakeLists.txt
new file mode 100644
index 00000000000..a8a79f2c475
--- /dev/null
+++ b/montecarlo/pythia8/CMakeLists.txt
@@ -0,0 +1,13 @@
+############################################################################
+# CMakeLists.txt file for building ROOT montecarlo/pythia8 package
+# @author Pere Mato, CERN
+############################################################################
+
+ROOT_USE_PACKAGE(montecarlo/EG)
+ROOT_USE_PACKAGE(math/physics)
+include_directories(${PYTHIA8_INCLUDE_DIR})
+
+ROOT_GENERATE_DICTIONARY(G__Pythia8 *.h  LINKDEF LinkDef.h)
+ROOT_GENERATE_ROOTMAP(EGPythia8 LINKDEF LinkDef.h DEPENDENCIES EG Graf VMC Physics )
+ROOT_LINKER_LIBRARY(EGPythia8 *.cxx G__Pythia8.cxx LIBRARIES Core ${PYTHIA8_LIBRARIES} DEPENDENCIES EG Graf VMC Physics)
+ROOT_INSTALL_HEADERS()
diff --git a/roofit/CMakeLists.txt b/roofit/CMakeLists.txt
index af579ce3d31..861deefa6d2 100644
--- a/roofit/CMakeLists.txt
+++ b/roofit/CMakeLists.txt
@@ -21,6 +21,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/roostats/inc)
 add_subdirectory(roofitcore)
 add_subdirectory(roofit)
 add_subdirectory(roostats)
-add_subdirectory(histfactory)
+if(xml)
+  add_subdirectory(histfactory)
+endif()
 
 
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
new file mode 100644
index 00000000000..267c2f10100
--- /dev/null
+++ b/sql/CMakeLists.txt
@@ -0,0 +1,10 @@
+if(mysql)
+  add_subdirectory(mysql)
+endif()
+if(oracle)
+  add_subdirectory(oracle)
+endif()
+if(odbc)
+  add_subdirectory(odbc)
+endif()
+
diff --git a/sql/mysql/CMakeLists.txt b/sql/mysql/CMakeLists.txt
new file mode 100644
index 00000000000..87b84309228
--- /dev/null
+++ b/sql/mysql/CMakeLists.txt
@@ -0,0 +1,13 @@
+############################################################################
+# CMakeLists.txt file for building ROOT sql/mysql package
+############################################################################
+
+ROOT_USE_PACKAGE(io/io)
+ROOT_USE_PACKAGE(net/net)
+
+include_directories(${MYSQL_INCLUDE_DIR})
+
+ROOT_GENERATE_DICTIONARY(G__MySQL *.h LINKDEF LinkDef.h)
+ROOT_GENERATE_ROOTMAP(RMySQL LINKDEF LinkDef.h DEPENDENCIES Net RIO)
+ROOT_LINKER_LIBRARY(RMySQL *.cxx G__MySQL.cxx LIBRARIES Core ${MYSQL_LIBRARIES} DEPENDENCIES Net RIO)
+ROOT_INSTALL_HEADERS()
diff --git a/sql/odbc/CMakeLists.txt b/sql/odbc/CMakeLists.txt
new file mode 100644
index 00000000000..a477252a4e6
--- /dev/null
+++ b/sql/odbc/CMakeLists.txt
@@ -0,0 +1,13 @@
+############################################################################
+# CMakeLists.txt file for building ROOT sql/odbc package
+############################################################################
+
+ROOT_USE_PACKAGE(io/io)
+ROOT_USE_PACKAGE(net/net)
+
+include_directories(${ODBC_INCLUDE_DIR})
+
+ROOT_GENERATE_DICTIONARY(G__ODBC *.h LINKDEF LinkDef.h)
+ROOT_GENERATE_ROOTMAP(RODBC LINKDEF LinkDef.h DEPENDENCIES Net RIO)
+ROOT_LINKER_LIBRARY(RODBC *.cxx G__ODBC.cxx LIBRARIES Core ${ODBC_LIBRARIES} DEPENDENCIES Net RIO)
+ROOT_INSTALL_HEADERS()
diff --git a/sql/oracle/CMakeLists.txt b/sql/oracle/CMakeLists.txt
new file mode 100644
index 00000000000..034958e58ae
--- /dev/null
+++ b/sql/oracle/CMakeLists.txt
@@ -0,0 +1,13 @@
+############################################################################
+# CMakeLists.txt file for building ROOT sql/oracle package
+############################################################################
+
+ROOT_USE_PACKAGE(io/io)
+ROOT_USE_PACKAGE(net/net)
+
+include_directories(${ORACLE_INCLUDE_DIR})
+
+ROOT_GENERATE_DICTIONARY(G__Oracle *.h LINKDEF LinkDef.h)
+ROOT_GENERATE_ROOTMAP(Oracle LINKDEF LinkDef.h DEPENDENCIES Net RIO)
+ROOT_LINKER_LIBRARY(Oracle *.cxx G__Oracle.cxx LIBRARIES Core ${ORACLE_LIBRARIES} DEPENDENCIES Net RIO)
+ROOT_INSTALL_HEADERS()
-- 
GitLab