ITK: Cannot find ITKConfig.cmake
Asked Answered
S

5

5

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
Sauterne answered 27/1, 2016 at 1:35 Comment(5)
Are you sure that FindITK.cmake exists in your modules directory? I do not have a Windows machine ATM, but on Ubuntu modules reside under /cmake-root/Modules.Lareine
Search algorithm of find_package() is fully described in documentation. Try to set ITK_DIR to E:\\ITK\\InsightToolkit-4.8.2-build (\` should be interpreted by CMake as single backslash). Two things looks suspicious for me: 1. running cmake CMakeLists.txt. Normally, argument for cmake is source directory, not a script file itself. And it is better to perform out-of-source builds. 2. Having second ITKConfig.cmake` under CMakeFiles. Looks like same directory have been used as build and install one for ITK.Cholecystectomy
@Lareine Just checked and, no, FindITK.cmake is not in the Modules directory.Sauterne
@Cholecystectomy In the example above, I'm running CMakeLists.txt to create a HelloWorld project to verify that ITK was configured properly. I set ITK_DIR to the path you suggested, but I still get the same error when trying to create that test project. As for the directories, the source and build are in separate subfolders (i.e. E:\ITK\InsightToolkit-4.8.2\ and E:\ITK|InsightToolkit-4.8.2-build\ ).Sauterne
` As for the directories, the source and build are in separate subfolders` - you need separate build and install subfolders too.Cholecystectomy
G
5

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.

Gwalior answered 5/2, 2016 at 10:10 Comment(2)
Thank you for the info. Just to clarify here, what would be a default location for ITKConfig.cmake? The file I have is located in the directory ITK was built in using cmake.Sauterne
If you build and install ITK, it will choose a default location. Not sure what that means e.g. for Windows. When you don't install it, you have to add the right path to your CMAKE_PRFIX_PATH, which is the way I usually chose. Maybe use some shell script to call cmake.Gwalior
S
2

I found a way to successfully build the test project (as well as another project I am currently working on). I specified the location of the ITK build folder in as an argument when building the project:

cmake -DITK_DIR=E:/ITK/Insight-Toolkit-4.8.2 CMakeLists.txt

I'm still not sure why I've never had to do this before, and why ITK_DIR variable does not persist after I configure ITK in the cmake GUI, but this did allow me to build the projects.

Sauterne answered 28/1, 2016 at 17:44 Comment(0)
P
1

None of these or other flavors worked for me, as if ITK_DIR never got defined:

cmake -DITK_DIR=C:\Users\user\InsightToolkit-5.0.0_bld C:\Users\user\HelloWorldITK cmake
-DITK_DIR=C:\\Users\\user\\InsightToolkit-5.0.0_bld C:\Users\user\HelloWorldITK cmake
-DITK_DIR=C:/Users/user/InsightToolkit-5.0.0_bld C:\Users\user\HelloWorldITK

However, adding this to the CMakeLists.txt resolved the problem:

SET(ITK_DIR "C:\\Users\\user\\InsightToolkit-5.0.0_bld")
Pia answered 23/6, 2019 at 2:22 Comment(0)
A
1

This is like "a simple spell but quite unbreakable" as Dr. Strange tell in avengers infinity war.

Here cmake GUI is not detecting the ITK_DIR so you can add the path manually which is the ITK bin folder. In my case my path to directory

other than that if you may not installed or configure ITK correctly please configure it by going through these steps.

  1. Create ITK source folder.

  2. Create ITK build folder.

  3. Run CMake and select source and build folders.

  4. Select respective compiler, and if there are any compiler issues refer this discussion.

  5. Configure and generate cmake.

  6. Open the build files in build folder with respective IDE (use .sln file if visual studio compilers are used).

  7. Build all once on visual studio.

  8. Now for your new project use same steps and point CMAKE_PREFIX_PATH and ITK to your ITK Build Directory.

And everything should work. Good Luck!!!

Abominable answered 21/10, 2022 at 2:39 Comment(0)
E
0

Need to set ITK_DIR in elastix\CMakeLists.txt before find_package with ITK Build path where ITKConfig.cmake is available.

So need to add like this:

set(ITK_DIR
    "${CMAKE_CURRENT_SOURCE_DIR}/../InsightToolkit-5.3.0/build")
Egestion answered 8/3, 2023 at 13:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.