Paulo Ziemer
Paulo Ziemer

Reputation: 31

Include VTK dir as System include in Cmake

I have a project that uses VTK as an external library. In my own source code, is use -Werror to ensure that those are always fixed. In order to do this "checking" in my code, external libraries are loaded in CMake with the INCLUDE_DIRECTORIES directive using the parameter SYSTEM. But if some external library is loaded through a CMakeLists.txt file (as VTK is)? I cannot specify that specify that VTK is a SYSTEM library and therefore VTK warnings are shown as errors. Is there a way to disable warnings from included libraries?

Upvotes: 3

Views: 2635

Answers (2)

Guillaume Jacquenot
Guillaume Jacquenot

Reputation: 11717

You can insert include_directories(SYSTEM ${VTK_INCLUDE_DIRS}) instructions right after the find_package instructions.

find_package(VTK REQUIRED)
include_directories(SYSTEM ${VTK_INCLUDE_DIRS})
include(${VTK_USE_FILE})

Upvotes: 2

Xilexio
Xilexio

Reputation: 1238

VTK adds include_directories itself, so unless you change VTK's CMake file with that line, you will most probably have to change your included directories property with some string operations. A faster way that worked for me is to change the line in VTK with include_directories, namely lib/cmake/vtk-*/UseVTK.cmake - the one you include with include(${VTK_USE_FILE}). I just changed the line

# Add include directories needed to use VTK.
include_directories(${VTK_INCLUDE_DIRS})

to

# Add include directories needed to use VTK.
include_directories(SYSTEM ${VTK_INCLUDE_DIRS})

and it seems to have squelched the warnings from VTK header files by marking them as SYSTEM libraries.

Upvotes: 2

Related Questions