This should only happen when `HAVE_PVAPI` is true, and only for the modules that use it (that is, only for `highgui`). I would suggest you add a variable named `PVAPI_DECLARATIONS` here, and use it in `highgui`'s CMakeLists.txt.