-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
153 lines (126 loc) · 5.15 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
project( GPURigidRegistration )
#----------------------------------------
# Tell the compiler to use c++11
set( CMAKE_CXX_STANDARD 11 )
#----------------------------------------
#-----------------------------------------------------------------------------
# GIT - Let's check if a valid version of GIT is available
#-----------------------------------------------------------------------------
OPTION(USE_GIT_PROTOCOL "If behind a firewall turn this off to use https instead." OFF)
SET(GIT_PROTOCOL "git")
IF(NOT USE_GIT_PROTOCOL)
SET(GIT_PROTOCOL "https")
ENDIF()
#==================================================================
# Look for VTK, only using vtkTransform, so any version should work
#==================================================================
find_package(VTK REQUIRED)
#==================================================================
# Look for ITK, version should be > 4.12
#==================================================================
find_package( ITK REQUIRED )
include( ${ITK_USE_FILE} )
#==================================================================
# Look for Elastix
#==================================================================
find_package( Elastix REQUIRED )
include( ${ELASTIX_USE_FILE} )
# Elastix 4.9 does not seem to include CMAEvolutionStrategy directory, we need to do it manually
include_directories( ${Elastix_DIR}/../src/Components/Optimizers/CMAEvolutionStrategy )
#==================================================================
# Define sources
#==================================================================
set( CL_files
GPUDiscreteGaussianGradientImageFilter
GPUGradientOrientationMatchingKernel )
set( SRC_files
gpu_rigidregistration.cpp )
set( HDR_files
gpu_rigidregistration.h
itkGPUGradientOrientationMatching.hxx
itkGPU3DRigidSimilarityMetric.h
itkGPUGradientOrientationMatching.h )
#================================
# Create custom commands to
# encode each cl file into a
# C string literal in a header
# file.
#================================
# Find vtkEncodeString utility executable. Look in built or installed dir structure
if( ${VTK_MAJOR_VERSION} LESS "9" )
include(${VTK_USE_FILE})
set( vtkEncodeStringExeFile vtkEncodeString-${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION} )
find_program( VTK_ENCODESTRING_EXE ${vtkEncodeStringExeFile} PATHS
${VTK_DIR}/bin/
${VTK_DIR}/bin/Debug/
${VTK_DIR}/bin/Release/
${VTK_INSTALL_PREFIX}/bin
NO_DEFAULT_PATH )
if( NOT VTK_ENCODESTRING_EXE )
message( FATAL_ERROR "the vtkEncodeString executable could not be found in the VTK directory.")
endif()
foreach( file ${CL_files} )
set( clKernel_src ${CMAKE_CURRENT_SOURCE_DIR}/${file}.cl )
set( clKernel_cxx ${CMAKE_CURRENT_BINARY_DIR}/${file}.cxx )
set( clKernel_h ${CMAKE_CURRENT_BINARY_DIR}/${file}.h )
add_custom_command(
OUTPUT ${clKernel_cxx} ${clKernel_h}
DEPENDS ${clKernel_src}
COMMAND ${VTK_ENCODESTRING_EXE}
ARGS ${clKernel_cxx} ${clKernel_src} ${file} --build-header " " vtkSystemIncludes.h )
set( SRC_CL ${SRC_CL} ${clKernel_src} ${clKernel_h} ${clKernel_cxx} )
set( HDR_CL ${HDR_CL} ${clKernel_h} )
endforeach(file)
else()
set( LibCLSrc )
set( LibCLHdr )
foreach (shader_file IN LISTS CL_files)
vtk_encode_string(
INPUT "${shader_file}.cl"
HEADER_OUTPUT clKernel_h
SOURCE_OUTPUT clKernel_cxx)
list(APPEND SRC_CL ${clKernel_cxx})
list(APPEND HDR_CL ${clKernel_h})
endforeach ()
endif()
#================================
# Define output
#================================
set( libName GPURigidRegistrationLib )
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_library( ${libName} ${SRC_files} ${HDR_files} ${SRC_CL} ${HDR_CL} )
target_link_libraries( ${libName} ${ITK_LIBRARIES} ${VTK_LIBRARIES} ${ELASTIX_LIBRARIES} )
target_include_directories( ${libName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
#================================
# Options
#================================
option(GPURR_BUILD_EXECUTABLE "Generate executable for GPURigidRegistration." ON)
option(GPURR_BUILD_TEST "Enable testing for GPURigidRegistration.\n" ON)
#================================
# Define executable
#================================
if(GPURR_BUILD_EXECUTABLE)
# Build vtkMNI utility lib (only needed by the executable)
add_subdirectory(utils)
add_executable( GPURigidRegistration utils/main.cpp )
target_link_libraries( GPURigidRegistration ${libName} vtkMNI )
else()
# disable testing
if(GPURR_BUILD_TEST)
message( WARNING "Testing has been disabled." )
endif()
set(GPURR_BUILD_TEST OFF CACHE BOOL "Disable tests." FORCE)
endif()
#================================
# Define tests
#================================
if(GPURR_BUILD_TEST)
if(NOT GPURR_BUILD_EXECUTABLE)
message( SEND_ERROR "Need to generate executable for testing. Please set GPURR_BUILD_EXECUTABLE ON or disable GPURR_BUILD_TEST.\n" )
else()
include(ExternalProject)
enable_testing()
add_subdirectory(tests)
endif()
endif()