CMakeLists.txt 13 KB
Newer Older
1
cmake_minimum_required(VERSION 3.9)
2
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "Install location")
3
project(iMSTK VERSION 0.0.1 LANGUAGES C CXX)
4

5 6 7
if(UNIX AND NOT APPLE)
  set(LINUX TRUE)
endif()
8

9 10 11 12 13
#-----------------------------------------------------------------------------
# CTest/Dashboards
#-----------------------------------------------------------------------------
include(CTest)

14 15 16 17 18
#-----------------------------------------------------------------------------
# Update CMake module path & cmake dir
#-----------------------------------------------------------------------------
set(CMAKE_MODULE_PATH
    ${CMAKE_CURRENT_SOURCE_DIR}/CMake
19
    ${CMAKE_CURRENT_SOURCE_DIR}/CMake/Utilities
20 21
    ${CMAKE_MODULE_PATH}
    )
22
set(${PROJECT_NAME}_CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
23 24 25 26 27 28 29 30 31 32 33

#-----------------------------------------------------------------------------
# Set a default build type if none was specified
#-----------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message(STATUS "Setting build type to 'Debug' as none was specified.")
  set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
  # Set the possible values of build type for cmake-gui
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

34 35
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

36 37 38
#-----------------------------------------------------------------------------
# Project build directories
#-----------------------------------------------------------------------------
39 40 41 42 43 44 45 46 47 48 49 50
if(NOT DEFINED ${PROJECT_NAME}_BIN_DIR)
  set(${PROJECT_NAME}_BIN_DIR "bin")
endif()
if(NOT DEFINED ${PROJECT_NAME}_LIB_DIR)
  set(${PROJECT_NAME}_LIB_DIR "lib")
endif()
if(NOT DEFINED ${PROJECT_NAME}_INCLUDE_DIR)
  set(${PROJECT_NAME}_INCLUDE_DIR "include")
endif()
if(NOT DEFINED ${PROJECT_NAME}_SHARE_DIR)
  set(${PROJECT_NAME}_SHARE_DIR "share")
endif()
51 52 53 54 55

#-----------------------------------------------------------------------------
# Project install directories
#-----------------------------------------------------------------------------
if(APPLE)
56
  set(${PROJECT_NAME}_INSTALL_ROOT "${CMAKE_INSTALL_PREFIX}/${${PROJECT_NAME}_MAIN_PROJECT_APPLICATION_NAME}.app/Contents") # Set to create Bundle
57
else()
58
  set(${PROJECT_NAME}_INSTALL_ROOT "${CMAKE_INSTALL_PREFIX}")
59
endif()
60 61 62 63
set(${PROJECT_NAME}_INSTALL_BIN_DIR "${${PROJECT_NAME}_INSTALL_ROOT}/${${PROJECT_NAME}_BIN_DIR}/${PROJECT_NAME}-${${PROJECT_NAME}_VERSION}")
set(${PROJECT_NAME}_INSTALL_LIB_DIR "${${PROJECT_NAME}_INSTALL_ROOT}/${${PROJECT_NAME}_LIB_DIR}/${PROJECT_NAME}-${${PROJECT_NAME}_VERSION}")
set(${PROJECT_NAME}_INSTALL_INCLUDE_DIR "${${PROJECT_NAME}_INSTALL_ROOT}/${${PROJECT_NAME}_INCLUDE_DIR}/${PROJECT_NAME}-${${PROJECT_NAME}_VERSION}")
set(${PROJECT_NAME}_INSTALL_SHARE_DIR "${${PROJECT_NAME}_INSTALL_ROOT}/${${PROJECT_NAME}_SHARE_DIR}/${PROJECT_NAME}-${${PROJECT_NAME}_VERSION}")
64 65 66 67

#-----------------------------------------------------------------------------
# C++11 Support
#-----------------------------------------------------------------------------
68 69 70
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
71

72
# Prevents a compiler error for Visual Studio 15.8
73 74 75
if(MSVC)
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  add_definitions(-D_SCL_SECURE_NO_WARNINGS)
76 77 78
  if(${MSVC_VERSION} GREATER_EQUAL 1915)
    add_definitions(-D_DISABLE_EXTENDED_ALIGNED_STORAGE)
  endif()
79 80
endif()

81 82 83 84 85
#-----------------------------------------------------------------------------
# Options
#-----------------------------------------------------------------------------
option(BUILD_EXAMPLES "Build iMSTK examples" ON)

86
#-----------------------------------------------------------------------------
87
# SUPERBUILD
88
#-----------------------------------------------------------------------------
89
option(${PROJECT_NAME}_SUPERBUILD "Build ${PROJECT_NAME} and the projects it depends on." ON)
90

91
if(${PROJECT_NAME}_SUPERBUILD)
92

93 94 95 96 97 98 99 100
  #-----------------------------------------------------------------------------
  # Define External dependencies
  #-----------------------------------------------------------------------------
  macro(imstk_define_dependency extProj)
    list(APPEND ${PROJECT_NAME}_DEPENDENCIES ${extProj})
    option(USE_SYSTEM_${extProj} "Exclude ${extProj} from superbuild and use an existing build." OFF)
    mark_as_advanced(USE_SYSTEM_${extProj})
  endmacro()
101

102
  option(${PROJECT_NAME}_USE_Uncrustify "Use Uncrustify as a code style beautifier." ON)
103 104 105
  if(${PROJECT_NAME}_USE_Uncrustify)
    imstk_define_dependency(Uncrustify)
  endif()
106

107 108
  option(${PROJECT_NAME}_USE_Vulkan "Use the custom Vulkan renderer." OFF)

109 110
  imstk_define_dependency(glm)

111
  if(${PROJECT_NAME}_USE_Vulkan)
112
    imstk_define_dependency(glfw)
113 114 115
    imstk_define_dependency(gli)
  endif()

116 117 118 119 120 121
  option(${PROJECT_NAME}_ENABLE_VR "Allow the usage of VR rendering." OFF)

  if(${PROJECT_NAME}_ENABLE_VR)
    imstk_define_dependency(openvr)
  endif()

122 123 124 125 126
  if(WIN32)
    imstk_define_dependency(PThreads)
    imstk_define_dependency(Libusb) #for VRPN
    imstk_define_dependency(FTD2XX) #for LibNiFalcon
  endif()
127

128
  imstk_define_dependency(Assimp)
129 130 131 132 133 134 135
  imstk_define_dependency(g3log)
  imstk_define_dependency(Eigen)
  imstk_define_dependency(SCCD)
  imstk_define_dependency(VegaFEM)
  imstk_define_dependency(VTK)
  imstk_define_dependency(VRPN)
  imstk_define_dependency(LibNiFalcon)
136
  imstk_define_dependency(imgui)
137
  imstk_define_dependency(tbb)
138 139 140

  if(APPLE OR LINUX)
   message("Warning: Building iMSTK WITHOUT audio support!")
141
   set(${PROJECT_NAME}_AUDIO_ENABLED OFF)
142
  else()
143 144
   set(${PROJECT_NAME}_AUDIO_ENABLED "Windows OS detected: Building iMSTK with AUDIO support." ON)
    imstk_define_dependency(SFML)
145
  endif()
146

147 148 149 150 151 152 153 154 155 156
  option(${PROJECT_NAME}_USE_ODE "Build iMSTK with ODE support." OFF)
  if(${PROJECT_NAME}_USE_ODE)
    imstk_define_dependency(ODE)
  endif()

  #----------------------------------------------------
  # Setting up ODE from preinstalled directories.
  #----------------------------------------------------
  #include(CMake/External/External_ODE.cmake)

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
  if(BUILD_TESTING)
    imstk_define_dependency(GoogleTest)

    #-----------------------------------------------------------------------------
    # Allow CTest to cover Innerbuild
    #-----------------------------------------------------------------------------
    configure_file(
      "${CMAKE_CURRENT_LIST_DIR}/CMake/Utilities/imstkCTestAddInnerbuild.cmake.in"
      "${CMAKE_CURRENT_BINARY_DIR}/imstkCTestAddInnerbuild.cmake"
      @ONLY
    )
    set_directory_properties(PROPERTIES TEST_INCLUDE_FILE
      "${CMAKE_CURRENT_BINARY_DIR}/imstkCTestAddInnerbuild.cmake"
    )
  endif()

  #-----------------------------------------------------------------------------
  # Solve project dependencies
  #-----------------------------------------------------------------------------
176 177 178 179 180
  # Call CMakeLists.txt in CMake/External which will solve the dependencies
  # and add the External projects, including this one: this top-level
  # CMakeLists.txt will be called back with SUPERBUILD=OFF, to execute
  # the rest of the code below (INNERBUILD), which explains the `return`
  add_subdirectory(CMake/External)
181

182
  return()
183

184 185 186
endif()

#-----------------------------------------------------------------------------
187
#                               INNERBUILD
188 189 190
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Find external dependencies
191
#-----------------------------------------------------------------------------
192
# Uncrustify
193
find_program(Uncrustify_EXECUTABLE uncrustify)
194
include(SetupUncrustifyConfig)
195
if(Uncrustify_EXECUTABLE)
196
  include(imstkAddUncrustifyCustomTarget)
197
else(Uncrustify_EXECUTABLE)
198
  message(WARNING "uncrustify not found! Cannot run code-style test.")
199
endif(Uncrustify_EXECUTABLE)
200

201 202 203 204
# Assimp
find_package( Assimp REQUIRED )
include_directories( ${Assimp_INCLUDE_DIRS} )

205
# glm
206
find_package( glm )
207 208
include_directories( ${glm_INCLUDE_DIR} )

209 210
if( ${PROJECT_NAME}_USE_Vulkan )
  # glfw
211
  find_package( glfw )
212 213 214
  include_directories( ${glfw_INCLUDE_DIR} )

  # gli
215
  find_package( gli )
216 217 218
  include_directories( ${gli_INCLUDE_DIR} )
endif()

219 220
if(${PROJECT_NAME}_ENABLE_VR)
  add_definitions( -DiMSTK_ENABLE_VR )
221
  find_package( openvr REQUIRED )
222 223 224 225
else()
  remove_definitions( -DiMSTK_ENABLE_VR )
endif()

226 227
# g3log
find_package( g3log REQUIRED )
228
include_directories( ${g3log_INCLUDE_DIR} )
229

230 231 232 233
# Eigen
find_package( Eigen 3.1.2 REQUIRED )
include_directories( ${Eigen_INCLUDE_DIR} )

234 235 236 237
# imgui
find_package( imgui REQUIRED )
include_directories( ${imgui_INCLUDE_DIR} )

238 239 240 241
# SCCD
find_package( SCCD REQUIRED )
include_directories( ${SCCD_INCLUDE_DIR} )

242
# VegaFEM
243 244 245
find_package( VegaFEM REQUIRED CONFIG )

# VTK
246
find_package( VTK REQUIRED CONFIG )
247
include( ${VTK_USE_FILE} )
248

249 250 251
# VRPN
find_package( VRPN REQUIRED )
include_directories( ${VRPN_INCLUDE_DIRS} )
252 253
add_definitions( -DVRPN_USE_LIBNIFALCON )
if(${PROJECT_NAME}_USE_OMNI)
254
  add_definitions( -DiMSTK_USE_OPENHAPTICS )
255
  add_definitions( -DVRPN_USE_PHANTOM_SERVER )
256 257 258
else()
  remove_definitions( -DiMSTK_USE_OPENHAPTICS )
  remove_definitions( -DVRPN_USE_PHANTOM_SERVER )
259
endif()
260

261 262 263 264 265 266 267 268 269 270 271
# ODE
if(${PROJECT_NAME}_USE_ODE)
    find_package(ODE)
    # Assuming that ODE was compiled with Double precision.
    add_definitions( -DdDOUBLE ) # Needed by ODE library.
    add_definitions( -DiMSTK_USE_ODE )
else()
    remove_definitions( -DdDouble )
    remove_definitions( -DiMSTK_USE_ODE )
endif()

272 273 274 275 276 277 278 279 280
# Vulkan
if(${PROJECT_NAME}_USE_Vulkan)
  find_package( VulkanSDK )
  include_directories( ${VulkanSDK_INCLUDE_DIR} )
  add_definitions( -DiMSTK_USE_Vulkan )
else()
  remove_definitions( -DiMSTK_USE_Vulkan )
endif()

281
# SFML
282 283 284 285 286 287
if(APPLE OR LINUX)
  remove_definitions( -DiMSTK_AUDIO_ENABLED )
else()
  find_package( SFML REQUIRED )
  add_definitions( -DiMSTK_AUDIO_ENABLED )
endif()
288

289 290 291 292 293 294 295 296
# Google Test
if(BUILD_TESTING)
  find_package( GoogleTest REQUIRED )
  include_directories(${GoogleTest_INCLUDE_DIRS})
  find_package( GoogleMock REQUIRED )
  include_directories(${GoogleMock_INCLUDE_DIRS})
endif()

297
# TBB
298 299
# Define  __TBB_NO_IMPLICIT_LINKAGE so that MSVC will not always look for tbb_debug in debug mode
add_definitions(-D__TBB_NO_IMPLICIT_LINKAGE)
300 301 302 303
find_package(tbb REQUIRED)
add_definitions(${TBB_DEFINITIONS})
include_directories( ${TBB_INCLUDE_DIRS} )

304
# External data
305
if(BUILD_TESTING OR BUILD_EXAMPLES)
306 307 308
  include(imstkExternalData)
endif()

309
#--------------------------------------------------------------------------
310
# Add Source code subdirectories
311
#--------------------------------------------------------------------------
312
add_subdirectory(Source/Core)
313
add_subdirectory(Source/DataStructures)
314 315
add_subdirectory(Source/Geometry)
add_subdirectory(Source/Devices)
316 317
add_subdirectory(Source/Rendering/Materials)
add_subdirectory(Source/Rendering/GUIOverlay)
318 319 320 321
add_subdirectory(Source/Rendering)
add_subdirectory(Source/Solvers)
add_subdirectory(Source/DynamicalModels)
add_subdirectory(Source/Collision)
322
add_subdirectory(Source/Scene/SceneElements)
323 324 325
add_subdirectory(Source/Scene)
add_subdirectory(Source/SimulationManager)
add_subdirectory(Source/Constraint)
326
add_subdirectory(Source/Animation)
327
add_subdirectory(Source/apiUtilities)
328

329 330 331
#--------------------------------------------------------------------------
# Export Targets
#--------------------------------------------------------------------------
332 333 334
string(TOLOWER "${PROJECT_NAME}" PROJECT_NAMESPACE)
set(PROJECT_NAMESPACE "${PROJECT_NAMESPACE}::")

335 336 337 338 339 340
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
  "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
  VERSION ${Upstream_VERSION}
  COMPATIBILITY AnyNewerVersion
  )
341 342 343
export(EXPORT ${PROJECT_NAME}_TARGETS
  FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake
  NAMESPACE ${PROJECT_NAMESPACE}
344
  )
345 346 347 348
configure_file(${PROJECT_NAME}Config.cmake.in
  "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  @ONLY
  )
349

350
install(EXPORT ${PROJECT_NAME}_TARGETS
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
  FILE
    ${PROJECT_NAME}Targets.cmake
  NAMESPACE
    ${PROJECT_NAMESPACE}
  DESTINATION
    ${${PROJECT_NAME}_INSTALL_SHARE_DIR}
  )
install(
  FILES
    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  DESTINATION
    ${${PROJECT_NAME}_INSTALL_SHARE_DIR}
  COMPONENT
    Devel
366
  )
367 368 369 370

#--------------------------------------------------------------------------
# Add Examples subdirectories
#--------------------------------------------------------------------------
371 372 373
if(BUILD_EXAMPLES)
    add_subdirectory(Examples)
endif()
374

375 376 377
#-----------------------------------------------------------------------------
# Download the external data needed for both testing and examples
#-----------------------------------------------------------------------------
378
if(BUILD_TESTING OR BUILD_EXAMPLES)
379
    include(imstkExternalDataDownloadTest)
380 381
    imstk_add_data(${PROJECT_NAME} ${FILE_LIST})
endif()
Alexis Girault's avatar
Alexis Girault committed
382 383 384 385 386 387 388

#--------------------------------------------------------------------------
# Innerbuild dummy test
#--------------------------------------------------------------------------
add_test(
  NAME imstkDummyTest
  COMMAND ${CMAKE_COMMAND} -E echo "Success"
389
)