diff --git a/cmake/Modules/G4CMakeUtilities.cmake b/cmake/Modules/G4CMakeUtilities.cmake
index 511c4d99911b7a90c9bad48e37095bddfdeaa7d0..33e384c4b8984b67d7ab0500d858e10ecb565115 100644
--- a/cmake/Modules/G4CMakeUtilities.cmake
+++ b/cmake/Modules/G4CMakeUtilities.cmake
@@ -220,7 +220,10 @@ function(geant4_export_package_variables _file)
       get_property(__var_value CACHE ${__var} PROPERTY VALUE)
       get_property(__var_type CACHE ${__var} PROPERTY TYPE)
       get_property(__var_help CACHE ${__var} PROPERTY HELPSTRING)
-      list(APPEND __local_build_setting "geant4_set_and_check_package_variable(${__var} \"${__var_value}\" ${__var_type} \"${__var_help}\")")
+      # make sure the cache variable is defined before recording it for geant4_set_and_check_package_variable
+      if(__var_type)
+        list(APPEND __local_build_setting "geant4_set_and_check_package_variable(${__var} \"${__var_value}\" ${__var_type} \"${__var_help}\")")
+      endif()
     endforeach()
 
     list(APPEND GEANT4_PACKAGE_SETTINGS ${__local_build_setting})