Skip to content
Draft
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)
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;
}
48 changes: 48 additions & 0 deletions Examples/HelloFetchITK/ITKFetchContents.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#-----------------------------------------------------------------------------
# Get and build ITK using FetchContent

include(FetchContent)

# Set ITK Git repository and tag
set(ITK_GIT_REPOSITORY "https://github.com/blowekamp/ITK.git")
Copy link
Member

Choose a reason for hiding this comment

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

@blowekamp This should probably default to InsightSoftwareConsortium rather than blowekamp organization.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is dependent PR #5721 for the modular interface libraries.


set(ITK_GIT_TAG "cmake_interface_module")
Copy link
Member

Choose a reason for hiding this comment

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

OK for DRAFT pr, but should this default to "main" or "v5.4.5" or "latest"? as the default?


# Set ITK build options
set(ITK_BUILD_DEFAULT_MODULES ON)
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}")
set(ITK_DIR "${ITK_BINARY_DIR}")

include(${ITK_DIR}/ITKConfig.cmake)
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()

# These ITK option conflict with SimpleITK.
# Allow a user's cache variable to be respected.
unset(BUILD_TESTING)
unset(BUILD_EXAMPLES)
Loading