CMakeLists.txt 12.8 KB
Newer Older
1
cmake_minimum_required(VERSION 3.9)
2
project(iMSTK VERSION 0.0.1 LANGUAGES C CXX)
3

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

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

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

#-----------------------------------------------------------------------------
# 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()

#-----------------------------------------------------------------------------
# Project build directories
#-----------------------------------------------------------------------------
36 37 38 39 40 41 42 43 44 45 46 47
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()
48 49 50 51 52

#-----------------------------------------------------------------------------
# Project install directories
#-----------------------------------------------------------------------------
if(APPLE)
53
  set(${PROJECT_NAME}_INSTALL_ROOT "${${PROJECT_NAME}_MAIN_PROJECT_APPLICATION_NAME}.app/Contents") # Set to create Bundle
54
else()
55
  set(${PROJECT_NAME}_INSTALL_ROOT ".")
56
endif()
57 58 59 60
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}")
61 62 63 64

#-----------------------------------------------------------------------------
# C++11 Support
#-----------------------------------------------------------------------------
65 66 67
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
68

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

78 79 80 81 82
#-----------------------------------------------------------------------------
# Options
#-----------------------------------------------------------------------------
option(BUILD_EXAMPLES "Build iMSTK examples" ON)

83
#-----------------------------------------------------------------------------
84
# SUPERBUILD
85
#-----------------------------------------------------------------------------
86
option(${PROJECT_NAME}_SUPERBUILD "Build ${PROJECT_NAME} and the projects it depends on." ON)
87

88
if(${PROJECT_NAME}_SUPERBUILD)
89

90 91 92 93 94 95 96 97
  #-----------------------------------------------------------------------------
  # 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()
98

99
  option(${PROJECT_NAME}_USE_Uncrustify "Use Uncrustify as a code style beautifier." ON)
100 101 102
  if(${PROJECT_NAME}_USE_Uncrustify)
    imstk_define_dependency(Uncrustify)
  endif()
103

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

106 107
  imstk_define_dependency(glm)

108
  if(${PROJECT_NAME}_USE_Vulkan)
109
    imstk_define_dependency(glfw)
110 111 112
    imstk_define_dependency(gli)
  endif()

113 114 115 116 117 118
  option(${PROJECT_NAME}_ENABLE_VR "Allow the usage of VR rendering." OFF)

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

119 120 121 122 123
  if(WIN32)
    imstk_define_dependency(PThreads)
    imstk_define_dependency(Libusb) #for VRPN
    imstk_define_dependency(FTD2XX) #for LibNiFalcon
  endif()
124

125
  imstk_define_dependency(Assimp)
126 127 128 129 130 131 132
  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)
133
  imstk_define_dependency(imgui)
134
  imstk_define_dependency(tbb)
135 136 137

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

144 145 146 147 148 149 150 151 152 153
  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)

154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
  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
  #-----------------------------------------------------------------------------
173 174 175 176 177
  # 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)
178

179
  return()
180

181 182 183
endif()

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

198 199 200 201
# Assimp
find_package( Assimp REQUIRED )
include_directories( ${Assimp_INCLUDE_DIRS} )

202
# glm
203
find_package( glm )
204 205
include_directories( ${glm_INCLUDE_DIR} )

206 207
if( ${PROJECT_NAME}_USE_Vulkan )
  # glfw
208
  find_package( glfw )
209 210 211
  include_directories( ${glfw_INCLUDE_DIR} )

  # gli
212
  find_package( gli )
213 214 215
  include_directories( ${gli_INCLUDE_DIR} )
endif()

216 217
if(${PROJECT_NAME}_ENABLE_VR)
  add_definitions( -DiMSTK_ENABLE_VR )
218
  find_package( openvr REQUIRED )
219 220 221 222
else()
  remove_definitions( -DiMSTK_ENABLE_VR )
endif()

223 224
# g3log
find_package( g3log REQUIRED )
225
include_directories( ${g3log_INCLUDE_DIR} )
226

227 228 229 230
# Eigen
find_package( Eigen 3.1.2 REQUIRED )
include_directories( ${Eigen_INCLUDE_DIR} )

231 232 233 234
# imgui
find_package( imgui REQUIRED )
include_directories( ${imgui_INCLUDE_DIR} )

235 236 237 238
# SCCD
find_package( SCCD REQUIRED )
include_directories( ${SCCD_INCLUDE_DIR} )

239
# VegaFEM
240 241 242
find_package( VegaFEM REQUIRED CONFIG )

# VTK
243
find_package( VTK REQUIRED CONFIG )
244
include( ${VTK_USE_FILE} )
245

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

258 259 260 261 262 263 264 265 266 267 268
# 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()

269 270 271 272 273 274 275 276 277
# 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()

278
# SFML
279 280 281 282 283 284
if(APPLE OR LINUX)
  remove_definitions( -DiMSTK_AUDIO_ENABLED )
else()
  find_package( SFML REQUIRED )
  add_definitions( -DiMSTK_AUDIO_ENABLED )
endif()
285

286 287 288 289 290 291 292 293
# Google Test
if(BUILD_TESTING)
  find_package( GoogleTest REQUIRED )
  include_directories(${GoogleTest_INCLUDE_DIRS})
  find_package( GoogleMock REQUIRED )
  include_directories(${GoogleMock_INCLUDE_DIRS})
endif()

294
# TBB
295 296
# 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)
297 298 299 300
find_package(tbb REQUIRED)
add_definitions(${TBB_DEFINITIONS})
include_directories( ${TBB_INCLUDE_DIRS} )

301
# External data
302
if(BUILD_TESTING OR BUILD_EXAMPLES)
303 304 305
  include(imstkExternalData)
endif()

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

326 327 328
#--------------------------------------------------------------------------
# Export Targets
#--------------------------------------------------------------------------
329 330 331
string(TOLOWER "${PROJECT_NAME}" PROJECT_NAMESPACE)
set(PROJECT_NAMESPACE "${PROJECT_NAMESPACE}::")

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

347
install(EXPORT ${PROJECT_NAME}_TARGETS
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
  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
363
  )
364 365 366 367

#--------------------------------------------------------------------------
# Add Examples subdirectories
#--------------------------------------------------------------------------
368 369 370
if(BUILD_EXAMPLES)
    add_subdirectory(Examples)
endif()
371

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

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