Thank you for your answer.
I don't have a problem detecting if Apex is installed.
The problem is that conditional compilation requires static defines.
It cannot be anything dynamic like select or a function call.
So I was looking for something similar to sys package
DBMS_DB_VERSION and defines like ver_le_9_1.