Choosing proper wire gauge
Is 100 A for all 3 phases or only for one phases?


That will be each phase.


  What does it mean by 400V? Line to line voltage? or the phase one?


It is line to line voltage.


  Is 40 kW the maximum power consuming? Or I should consider the reactive power and provide a larger source power such as 50 kW? 


An easy way to calculate is to use the phase to neutral voltage and calculate for one phase.


One phase will have \$ P = \frac {P_{TOT}}{3} = \frac {40}{3} = 13.3 \ \text{kW} \$.
The phase to neutral voltage will be \$ {V_{L-L}}{\sqrt 3} = {400}{\sqrt 3} = 234\ \text V\$.
If the load is purely resistive then \$ I = \frac {P}{V} = \frac {13300}{234} = 57 \ \text A \$.


The 100 A rating, therefore, must be to cover start-up current and reactive power.


  Also is it for all phases?


Yes. The power rating is for the whole machine.


  What size of wire shall I choose?


Check your local regulations which should have tables to guide you. The distance from the supply will be a factor and whether any power-factor correction capacitors are placed at the feed or load end of the cable.