CMakeLists.txt 13.4 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.
##
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
##
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
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()
56 57 58
if (NOT DEFINED VTKm_INSTALL_SHARE_DIR)
  set(VTKm_INSTALL_SHARE_DIR "share/vtkm-${VTKm_VERSION_MAJOR}.${VTKm_VERSION_MINOR}")
endif()
59
if (NOT DEFINED VTKm_INSTALL_CMAKE_MODULE_DIR)
60
  set(VTKm_INSTALL_CMAKE_MODULE_DIR "${VTKm_INSTALL_SHARE_DIR}/cmake")
61
endif()
62

63
set(VTKm_BINARY_INCLUDE_DIR "${VTKm_BINARY_DIR}/include")
64

65
set(VTKm_EXPORT_NAME "VTKmTargets")
66

67 68 69
# Setup default build types
include(VTKmBuildType)

70
# include some vtkm-specific cmake code.
71
include(VTKmMacros)
72

73 74 75 76 77 78 79 80
# 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)
81
target_compile_features(vtkm INTERFACE cxx_auto_type)
82 83
target_include_directories(vtkm INTERFACE
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
84 85
  $<BUILD_INTERFACE:${VTKm_BINARY_INCLUDE_DIR}>
  $<INSTALL_INTERFACE:${VTKm_INSTALL_INCLUDE_DIR}>
86
  )
87 88
install(TARGETS vtkm EXPORT ${VTKm_EXPORT_NAME})

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

96
#-----------------------------------------------------------------------------
97 98 99
# 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)
100 101 102

#-----------------------------------------------------------------------------
# Add supplemental compiler warnings, and GCC visibility support.
103 104 105 106
# 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
107
# symbols for any third party library.
108
vtkm_option(VTKm_USE_DEFAULT_SYMBOL_VISIBILITY "Don't explicitly hide symbols from libraries." OFF)
109 110 111 112 113
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()
114
include(GenerateExportHeader)
115 116 117 118
include(CMake/VTKmCompilerExtras.cmake)

#-----------------------------------------------------------------------------
# Configurable Options
119 120 121 122 123 124 125 126 127 128 129 130
vtkm_option(VTKm_ENABLE_CUDA "Enable Cuda support" OFF)
vtkm_option(VTKm_ENABLE_TBB "Enable TBB support" OFF)
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)
vtkm_option(VTKm_ENABLE_OSMESA "Enable creating the OSMesa canvas" OFF)
vtkm_option(VTKm_ENABLE_MPI "Enable MPI support" OFF)

vtkm_option(VTKm_ENABLE_DOCUMENTATION "Build Doxygen documentation" OFF)
vtkm_option(VTKm_ENABLE_EXAMPLES "Build examples" OFF)

vtkm_option(VTKm_USE_DOUBLE_PRECISION
131 132 133
  "Use double precision for floating point calculations"
  OFF
  )
134
vtkm_option(VTKm_USE_64BIT_IDS "Use 64-bit indices." ON)
135

136
vtkm_option(VTKm_NO_ASSERT "Disable assertions in debugging builds." OFF)
137 138
mark_as_advanced(VTKm_NO_ASSERT)

139
vtkm_option(BUILD_SHARED_LIBS "Build VTK-m with shared libraries" ON)
140 141
set(VTKm_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})

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

149 150
#-----------------------------------------------------------------------------
# Set up devices selected.
151 152 153 154
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
155
if (VTKm_ENABLE_TBB)
156 157 158 159
  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
160
endif (VTKm_ENABLE_TBB)
161
if (VTKm_ENABLE_CUDA)
162 163
  vtkm_configure_component_CUDA()
  if(NOT VTKm_CUDA_FOUND)
164
    message(SEND_ERROR "Could not load CUDA configuration. If CUDA is not available, turn off VTKm_ENABLE_CUDA.")
165
  endif()
166
endif (VTKm_ENABLE_CUDA)
167

168 169 170
#-----------------------------------------------------------------------------

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

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

#-----------------------------------------------------------------------------
188 189 190 191
# 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
192
if (VTKm_ENABLE_TESTING)
193 194 195
  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"
    )
196 197 198
  add_test(NAME CopyrightStatement
    COMMAND ${CMAKE_COMMAND} "-DVTKm_SOURCE_DIR=${VTKm_SOURCE_DIR}" -P "${VTKm_SOURCE_DIR}/CMake/VTKmCheckCopyright.cmake"
    )
199 200
  add_test(NAME SourceInBuild
    COMMAND ${CMAKE_COMMAND} "-DVTKm_SOURCE_DIR=${VTKm_SOURCE_DIR}" -P "${VTKm_SOURCE_DIR}/CMake/VTKmCheckSourceInBuild.cmake"
201
    )
202 203 204 205 206 207 208 209
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)
210 211
check_type_size(char VTKm_SIZE_CHAR BUILTIN_TYPES_ONLY)
check_type_size(short VTKm_SIZE_SHORT BUILTIN_TYPES_ONLY)
212 213 214 215
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)

216 217 218 219
#-----------------------------------------------------------------------------
# Find the Python interpreter, which we will use during the build process
find_package(PythonInterp)

220 221 222
#-----------------------------------------------------------------------------
# Find Pyexpander in case somebody wants to update the auto generated
# faux variadic template code
223
find_package(Pyexpander QUIET)
224

225 226 227 228
#-----------------------------------------------------------------------------
# Add subdirectories
add_subdirectory(vtkm)

229 230
#-----------------------------------------------------------------------------
# Build documentation
231
if (VTKm_ENABLE_DOCUMENTATION)
232 233 234 235 236
  include(CMake/VTKmBuildDocumentation.cmake)
  vtkm_build_documentation()
endif()

#-----------------------------------------------------------------------------
237 238 239
# Ready files for find_package
include(CMakePackageConfigHelpers)

240 241 242 243
string(REPLACE ";" " " VTKm_AVAILABLE_COMPONENTS_LIST
  "${VTKm_AVAILABLE_COMPONENTS}"
  )

244 245 246 247 248 249 250 251 252 253
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
254 255
foreach(comp \${VTKm_FIND_COMPONENTS})")

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

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

280 281 282 283
if (NOT DEFINED VTKm_BUILD_CMAKE_BASE_DIR)
  set(VTKm_BUILD_CMAKE_BASE_DIR "${VTKm_BINARY_DIR}")
endif ()

284
configure_package_config_file(
285
  ${VTKm_SOURCE_DIR}/CMake/VTKmConfig.cmake.in
286
  ${VTKm_BUILD_CMAKE_BASE_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfig.cmake
287
  INSTALL_DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
288 289 290 291 292 293
  PATH_VARS
    VTKm_INSTALL_INCLUDE_DIR
    VTKm_INSTALL_CONFIG_DIR
    VTKm_INSTALL_LIB_DIR
    VTKm_INSTALL_BIN_DIR
    VTKm_INSTALL_CMAKE_MODULE_DIR
294 295
  )

296
write_basic_package_version_file(
297
  ${VTKm_BUILD_CMAKE_BASE_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfigVersion.cmake
298 299
  VERSION ${VTKm_VERSION}
  COMPATIBILITY ExactVersion )
300
install(
301
  FILES
302 303
    ${VTKm_BUILD_CMAKE_BASE_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfig.cmake
    ${VTKm_BUILD_CMAKE_BASE_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfigVersion.cmake
304 305 306
  DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
  )

307 308
# Install the readme and license files.
install(FILES ${VTKm_SOURCE_DIR}/README.md
309
  DESTINATION ${VTKm_INSTALL_SHARE_DIR}
310 311 312
  RENAME VTKmREADME.md
  )
install(FILES ${VTKm_SOURCE_DIR}/LICENSE.txt
313
  DESTINATION ${VTKm_INSTALL_SHARE_DIR}
314 315 316 317 318 319
  RENAME VTKmLICENSE.txt
  )

# Install helper configure files.
install(
  FILES
320
    ${VTKm_SOURCE_DIR}/CMake/FindEGL.cmake
321
    ${VTKm_SOURCE_DIR}/CMake/FindGLEW.cmake
322 323
    ${VTKm_SOURCE_DIR}/CMake/FindGLFW.cmake
    ${VTKm_SOURCE_DIR}/CMake/FindMESA.cmake
324 325
    ${VTKm_SOURCE_DIR}/CMake/FindTBB.cmake
    ${VTKm_SOURCE_DIR}/CMake/FindThrust.cmake
326 327 328
  DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR}
  )

329 330 331
# Install support files.
install(
  FILES
332
    ${VTKm_SOURCE_DIR}/CMake/VTKmMacros.cmake
333
    ${VTKm_SOURCE_DIR}/CMake/VTKmConfigureComponents.cmake
334
    ${VTKm_SOURCE_DIR}/CMake/VTKmCompilerOptimizations.cmake
335
    ${VTKm_SOURCE_DIR}/CMake/VTKmDetectCUDAVersion.cu
336
    ${VTKm_SOURCE_DIR}/CMake/VTKmExportHeaderTemplate.h.in
337 338 339
  DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR}
  )

340
# Create and install exports for external projects
341
export(EXPORT ${VTKm_EXPORT_NAME}
342
  FILE ${VTKm_BUILD_CMAKE_BASE_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmTargets.cmake
343 344
  )
install(EXPORT ${VTKm_EXPORT_NAME}
345
  DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
346 347
  FILE VTKmTargets.cmake
  )
348

349 350 351 352
# 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")
353 354 355
set(CPACK_PACKAGE_VERSION_MAJOR ${VTKm_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VTKm_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VTKm_VERSION_PATCH})
356 357 358 359
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)
360 361 362

#-----------------------------------------------------------------------------
# Build examples
363
if(VTKm_ENABLE_EXAMPLES)
364
  add_subdirectory(examples)
365
endif(VTKm_ENABLE_EXAMPLES)