cmCoreTryCompile: use the source type context for source files

Also add a test to `RunCMake/CXXModules` to test `try_compile` with C++
modules.

Fixes: #25097
11 files changed