Skip to content

Commit 4e88c8e

Browse files
authored
Merge pull request #5740 from blowekamp/fetch_world
2 parents 86c3696 + f8c35f0 commit 4e88c8e

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.22.1...3.29.0 FATAL_ERROR)
2+
3+
# This project is designed to be built outside the Insight source tree.
4+
project(HelloFetchITK)
5+
6+
# Use an existing ITK installation if specified with ITK_DIR, or fetch and configure ITK.
7+
include(ITKFetchContents.cmake)
8+
9+
itk_generate_factory_registration()
10+
11+
add_executable(HelloFetchITK FetchWorld.cxx)
12+
13+
# If ITK was fetched and configure, only the required modules are built.
14+
target_link_libraries(HelloFetchITK ITK::ITKCommonModule)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*=========================================================================
2+
*
3+
* Copyright NumFOCUS
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0.txt
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*=========================================================================*/
18+
19+
#include "itkImage.h"
20+
#include <iostream>
21+
22+
int
23+
main()
24+
{
25+
using ImageType = itk::Image<unsigned short, 3>;
26+
27+
auto image = ImageType::New();
28+
29+
std::cout << "ITK Hello World !" << std::endl;
30+
31+
return EXIT_SUCCESS;
32+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#-----------------------------------------------------------------------------
2+
# Get and build ITK using FetchContent
3+
4+
include(FetchContent)
5+
6+
# Set ITK Git repository and tag
7+
set(ITK_GIT_REPOSITORY "https://github.com/InsightSoftwareConsortium/ITK.git")
8+
9+
set(ITK_GIT_TAG "main")
10+
11+
# Set ITK build options
12+
set(ITK_BUILD_DEFAULT_MODULES ON)
13+
set(ITK_USE_KWSTYLE OFF)
14+
set(BUILD_TESTING OFF)
15+
set(BUILD_EXAMPLES OFF)
16+
17+
FetchContent_Declare(
18+
ITK
19+
GIT_REPOSITORY "${ITK_GIT_REPOSITORY}"
20+
GIT_TAG "${ITK_GIT_TAG}"
21+
EXCLUDE_FROM_ALL
22+
FIND_PACKAGE_ARGS
23+
NAMES
24+
ITK
25+
)
26+
27+
FetchContent_MakeAvailable(ITK)
28+
29+
# Check if FetchContent used find_package() or fetched from source
30+
FetchContent_GetProperties(ITK)
31+
if(ITK_SOURCE_DIR)
32+
message(STATUS "ITK fetched from repository and built from source")
33+
message(STATUS " Source directory: ${ITK_SOURCE_DIR}")
34+
message(STATUS " Binary directory: ${ITK_BINARY_DIR}")
35+
elseif(DEFINED ITK_FOUND)
36+
message(STATUS "ITK found via find_package()")
37+
# ITK_DIR should already be set by find_package()
38+
else()
39+
message(FATAL_ERROR "ITK configuration failed - no targets available")
40+
endif()

0 commit comments

Comments
 (0)