CMakeLists.txt 12.1 KB
Newer Older
1 2 3 4
##============================================================================
##  Copyright (c) Kitware, Inc.
##  All rights reserved.
##  See LICENSE.txt for details.
5
##
6 7 8 9 10
##  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.
##============================================================================

11
# If you want CUDA support, you will need to have CMake 3.9 on Linux/OSX.
12 13
# We require CMake 3.11 with the MSVC generator as the $<COMPILE_LANGUAGE:>
# generator expression is not supported on older versions.
14
cmake_minimum_required(VERSION 3.8...3.14 FATAL_ERROR)
15 16
project (VTKm)

17
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
18
  cmake_minimum_required(VERSION 3.11...3.14 FATAL_ERROR)
19 20
endif()

21 22 23 24 25 26 27 28 29 30 31 32 33 34
# 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")

35
if (NOT DEFINED VTKm_INSTALL_INCLUDE_DIR)
36
  set(VTKm_INSTALL_INCLUDE_DIR "include/vtkm-${VTKm_VERSION_MAJOR}.${VTKm_VERSION_MINOR}")
37 38
endif()
if (NOT DEFINED VTKm_INSTALL_CONFIG_DIR)
39
  set(VTKm_INSTALL_CONFIG_DIR "lib/cmake/vtkm-${VTKm_VERSION_MAJOR}.${VTKm_VERSION_MINOR}")
40 41 42 43 44 45 46
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()
47 48 49
if (NOT DEFINED VTKm_INSTALL_SHARE_DIR)
  set(VTKm_INSTALL_SHARE_DIR "share/vtkm-${VTKm_VERSION_MAJOR}.${VTKm_VERSION_MINOR}")
endif()
50
if (NOT DEFINED VTKm_INSTALL_CMAKE_MODULE_DIR)
51
  set(VTKm_INSTALL_CMAKE_MODULE_DIR "${VTKm_INSTALL_SHARE_DIR}/cmake")
52
endif()
53 54
if (NOT DEFINED VTKm_BUILD_CMAKE_BASE_DIR)
  set(VTKm_BUILD_CMAKE_BASE_DIR "${VTKm_BINARY_DIR}")
55 56 57 58 59 60 61 62 63
endif()
if(NOT DEFINED VTKm_EXECUTABLE_OUTPUT_PATH)
  ## Set the directory where the binaries will be stored
  set(VTKm_EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
endif()
if(NOT DEFINED VTKm_LIBRARY_OUTPUT_PATH)
  ## Set the directory where the libraries will be stored
  set(VTKm_LIBRARY_OUTPUT_PATH  ${PROJECT_BINARY_DIR}/lib)
endif()
64 65
if (NOT DEFINED VTKm_EXPORT_NAME)
  set(VTKm_EXPORT_NAME "VTKmTargets")
66 67
endif()

68 69
set(VTKm_BINARY_INCLUDE_DIR "${VTKm_BINARY_DIR}/include")

70
#-----------------------------------------------------------------------------
71 72
# vtkm_option(variable doc [initial])
#   Provides an option if it is not already defined.
73
# This can be replaced when CMake 3.13 is our cmake_minimum_required
74 75 76 77 78 79
macro (vtkm_option variable)
  if (NOT DEFINED "${variable}")
    option("${variable}" ${ARGN})
  endif ()
endmacro ()

80
# Configurable Options
81 82
vtkm_option(VTKm_ENABLE_CUDA "Enable Cuda support" OFF)
vtkm_option(VTKm_ENABLE_TBB "Enable TBB support" OFF)
83
vtkm_option(VTKm_ENABLE_OPENMP "Enable OpenMP support" OFF)
84 85 86
vtkm_option(VTKm_ENABLE_RENDERING "Enable rendering library" ON)
vtkm_option(VTKm_ENABLE_TESTING "Enable VTKm Testing" ON)
vtkm_option(VTKm_ENABLE_BENCHMARKS "Enable VTKm Benchmarking" OFF)
87
vtkm_option(VTKm_ENABLE_LOGGING "Enable VTKm Logging" OFF)
88
vtkm_option(VTKm_ENABLE_MPI "Enable MPI support" OFF)
89

90 91
vtkm_option(VTKm_ENABLE_DOCUMENTATION "Build Doxygen documentation" OFF)
vtkm_option(VTKm_ENABLE_EXAMPLES "Build examples" OFF)
92

93 94
vtkm_option(VTKm_USE_DOUBLE_PRECISION "Use double precision for floating point calculations" OFF)
vtkm_option(VTKm_USE_64BIT_IDS "Use 64-bit indices." ON)
95

96 97 98
# When VTK-m is embedded into larger projects they may desire to turn off
# VTK-m internal assert checks when in debug mode to improve debug runtime
# performance.
99
vtkm_option(VTKm_NO_ASSERT "Disable assertions in debugging builds." OFF)
100 101 102 103

# When VTK-m is embedded into larger projects that wish to make end user
# applications they want to only install libraries and don't want CMake/headers
# installed.
104
vtkm_option(VTKm_INSTALL_ONLY_LIBRARIES "install only vtk-m libraries and no headers" OFF)
105

106 107 108 109 110
# 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. This flag is added so that consumers
# which require static builds can force all symbols on, which is something
# VTK does.
111
vtkm_option(VTKm_USE_DEFAULT_SYMBOL_VISIBILITY "Don't explicitly hide symbols from libraries." OFF)
112

Ben Boeckel's avatar
Ben Boeckel committed
113
vtkm_option(BUILD_SHARED_LIBS "Build VTK-m with shared libraries" ON)
114 115
set(VTKm_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})

116 117 118
# This flag can be used to prevent VTK-m from exporting its warning flags in its
# build interface. This is useful when building VTK-m as a thirdparty library
# and the warnings are too strict for the parent project.
luz.paz's avatar
luz.paz committed
119
vtkm_option(VTKm_ENABLE_DEVELOPER_FLAGS "Enable compiler flags that are useful while developing VTK-m" ON)
120

121 122 123 124
mark_as_advanced(
  VTKm_NO_ASSERT
  VTKm_INSTALL_ONLY_LIBRARIES
  VTKm_USE_DEFAULT_SYMBOL_VISIBILITY
125
  VTKm_ENABLE_DEVELOPER_FLAGS
126
  )
127

128
#-----------------------------------------------------------------------------
129 130
# When using C++11 support make sure you use the standard C++ extensions rather
# than compiler-specific versions of the extensions (to preserve portability).
131
set(CMAKE_CXX_EXTENSIONS Off)
132

133 134 135
# Setup default build types
include(VTKmBuildType)

136 137 138
# Include the vtk-m wrappers
include(VTKmWrappers)

139 140 141
# Create vtkm_compiler_flags library. This is an interface library that
# holds all the C++ compiler flags that are needed for consumers and
# when building VTK-m.
142
include(VTKmCompilerFlags)
143

144

145
#-----------------------------------------------------------------------------
146
if (VTKm_ENABLE_TESTING)
147
  enable_testing()
148 149 150 151 152 153 154 155 156 157
  # Only include CTest if it has not been included by a superproject. The
  # variable DEFAULT_CTEST_CONFIGURATION_TYPE is a non-cached variable set by
  # CTest.cmake, so we'll use that to determine if it's already included.
  if(NOT DEFINED DEFAULT_CTEST_CONFIGURATION_TYPE)
    include(CTest)
    # Mark this as advanced to avoid confusion, since we actually rely on
    # VTKm_ENABLE_TESTING.
    mark_as_advanced(BUILD_TESTING)
  endif()

158 159
  configure_file(${VTKm_SOURCE_DIR}/CTestCustom.cmake.in
    ${VTKm_BINARY_DIR}/CTestCustom.cmake @ONLY)
160 161 162

  #-----------------------------------------------------------------------------
  # Find the Python interpreter, which we will use during the build process
163
  find_package(PythonInterp QUIET)
164 165 166 167

  #-----------------------------------------------------------------------------
  # Find Pyexpander in case somebody wants to update the auto generated
  # faux variadic template code
168
  find_package(Pyexpander QUIET)
169 170 171 172 173

  #-----------------------------------------------------------------------------
  # Setup compiler flags for dynamic analysis if needed
  include(VTKmCompilerDynamicAnalysisFlags)
  vtkm_check_sanitizer_build()
174 175 176 177 178 179 180 181 182 183 184
endif (VTKm_ENABLE_TESTING)

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

check_type_size(long VTKm_SIZE_LONG BUILTIN_TYPES_ONLY)
check_type_size("long long" VTKm_SIZE_LONG_LONG BUILTIN_TYPES_ONLY)

#-----------------------------------------------------------------------------
# Add subdirectories
185 186 187
if(VTKm_ENABLE_MPI)
  # This `if` is temporary and will be removed once `diy` supports building
  # without MPI.
188 189 190
  if (NOT MPI_C_FOUND)
    find_package(MPI ${VTKm_FIND_PACKAGE_QUIETLY})
  endif()
191
endif()
192

193 194
add_subdirectory(vtkm)

195 196
#-----------------------------------------------------------------------------
# Build documentation
197
if (VTKm_ENABLE_DOCUMENTATION)
198 199 200 201
  include(CMake/VTKmBuildDocumentation.cmake)
endif()

#-----------------------------------------------------------------------------
202 203 204
# Ready files for find_package
include(CMakePackageConfigHelpers)

205
configure_package_config_file(
206
  ${VTKm_SOURCE_DIR}/CMake/VTKmConfig.cmake.in
207
  ${VTKm_BUILD_CMAKE_BASE_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfig.cmake
208
  INSTALL_DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
209 210 211 212 213 214
  PATH_VARS
    VTKm_INSTALL_INCLUDE_DIR
    VTKm_INSTALL_CONFIG_DIR
    VTKm_INSTALL_LIB_DIR
    VTKm_INSTALL_BIN_DIR
    VTKm_INSTALL_CMAKE_MODULE_DIR
215 216
  )

217
write_basic_package_version_file(
218
  ${VTKm_BUILD_CMAKE_BASE_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfigVersion.cmake
219 220
  VERSION ${VTKm_VERSION}
  COMPATIBILITY ExactVersion )
221

222 223 224
if(NOT VTKm_INSTALL_ONLY_LIBRARIES)
  install(
    FILES
225 226
      ${VTKm_BUILD_CMAKE_BASE_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfig.cmake
      ${VTKm_BUILD_CMAKE_BASE_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfigVersion.cmake
227 228
    DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
    )
229

230 231
  # Install the readme and license files.
  install(FILES ${VTKm_SOURCE_DIR}/README.md
232
    DESTINATION ${VTKm_INSTALL_SHARE_DIR}
233 234 235
    RENAME VTKmREADME.md
    )
  install(FILES ${VTKm_SOURCE_DIR}/LICENSE.txt
236
    DESTINATION ${VTKm_INSTALL_SHARE_DIR}
237 238
    RENAME VTKmLICENSE.txt
    )
239

240 241 242 243 244
  # Install helper configure files.
  install(
    FILES
      ${VTKm_SOURCE_DIR}/CMake/FindTBB.cmake
      ${VTKm_SOURCE_DIR}/CMake/FindOpenGL.cmake
245
      ${VTKm_SOURCE_DIR}/CMake/FindOpenMP.cmake
246 247
    DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR}
    )
248

249 250 251
  # Install support files.
  install(
    FILES
252
      ${VTKm_SOURCE_DIR}/CMake/VTKmCPUVectorization.cmake
253
      ${VTKm_SOURCE_DIR}/CMake/VTKmDetectCUDAVersion.cu
254
      ${VTKm_SOURCE_DIR}/CMake/VTKmDeviceAdapters.cmake
255
      ${VTKm_SOURCE_DIR}/CMake/VTKmExportHeaderTemplate.h.in
256 257
      ${VTKm_SOURCE_DIR}/CMake/VTKmRenderingContexts.cmake
      ${VTKm_SOURCE_DIR}/CMake/VTKmWrappers.cmake
258 259 260 261 262
    DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR}
    )

  # Create and install exports for external projects
  export(EXPORT ${VTKm_EXPORT_NAME}
263
    FILE ${VTKm_BUILD_CMAKE_BASE_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmTargets.cmake
264 265 266 267 268 269
    )
  install(EXPORT ${VTKm_EXPORT_NAME}
    DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
    FILE VTKmTargets.cmake
    )
endif()
270

271 272 273 274 275 276 277 278 279 280 281 282 283 284
vtkm_option(VTKm_ENABLE_CPACK "Enable CPack packaging of VTKm" ON)
if (VTKm_ENABLE_CPACK)
  # 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")
  set(CPACK_PACKAGE_VERSION_MAJOR ${VTKm_VERSION_MAJOR})
  set(CPACK_PACKAGE_VERSION_MINOR ${VTKm_VERSION_MINOR})
  set(CPACK_PACKAGE_VERSION_PATCH ${VTKm_VERSION_PATCH})
  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)
endif ()
285

286 287 288 289 290 291
#-----------------------------------------------------------------------------
#add the benchmarking folder
if(VTKm_ENABLE_BENCHMARKS)
    add_subdirectory(benchmarking)
endif()

292 293 294 295 296 297 298 299 300 301
#-----------------------------------------------------------------------------
if (VTKm_ENABLE_TESTING)

  #-----------------------------------------------------------------------------
  # 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
  # SourceInInstall checks that all source files are installed in the build
  add_test(NAME SystemInformation
302
    COMMAND ${CMAKE_COMMAND} "-DVTKm_SOURCE_DIR=${VTKm_SOURCE_DIR}" "-DVTKm_BINARY_DIR=${VTKm_BINARY_DIR}" -P "${VTKm_SOURCE_DIR}/CMake/testing/VTKmSystemInformation.cmake"
303 304 305 306 307 308 309
    )
  add_test(NAME CopyrightStatement
    COMMAND ${CMAKE_COMMAND} "-DVTKm_SOURCE_DIR=${VTKm_SOURCE_DIR}" -P "${VTKm_SOURCE_DIR}/CMake/VTKmCheckCopyright.cmake"
    )
  # increase timeout since on some machines CopyrightStatement test takes a long time.
  set_tests_properties(CopyrightStatement PROPERTIES TIMEOUT 300)

310 311 312 313
  # Setup the infrastructure to allow VTK-m to run tests against a temporary
  # installed version of VTK-m.
  include(testing/VTKmTestInstall)
  vtkm_test_install()
314
endif()
315 316 317 318 319 320

#-----------------------------------------------------------------------------
# Build examples
if(VTKm_ENABLE_EXAMPLES)
  add_subdirectory(examples)
endif(VTKm_ENABLE_EXAMPLES)