-
-
Notifications
You must be signed in to change notification settings - Fork 717
ENH: Add example project which used ITK Modules and FetchContent #5740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
blowekamp
wants to merge
1
commit into
InsightSoftwareConsortium:main
Choose a base branch
from
blowekamp:fetch_world
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+94
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
|
|
||
| set(ITK_GIT_TAG "cmake_interface_module") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
hjmjohnson marked this conversation as resolved.
Show resolved
Hide 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}") | ||
| 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) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.