使用CMake查找GLib:使用无效参数调用的target_include_directories

时间:2018-07-31 14:33:36

标签: cmake glib

我有以下(最少的)CMakeLists.txt通过pkg-config查找GLib,并将库添加到foo目标中:

cmake_minimum_required(VERSION 2.10 FATAL_ERROR)
project(foo)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLib REQUIRED glib-2.0)
add_executable(foo foo.cpp)
message(WARNING "libs:" ${GLIB_LIBRARIES})
message(WARNING "includes:" ${GLIB_INCLUDE_DIRS})
target_link_libraries(foo PUBLIC ${GLIB_LIBRARIES})
target_include_directories(foo PUBLIC ${GLIB_INCLUDE_DIRS})

无论我尝试什么,我都会得到(请注意Found glib-2.0部分):

-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Checking for module 'glib-2.0'
--   Found glib-2.0, version 2.56.1
CMake Warning at CMakeLists.txt:6 (message):
  libs:


CMake Warning at CMakeLists.txt:7 (message):
  includes:


CMake Error at CMakeLists.txt:9 (target_include_directories):
  target_include_directories called with invalid arguments


-- Configuring incomplete, errors occurred!
See also "/tmp/aaa/CMakeFiles/CMakeOutput.log".

,我看不到the CMake reference哪些参数无效(请注意:此问题与cmake target_include_directories called with invalid arguments不同)。我还查看了CMake's FindPkgConfig documentation,它以glib为例,但我无法复制它(${GLIB_VERSION})。我尝试使用GLIB_GLIB2_前缀,但我得到的只是空字符串。

消息显示变量为空,尽管pkg-config正确报告了值:

$ pkg-config glib-2.0 --cflags --libs
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0

我拥有的CMake版本是2.10。

有人可以阐明这个问题吗?

1 个答案:

答案 0 :(得分:1)

我认为您的问题是GLIB_INCLUDE_DIRS和GLIB_LIBRARIES的大小写。由于您将“ GLib”指定为GLib_INCLUDE_DIRS的第一个参数,因此它们应为GLib_LIBRARIESpkg_check_modules。我猜想target_include_directories()不喜欢在  PUBLIC(尽管它在cmake 3.5中对我有效)。