Optional Credentials.h, avoid the compiler error

Hi
I would like to outsource my private credentials in an optional Credentials.h file before I publish my code.

My Credentials.h has a double inclusion prevention.

#ifndef __CREDENTIALS_H__
#define __CREDENTIALS_H__

#define WIFI_SSID "???"
#define WIFI_PASS "???"

#endif

I would like to write the main code in a way that #include "Credentials.h" should only happen, if the file exists, else having in the code itself:

#ifndef __CREDENTIALS_H__
#define WIFI_SSID "???"
#define WIFI_PASS "???"
#endif

How can I avoid the compiler error when Credentials.h does not exist?

Maybe be this:
https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html#g_t_005f_005fhas_005finclude
But I’m not sure if it solves your problem. I’ve never used it myself.

For publication, I anyway create a special version of a program where I not only obscure credentials etc. but remove todo lists and notes i’ve made about the development history which might be confusing to others.

I just put my credentials.h file in the Arduino Libraries. The first line of credentials.h is

#define credentials

In my sketches, I do:

#ifndef credentials
#include "D:\River Documents\Arduino\libraries\credentials.h"  // WiFi credentials
#endif

SteveMann:
In my sketches, I do:

#ifndef credentials

#include “D:\River Documents\Arduino\libraries\credentials.h”  // WiFi credentials
#endif

Yes, but that is not noob-user friendly.
Without a credentials.h file the compiler will throw an error.
I think about beginning that way:

// Credentials 

#if defined __has_include
#if __has_include ("credentials.h")
#include "credentials.h"
#else   
// if you dont have a credentials.h file you may adjust the "secret Infos" inplace. 
#define WIFI_SSID "secret Info"
#define WIFI_PASS "secret Info"
#endif
#endif

That way others can use the program directly by populating the secret info inplace and you may ignore it will use credentials.h
The other advantage, is that you are telling what your program expects from credentials.h.

By the way: you don’t have to enter the full path.
If you write #include “credentials.h” the compiler will first search for a file in your project folder then in the libraries.
If you write #include <credentials.h> the compiler will search for a file in the libraries.