How to use cmake fetchcontent to download itk and it's devedent projects?

Hi, I am new to ITK. I am trying to use cmake to download ITK source code and build my projects. By it gives me strange error:

“CMake Error at CMakeLists.txt:18 (include):
include called with wrong number of arguments. include() only takes one
file.”

Does anybody know what I am doing wrong here?
Thanks!

Here is my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.19.7 FATAL_ERROR)

project(test LANGUAGES CXX)

set(BUILD_TESTING OFF)
set(BUILD_EXAMPLES OFF)

include(FetchContent)
FetchContent_Declare(
  ITK
  GIT_REPOSITORY https://github.com/InsightSoftwareConsortium/ITK.git
  GIT_TAG        v5.3.0 
  FIND_PACKAGE_ARGS NAMES ITK
)
FetchContent_MakeAvailable(ITK)

find_package(ITK REQUIRED)
add_executable(test test.cpp)
target_link_libraries(test ${ITK_LIBRARIES})

What happens if you replace find_package(ITK REQUIRED) by this:

set(ITK_DIR ${itk_BINARY_DIR} CACHE PATH "ITK's build directory" FORCE)
find_package(ITK REQUIRED CONFIG)
include(${ITK_USE_FILE})

Not all this might be necessary, you might be missing only include(${ITK_USE_FILE}).

2 Likes

Dženan,
Thanks for the help, but I am still getting the same error.
Thanks,
BR

Maybe try a clean build, or at least deleting CMake cache?

1 Like

It turns out that I need to set

set(ITK_DIR ${ITK_BINARY_DIR} CACHE STRING "Make the ITK_DIR available to other modules" FORCE)
1 Like