You have passed both the arguments --cflags
and --libs
in the command which will give both -I and -L parts of the .pc file in one variable.
Try running message("${GTK2_PKG_FLAGS}")
to print the contents.
Hence it may not be prudent to link the complete variable $GTK2_PKG_FLAGS using target_link_libraries().
You may also want to try below steps
INCLUDE(FindPkgConfig)
pkg_check_modules(GTK REQUIRED gtk+-2.0)
#include
include_directories(${GTK_INCLUDE_DIRS})
#link
link_directories(${GTK_LIBRARY_DIRS})
target_link_libraries(program ${GTK_LIBRARIES})
Refer question