These days, calling someone a square is just another way of saying they're unhip or "not with it." However, the definition used to be a lot different.
According to Phrase Finder, a square used to mean "an honest or direct person." The expressions "fair and square" and "square meal" are likely offshoots. The shapely saying didn't take a turn for the nerdy until the 1920s.
World Wide Words explains that during the '20s, people who didn't dig jazz were sometimes called squares. Jazz legend Thelonious Monk actually adopted the middle name "Sphere." Later, after World War II, the word took on its current, more broad definition, as in "Sheesh, that guy's such a square." The etymology experts believe the word's meaning changed gradually from honest to "boringly conventional."
The expression "Be there or be square" is sort of a half-joking ultimatum that works because it rhymes. It probably originated in the U.S. during the '40s or '50s and was made popular by the whole James Dean "Rebel Without a Cause" vibe, which preached that being square was about as uncool as you could get.