-
Notifications
You must be signed in to change notification settings - Fork 22
/
CMakeLists.txt
124 lines (107 loc) · 4.38 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
cmake_minimum_required(VERSION 3.16.3)
project(Elastix)
if(NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 17)
# SuperElastix/elastix uses C++17 specific features in some of its header files.
set(CMAKE_CXX_STANDARD 17)
endif()
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
# To ease enablement with Python packaging
if(DEFINED ENV{ELASTIX_USE_OPENCL})
set(ELASTIX_USE_OPENCL ON CACHE BOOL "Enable OpenCL support in Elastix")
endif()
set(Elastix_LIBRARIES elastix_lib transformix_lib)
if(ELASTIX_USE_OPENCL)
list(APPEND Elastix_LIBRARIES elxOpenCL)
endif()
set(ELASTIX_BUILD_EXECUTABLE OFF)
set(ELASTIX_BUILD_EXECUTABLE OFF CACHE BOOL "Generate executable or library")
# Avoid LGPL code and ANN shared library
if(NOT DEFINED USE_KNNGraphAlphaMutualInformationMetric)
set(USE_KNNGraphAlphaMutualInformationMetric OFF)
set(USE_KNNGraphAlphaMutualInformationMetric OFF CACHE BOOL "Use KNN metric. Requires ANN library.")
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-aggressive-loop-optimizations")
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(NOT ITK_SOURCE_DIR)
find_package(ITK REQUIRED)
endif()
include(FetchContent)
# Set up Elastix build parameters for populate step
option(ELASTIX_BUILD_TESTING OFF)
set(_itk_build_testing ${BUILD_TESTING})
set(BUILD_TESTING ${ELASTIX_BUILD_TESTING})
set(_itk_build_shared ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF) # Elastix does not support shared libs
# Building Python wheels, disable installation of elastix artifacts
if(SKBUILD)
option(ELASTIX_NO_INSTALL_RUNTIME_LIBRARIES "Do not install runtime libraries" ON)
option(ELASTIX_NO_INSTALL_EXECUTABLES "Do not install executables" ON)
option(ELASTIX_NO_INSTALL_DEVELOPMENT "Do not install development headers and static libraries" ON)
mark_as_advanced(ELASTIX_NO_INSTALL_EXECUTABLES ELASTIX_NO_INSTALL_RUNTIME_LIBRARIES ELASTIX_NO_INSTALL_DEVELOPMENT)
endif()
if(WASI OR EMSCRIPTEN)
option(ELASTIX_NO_INSTALL_EXECUTABLES "Do not install executables" ON)
endif()
# set(elastix_GIT_REPOSITORY "https://github.com/SuperElastix/elastix.git")
set(elastix_GIT_REPOSITORY "https://github.com/thewtex/elastix.git")
# Upstream + wasm patches
# Branch: ITKElastix-2024-07-18-ebb429a33b
set(elastix_GIT_TAG "0ab3f57a6528cce609feedeb1650e7c850beca94")
FetchContent_Declare(
elx
GIT_REPOSITORY ${elastix_GIT_REPOSITORY}
GIT_TAG ${elastix_GIT_TAG})
FetchContent_GetProperties(elx)
if(NOT elx_POPULATED)
FetchContent_Populate(elx)
# Use CMake's FindOpenCL.cmake, which is backend agnostic
file(REMOVE ${elx_SOURCE_DIR}/CMake/FindOpenCL.cmake)
if(ELASTIX_USE_OPENCL)
find_package(OpenCL REQUIRED)
set(OPENCL_INCLUDE_DIRS ${OpenCL_INCLUDE_DIRS} CACHE PATH "OpenCL include directories")
set(OPENCL_LIBRARIES ${OpenCL_LIBRARIES} CACHE FILEPATH "OpenCL library")
endif()
add_subdirectory(${elx_SOURCE_DIR} ${elx_BINARY_DIR})
endif()
set(Elastix_DIR "${elx_BINARY_DIR}")
find_package(Elastix REQUIRED)
include_directories( ${ELASTIX_INCLUDE_DIRS} )
link_directories( ${ELASTIX_LIBRARY_DIRS} )
#include(${ELASTIX_USE_FILE})
if(ELASTIX_USE_OPENCL)
add_definitions(-DELASTIX_USE_OPENCL)
endif()
# Reset parameters for ITK remote module build
if (NOT WASI AND NOT EMSCRIPTEN)
set(BUILD_TESTING ${_itk_build_testing})
set(BUILD_SHARED_LIBS ${_itk_build_shared})
endif()
if(ITK_WRAP_PYTHON) # Python wrapping is enabled
get_property(multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(multi_config)
if(NOT (CMAKE_CONFIGURATION_TYPES STREQUAL "Release"))
message(WARNING "Python wrapping of ITKElastix is known not to work with RelWithDebInfo configuration. Release is recommended. Your CMAKE_CONFIGURATION_TYPES: ${CMAKE_CONFIGURATION_TYPES}")
endif()
else()
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Release"))
message(WARNING "Python wrapping of ITKElastix is known not to work with RelWithDebInfo configuration. Release is recommended. Your CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
endif()
endif()
endif()
option(ITKELASTIX_BUILD_WASM_EXECUTABLES "Build WASM executables" OFF)
if(NOT ITK_SOURCE_DIR)
find_package(ITK REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR})
include(ITKModuleExternal)
if(WASI OR EMSCRIPTEN OR ITKELASTIX_BUILD_WASM_EXECUTABLES)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(wasm)
endif()
else()
set(ITK_DIR ${CMAKE_BINARY_DIR})
itk_module_impl()
endif()