Both recent versions of GNU Prolog and SWI-Prolog define a flag named dialect
(which, btw, is a de fact standard as it's implemented by most Prolog systems) that you can use in the conditional compilation directives:
$ gprolog
GNU Prolog 1.4.4 (64 bits)
Compiled Apr 23 2013, 17:24:33 with /opt/local/bin/gcc-apple-4.2
By Daniel Diaz
Copyright (C) 1999-2013 Daniel Diaz
| ?- current_prolog_flag(dialect, Dialect).
Dialect = gprolog
yes
$ swipl
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.3.16-6-g9c0199c-DIRTY)
Copyright (c) 1990-2013 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- current_prolog_flag(dialect, Dialect).
Dialect = swi.
Thus, simple write something like:
:- if(current_prolog_flag(dialect, swi)).
% SWI-Prolog specific code
:- elif(current_prolog_flag(dialect, gprolog)).
% GNU Prolog specific code
:- else.
% catchall code
:- endif.