I've even found another approach called "CreateSILPILBlock". This will directly compile and build a MEX S-Function block (without creating a shared library, at least not visible to the end user). Advantage: no need to use the LCT to generate a shared library for the host - especially no need to define the function specification manually.
However, this will not allow me to generate calling code from a top model:
Error evaluating 'InitFcn' callback of S-Function block (mask) 'untitled/<modelname>'.
Callback string is 'rtw.pil.SILPILBlock.initFcnCallback(gcb);'
Caused by:
Code generation or simulation modes other than 'Normal' and 'Accelerator' (top-model only) are not supported when the model includes a SIL/PIL block ('untitled/UniversalBeatDetector'). Check that the model's simulation mode is 'Normal' or 'Accelerator' (top-model only).
As a workaround I tried to create a new model which uses the MEX function just as if it was any other "normal" MEX function by including it in an S-function block - and optionally including a custom TLC file for code generation.
Though, the MEX function seems to incorporate meta data about being built for a SIL/PIL block:
The PIL Block is not correctly configured. Please open the PIL Block, then build and download the PIL Application.
Question: Is there a way to use the generated MEX function for simulation and code generation?