diff --git a/cmake/waLBerlaFunctions.cmake b/cmake/waLBerlaFunctions.cmake
index 3de113afac0545faed736328fb79f84d1aa35b79..091a9048bb9106c755d9aaf72fa3f96fc24bc2b3 100644
--- a/cmake/waLBerlaFunctions.cmake
+++ b/cmake/waLBerlaFunctions.cmake
@@ -263,13 +263,20 @@ endfunction ( waLBerla_add_executable )
 # Function to tell CMake which C/C++/CUDA files are generated by a python file
 #
 # Example:
-#    waLBerla_python_file_generates(MyPythonCodeGenScript.py Sweep1.cpp Sweep1.h Sweep2.h Sweep2.cu)
+#    waLBerla_python_file_generates(MyPythonCodeGenScript.py Sweep1.cpp Sweep2.cu)
 #
 #
 #######################################################################################################################
 function( waLBerla_python_file_generates pythonFile )
+    set(generatedFiles "")
+    foreach(element ${ARGN})
+        string(REGEX REPLACE "\\.[^.]*$" "" elementWithoutExtension ${element})
+        list(APPEND generatedFiles ${element})
+        list(APPEND generatedFiles "${elementWithoutExtension}.h")
+    endforeach()
+    list(REMOVE_DUPLICATES generatedFiles)
     get_filename_component(pythonFileAbsolutePath ${pythonFile} ABSOLUTE)
-    set( "WALBERLA_CODEGEN_INFO_${pythonFileAbsolutePath}" ${ARGN}
+    set( "WALBERLA_CODEGEN_INFO_${pythonFileAbsolutePath}" ${generatedFiles}
             CACHE INTERNAL "Files generated by python script ${pythonFile}" FORCE)
 endfunction(waLBerla_python_file_generates)
 
diff --git a/tests/cuda/CMakeLists.txt b/tests/cuda/CMakeLists.txt
index 11213e0111459bdc2aaf9bdeb719a37e3cb255a8..6fdeb8352919f3f01af469fff25877c329a49c3b 100644
--- a/tests/cuda/CMakeLists.txt
+++ b/tests/cuda/CMakeLists.txt
@@ -38,8 +38,5 @@ waLBerla_compile_test( FILES CudaMPI DEPENDS blockforest timeloop gui )
 
 waLBerla_compile_test( FILES AlignmentTest.cpp DEPENDS blockforest timeloop )
 
-
-waLBerla_python_file_generates(codegen/MicroBenchmarkGpuLbm.py
-        MicroBenchmarkStreamKernel.cu MicroBenchmarkStreamKernel.h
-        MicroBenchmarkCopyKernel.cu MicroBenchmarkCopyKernel.h)
+waLBerla_python_file_generates(codegen/MicroBenchmarkGpuLbm.py MicroBenchmarkStreamKernel.cu MicroBenchmarkCopyKernel.cu)
 waLBerla_compile_test( FILES codegen/MicroBenchmarkGpuLbm.cpp codegen/MicroBenchmarkGpuLbm.py)
diff --git a/tests/field/CMakeLists.txt b/tests/field/CMakeLists.txt
index 57114a6d1acda0386de2cdf7da480b707f244624..2fb6b91887db6aea9ef2c21d67d687a55f2b7e0f 100644
--- a/tests/field/CMakeLists.txt
+++ b/tests/field/CMakeLists.txt
@@ -60,11 +60,8 @@ endif( WALBERLA_BUILD_WITH_MPI )
 
 # CodeGen Tests
 
-waLBerla_python_file_generates(codegen/JacobiKernel.py
-                                  JacobiKernel2D.cpp JacobiKernel2D.h
-                                  JacobiKernel3D.cpp JacobiKernel3D.h)
-waLBerla_compile_test( FILES codegen/CodegenJacobiCPU.cpp codegen/JacobiKernel.py
-                       DEPENDS gui timeloop )
+waLBerla_python_file_generates(codegen/JacobiKernel.py JacobiKernel2D.cpp JacobiKernel3D.cpp )
+waLBerla_compile_test( FILES codegen/CodegenJacobiCPU.cpp codegen/JacobiKernel.py DEPENDS gui timeloop )
 waLBerla_execute_test( NAME CodegenJacobiCPU )