I'm using a library called Simple2D. It installs a simple2d binary, and you can run simple2d --libs to get the list of library and include directories you need for Simple2D projects. For example, you can run this to build a project with 1 source file:
cc triangle.c `simple2d --libs` -o triangle
simple2d --libs evaluates to this on a Mac:
-lsimple2d -I/usr/local/include/SDL2 -D_THREAD_SAFE
-L/usr/local/lib -lSDL2 -Wl,-framework,OpenGL -lSDL2_image -lSDL2_mixer -lSDL2_ttf
How can I evaluate that in CMake?