cmakeitk

ITK: Cannot find ITKConfig.cmake


I’ve been trying to set up ITK on a new PC and have run into a problem when I go to run CMake on a project.

I downloaded ITK 4.8.2, extracted it, configured with CMake and generated as always. However, this time CMake emitts the following error:

CMake Error at CMakeLists.txt:4 (find_package):
  By not providing "FindITK.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "ITK", but
  CMake did not find one.

  Could not find a package configuration file provided by "ITK" with any of
  the following names:

    ITKConfig.cmake
    itk-config.cmake

  Add the installation prefix of "ITK" to CMAKE_PREFIX_PATH or set "ITK_DIR"
  to a directory containing one of the above files.  If "ITK" provides a
  separate development package or SDK, be sure it has been installed.

-- Configuring incomplete, errors occurred!

The CMakeLists.txt file is pretty baron, just trying to ensure cmake/ITK is set up properly:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(ITKTest)

find_package(ITK REQUIRED)
include(${ITK_USE_FILE})

add_executable(ITKTest main.cpp)

target_link_libraries(ITKTest ${ITK_LIBRARIES})

I added CMAKE_PREFIX_PATH and ITK_DIR as additional entries, with the latter pointing to the location of the ITK folder. But the problem persists.

As for the files it says it cannot find, one is present in the folder that I set cmake to build the binaries to. In my case there are two files in two directories:

--E:\ITK\InsightToolkit-4.8.2-build\ITKConfig.cmake
--E:\ITK\InsightToolkit-4.8.2-build\CMakeFiles\ITKConfig.cmake

Solution

  • The file FindITK.cmake was removed in CMake 3.0.

    FindITK
    This module no longer exists.

    This module existed in versions of CMake prior to 3.1, but became only a thin wrapper around find_package(ITK NO_MODULE) to provide compatibility for projects using long-outdated conventions. Now find_package(ITK) will search for ITKConfig.cmake directly.

    Source: https://cmake.org/cmake/help/v3.4/module/FindITK.html

    As a result CMake looks for ITKConfig.cmake, which must be either installed to a default location or you have to add the path to ITKConfig.cmake to the CMAKE_PREFIX_PATH.