comparison Resources/CMake/LibVtkConfiguration.cmake @ 1:0f03a8a0bd6f

encoding of RT-STRUCT as STL
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Jul 2023 18:54:31 +0200
parents
children ed7047aa4d3b
comparison
equal deleted inserted replaced
0:4e889a8e8be2 1:0f03a8a0bd6f
1 # SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
2 # SPDX-License-Identifier: GPL-3.0-or-later
3
4
5 # STL plugin for Orthanc
6 # Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium
7 #
8 # This program is free software: you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21
22 if (NOT STATIC_BUILD AND USE_SYSTEM_VTK)
23 find_package(VTK REQUIRED COMPONENTS
24 vtkCommonDataModel
25 vtkFiltersCore
26 vtkImagingCore
27 )
28
29 include_directories(${VTK_INCLUDE_DIRS})
30
31 # Add a void target
32 add_custom_target(VTK)
33
34 else()
35 set(VTK_MAJOR 7)
36 set(VTK_MINOR 1)
37 set(VTK_REVISION 1)
38 set(VTK_MD5 "daee43460f4e95547f0635240ffbc9cb")
39
40 set(VTK_SOURCES_DIR "${CMAKE_BINARY_DIR}/VTK-${VTK_MAJOR}.${VTK_MINOR}.${VTK_REVISION}")
41
42 DownloadPackage(
43 "${VTK_MD5}"
44 "https://orthanc.uclouvain.be/third-party-downloads/VTK-${VTK_MAJOR}.${VTK_MINOR}.${VTK_REVISION}.tar.gz"
45 "${VTK_SOURCES_DIR}")
46
47 if (CMAKE_TOOLCHAIN_FILE)
48 # Take absolute path to the toolchain
49 get_filename_component(TMP ${CMAKE_TOOLCHAIN_FILE} REALPATH BASE ${CMAKE_SOURCE_DIR}/..)
50 list(APPEND VTKCMakeFlags
51 -DCMAKE_TOOLCHAIN_FILE=${TMP}
52 -DLSB_CC=${LSB_CC}
53 -DLSB_CXX=${LSB_CXX}
54 )
55 endif()
56
57 cmake_host_system_information(RESULT NumberOfPhysicalCores QUERY NUMBER_OF_PHYSICAL_CORES)
58
59 include(ExternalProject)
60
61 if (CMAKE_CROSSCOMPILING)
62 # First, generate the "VTKCompileToolsConfig.cmake" file on the host
63 # computer. This is necessary before cross-compiling. Explanations:
64 # https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html#cross-compiling-a-complex-project-vtk
65 externalproject_add(VTKCompileTools
66 SOURCE_DIR "${VTK_SOURCES_DIR}"
67
68 CMAKE_ARGS
69 -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
70 -DCMAKE_CXX_COMPILER=g++
71 -DCMAKE_C_COMPILER=gcc
72
73 BUILD_COMMAND
74 ${CMAKE_COMMAND} --build <BINARY_DIR> --config <CONFIG> --parallel ${NumberOfPhysicalCores} -t
75 VTKCompileToolsConfig.cmake
76
77 INSTALL_COMMAND "" # Skip the install step
78 )
79
80 ExternalProject_Get_Property(VTKCompileTools binary_dir)
81 list(APPEND VTKCMakeFlags
82 -DVTKCompileTools_DIR=${binary_dir}
83 )
84
85 list(APPEND VTKCMakeFlags
86 -DCMAKE_REQUIRE_LARGE_FILE_SUPPORT=ON
87 -DCMAKE_REQUIRE_LARGE_FILE_SUPPORT__TRYRUN_OUTPUT=""
88 -DKWSYS_LFS_WORKS=ON
89 -DKWSYS_LFS_WORKS__TRYRUN_OUTPUT=""
90 -DFILE_OFFSET_BITS=64
91
92 # This simply disables HDF5, which is not used in Orthanc
93 -DVTK_USE_SYSTEM_HDF5=ON
94 )
95 else()
96 add_custom_target(VTKCompileTools) # Empty target
97 endif()
98
99 if (CMAKE_COMPILER_IS_GNUCXX OR
100 CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
101 # The following flag is necessary to statically link VTK within
102 # the shared library containing the plugin
103 set(Flags "-fPIC")
104 else()
105 set(Flags "")
106 endif()
107
108 externalproject_add(VTK
109 SOURCE_DIR "${VTK_SOURCES_DIR}"
110
111 CMAKE_ARGS
112 ${VTKCMakeFlags}
113 -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
114 -DBUILD_SHARED_LIBS=OFF
115 -DVTK_Group_Rendering=OFF
116
117 -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
118 "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} ${Flags}"
119 -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
120 "-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} ${Flags}"
121 -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
122 -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
123
124 BUILD_COMMAND
125 ${CMAKE_COMMAND} --build <BINARY_DIR> --config <CONFIG> --parallel ${NumberOfPhysicalCores} -t
126 vtkCommonCore
127 vtkCommonDataModel
128 vtkCommonMath
129 vtkCommonMisc
130 vtkCommonSystem
131 vtkCommonTransforms
132 vtkFiltersCore
133 vtkFiltersPoints
134 vtkImagingCore
135
136 EXCLUDE_FROM_ALL TRUE
137
138 INSTALL_COMMAND "" # Skip the install step
139
140 DEPENDS VTKCompileTools
141 )
142
143 if(MSVC)
144 set(Suffix ".lib")
145 set(Prefix "")
146 else()
147 set(Suffix ".a")
148 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix)
149 endif()
150
151 foreach(module IN ITEMS
152 # WARNING: The order of the modules below *is* important!
153 ImagingCore
154 FiltersCore
155 CommonExecutionModel
156 CommonDataModel
157 CommonTransforms
158 CommonMath
159 CommonMisc
160 CommonSystem
161 CommonCore
162 sys
163 )
164 list(APPEND VTK_LIBRARIES
165 ${Prefix}vtk${module}-${VTK_MAJOR}.${VTK_MINOR}${Suffix}
166 )
167 endforeach()
168
169 ExternalProject_Get_Property(VTK binary_dir)
170 ExternalProject_Get_Property(VTK source_dir)
171
172 link_directories(${binary_dir}/lib)
173
174 foreach(dir IN ITEMS
175 Common/Core
176 Common/DataModel
177 Common/ExecutionModel
178 Common/Misc
179 Filters/Core
180 IO/Image
181 Imaging/Core
182 Utilities/KWIML
183 )
184 include_directories(
185 ${source_dir}/${dir}
186 ${binary_dir}/${dir}
187 )
188 endforeach()
189
190 endif()