how to control an #ifdef stracture in .h file with a #define from .ino file

Hi
I’m working on a project for IoT.
I have created a library for a web server. In this library I have to include another library which depends on the hardware I use.
So in the .h (header) file of my library I wrote the code:

#ifdef enc28j60
    #include <UIPEthernet.h>
#else
    #include <Ethernet.h>
    #include <SPI.h>
#endif

In my .ino file I wrote the code:

#define enc28j60 // comment this line if you're using an ethernet module with W5100 chip

The code runs the “else” part of the “ifdef stracture” either I comment the “define” statement or not.
Any suggestions how to make it work ??

how to control an #ifdef stracture in .h file with a #define from .ino file

You can’t. The ino file becomes a cpp file, and is a compilation unit.

The .h file goes with, presumably, a cpp file, which is another compilation unit.

Preprocessor directives in one compilation unit can not affect another compilation unit.

OK
So I guess, the only solution is to have 2 libraries with different #import statements.
One to use with enc28j6o modules and one to use with w5100 modules.
Right?

If you put all code that depends on the value of the enc28j60 macro in the .h file and you define the enc28j60 macro in your sketch before the include of the .h file then you can do it but, as PaulS said, you can’t do that with a .cpp file. You can see an example of this in the Encoder library where you are able to configure the library by adding:

#define ENCODER_OPTIMIZE_INTERRUPTS

or

#define ENCODER_DO_NOT_USE_INTERRUPTS

to your sketch before

#include <Encoder.h>

This is one reason why all the code of that library is in the .h file.

So I guess, the only solution is to have 2 libraries with different #import statements.

You will have two libraries, with different names, but NO #import statements. #include, yes. #import, no.

Thanks PaulS, that was a typo !!! Thanks pert, I'll be reading this in a while !!