[CMake] suspicious behaviour of FindPkgConfig

Ryan Pavlik rpavlik at iastate.edu
Thu Jan 6 18:27:38 EST 2011


FindPkgConfig and find_package are not really related: some scripts for
find_package do use pkg-config to help them, but you shouldn't need to check
for it yourself.

Also, find scripts shouldn't be used with "include".

It looks a bit like build system overkill: this should do roughly the same
thing, but simpler and more reliably.  Though I'm sure you probably have
more libraries (otherwise I'm really confused by your use of a foreach
loop), something like this is clearer, and at least in my eyes, the tradeoff
of small code duplication (which isn't always wrong because some find
modules work differently) for the clarity (versus all those nested variable
evaluations) is definitely worth it.

cmake_minimum_required(VERSION 2.6.4 FATAL_ERROR)

project(test CXX C)

find_package(flann)
if(FLANN_FOUND)
set(HAVE_FLANN YES)
include_directories(${FLANN_INCLUDE_DIRS})
list(APPEND LIBS ${FLANN_LIBRARIES})
endif()

find_package(Doxygen)


On Thu, Jan 6, 2011 at 11:39 AM, Nizar Khalifa Sallem <nksallem at laas.fr>wrote:

> Hi all,
>
> I am getting in trouble with the FindPkgConfig module. Here is a piece
> of rather bigger CMakeLists.txt file that doesn't success to find
> Doxygen although installed on the machine(ubuntu 10.4, cmake 2.8.3)
>
>
> # $Id$ #
> #
> ----------------------------------------------------------------------------
> # A CMakeLists.txt file to test FindPkgConfig
> #
> ----------------------------------------------------------------------------
>
> set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
>
> # it MUST go before PROJECT(Jafar) in order to work
> if (NOT CMAKE_INSTALL_PREFIX)
>  set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR} CACHE INTERNAL "" FORCE)
> endif()
>
> cmake_minimum_required(VERSION 2.6.4 FATAL_ERROR)
>
> project(test CXX C)
>
> include(CheckIncludeFile)
>
> macro(FIND_PACKAGE package_name)
>                string(TOUPPER "${package_name}" PACKAGE_NAME)
> #               string(TOUPPER "${package_name}_FOUND" PACKAGE_NAME_FOUND)
>                pkg_check_modules(${PACKAGE_NAME} ${package_name})
> #               message(STATUS "finding ${package_name}
> ${${PACKAGE_NAME_FOUND}}")
> endmacro(FIND_PACKAGE package_name)
>
> include(FindPkgConfig)
> if(PKG_CONFIG_FOUND)
>        foreach(package
>                        flann)
>                string(TOUPPER "${package}" PACKAGE)
>                string(TOUPPER "HAVE_${package}" HAVE_PACKAGE)
>                string(TOUPPER "${package}_FOUND" PACKAGE_FOUND)
>                find_package(${package})
>                set(${HAVE_PACKAGE} ${${PACKAGE_FOUND}})
>                if(${PACKAGE_FOUND})
>                        string(TOUPPER "LIBS_MAP_${package}"
> LIBS_MAP_PACKAGE)
>                        set(${LIBS_MAP_PACKAGE} "${PACKAGE}")
>                        set(LIBS ${LIBS} ${${PACKAGE}_LIBRARIES})
>                        include_directories(${${PACKAGE}_INCLUDE_DIRS})
>                endif(${PACKAGE_FOUND})
>        endforeach(package)
> else(PKG_CONFIG_FOUND)
>  message(ERROR " pkgconfig not found you won't be able to build some
> modules")
> endif(PKG_CONFIG_FOUND)
>
> find_package(Doxygen)
>
> ==================================================================
> It says :
> Running CMake to regenerate build system...
> -- checking for module 'Doxygen'
> -- package 'Doxygen' not found
>
> I get it work by putting find_package(Doxygen) before
> include(FindPkgConfig) statement. Can someone explain me this strange
> behaviour please ?
>
> Cheers,
> --
> Nizar
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>



-- 
Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

rpavlik at iastate.edu
http://academic.cleardefinition.com
Internal VRAC/HCI Site: http://tinyurl.com/rpavlik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110106/6a8c4b3e/attachment-0001.htm>


More information about the CMake mailing list