Automatic detection of native USB port

Is there a way to detect which port is used (native USB / programming port)?
This will avoid #define nativeUSB used in the program below that solves several Serial problems with SAM D21 boards:

/* Solve_Serial_problems with SAM D21 boards  

Attention using the Programming Port:
Upload to a wrong port doesn't give any error message, be sure to select EDBG USB Port (COMxx)
Opening the serial monitor does not reset the board as normal, use the delay shown below
*/

#define __nativeUSB__ // for using the native USB port (tested on Arduino M0 PRO)

#if defined(__nativeUSB__)
#define PORT SerialUSB
#else
#define PORT Serial
#endif

#include <Arduino.h>
#include <Streaming.h>

void setup() 
{ PORT.begin(9600); 
  while(!PORT); // for the native USB port to print from start or reset
  delay(2000); // for the SAM D21 Programming (USB) Port to print from reset or start, do open the serial monitor within two seconds 
}

void loop()
{ static int i;
  delay(100);
  PORT << i++ << endl;
}