Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Examples/HelloFetchITK/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.22.1...3.29.0 FATAL_ERROR)

# This project is designed to be built outside the Insight source tree.
project(HelloFetchITK)

# Use an existing ITK installation if specified with ITK_DIR, or fetch and configure ITK.
include(ITKFetchContents.cmake)

itk_generate_factory_registration()

add_executable(HelloFetchITK FetchWorld.cxx)

# If ITK was fetched and configure, only the required modules are built.
target_link_libraries(HelloFetchITK ITK::ITKCommonModule)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing this here, I am now thinking that Module suffix is going to get repetitive quickly. Can you remind me why not use ITK::ITKCommon as the naming pattern? I guess that second ITK is needed to distinguish built-in modules vs. remotes (e.g. ITK::Montage).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I encourage you to look at an ITKTargets.cmake file to see the library interfaces.

Let's ignore the namespace for now. ITKCommon references the compiled library. However, not every module has a library, and not every module that has a library is named the same as the module. And some modules have multiple libraries.

So the {itk-module}Module interface library refers to all the includes, libraries and dependecies of an ITK module. Even when a module does not have a library is still has the includes, and a list of other {itk-module}Modules that it depends on. For example a recent change was to use ITKZLIBModule for the zlib library. This may reference an imported ZLIB::ZLIB target or our third-party itkzlib library.

You can see more usage of the new ITK interface pattern in SimpleITK too: https://github.com/SimpleITK/SimpleITK/blob/main/Code/Common/CMakeLists.txt

32 changes: 32 additions & 0 deletions Examples/HelloFetchITK/FetchWorld.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/

#include "itkImage.h"
#include <iostream>

int
main()
{
using ImageType = itk::Image<unsigned short, 3>;

auto image = ImageType::New();

std::cout << "ITK Hello World !" << std::endl;

return EXIT_SUCCESS;
}
40 changes: 40 additions & 0 deletions Examples/HelloFetchITK/ITKFetchContents.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#-----------------------------------------------------------------------------
# Get and build ITK using FetchContent

include(FetchContent)

# Set ITK Git repository and tag
set(ITK_GIT_REPOSITORY "https://github.com/InsightSoftwareConsortium/ITK.git")

set(ITK_GIT_TAG "main")

# Set ITK build options
set(ITK_BUILD_DEFAULT_MODULES ON)
Comment thread
hjmjohnson marked this conversation as resolved.
set(ITK_USE_KWSTYLE OFF)
set(BUILD_TESTING OFF)
set(BUILD_EXAMPLES OFF)

FetchContent_Declare(
ITK
GIT_REPOSITORY "${ITK_GIT_REPOSITORY}"
GIT_TAG "${ITK_GIT_TAG}"
EXCLUDE_FROM_ALL
FIND_PACKAGE_ARGS
NAMES
ITK
)

FetchContent_MakeAvailable(ITK)

# Check if FetchContent used find_package() or fetched from source
FetchContent_GetProperties(ITK)
if(ITK_SOURCE_DIR)
message(STATUS "ITK fetched from repository and built from source")
message(STATUS " Source directory: ${ITK_SOURCE_DIR}")
message(STATUS " Binary directory: ${ITK_BINARY_DIR}")
elseif(DEFINED ITK_FOUND)
message(STATUS "ITK found via find_package()")
# ITK_DIR should already be set by find_package()
else()
message(FATAL_ERROR "ITK configuration failed - no targets available")
endif()
Loading