[CMake] PKG_SEARCH_MODULE

Micha Renner Micha.Renner at t-online.de
Mon Oct 26 05:09:31 EDT 2009


Recently, someone ask for PKG_SEARCH_MODULE

At first, I thought simple flag is flag:

PROJECT(MiG)
INCLUDE (FindPkgConfig)
# For GTK
PKG_SEARCH_MODULE(GTK REQUIRED gtk+-2.0)
SET(_targetname ULS)
SET(_src CTest.c)

ADD_EXECUTABLE(${_targetname} ${_src})
SET_TARGET_PROPERTIES(${_targetname} 
	PROPERTIES COMPILE_FLAGS "${GTK_CFLAGS}"
		LINK_FLAGS ${GTK_LDFLAGS})

Alas, in this case SET_TARGET_PROPERTIES is not practical.

For the header file I can use

INCLUDE_DIRECTORIES(${GTK_INCLUDE_DIRS})
or 
ADD_DEFINITIONS(${GTK_CFLAGS})

The problem is how to link the libraries.

If I assume that all needed libraries start with lib, are in the same
location and have the suffix .so, I could write something like this:

FOREACH(_libname ${GTK_LIBRARIES})
	LIST(APPEND NEW_GTK_LIBRARIES
${GTK_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${_libname}${CMAKE_SHARED_LIBRARY_SUFFIX})
ENDFOREACH(_libname)

TARGET_LINK_LIBRARIES(${_targetname} ${NEW_GTK_LIBRARIES})

Of course my assumptions are not always true.

So what is the best and practical way to link the libraries with the
data of PKG_SEARCH_MODULE.

Greetings

Micha






More information about the CMake mailing list