CMakeLists.txt 16.6 KB
Newer Older
1 2
cmake_minimum_required (VERSION 2.8.11)
cmake_policy(SET CMP0020 NEW)
3 4 5
if (POLICY CMP0042)
  cmake_policy(SET CMP0042 NEW)
endif()
David Thompson's avatar
David Thompson committed
6 7 8
if (POLICY CMP0046)
  cmake_policy(SET CMP0046 NEW)
endif()
9 10 11
if (POLICY CMP0054)
  cmake_policy(SET CMP0054 OLD)
endif()
12 13 14 15 16 17

# Remove SMTKConfig.cmake at the beginning of each CMake run; each time
# a library is declared below, the file is appended and we do not want
# to keep appending over multiple runs.
file(REMOVE SMTKConfig.cmake)

18 19
project(SMTK)

20 21 22
################################################################################
# SMTK version number

23 24
set(SMTK_VERSION_MAJOR 1)
set(SMTK_VERSION_MINOR 0)
25 26 27 28 29 30
set(SMTK_VERSION_PATCH 0)
set(SMTK_VERSION
  "${SMTK_VERSION_MAJOR}.${SMTK_VERSION_MINOR}.${SMTK_VERSION_PATCH}")
#
################################################################################

31 32 33
#Add our Cmake directory to the module search path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${SMTK_SOURCE_DIR}/CMake)

34 35 36 37 38
# Include GNU install directory module to detect where to install
# files on Linux/Unix systems (e.g., lib vs lib64)
include(GNUInstallDirs)

# Include export header so that we can easily expose symbols
39 40 41
# in dynamic libraries
include(GenerateExportHeader)

42
# Include cmake code that builds automatic header tests,
43 44
# makes targets for unit tests, and makes it easier to generate
# export install targets
45
include(SMTKMacros)
46

47 48 49 50
# include cmake code that allows for easier testing of SMTK classes
# and also provides helpers around create_test_sourcelist
include(CMake/SMTKTestingMacros.cmake)

51
# Include mechanism for determining shared and weak pointer support
52
include(SharedPtr)
53 54

# Include mechanism for determining function and bind support
55
include(Function)
56 57

# Include mechanism for determining how to specialize hash<X>()
58
include(FindHashFunctor)
59

David Thompson's avatar
David Thompson committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
################################################################################
## Paths for output

# Set the directory where the binaries will be stored
set(EXECUTABLE_OUTPUT_PATH
  ${PROJECT_BINARY_DIR}/bin
  CACHE PATH
  "Directory where all executable will be stored"
)

# Set the directory where the libraries will be stored
set(LIBRARY_OUTPUT_PATH
  ${PROJECT_BINARY_DIR}/lib
  CACHE PATH
  "Directory where all the libraries will be stored"
)

mark_as_advanced(
  EXECUTABLE_OUTPUT_PATH
  LIBRARY_OUTPUT_PATH
)

82 83 84 85 86 87
################################################################################
# Options that the user controls
################################################################################
option(BUILD_SHARED_LIBS "Build SMTK using shared libraries" OFF)
option(SMTK_NO_SYSTEM_BOOST "Allow boost to search for system installed boost" ON)
# Option to build Qt ui compoments for attributes
88 89
option(SMTK_ENABLE_TESTING "Enable Testing" ON)
option(SMTK_ENABLE_PYTHON_WRAPPING "Build Python Wrappings using Shiboken" OFF)
90 91 92 93 94 95 96 97 98 99 100 101
if (SMTK_ENABLE_PYTHON_WRAPPING)
  # Provide system packagers with the ability to install SMTK
  # to the system's Python site package directory. The default
  # is off so that people building relocatable bundles (such as
  # CMB) can distribute their own Python interpreter with
  # internal packages (e.g., as part of a Mac ".app" bundle).
  option(
    SMTK_INSTALL_PYTHON_TO_SITE_PACKAGES
    "Install Python modules to the interpreter's site-packages directory or into CMAKE_INSTALL_PREFIX?"
    OFF)
  mark_as_advanced(SMTK_INSTALL_PYTHON_TO_SITE_PACKAGES)
endif()
David Thompson's avatar
David Thompson committed
102 103
option(SMTK_ENABLE_QT_SUPPORT "Build Qt GUI" OFF)
option(SMTK_ENABLE_VTK_SUPPORT "Build VTK component" OFF)
104 105 106
option(SMTK_ENABLE_REMUS_SUPPORT "Build Remus components" OFF)
option(SMTK_ENABLE_PARAVIEW_SUPPORT "Build paraview plugins for model sessions" OFF)

David Thompson's avatar
David Thompson committed
107 108 109
option(SMTK_ENABLE_CGM_SESSION "Build CGM component" OFF)
option(SMTK_ENABLE_DISCRETE_SESSION "Build discrete model session components" OFF)
if (SMTK_ENABLE_VTK_SUPPORT)
110
  option(SMTK_ENABLE_EXODUS_SESSION "Build a session to Exodus-II side sets" ON)
111
endif()
112 113 114
if (SMTK_ENABLE_REMUS_SUPPORT)
  option(SMTK_ENABLE_REMOTE_SESSION "Build a session that allows modeling in a remote process." ON)
endif()
115

116
option(SMTK_USE_SYSTEM_MOAB "Use the system-installed moab?" OFF)
117 118 119 120 121
option(SMTK_USE_SYSTEM_SPARSEHASH "Use the system-installed sparsehash?" OFF)
option(SMTK_HASH_STORAGE "Use sparsehash library for primary storage?" OFF)
set(SMTK_DATA_DIR "" CACHE PATH "Path to a directory of SMTK test data.")
mark_as_advanced(SMTK_USE_SYSTEM_SPARSEHASH SMTK_HASH_STORAGE)

122 123 124 125 126 127
option(SMTK_ENABLE_DOCUMENTATION
  "Include targets for Doxygen- and Sphinx-generated documentation" OFF)
if (SMTK_ENABLE_DOCUMENTATION)
  find_package(Doxygen)
  find_package(Sphinx)
endif()
128 129 130 131 132 133 134 135 136

################################################################################
# Testing Related Settings
################################################################################

#turn on ctest if we want testing
if (SMTK_ENABLE_TESTING)
  enable_testing()
  include(CTest)
137 138 139 140
  # Do not report some warnings from generated code to the dashboard:
  configure_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/CMake/CTestCustom.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake" COPYONLY)
141

142
  # Add a test to check for the copyright statment in all source:
143 144 145 146
  add_test(NAME CopyrightStatement
    COMMAND ${CMAKE_COMMAND}
        "-DSMTK_SOURCE_DIR=${SMTK_SOURCE_DIR}"
        -P "${SMTK_SOURCE_DIR}/CMake/CheckCopyright.cmake")
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
endif()

################################################################################
# Boost Related Settings
################################################################################

# Boost is required for boost::uuids::uuid and, depending
# on the platform, for boost::shared_ptr, as well as for filesystem support.
#setup if we should use boost static libraries based on if we are
#building static or shared. We need to match boosts library type to ours so
#that we handle symbol visibility properly, plus at the same time we have
#to understand that on some platforms or builds we will only have the static
#libraries so we need to handle that when presented
if(NOT DEFINED Boost_USE_STATIC_LIBS)
  if(${BUILD_SHARED_LIBS})
    set(Boost_USE_STATIC_LIBS OFF)
  else()
    set(Boost_USE_STATIC_LIBS ON)
  endif()
endif()

#if boost is installed as a system library on a machine, we will never
#be able to set the superbuild to use the custom boost version. The solution
#is that when doing a system
set(Boost_NO_SYSTEM_PATHS ${SMTK_NO_SYSTEM_BOOST})

# List of Boost features used:
# * Filesystem
# * Scoped Ptr
# * Shared Ptr
# * String algorithms
# * UUID Generation
find_package(Boost 1.50.0
             COMPONENTS   filesystem system  REQUIRED)

#setup windows exception handling so we can compile properly with boost enabled
if(WIN32 AND MSVC)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
endif()

187 188 189
################################################################################
# Moab Related Settings
################################################################################
190 191 192 193 194 195 196 197 198

#if we are not using system moab we will build our own version through
#the thirdparty folder
if (SMTK_USE_SYSTEM_MOAB)
  # Moab is required for building smtk::mesh, as it is the default storage
  # format for meshes.
  find_package(MOAB REQUIRED)
endif()

199

200 201 202 203 204
################################################################################
# Qt Related Settings
################################################################################

#make find qt4 bring in import targets which are far nicer to use
David Thompson's avatar
David Thompson committed
205
if(SMTK_ENABLE_QT_SUPPORT)
206 207 208 209
  set(QT_USE_IMPORTED_TARGETS TRUE)
  find_package(Qt4 REQUIRED)
endif()

210 211 212 213 214
################################################################################
# NOTE: This has be before any find_package(VTK), because currently ParaView
# and VTK can NOT be easily switched due to modules and macros intermixed
################################################################################
################################################################################
215
# Look for Discrete session discrete model modules
216 217
################################################################################

David Thompson's avatar
David Thompson committed
218
if(SMTK_ENABLE_PARAVIEW_SUPPORT)
219 220 221
  find_package(ParaView REQUIRED)
endif()

222
################################################################################
223
# VTK Related Settings
224 225
################################################################################

David Thompson's avatar
David Thompson committed
226 227
if(SMTK_ENABLE_VTK_SUPPORT)
  if(SMTK_ENABLE_PARAVIEW_SUPPORT)
228 229 230 231 232 233 234 235
    find_package(ParaView REQUIRED)
  else()
    # Find the package here so environment variables are set, but
    # be careful not to include the VTK_USE_FILE until inside
    # a subdirectory that requires it; otherwise the list of include
    # paths can become too long for some platforms.
    find_package(VTK REQUIRED)
  endif()
236 237
endif()

238 239 240 241 242 243
# Maintain compatibility with older VTK/ParaView, check for the definition
# of, and define if not, VTK_RENDERING_BACKEND.
if(NOT DEFINED VTK_RENDERING_BACKEND)
  set(VTK_RENDERING_BACKEND "OpenGL")
endif()

244 245 246 247
################################################################################
# CGM Related Settings
################################################################################

David Thompson's avatar
David Thompson committed
248
if(SMTK_ENABLE_CGM_SESSION)
249
  find_package(CGM REQUIRED)
David Thompson's avatar
David Thompson committed
250
endif(SMTK_ENABLE_CGM_SESSION)
251 252 253 254 255

################################################################################
# Remus related settings
################################################################################

256
if (SMTK_ENABLE_REMUS_SUPPORT)
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
  find_package(Remus REQUIRED)
endif()

################################################################################
# Sparsehash Related Settings
################################################################################

if (SMTK_USE_SYSTEM_SPARSEHASH)
  # A system sparsehash implementation must be detected with pkgconfig:
  set(SYSTEM_SPARSEHASH_REQUIRED "REQUIRED")
  include(FindPkgConfig)
  pkg_check_modules(SPARSEHASH ${SYSTEM_SPARSEHASH_REQUIRED} libsparsehash)
else()
  set(SPARSEHASH_INCLUDE_DIRS
    "${SMTK_SOURCE_DIR}/thirdparty"
    "${SMTK_BINARY_DIR}/thirdparty")
endif()

################################################################################
# Wrapping Related Settings
################################################################################
David Thompson's avatar
David Thompson committed
278
if(SMTK_ENABLE_PYTHON_WRAPPING)
279
  include(UseShiboken)
280 281 282 283 284 285 286
  find_package(PythonInterp 2.7 REQUIRED)
  # Set up environment variables needed to import the python modules for tests.
  if (PYTHONINTERP_FOUND AND SMTK_ENABLE_TESTING)
    get_filename_component(SHIBOKEN_LIBRARY_PATH ${SHIBOKEN_LIBRARY} PATH)
    set(LIB_ENV_VAR "")
    if(APPLE AND UNIX)
      set(LIB_ENV_VAR "DYLD_FALLBACK_LIBRARY_PATH=${SHIBOKEN_LIBRARY_PATH}:${LIBRARY_OUTPUT_PATH}")
287 288 289 290 291
      if (ParaView_DIR)
        set(VTKPY_DIR "${ParaView_DIR}/lib/site-packages:${ParaView_DIR}/lib:")
      elseif (VTK_DIR)
        set(VTKPY_DIR "${VTK_DIR}/lib/site-packages:${VTK_DIR}/lib:")
      endif()
292
    elseif(UNIX)
293 294 295 296
      if (ParaView_DIR)
        # Note that ending with a colon should only be done if followed by
        # another path... be careful when changing LIB_ENV_VAR!
        set(PV_LIB_DIR "${ParaView_DIR}/lib:")
297 298 299 300
        set(VTKPY_DIR "${ParaView_DIR}/lib/site-packages:${PV_LIB_DIR}")
      elseif (VTK_DIR)
        set(PV_LIB_DIR "${VTK_DIR}/lib:")
        set(VTKPY_DIR "${VTK_DIR}/lib/site-packages:${PV_LIB_DIR}")
301 302
      endif()
      set(LIB_ENV_VAR "LD_LIBRARY_PATH=${PV_LIB_DIR}${SHIBOKEN_LIBRARY_PATH}:${LIBRARY_OUTPUT_PATH}")
303
    endif()
304
    set(SHIBOKEN_SMTK_PYTHON "${CMAKE_BINARY_DIR}")
305
    if(UNIX)
306
      set(sep ":")
307
    else() #windows
308
      set(sep ";")
309
    endif()
310 311 312 313 314 315 316 317
    execute_process(
      COMMAND "${PYTHON_EXECUTABLE}" -c "import shiboken"
      OUTPUT_QUIET
      ERROR_QUIET
      RESULT_VARIABLE rc)
    if (rc)
      set(SHIBOKEN_SMTK_PYTHON "${SHIBOKEN_SMTK_PYTHON}${sep}${SHIBOKEN_PYTHONPATH}")
    endif ()
318
  endif()
319
  #message("${LIB_ENV_VAR}   PYTHONPATH=${SHIBOKEN_SMTK_PYTHON}")
320
  #message("${SHIBOKEN_LIBRARY_PATH}")
321 322 323 324 325
endif()

################################################################################
# Determine function
################################################################################
326 327 328 329 330 331 332 333 334 335 336 337 338
determineFunctionType(
  FUNCTION_FOUND
  FUNCTION_NAMESPACE
  USING_PLACEHOLDERS
  FUNCTION_TYPE_HEADERS)

if (NOT FUNCTION_FOUND)
  message(FATAL_ERROR
    "
    SMTK requires std::function, std::tr1::function, or boost::function.
    Please examine CMake's logs to see why CMake/function*.cxx won't compile.
    ")
endif()
339 340 341 342 343 344 345

configure_file(
  ${PROJECT_SOURCE_DIR}/CMake/Function.h.in
  ${PROJECT_BINARY_DIR}/smtk/Function.h
  @ONLY)

install (FILES ${PROJECT_BINARY_DIR}/smtk/Function.h
346
  DESTINATION include/smtk/${SMTK_VERSION}/smtk)
347 348 349 350 351 352 353 354 355 356 357 358

################################################################################
# Determine shared_ptr
################################################################################
determineSharedPtrType(POINTER_NAMESPACE POINTER_TYPE_HEADERS)

configure_file(
  ${PROJECT_SOURCE_DIR}/CMake/SharedPtr.h.in
  ${PROJECT_BINARY_DIR}/smtk/SharedPtr.h
  @ONLY)

install (FILES ${PROJECT_BINARY_DIR}/smtk/SharedPtr.h
359
  DESTINATION include/smtk/${SMTK_VERSION}/smtk)
360 361 362 363 364 365 366 367 368 369 370

################################################################################
# Determine hash<X> specialization
################################################################################
find_hash_functor(SMTK_HASH_H SMTK_HASH_NS SMTK_HASH_BEGIN_NS SMTK_HASH_END_NS SMTK_HASH_SPECIALIZATION)
configure_file(
  ${PROJECT_SOURCE_DIR}/CMake/HashFunctor.h.in
  ${PROJECT_BINARY_DIR}/smtk/HashFunctor.h
  @ONLY)

install (FILES ${PROJECT_BINARY_DIR}/smtk/HashFunctor.h
371
  DESTINATION include/smtk/${SMTK_VERSION}/smtk)
372 373 374 375 376 377


################################################################################
# Save compile-time options for use by other packages
################################################################################
configure_file(
378
  ${PROJECT_SOURCE_DIR}/CMake/Options.h.in
379
  ${PROJECT_BINARY_DIR}/smtk/Options.h
380 381
  @ONLY)

382
install (FILES ${PROJECT_BINARY_DIR}/smtk/Options.h
383
  DESTINATION include/smtk/${SMTK_VERSION}/smtk)
384 385 386 387 388 389 390 391 392 393 394


################################################################################
# Install Related Settings
################################################################################

# Install rules for SMTK macros usable by external packages:
install(
  FILES
    ${PROJECT_SOURCE_DIR}/CMake/EncodeCStringFunctions.cmake
    ${PROJECT_SOURCE_DIR}/CMake/SMTKOperatorXML.cmake
395
    ${PROJECT_SOURCE_DIR}/CMake/SMTKSessionJSON.cmake
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
  DESTINATION
    lib/cmake/SMTK
)

################################################################################
# Build third party libraries
################################################################################

add_subdirectory(thirdparty)

################################################################################
# Include Dirs Settings
################################################################################

# Add the current directory so we can include files like: <smtk/internal/Test.h>
411
# Save the include directories in a variable so that VTK modules
412
# (inside the extension/vtk and bridge/discrete directories) can reuse them.
413 414 415 416 417 418 419 420 421 422
include_directories(
  "${CMAKE_CURRENT_BINARY_DIR}"
  "${CMAKE_CURRENT_SOURCE_DIR}"
  "${SPARSEHASH_INCLUDE_DIRS}"
  "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cJSON"
  "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/pugixml"
  "${Boost_INCLUDE_DIRS}"
)

################################################################################
423
# Look for Discrete session discrete model modules
424 425
################################################################################

David Thompson's avatar
David Thompson committed
426 427
if(SMTK_ENABLE_DISCRETE_SESSION)
  if(SMTK_ENABLE_PARAVIEW_SUPPORT)
428 429 430 431
    find_package(ParaView REQUIRED)
  else()
    find_package(VTK REQUIRED)
  endif()
432

David Thompson's avatar
David Thompson committed
433
  # This option is only available when SMTK_ENABLE_DISCRETE_SESSION is ON
434
  option(SMTK_ENABLE_MOAB_DISCRETE_READER "Build moab reader for discrete model" ${SMTK_USE_SYSTEM_MOAB} )
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
endif()

################################################################################
# Finally build smtk
################################################################################

add_subdirectory(smtk)

################################################################################
# Build documentation
# This also includes tutorials and other documentation that has its
# source checked against SMTK libraries, so it must come after those
# targets have been declared.
################################################################################

450 451 452
if (SMTK_ENABLE_DOCUMENTATION)
  add_subdirectory(doc)
endif()
453 454 455 456 457 458 459 460 461 462 463

################################################################################
# Install a package configuration file
#
# Setup the exports for the library when used from an installed location
install(
  EXPORT SMTK
  DESTINATION lib/cmake/SMTK
  FILE SMTKConfig.cmake
)
export(PACKAGE SMTK)