Hi, I am facing an issue with the includes in my code.
In my CMakeLists.txt I first create a library, then an executable which include vtk headers.
If I remove the add_library (so far my executable does not depend on it), there is no issue, my executable is produced.
Otherwise, running make fails with first vtk header included “vtkActor.h” no such file… Weirdly, If i place my main.cpp aside my CMakeLists.txt no issue encountered.
So far, my fix has been to create the variable VTK_INCLUDE_DIRS and to get all vtk include directories.
Personally, I think it is a shame that the VTK_INCLUDE_DIRS is not filled automatically with the command find_package …
VTK_INCLUDE_DIRS is no longer needed. Just link to the appropriate library and the include directories come in automatically. For vtkActor.h, you would want the VTK::RenderingCore library.
I know, I have actually based my CMakeLists.txt on the one in the example.
I have reproduced the bug within this example. Say I use add_library(…) before add_executable and the error with the includes arise. As I said I moved the main.cpp to src/apps because when it stays aside the CMakeLists.txt the issue disappears…
So this looks very much like a bug ?
Here is my CMakeLists.txtCMakeLists.txt (1.9 KB)
Anyway, I think, filling the VTK_INCLUDE_DIRS by the find_package provides more freedom and is more custom …
VTK_INCLUDE_DIRS is gone and I’m not bringing it back because it shouldn’t be needed. Its usage would just be papering over other problems. Can you post the actual error you’re getting?
Have you download the tar file in PolyLine and built it? This should build with no issues. In the CMakeLists.txt file include(${VTK_USE_FILE}) is only applicable to VTK versions less then 8.90.
Use VTK_LIBRARIES instead. You can check what libraries will be used by:
I just had a look at your CmakeLists.txt file, in particular add_executable(Writer MACOSX_BUNDLE src/apps/main.cpp ). I don’t know your directory layout but CMake expects absolute paths so you should be expressing the path to main.cpp relative to ${CMAKE_CURRENT_SOURCE_DIR} , which is the directory containing the current CMakeLists.txt file e.g perhaps:
Week-end rest gave me the answer. It happens that in the add_library I used a file( GLOB RECURSE …)
which searches in the Apps folder. In this Apps folder, are the files with main function for which I want to produce an exectuable and they are then liked with the library.
So my fix, is to put this folder somewhere else so that those files are now sources of the library.
This is just false. CMake looks up source files relative to ${CMAKE_CURRENT_SOURCE_DIR} when they are relative automatically.
It seems the issue was that there was a file(GLOB_RECURSE) laying around (IMO, a bad habit for listing source files), not anything with a path specification.