[CMake] Using pkg-config
Maik Beckmann
maikbeckmann at gmx.de
Tue Dec 19 02:20:36 EST 2006
Am Dienstag, den 19.12.2006, 02:12 +0100 schrieb Marko Anastasov:
> Hello,
>
> I'm new to CMake. I'm trying to write a CMakeLists.txt file to
> build a simple gtkmm test program (should work with any though).
> I can build and run it, but I need to fix something.
>
> Here's the main part:
>
> EXEC_PROGRAM(pkg-config ARGS --cflags --libs gtkmm-2.4
> OUTPUT_VARIABLE GTKMM_PKG_FLAGS)
> SET(GTKMM_PKG_FLAGS "${GTKMM_PKG_FLAGS}" CACHE STRING "GTKMM Flags")
> SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GTKMM_PKG_FLAGS}")
>
> add_executable(example ${SOURCES})
>
> target_link_libraries(example ${GTKMM_PKG_FLAGS})
A new autoconf-style pkg-config module has been uploaded to CVS:
http://public.kitware.com/cgi-bin/viewcvs.cgi/Modules/FindPkgConfig.cmake?cvsroot=CMake&rev=1.1&content-type=text/x-cvsweb-markup
You can copy it to your project folder, say into a folder named
cmake-extensions and use it like follows:
<CMakeLists.txt>
project(test)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake-extensions/ )
find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-2.4)
link_directories(
${GTKMM_LIBRARY_DIRS}
)
include_directories(
${GTKMM_INCLUDE_DIRS}
)
add_executable(test_exe main.cpp)
target_link_libraries(test_exe
${GTKMM_LIBRARIES}
)
</ CMakeLists.txt>
Note: If you change the package names at pkg_check_modules you have to
delete CMakeCache.txt at your build folder, otherwise it won't take
effect.
Regards,
Maik
More information about the CMake
mailing list