CMakeLists.txt 13.1 KB
Newer Older
1
2
3
4
5
6
7
8
##============================================================================
##  Copyright (c) Kitware, Inc.
##  All rights reserved.
##  See LICENSE.txt for details.
##  This software is distributed WITHOUT ANY WARRANTY; without even
##  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
##  PURPOSE.  See the above copyright notice for more information.
##
Kenneth Moreland's avatar
Kenneth Moreland committed
9
##  Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10
##  Copyright 2014 UT-Battelle, LLC.
11
##  Copyright 2014 Los Alamos National Security.
12
##
Kenneth Moreland's avatar
Kenneth Moreland committed
13
##  Under the terms of Contract DE-NA0003525 with NTESS,
14
15
16
17
18
19
20
##  the U.S. Government retains certain rights in this software.
##
##  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
##  Laboratory (LANL), the U.S. Government retains certain rights in
##  this software.
##============================================================================

21
22
23
24
25
26
#We require CMake 3.3 for Modern CMake which as features such as:
# - Better custom command support
# - Better acting if() argument expansion
# - Support for usage requirements
# -
cmake_minimum_required(VERSION 3.3)
27

28
29
project (VTKm)

30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Update module path
set(VTKm_CMAKE_MODULE_PATH ${VTKm_SOURCE_DIR}/CMake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${VTKm_CMAKE_MODULE_PATH})

# Determine VTK-m version
include(Utilities/Git/Git.cmake)
include(VTKmDetermineVersion)

# Load hardcoded version in case this is not a Git repository
file(STRINGS version.txt version_txt)
extract_version_components("${version_txt}" "VTKm")
# Get the version from git if we can
determine_version(${VTKm_SOURCE_DIR} ${GIT_EXECUTABLE} "VTKm")

44
if (NOT DEFINED VTKm_INSTALL_INCLUDE_DIR)
45
  set(VTKm_INSTALL_INCLUDE_DIR "include/vtkm-${VTKm_VERSION_MAJOR}.${VTKm_VERSION_MINOR}")
46
47
endif()
if (NOT DEFINED VTKm_INSTALL_CONFIG_DIR)
48
  set(VTKm_INSTALL_CONFIG_DIR "lib/cmake/vtkm-${VTKm_VERSION_MAJOR}.${VTKm_VERSION_MINOR}")
49
50
51
52
53
54
55
56
endif()
if (NOT DEFINED VTKm_INSTALL_LIB_DIR)
  set(VTKm_INSTALL_LIB_DIR "lib")
endif()
if (NOT DEFINED VTKm_INSTALL_BIN_DIR)
  set(VTKm_INSTALL_BIN_DIR "bin")
endif()
if (NOT DEFINED VTKm_INSTALL_CMAKE_MODULE_DIR)
57
  set(VTKm_INSTALL_CMAKE_MODULE_DIR "share/vtkm-${VTKm_VERSION_MAJOR}.${VTKm_VERSION_MINOR}/cmake")
58
endif()
59

60
set(VTKm_BINARY_INCLUDE_DIR "${VTKm_BINARY_DIR}/include")
61

62
set(VTKm_EXPORT_NAME "VTKmTargets")
63

64
65
66
# Setup default build types
include(VTKmBuildType)

67
# include some vtkm-specific cmake code.
68
include(VTKmMacros)
69

70
71
72
73
74
75
76
77
# Create an "interface" target library. This is not a real library but rather
# holds CMake configuration that is required for CXX targets that use VTK-m
# headers. In particular, it makes sure the appropriate C++11 version is being
# used. (The cxx_constexpr and cxx_auto_type features happen to force C++11.
# Directly asking for C++11 with this interface is not supported in CMake 3.3.)
# This is also exported so that dependent CMake projects can load the same
# configuration.
add_library(vtkm INTERFACE)
78
target_compile_features(vtkm INTERFACE cxx_auto_type)
79
80
target_include_directories(vtkm INTERFACE
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
81
82
  $<BUILD_INTERFACE:${VTKm_BINARY_INCLUDE_DIR}>
  $<INSTALL_INTERFACE:${VTKm_INSTALL_INCLUDE_DIR}>
83
  )
84
85
install(TARGETS vtkm EXPORT ${VTKm_EXPORT_NAME})

86
87
88
89
# Load the base VTK-m configuration, which is required for some of the later
# config.
vtkm_configure_component_Base()
if(NOT VTKm_Base_FOUND)
90
  message(SEND_ERROR "Could not load base VTK-m component.")
91
92
endif()

93
#-----------------------------------------------------------------------------
94
95
96
# When using C++11 suport make sure you use the standard C++ extensions rather
# than compiler-specific versions of the extensions (to preserve portability).
set(CMAKE_CXX_EXTENSIONS False)
97
98
99

#-----------------------------------------------------------------------------
# Add supplemental compiler warnings, and GCC visibility support.
100
101
102
103
# include export header modules so that we can easily control symbol exporting
# VTK-m is setup by default not to export symbols unless explicitly stated.
# We prefer to only export symbols of a small set of user facing classes,
# rather than exporting all symbols. In practice we will try to not export
104
105
106
107
108
109
110
# symbols for any third party library.
option(VTKm_USE_DEFAULT_SYMBOL_VISIBILITY "Don't explicitly hide symbols from libraries." OFF)
mark_as_advanced(VTKm_USE_DEFAULT_SYMBOL_VISIBILITY)
if(NOT VTKm_USE_DEFAULT_SYMBOL_VISIBILITY)
  set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
endif()
111
include(GenerateExportHeader)
112
113
114
115
include(CMake/VTKmCompilerExtras.cmake)

#-----------------------------------------------------------------------------
# Configurable Options
116
option(VTKm_ENABLE_CUDA "Enable Cuda support" OFF)
Sujin Philip's avatar
Sujin Philip committed
117
option(VTKm_ENABLE_TBB "Enable TBB support" OFF)
118
option(VTKm_ENABLE_RENDERING "Enable rendering library" ON)
119
option(VTKm_ENABLE_TESTING "Enable VTKm Testing" ON)
Will Usher's avatar
Will Usher committed
120
option(VTKm_ENABLE_BENCHMARKS "Enable VTKm Benchmarking" OFF)
121
option(VTKm_ENABLE_OSMESA "Enable creating the OSMesa canvas" OFF)
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
122
option(VTKm_ENABLE_MPI "Enable MPI support" OFF)
123

124
125
option(VTKm_ENABLE_DOCUMENTATION "Build Doxygen documentation" OFF)
option(VTKm_ENABLE_EXAMPLES "Build examples" OFF)
126

127
128
129
130
option(VTKm_USE_DOUBLE_PRECISION
  "Use double precision for floating point calculations"
  OFF
  )
Sujin Philip's avatar
Sujin Philip committed
131
option(VTKm_USE_64BIT_IDS "Use 64-bit indices." ON)
132

133
134
135
option(VTKm_NO_ASSERT "Disable assertions in debugging builds." OFF)
mark_as_advanced(VTKm_NO_ASSERT)

136
137
138
option(BUILD_SHARED_LIBS "Build VTK-m with shared libraries" ON)
set(VTKm_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})

139
140
141
if (VTKm_ENABLE_TESTING)
  enable_testing()
  include(CTest)
142
143
  configure_file(${VTKm_SOURCE_DIR}/CTestCustom.cmake.in
    ${VTKm_BINARY_DIR}/CTestCustom.cmake @ONLY)
144
145
endif()

146
147
#-----------------------------------------------------------------------------
# Set up devices selected.
148
149
150
151
vtkm_configure_component_Serial()
if(NOT VTKm_Serial_FOUND)
  message(SEND_ERROR "Could not load serial VTK-m component.")
endif()
Sujin Philip's avatar
Sujin Philip committed
152
if (VTKm_ENABLE_TBB)
153
154
155
156
  vtkm_configure_component_TBB()
  if(NOT VTKm_TBB_FOUND)
    message(SEND_ERROR "Could not load TBB configuration. If TBB is not available, turn off VTKm_ENABLE_TBB.")
  endif()
Sujin Philip's avatar
Sujin Philip committed
157
endif (VTKm_ENABLE_TBB)
158
if (VTKm_ENABLE_CUDA)
159
160
  vtkm_configure_component_CUDA()
  if(NOT VTKm_CUDA_FOUND)
161
    message(SEND_ERROR "Could not load CUDA configuration. If CUDA is not available, turn off VTKm_ENABLE_CUDA.")
162
  endif()
163
endif (VTKm_ENABLE_CUDA)
164

165
166
167
#-----------------------------------------------------------------------------

## Set the directory where the binaries will be stored
168
set( VTKm_EXECUTABLE_OUTPUT_PATH
169
170
171
172
173
174
  ${PROJECT_BINARY_DIR}/bin
  CACHE PATH
  "Directory where all executable will be stored"
)

## Set the directory where the libraries will be stored
175
set( VTKm_LIBRARY_OUTPUT_PATH
176
  ${PROJECT_BINARY_DIR}/lib
177
178
179
180
  CACHE PATH
  "Directory where all the libraries will be stored"
)
mark_as_advanced(
181
182
  VTKm_EXECUTABLE_OUTPUT_PATH
  VTKm_LIBRARY_OUTPUT_PATH)
183
184

#-----------------------------------------------------------------------------
185
186
187
188
# Add "meta" tests that check the state of the repository
# SystemInformation prints out information about the current configuration
# CopyrightStatement checks that the copyright statement is in all source files
# SourceInBuild checks that all source files are listed in the build
189
if (VTKm_ENABLE_TESTING)
190
191
192
  add_test(NAME SystemInformation
    COMMAND ${CMAKE_COMMAND} "-DVTKm_SOURCE_DIR=${VTKm_SOURCE_DIR}" "-DVTKm_BINARY_DIR=${VTKm_BINARY_DIR}" -P "${VTKm_SOURCE_DIR}/CMake/VTKmSystemInformation.cmake"
    )
193
194
195
  add_test(NAME CopyrightStatement
    COMMAND ${CMAKE_COMMAND} "-DVTKm_SOURCE_DIR=${VTKm_SOURCE_DIR}" -P "${VTKm_SOURCE_DIR}/CMake/VTKmCheckCopyright.cmake"
    )
196
197
  add_test(NAME SourceInBuild
    COMMAND ${CMAKE_COMMAND} "-DVTKm_SOURCE_DIR=${VTKm_SOURCE_DIR}" -P "${VTKm_SOURCE_DIR}/CMake/VTKmCheckSourceInBuild.cmake"
Kenneth Moreland's avatar
Kenneth Moreland committed
198
    )
199
200
201
202
203
204
205
206
endif (VTKm_ENABLE_TESTING)

#-----------------------------------------------------------------------------
# Check basic type sizes.
include(CheckTypeSize)

check_type_size(float VTKm_SIZE_FLOAT BUILTIN_TYPES_ONLY)
check_type_size(double VTKm_SIZE_DOUBLE BUILTIN_TYPES_ONLY)
207
208
check_type_size(char VTKm_SIZE_CHAR BUILTIN_TYPES_ONLY)
check_type_size(short VTKm_SIZE_SHORT BUILTIN_TYPES_ONLY)
209
210
211
212
check_type_size(int VTKm_SIZE_INT BUILTIN_TYPES_ONLY)
check_type_size(long VTKm_SIZE_LONG BUILTIN_TYPES_ONLY)
check_type_size("long long" VTKm_SIZE_LONG_LONG BUILTIN_TYPES_ONLY)

213
214
215
216
#-----------------------------------------------------------------------------
# Find the Python interpreter, which we will use during the build process
find_package(PythonInterp)

217
218
219
#-----------------------------------------------------------------------------
# Find Pyexpander in case somebody wants to update the auto generated
# faux variadic template code
220
find_package(Pyexpander)
221

222
223
224
225
#-----------------------------------------------------------------------------
# Add subdirectories
add_subdirectory(vtkm)

226
227
#-----------------------------------------------------------------------------
# Build documentation
228
if (VTKm_ENABLE_DOCUMENTATION)
229
230
231
232
233
  include(CMake/VTKmBuildDocumentation.cmake)
  vtkm_build_documentation()
endif()

#-----------------------------------------------------------------------------
234
235
236
# Ready files for find_package
include(CMakePackageConfigHelpers)

237
238
239
240
string(REPLACE ";" " " VTKm_AVAILABLE_COMPONENTS_LIST
  "${VTKm_AVAILABLE_COMPONENTS}"
  )

241
242
243
244
245
246
247
248
249
250
set(VTKm_LOAD_COMPONENTS_COMMANDS "# Clear out old FOUND flags")
foreach(component ${VTKm_AVAILABLE_COMPONENTS})
  set(VTKm_LOAD_COMPONENTS_COMMANDS "${VTKm_LOAD_COMPONENTS_COMMANDS}
set(VTKm_${component}_FOUND)"
    )
endforeach(component)

set(VTKm_LOAD_COMPONENTS_COMMANDS "${VTKm_LOAD_COMPONENTS_COMMANDS}

# Load each component selected in find_package
251
252
foreach(comp \${VTKm_FIND_COMPONENTS})")

253
254
foreach(component ${VTKm_AVAILABLE_COMPONENTS})
  set(VTKm_LOAD_COMPONENTS_COMMANDS "${VTKm_LOAD_COMPONENTS_COMMANDS}
255
256
  if(\"${component}\" STREQUAL \${comp})
    vtkm_configure_component_${component}()
257
    if(VTKm_${component}_FOUND AND NOT VTKm_CONFIGURE_QUIET)
258
259
      message(STATUS \"Successfully loaded VTK-m component ${component}\")
    else()
260
      if(VTKm_FIND_REQUIRED_${component} AND NOT VTKm_CONFIGURE_QUIET)
261
        message(\"Could not load REQUIRED VTK-m component ${component}\")
262
      elseif(NOT VTKm_CONFIGURE_QUIET)
263
264
265
        message(STATUS \"Could not load optional VTK-m component ${component}\")
      endif()
    endif()
266
    continue()
267
268
  endif()"
    )
269
270
271
endforeach()

set(VTKm_LOAD_COMPONENTS_COMMANDS "${VTKm_LOAD_COMPONENTS_COMMANDS}
272
273
274
  if(NOT VTKm_CONFIGURE_QUIET)
    message(WARNING \"No such VTK-m component: \${comp}\")
  endif()
275
endforeach()" )
276

277
configure_package_config_file(
278
  ${VTKm_SOURCE_DIR}/CMake/VTKmConfig.cmake.in
279
280
  ${VTKm_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfig.cmake
  INSTALL_DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
281
282
283
284
285
286
  PATH_VARS
    VTKm_INSTALL_INCLUDE_DIR
    VTKm_INSTALL_CONFIG_DIR
    VTKm_INSTALL_LIB_DIR
    VTKm_INSTALL_BIN_DIR
    VTKm_INSTALL_CMAKE_MODULE_DIR
287
288
  )

289
write_basic_package_version_file(
290
  ${VTKm_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfigVersion.cmake
291
292
  VERSION ${VTKm_VERSION}
  COMPATIBILITY ExactVersion )
293
install(
294
295
296
  FILES
    ${VTKm_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfig.cmake
    ${VTKm_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfigVersion.cmake
297
298
299
  DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
  )

300
301
302
303
304
305
306
307
308
309
310
311
312
# Install the readme and license files.
install(FILES ${VTKm_SOURCE_DIR}/README.md
  DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
  RENAME VTKmREADME.md
  )
install(FILES ${VTKm_SOURCE_DIR}/LICENSE.txt
  DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
  RENAME VTKmLICENSE.txt
  )

# Install helper configure files.
install(
  FILES
313
    ${VTKm_SOURCE_DIR}/CMake/FindEGL.cmake
314
    ${VTKm_SOURCE_DIR}/CMake/FindGLEW.cmake
315
316
    ${VTKm_SOURCE_DIR}/CMake/FindGLFW.cmake
    ${VTKm_SOURCE_DIR}/CMake/FindMESA.cmake
317
318
    ${VTKm_SOURCE_DIR}/CMake/FindTBB.cmake
    ${VTKm_SOURCE_DIR}/CMake/FindThrust.cmake
319
320
321
  DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR}
  )

322
323
324
# Install support files.
install(
  FILES
325
    ${VTKm_SOURCE_DIR}/CMake/VTKmMacros.cmake
326
    ${VTKm_SOURCE_DIR}/CMake/VTKmConfigureComponents.cmake
327
    ${VTKm_SOURCE_DIR}/CMake/VTKmCompilerOptimizations.cmake
328
    ${VTKm_SOURCE_DIR}/CMake/VTKmDetectCUDAVersion.cu
329
    ${VTKm_SOURCE_DIR}/CMake/VTKmExportHeaderTemplate.h.in
330
331
332
  DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR}
  )

333
# Create and install exports for external projects
334
export(EXPORT ${VTKm_EXPORT_NAME}
335
  FILE ${VTKm_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmTargets.cmake
336
337
  )
install(EXPORT ${VTKm_EXPORT_NAME}
338
  DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
339
340
  FILE VTKmTargets.cmake
  )
341

342
343
344
345
# Enable CPack packaging
set(CPACK_PACKAGE_DESCRIPTION_FILE ${VTKm_SOURCE_DIR}/README.md)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The VTKm Toolkit")
set(CPACK_PACKAGE_NAME "VTKm")
346
347
348
set(CPACK_PACKAGE_VERSION_MAJOR ${VTKm_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VTKm_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VTKm_VERSION_PATCH})
349
350
351
352
set(CPACK_PACKAGE_FILE_NAME "VTKm-${VTKm_VERSION}")
set(CPACK_RESOURCE_FILE_LICENSE ${VTKm_SOURCE_DIR}/LICENSE.txt)
set(CPACK_RESOURCE_FILE_README ${VTKm_SOURCE_DIR}/README.md)
include(CPack)
353
354
355

#-----------------------------------------------------------------------------
# Build examples
356
if(VTKm_ENABLE_EXAMPLES)
357
  add_subdirectory(examples)
358
endif(VTKm_ENABLE_EXAMPLES)