There are combinations and maneuvers to deal with enemy cavalry using fewer resources than we are countering. Here I'll explain the ones I use the most, although I'm sure other players could teach another ones. However, none of them consists on making a square of pikes. Apart from providing more disadvantages than advantages, it's lazy. Only noobs do it.
To face enemy cavalry, you need cavalry. Spearmen can cause a lot of casualties among enemy cavalry, by pricking them in the guts, but they are not as fast as they are, so if your opponent knows a little he will avoid them. If your cavalry is lighter than the enemy's avoid a frontal collision or it'll go very bad for you.
Combining cavalry and spearmen
The simplest tactic is to escort your cavalry with spearmen on foot. There are armies that have unshielded spearmen that tend to be faster and do more damage than shielded ones. Those are the ideal ones. If you don't have them, any unit with spears will work. The advantage of using this combination lies in the fact that spears are cheaper than horses.
If our cavalry is lighter than the enemy's, you have to be very careful because if you seek the frontal collision of cavalries your unit may end up pureed. In this case you should try to redirect the enemy cavalry towards your spears, so that they enter into combat first with them and then you can charge from behind with your horses (if the enemey cavalry is heavier it will be slower and we should be able to execute the maneuver).
If you believe that your cavalry is going to beat the enemy cavalry, there's a trick you can use to take advantage of clueless enemies (AI is always clueless).
Let's suppose that we have a heavy cavalry unit and a medium one, and the enemy has two medium cavalry units. In this case, we should seek the collision between our heavy unit with the enemy units, to go around the combat with the medium cavalry unit and rearcharge, on diamond or wedge formation, if we can.
And wen the collision has taken place... it's the time for a charge.
Spears and javelins formation
Javelins can shoot down all kinds of cavalry, form the lighter to the heavier ones, and they are cheap. Combine spears with javelins and you will have a deadly formation to horses. The downside? Low mobility. It's a defensive formation and easy to overcome with good maneuvering, so have some cavalry in reserve to block enemy maneuvers at your rear.
Units with two-handed weapons are very vulnerable against cavalry charges, but once they are already on melee combat, big weapons can do a lot of damage to horses with a charge. Anything can be killed with big axes.