Many Republicans have criticized President Barack Obama for not identifying the Islamic State and other terrorist groups as Muslim. But Obama said Wednesday that would give the organizations legitimacy.

“Groups like ISIL are desperate for legitimacy,” Obama said at the Islamic Society of Baltimore. “We must never give them that legitimacy. They are not defending Islam.”

“The notion that America is a war with Islam ignores the fact that the world’s religions are who we are,” Obama said.

President Barack Obama speaks at the Islamic Society of Baltimore, in Windsor Mill, Maryland on February 3, 2016. / AFP / Mandel Ngan (MANDEL NGAN/AFP/Getty Images)

President Barack Obama speaks at the Islamic Society of Baltimore in Windsor Mill, Maryland, Wednesday. / AFP / Mandel Ngan (MANDEL NGAN/AFP/Getty Images)

This marked the first time Obama has visited an American mosque as president, and he used the occasion to take what seemed to be jabs at Republicans — and likely GOP presidential candidate Donald Trump, who has called for halting Muslim immigration — when he denounced negative rhetoric, while also calling for better depictions of Muslims in TV shows, praising the historic contributions of Muslim-Americans and reminding Americans of the importance of religious freedom.

“Recently, we’ve heard inexcusable political rhetoric against Muslim Americans that has no place in our country,” Obama said.

The choice of the mosque in Baltimore raised controversy because it has indirect ties to the Muslim Brotherhood, Fox News reported.

Obama said that some American Muslim children fear they will be “rounded up,” while others “feel like second-class citizens,” the president said.

He continued by noting that Thomas Jefferson believed religious freedom created a strong civil society, but added another note about the former president: “Thomas Jefferson’s opponents tried to stir things up by suggesting he was a Muslim. So I’m not the first. Look it up.”

Obama went on to criticize the “media distortions” of Islam and said, “Our TV shows should have some Muslim characters that are unrelated to national security.”

But as the speech went on, he also called for Muslim leaders to more aggressively speak out against extremism and to speak out.

“Muslims must speak up when Christians and Jews around the world are targeted, often by Muslims,” Obama said.

But the president said Christians in the United States have an obligation to look out for the rights of religious minorities: “I say this to my fellow Christians, an attack on one faith an attack on all of our faiths.”