Работает нормально для меня, как только я использую find_package(LibXml2)
вместо find_package(LIBXML2 CONFIG)
.Согласно cmake-документации , режим конфигурации пытается найти файл конфигурации, предоставляемый пакетом:
Попытка поиска в режиме конфигурации пытается найти файл конфигурации, предоставленныйпакет должен быть найден.В кеше создается запись _DIR для хранения каталога, содержащего файл.По умолчанию команда ищет пакет с именем.Если указан параметр NAMES, вместо него используются следующие имена.Команда ищет файл с именем Config.cmake или -config.cmake для каждого указанного имени.Сменный набор возможных имен файлов конфигурации может быть задан с помощью опции CONFIGS.
Так что мне кажется, что libxml2
не предоставляет такой файл конфигурации.
testusage.cpp
#include <iostream>
#include <libxml/parser.h>
int main(void)
{
xmlParserNodeInfo info;
std::cout << std::hex << &info << std::endl;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
find_package(LibXml2)
include_directories(${LIBXML2_INCLUDE_DIRS})
link_libraries(${LIBXML2_LIBRARY})
add_executable(testusage testusage.cpp)
вызов и построение
$ cmake .
-- 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 LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.4")
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/test/build
$ make --trace
Makefile:176: target 'cmake_check_build_system' does not exist
/usr/bin/cmake -H/tmp/test -B/tmp/test/build --check-build-system CMakeFiles/Makefile.cmake 0
Makefile:83: update target 'all' due to: cmake_check_build_system
/usr/bin/cmake -E cmake_progress_start /tmp/test/build/CMakeFiles /tmp/test/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
CMakeFiles/Makefile2:67: target 'CMakeFiles/testusage.dir/all' does not exist
make -f CMakeFiles/testusage.dir/build.make CMakeFiles/testusage.dir/depend
CMakeFiles/testusage.dir/build.make:112: target 'CMakeFiles/testusage.dir/depend' does not exist
cd /tmp/test/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /tmp/test /tmp/test /tmp/test/build /tmp/test/build /tmp/test/build/CMakeFiles/testusage.dir/DependInfo.cmake --color=
Scanning dependencies of target testusage
make -f CMakeFiles/testusage.dir/build.make CMakeFiles/testusage.dir/build
CMakeFiles/testusage.dir/build.make:62: update target 'CMakeFiles/testusage.dir/testusage.cpp.o' due to: ../testusage.cpp /usr/include/libxml2/libxml/SAX.h /usr/include/libxml2/libxml/SAX2.h /usr/include/libxml2/libxml/dict.h /usr/include/libxml2/libxml/encoding.h /usr/include/libxml2/libxml/entities.h /usr/include/libxml2/libxml/globals.h /usr/include/libxml2/libxml/hash.h /usr/include/libxml2/libxml/list.h /usr/include/libxml2/libxml/parser.h /usr/include/libxml2/libxml/threads.h /usr/include/libxml2/libxml/tree.h /usr/include/libxml2/libxml/valid.h /usr/include/libxml2/libxml/xlink.h /usr/include/libxml2/libxml/xmlIO.h /usr/include/libxml2/libxml/xmlautomata.h /usr/include/libxml2/libxml/xmlerror.h /usr/include/libxml2/libxml/xmlexports.h /usr/include/libxml2/libxml/xmlmemory.h /usr/include/libxml2/libxml/xmlregexp.h /usr/include/libxml2/libxml/xmlstring.h /usr/include/libxml2/libxml/xmlversion.h CMakeFiles/testusage.dir/flags.make
/usr/bin/cmake -E cmake_echo_color --switch= --green --progress-dir=/tmp/test/build/CMakeFiles --progress-num=1 "Building CXX object CMakeFiles/testusage.dir/testusage.cpp.o"
[ 50%] Building CXX object CMakeFiles/testusage.dir/testusage.cpp.o
/usr/bin/c++ -I/usr/include/libxml2 -o CMakeFiles/testusage.dir/testusage.cpp.o -c /tmp/test/testusage.cpp
CMakeFiles/testusage.dir/build.make:95: update target 'testusage' due to: CMakeFiles/testusage.dir/link.txt CMakeFiles/testusage.dir/testusage.cpp.o CMakeFiles/testusage.dir/build.make /usr/lib/x86_64-linux-gnu/libxml2.so
/usr/bin/cmake -E cmake_echo_color --switch= --green --bold --progress-dir=/tmp/test/build/CMakeFiles --progress-num=2 "Linking CXX executable testusage"
[100%] Linking CXX executable testusage
/usr/bin/cmake -E cmake_link_script CMakeFiles/testusage.dir/link.txt --verbose=
/usr/bin/cmake -E cmake_echo_color --switch= --progress-dir=/tmp/test/build/CMakeFiles --progress-num=1,2 "Built target testusage"
[100%] Built target testusage
/usr/bin/cmake -E cmake_progress_start /tmp/test/build/CMakeFiles 0
$ ./testusage
0x7ffe0c7a5360