# FindLibXml2 adds unexpected include flag breaking build

**URL:** https://discourse.cmake.org/t/findlibxml2-adds-unexpected-include-flag-breaking-build/15609
**Category:** Usage
**Created:** [April 19, 2026, 9:48pm UTC](https://discourse.cmake.org/t/findlibxml2-adds-unexpected-include-flag-breaking-build/15609 "2026-04-19T21:48:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jcurl](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jcurl/32/4992_2.png) [@jcurl](https://discourse.cmake.org/u/jcurl)
#### Post date: [April 19, 2026, 9:48pm UTC](https://discourse.cmake.org/t/findlibxml2-adds-unexpected-include-flag-breaking-build/15609/1 "2026-04-19T21:48:31Z")

</div>

I’m finding the LibXml2 package and would appreciate insights in what I’m doing wrong. CMake 3.22 on Ubuntu 22.04.5.

The `CMakeLists.txt` file contains the snippet:

```plaintext
find_package(LibXml2)
if (LibXml2_FOUND)
  #target_include_directories(${LIBRARY} PRIVATE ${LIBXML2_INCLUDE_DIRS})
  #target_link_libraries(${LIBRARY} PRIVATE ${LIBXML2_LIBRARIES})
  target_link_libraries(${LIBRARY} PRIVATE LibXml2::LibXml2)
endif()

```

Building on Linux works fine. The problem is when cross-compiling for QNX where flags are somehow unexpected injected for the ${LIBRARY} target that causes the system include path to be broken.

Specifically, I looked at the file in my local project called `tools/cpuid-x86/libcpuid/src/CMakeFiles/libcpuid.dir/flags.make` and it contains (split on lines to make it readable):

```plaintext
CXX_INCLUDES =
 -I/home/jcurl/source/code.research/qnx/lib/libubench/include
 -I/home/jcurl/source/code.research/qnx/lib/libstdext/include
 -I/home/jcurl/source/code.research/qnx/lib/libosqnx/include
 -I/home/jcurl/source/code.research/qnx/tools/cpuid-x86/libcpuid/src/../include
 -I/home/jcurl/source/code.research/qnx/build/qnx8-n/tools/cpuid-x86/libcpuid/src
 -Wp,-isystem,/home/jcurl/qnx/qnx800/target/qnx/usr/include

```

Removing the last line manually allows the build to succeed.

What is causing CMake to inject `-Wp,-isystem,/home/jcurl/qnx/qnx800/target/qnx/usr/include` and how do I get rid of it?

If I modify the `CMakeLists.txt` file to use `${LIBXML2_INCLUDE_DIRS}` and `${LIBXML2_LIBRARIES}` instead, I get a working build.

```plaintext
CXX_INCLUDES =
 -I/home/jcurl/source/code.research/qnx/lib/libubench/include
 -I/home/jcurl/source/code.research/qnx/lib/libstdext/include
 -I/home/jcurl/source/code.research/qnx/lib/libosqnx/include
 -I/home/jcurl/source/code.research/qnx/tools/cpuid-x86/libcpuid/src/../include
 -I/home/jcurl/qnx/qnx800/target/qnx/usr/include
 -I/home/jcurl/source/code.research/qnx/build/qnx8-w/tools/cpuid-x86/libcpuid/src

```

For information, I’m cross compiling on QNX, and my target file looks like:

```plaintext
set(CMAKE_SYSTEM_NAME QNX)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

set(arch gcc_ntox86_64)

set(CMAKE_C_COMPILER qcc)
set(CMAKE_C_COMPILER_TARGET ${arch})
set(CMAKE_CXX_COMPILER q++)
set(CMAKE_CXX_COMPILER_TARGET ${arch})

set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")

set(LIBXML2_LIBRARY "$ENV{QNX_TARGET}/x86_64/usr/lib/libxml2.so" CACHE FILEPATH "")
set(LIBXML2_INCLUDE_DIR "$ENV{QNX_TARGET}/usr/include" CACHE PATH "")

```

Note, I have to set it to the cache, because otherwise it would fail on a second `find_package(LibXml2)` call.

When I reviewed the code in `/usr/share/cmake-3.22/Modules/FindLibXml2.cmake`, I don’t really see where this is coming in, except it’s using `INTERFACE` instead of `PRIVATE`.

```plaintext
if(LibXml2_FOUND AND NOT TARGET LibXml2::LibXml2)
  add_library(LibXml2::LibXml2 UNKNOWN IMPORTED)
  set_target_properties(LibXml2::LibXml2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXML2_INCLUDE_DIRS}")
  set_target_properties(LibXml2::LibXml2 PROPERTIES INTERFACE_COMPILE_OPTIONS "${LIBXML2_DEFINITIONS}")
  set_property(TARGET LibXml2::LibXml2 APPEND PROPERTY IMPORTED_LOCATION "${LIBXML2_LIBRARY}")
endif()

```

Showing that it may not be that difference, I include using `INTERFACE` instead of `PRIVATE`:

```plaintext
    target_include_directories(${LIBRARY} INTERFACE ${LIBXML2_INCLUDE_DIRS})
    target_link_libraries(${LIBRARY} INTERFACE ${LIBXML2_LIBRARIES})

```

and the build still works.

---

<div class="post-metadata">

### Author: ![jcurl](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jcurl/32/4992_2.png) [@jcurl](https://discourse.cmake.org/u/jcurl)
#### Post date: [April 20, 2026, 4:59pm UTC](https://discourse.cmake.org/t/findlibxml2-adds-unexpected-include-flag-breaking-build/15609/2 "2026-04-20T16:59:40Z")

</div>

Under Ubuntu 22.04, not cross compiling and using no toolchain file, even though it compiles, I see the same behaviour that the folder is included as a system path, instead of a local path.

```plaintext
CXX_INCLUDES =
 -I/home/jcurl/source/code.research/qnx/lib/libubench/include
 -I/home/jcurl/source/code.research/qnx/lib/libstdext/include
 -I/home/jcurl/source/code.research/qnx/tools/cpuid-x86/libcpuid/src/../include
 -I/usr/include/libxml2
 -I/home/jcurl/source/code.research/qnx/build/local/tools/cpuid-x86/libcpuid/src

```

and

```plaintext
CXX_INCLUDES =
 -I/home/jcurl/source/code.research/qnx/lib/libubench/include
 -I/home/jcurl/source/code.research/qnx/lib/libstdext/include
 -I/home/jcurl/source/code.research/qnx/tools/cpuid-x86/libcpuid/src/../include
 -I/home/jcurl/source/code.research/qnx/build/local/tools/cpuid-x86/libcpuid/src
 -isystem /usr/include/libxml2

```

Thus it doesn’t appear related to my toolchain file.

---

<div class="post-metadata">

### Author: ![jcurl](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jcurl/32/4992_2.png) [@jcurl](https://discourse.cmake.org/u/jcurl)
#### Post date: [April 22, 2026, 5:54pm UTC](https://discourse.cmake.org/t/findlibxml2-adds-unexpected-include-flag-breaking-build/15609/3 "2026-04-22T17:54:48Z")

</div>

With lots of searching, I was finally able to find some documented behaviour for this: [NO\_SYSTEM\_FROM\_IMPORTED](https://cmake.org/cmake/help/v3.22/prop_tgt/NO_SYSTEM_FROM_IMPORTED.html).

I could set this variable in my toolchain file and everything builds and is implemented as per specifications.

Any possibility to set this per transitive dependency target? I would do this for some (like libxml2.so on QNX), but not others (such as out of tree builds).
