diff --git a/src/pystencils_autodiff/CMakeLists.tmpl.txt b/src/pystencils_autodiff/CMakeLists.tmpl.txt
index 99fc680a506d816f66c98b2862634c09ce1aecb4..67e939afe9c75fcd4f7e34cf78d90e03e200bc22 100644
--- a/src/pystencils_autodiff/CMakeLists.tmpl.txt
+++ b/src/pystencils_autodiff/CMakeLists.tmpl.txt
@@ -6,5 +6,7 @@ waLBerla_add_executable ( NAME {{ cmake_target_name }}
                           DEPENDS {{depends | join(' ')}})
 
 {% if 'walberla_openvdb' in depends -%}
+if (WALBERLA_BUILD_WITH_OPENVDB)
 target_link_libraries( {{ cmake_target_name }} tbb boundary openvdb Half IexMath Iex IlmThread Imath)
+endif(WALBERLA_BUILD_WITH_OPENVDB)
 {%- endif %}