# CMakelists.txt file question

**URL:** https://discourse.itk.org/t/cmakelists-txt-file-question/7685
**Category:** Uncategorized
**Created:** [December 22, 2025, 4:21pm UTC](https://discourse.itk.org/t/cmakelists-txt-file-question/7685 "2025-12-22T16:21:44Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ogdenk](https://discourse.itk.org/letter_avatar_proxy/v4/letter/o/bbe5ce/32.png) [@ogdenk](https://discourse.itk.org/u/ogdenk)
#### Post date: [December 22, 2025, 4:21pm UTC](https://discourse.itk.org/t/cmakelists-txt-file-question/7685/1 "2025-12-22T16:21:44Z")

</div>

Hi all.

I am a casual user of ITK, and haven’t used it in a few years. When I recently set it up again, I found that the original CMakelists.txt file I had previously used didn’t work any more in CMake. This is a small example program and only had 1 CMakelists file. I did get an error relating to the version requirement and fixed that. The file contents are here:

cmake\_minimum\_required(VERSION 3.1)

project(BinaryThresholdImageFilter)

find\_package(ITK REQUIRED)  
include({ITK\_USE\_FILE}) if (ITKVtkGlue\_LOADED) find\_package(VTK REQUIRED) else() find\_package(ItkVtkGlue REQUIRED) include({ItkVtkGlue\_USE\_FILE})  
set(Glue ItkVtkGlue)  
endif()

add\_executable(BinaryThresholdImageFilter MACOSX\_BUNDLE BinaryThresholdImageFilter.cxx)  
target\_link\_libraries(BinaryThresholdImageFilter {Glue} {VTK\_LIBRARIES} ${ITK\_LIBRARIES})

vtk\_module\_autoinit(  
TARGETS BinaryThresholdImageFilter  
MODULES  
VTK::RenderingOpenGL2  
)

Can anyone suggest changes/additions that would let this work? Is there some help somewhere that will help with this? I have been looking but haven’t been able to find anything.

Thanks!

Kent Ogden

---

<div class="post-metadata">

### Author: ![ogdenk](https://discourse.itk.org/letter_avatar_proxy/v4/letter/o/bbe5ce/32.png) [@ogdenk](https://discourse.itk.org/u/ogdenk)
#### Post date: [December 22, 2025, 4:22pm UTC](https://discourse.itk.org/t/cmakelists-txt-file-question/7685/2 "2025-12-22T16:22:41Z")

</div>

I see that the code got reformatted, here is another try:

```auto
 
project(BinaryThresholdImageFilter)
 
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
  find_package(VTK REQUIRED)
else()
  find_package(ItkVtkGlue REQUIRED)
  include(${ItkVtkGlue_USE_FILE})
  set(Glue ItkVtkGlue)
endif()
 
add_executable(BinaryThresholdImageFilter MACOSX_BUNDLE BinaryThresholdImageFilter.cxx)
target_link_libraries(BinaryThresholdImageFilter ${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES})

vtk_module_autoinit(
    TARGETS BinaryThresholdImageFilter
    MODULES 
    VTK::RenderingOpenGL2
    )

```

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 23, 2025, 3:22pm UTC](https://discourse.itk.org/t/cmakelists-txt-file-question/7685/3 "2025-12-23T15:22:49Z")

</div>

You did not say what is the actual problem. What does CMake/compiler report?

---

<div class="post-metadata">

### Author: ![ogdenk](https://discourse.itk.org/letter_avatar_proxy/v4/letter/o/bbe5ce/32.png) [@ogdenk](https://discourse.itk.org/u/ogdenk)
#### Post date: [December 23, 2025, 3:55pm UTC](https://discourse.itk.org/t/cmakelists-txt-file-question/7685/4 "2025-12-23T15:55:46Z")

</div>

Yes I did forget that. Turns out I did figure out the issue, I had to set some system variables (ITK\_DIR and VTK\_DIR). Once I did that, the problem went away. However, I have a new problem in that the linker won’t link my program because of the names assigned to the libraries don’t match the names that are assigned in the project. I am using Visual C++ 2026, and in the linker settings I see all of the ITK files listed as, for example, itkdouble-conversion.lib. This is the first file and the error occurs listing this file, though all of the rest have the same issue. In the ITK build directory, the file is listed as itkdouble-conversion-5.4.lib. I assume there is a setting in CMake, either in the ITK build or in my program that is causing this. I am looking for this issue, but will be happy to hear any suggestions. Thanks for your help!

Kent

---

<div class="post-metadata">

### Author: ![ogdenk](https://discourse.itk.org/letter_avatar_proxy/v4/letter/o/bbe5ce/32.png) [@ogdenk](https://discourse.itk.org/u/ogdenk)
#### Post date: [December 23, 2025, 3:58pm UTC](https://discourse.itk.org/t/cmakelists-txt-file-question/7685/5 "2025-12-23T15:58:32Z")

</div>

Maybe I should have mentioned, I am using BUILD\_STATIC\_LIBS for ITK and have a similar setting in the VTK build.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 23, 2025, 5:36pm UTC](https://discourse.itk.org/t/cmakelists-txt-file-question/7685/6 "2025-12-23T17:36:43Z")

</div>

`BUILD_STATIC_LIBS` is the usual, default, widely tested setting. ITK compiles with VS2026, and should generally work fine. Can you try a clean build of your project (choose a new, empty folder as the build directory)? If it fails, provide the complete configure and build logs.

---

<div class="post-metadata">

### Author: ![ogdenk](https://discourse.itk.org/letter_avatar_proxy/v4/letter/o/bbe5ce/32.png) [@ogdenk](https://discourse.itk.org/u/ogdenk)
#### Post date: [December 23, 2025, 6:14pm UTC](https://discourse.itk.org/t/cmakelists-txt-file-question/7685/7 "2025-12-23T18:14:38Z")

</div>

Dzenan,

It works now with a rebuild of my application. Thanks so much for your help.

One more question: Is there a resource somewhere that explains the cmakelists.txt file for ITK and VTK? I have always struggled with this aspect of writing ITK and VTK code.

Kent

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 23, 2025, 9:09pm UTC](https://discourse.itk.org/t/cmakelists-txt-file-question/7685/8 "2025-12-23T21:09:06Z")

</div>

For ITK, that would be Chapter 2 (“Configuring and Building ITK”) of ITK software guide. [PDF](https://itk.org/ItkSoftwareGuide.pdf) has full resolution screenshots, [HTML](https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch2.html) loads faster.

VTK has a more modernized docs [here](https://docs.vtk.org/en/latest/getting_started/index.html#using-c-and-cmake).
