diff --git a/CMakeLists.txt b/CMakeLists.txt
index c609743578c924d5f4097735020e476c2668f154..9f7e8d7f92b205a37ed6e8e956846fce92f35577 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -627,11 +627,13 @@ if(ENABLE_PETSC)
     if(PETSC_PACKAGES_INCLUDES)
       string(REPLACE "PACKAGES_INCLUDES = " "" PETSC_PACKAGES_INCLUDES
              ${PETSC_PACKAGES_INCLUDES})
-      string(REPLACE "-I" "" PETSC_PACKAGES_INCLUDES ${PETSC_PACKAGES_INCLUDES})
-      string(REPLACE " " ";" PETSC_PACKAGES_INCLUDES ${PETSC_PACKAGES_INCLUDES})
+      if(PETSC_PACKAGES_INCLUDES)
+        string(REPLACE "-I" "" PETSC_PACKAGES_INCLUDES ${PETSC_PACKAGES_INCLUDES})
+        string(REPLACE " " ";" PETSC_PACKAGES_INCLUDES ${PETSC_PACKAGES_INCLUDES})
         foreach(VAR ${PETSC_PACKAGES_INCLUDES})
-      list(APPEND EXTERNAL_INCLUDES ${VAR})
-      endforeach(VAR)
+          list(APPEND EXTERNAL_INCLUDES ${VAR})
+        endforeach(VAR)
+      endif(PETSC_PACKAGES_INCLUDES)
     endif(PETSC_PACKAGES_INCLUDES)
     # find libraries (<= 3.0)
     set(PETSC_LIBS_REQUIRED petscksp petscdm petscmat petscvec petsc)