CMakeLists.txt 13.9 KB
Newer Older
1 2
## Version: $Id$
##
Julien Wintz's avatar
Julien Wintz committed
3
######################################################################
4 5 6 7 8
##
### Commentary:
##
######################################################################
##
Julien Wintz's avatar
Julien Wintz committed
9
### Change Log:
10
##
Julien Wintz's avatar
Julien Wintz committed
11
######################################################################
12 13
##
### Code:
Julien Wintz's avatar
Julien Wintz committed
14

15
cmake_minimum_required(VERSION 3.2.0)
16

WINTZ Julien's avatar
WINTZ Julien committed
17 18
######################################################################

Julien Wintz's avatar
Julien Wintz committed
19 20 21 22 23 24
project(dtk)

## ###################################################################
## Version setup
## ###################################################################

25
set(dtk_VERSION_MAJOR 1)
CABEL Tristan's avatar
CABEL Tristan committed
26
set(dtk_VERSION_MINOR 6)
27
set(dtk_VERSION_PATCH 7)
28
set(dtk_VERSION
29
  ${dtk_VERSION_MAJOR}.${dtk_VERSION_MINOR}.${dtk_VERSION_PATCH})
30 31 32 33 34

## ###################################################################
## Path setup
## ###################################################################

35 36
include(GNUInstallDirs)

37 38
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
39
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
Julien Wintz's avatar
Julien Wintz committed
40

41 42
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

43 44 45 46 47
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
  set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
48

49 50
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")

51 52 53 54 55 56
## #################################################################
## Generate compilation database
## #################################################################

set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")

57 58 59 60 61 62 63 64 65 66 67
## ###################################################################
## Use ccache on every platform
## ###################################################################

find_program(CCACHE_FOUND ccache)

if(CCACHE_FOUND)
  set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)

68 69 70 71 72
## #################################################################
## Install prefix
## #################################################################

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
73
  set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/install" CACHE PATH "${PROJECT_NAME} install prefix" FORCE)
74 75
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

Julien Wintz's avatar
Julien Wintz committed
76 77 78 79 80 81 82
## ###################################################################
## Build setup
## ###################################################################

set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
83
include(GenerateExportHeader)
84

85 86 87
if(UNIX)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
endif(UNIX)
Julien Wintz's avatar
Julien Wintz committed
88

89 90 91
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
92
if(CMAKE_SIZEOF_VOID_P MATCHES 8)
93 94
  set(DTK_BUILD_32 0)
  set(DTK_BUILD_64 1)
95
else(CMAKE_SIZEOF_VOID_P MATCHES 8)
96 97
  set(DTK_BUILD_32 1)
  set(DTK_BUILD_64 0)
98
endif(CMAKE_SIZEOF_VOID_P MATCHES 8)
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
99

100
if(MSVC)
101
  add_definitions("/wd4068 /wd4244 /wd4996 /wd4005 /wd4305")
102
endif(MSVC)
103

104 105 106 107
## #################################################################
## Options
## #################################################################

108 109
option(DTK_ENABLE_COVERAGE           "enable coverage report"          false)
option(DTK_COVERAGE_USE_COBERTURA    "use cobertura coverage format"    true)
WINTZ Julien's avatar
WINTZ Julien committed
110
option(DTK_ENABLE_MEMCHECK           "enable valgrind memcheck report" false)
111

112
option(DTK_BUILD_COMPOSER            "Build composer layer"    true)
113
option(DTK_BUILD_DISTRIBUTED         "Build distributed layer" true)
114 115 116 117 118 119 120 121 122 123 124
option(DTK_BUILD_SCRIPT              "Build script layer"     false)
option(DTK_BUILD_WRAPPERS            "Build wrappers"         false)
option(DTK_BUILD_WIDGETS             "Build widgets"           true)
option(DTK_BUILD_SUPPORT_CORE        "Build support layer"    false)
option(DTK_BUILD_SUPPORT_CONTAINER   "Build support layer"    false)
option(DTK_BUILD_SUPPORT_COMPOSER    "Build support layer"    false)
option(DTK_BUILD_SUPPORT_DISTRIBUTED "Build support layer"    false)
option(DTK_BUILD_SUPPORT_GUI         "Build support layer"    false)
option(DTK_BUILD_SUPPORT_MATH        "Build support layer"    false)
option(DTK_BUILD_SUPPORT_PLOT        "Build support layer"    false)
option(DTK_BUILD_SUPPORT_VR          "Build support layer"    false)
125

126 127 128
## ###################################################################
## Test setup
## ###################################################################
129 130 131

if(DTK_ENABLE_MEMCHECK)

WINTZ Julien's avatar
WINTZ Julien committed
132 133 134
  find_program(CTEST_MEMORYCHECK_COMMAND valgrind)

  set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full --xml=yes --suppressions=${CMAKE_SOURCE_DIR}/tst/gtk.suppressions  --xml-file=valgrind-%p.xml")
135 136 137 138 139 140 141 142 143 144 145 146

  function(add_test name binary)
    set(memcheck_command "${CTEST_MEMORYCHECK_COMMAND} ${CTEST_MEMORYCHECK_COMMAND_OPTIONS}")
    separate_arguments(memcheck_command)
    _add_test(${name}_memcheck ${memcheck_command} ${binary} ${ARGN})
  endfunction(add_test)

  function(set_memcheck_test_properties name)
    set_tests_properties(${name}_memcheck ${ARGN})
  endfunction(set_memcheck_test_properties)

endif(DTK_ENABLE_MEMCHECK)
147 148

enable_testing()
149

150
if(DTK_ENABLE_COVERAGE)
151

152 153 154 155 156 157
  if(UNIX AND CMAKE_COMPILER_IS_GNUCXX)
    set(CMAKE_CXX_FLAGS        "${CMAKE_CXX_FLAGS}        -fprofile-arcs -ftest-coverage")
    set(CMAKE_C_FLAGS          "${CMAKE_CXX_FLAGS}        -fprofile-arcs -ftest-coverage")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  endif(UNIX AND CMAKE_COMPILER_IS_GNUCXX)

158
  include(dtkCodeCoverage)
159
  include(FindPythonInterp)
160

161 162 163 164 165
  if(DTK_COVERAGE_USE_COBERTURA)
    SETUP_TARGET_FOR_COVERAGE_COBERTURA(cov ctest coverage)
  else(DTK_COVERAGE_USE_COBERTURA)
    SETUP_TARGET_FOR_COVERAGE(cov ctest coverage)
  endif(DTK_COVERAGE_USE_COBERTURA)
166

167 168
endif(DTK_ENABLE_COVERAGE)

Julien Wintz's avatar
Julien Wintz committed
169
## #################################################################
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
170
## Dependencies
Julien Wintz's avatar
Julien Wintz committed
171 172
## #################################################################

173 174 175 176 177 178 179
find_package(Qt5 REQUIRED COMPONENTS
  Core
  Concurrent
  Quick
  Network
  Gui
  Test
180
  Svg
181
  Widgets
WINTZ Julien's avatar
WINTZ Julien committed
182
  Xml)
183

184 185 186 187
## ###################################################################
##
## ###################################################################

188
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/dtkWrap.cmake)
189

190 191 192 193 194
## ###################################################################
## Doc setup
## ###################################################################

set(dtk_INSTALL_DOCS ${CMAKE_BINARY_DIR}/html)
195
set(dtk_CONFIG_DOCS  ${CMAKE_BINARY_DIR}/doc/cfg)
196

197
get_target_property(QT5_QMAKE_EXECUTABLE Qt5::qmake LOCATION)
WINTZ Julien's avatar
WINTZ Julien committed
198

199 200
get_filename_component(QT5_BINARY_DIR ${QT5_QMAKE_EXECUTABLE} PATH)

201 202 203 204
## #################################################################
## Dependencies - Optional                           [TO BE REMOVED]
## #################################################################

205 206
set(DTK_HAVE_MPI "NO")

207 208
if(DTK_BUILD_SUPPORT_DISTRIBUTED)

209 210
find_package(MPI QUIET)

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
211 212 213 214 215
if(MPI_FOUND)
  include_directories(${MPI_INCLUDE_PATH})
  set(COMPILE_FLAGS ${COMPILE_FLAGS} ${MPI_COMPILE_FLAGS})
  set(DTK_HAVE_MPI "YES")
endif(MPI_FOUND)
216

217
endif(DTK_BUILD_SUPPORT_DISTRIBUTED)
218

219 220 221 222 223 224 225 226
set(DTK_HAVE_ZLIB "NO")

find_package(ZLIB QUIET)
if (ZLIB_FOUND)
  include_directories( ${ZLIB_INCLUDE_DIRS} )
  set(DTK_HAVE_ZLIB "YES")
endif (ZLIB_FOUND)

227 228 229 230 231
set(DTK_HAVE_VRPN "NO")

if(DTK_BUILD_SUPPORT_VR)

## #################################################################
WINTZ Julien's avatar
WINTZ Julien committed
232
## OpenNI / Nite
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
## #################################################################

find_path(OPENNI_INCLUDES XnOpenNI.h /usr/include/ni)
find_path(  NITE_INCLUDES XnVNite.h  /usr/include/nite)

if(OPENNI_INCLUDES AND NITE_INCLUDES)
  include_directories(/usr/include/ni)
  include_directories(/usr/include/nite)
endif(OPENNI_INCLUDES AND NITE_INCLUDES)

find_library(OPENNI_LIBRARY NAMES OpenNI  PATHS /usr/lib)
find_library(  NITE_LIBRARY NAMES XnVNite PATHS /usr/lib)

if(OPENNI_LIBRARY AND NITE_LIBRARY)
  link_directories(/usr/lib)
endif(OPENNI_LIBRARY AND NITE_LIBRARY)

if(OPENNI_INCLUDES AND NITE_INCLUDES AND NOT DEFINED DTK_HAVE_NITE)
  set(DTK_HAVE_NITE "YES")
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
252 253
else(OPENNI_INCLUDES AND NITE_INCLUDES AND NOT DEFINED DTK_HAVE_NITE)
  set(DTK_HAVE_NITE "NO")
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
endif(OPENNI_INCLUDES AND NITE_INCLUDES AND NOT DEFINED DTK_HAVE_NITE)

mark_as_advanced(OPENNI_INCLUDES)
mark_as_advanced(NITE_INCLUDES)

mark_as_advanced(OPENNI_LIBRARY)
mark_as_advanced(NITE_LIBRARY)

## #################################################################
## Vrpn
## #################################################################

find_path(QUAT_INCLUDES           quat.h /usr/include /usr/local/include)
find_path(VRPN_INCLUDES vrpn_Configure.h /usr/include /usr/local/include)

if(QUAT_INCLUDES AND VRPN_INCLUDES)
WINTZ Julien's avatar
WINTZ Julien committed
270 271
  include_directories(${QUAT_INCLUDES})
  include_directories(${VRPN_INCLUDES})
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
endif(QUAT_INCLUDES AND VRPN_INCLUDES)

mark_as_advanced(VRPN_INCLUDES)
mark_as_advanced(QUAT_INCLUDES)

find_library(QUAT_LIBRARY NAMES quat PATHS /usr/lib /usr/local/lib)
find_library(VRPN_LIBRARY NAMES vrpn PATHS /usr/lib /usr/local/lib)

if(QUAT_LIBRARY AND VRPN_LIBRARY)
  add_definitions(-DHAVE_VRPN)
  set(DTK_HAVE_VRPN "YES")
endif(QUAT_LIBRARY AND VRPN_LIBRARY)

mark_as_advanced(QUAT_LIBRARY)
mark_as_advanced(VRPN_LIBRARY)

endif(DTK_BUILD_SUPPORT_VR)

Julien Wintz's avatar
Julien Wintz committed
290 291 292 293
## #################################################################
## Dependencies - internal
## #################################################################

294
include_directories(${CMAKE_CURRENT_BINARY_DIR})
295 296 297 298 299
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtk)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkComposer)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkCore)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkDistributed)
300
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkDistributedTest)
301 302
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkLog)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkMath)
303
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkMeta)
304
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkScript)
305
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkTest)
306
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkWidgets)
Julien Wintz's avatar
Julien Wintz committed
307

308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
if(DTK_BUILD_SUPPORT_CORE)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkCoreSupport)
endif()

if(DTK_BUILD_SUPPORT_CONTAINER)
    include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkContainerSupport)
endif()

if(DTK_BUILD_SUPPORT_COMPOSER)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkComposerSupport)
endif()

if(DTK_BUILD_SUPPORT_DISTRIBUTED)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkDistributedSupport)
endif()

if(DTK_BUILD_SUPPORT_GUI)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkGuiSupport)
endif()

if(DTK_BUILD_SUPPORT_MATH)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkMathSupport)
endif()

if(DTK_BUILD_SUPPORT_PLOT)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkPlotSupport)
endif()

if(DTK_BUILD_SUPPORT_VR)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/dtkVrSupport)
endif()

Julien Wintz's avatar
Julien Wintz committed
340 341 342 343 344
## ###################################################################
## Input
## ###################################################################

add_subdirectory(src)
345
add_subdirectory(tst)
346
add_subdirectory(app)
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
347
add_subdirectory(doc)
348
add_subdirectory(wrp)
Julien Wintz's avatar
Julien Wintz committed
349

350 351 352 353 354 355
## ###################################################################
## Exporting
## ###################################################################

export(PACKAGE dtk)

356
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/dtkConfig.cmake.in
357
  "${CMAKE_CURRENT_BINARY_DIR}/dtkConfig.cmake" @ONLY)
358

359
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/dtkConfig.install.cmake.in
360 361 362 363
  "${PROJECT_BINARY_DIR}/install/dtkConfig.cmake" @ONLY)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/dtkConfigVersion.cmake.in
  "${CMAKE_CURRENT_BINARY_DIR}/dtkConfigVersion.cmake" @ONLY)
364

365
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/dtkSetTestEnvironment.cmake.in
366
  "${CMAKE_CURRENT_BINARY_DIR}/dtkSetTestEnvironment.cmake" @ONLY)
367

368
set_directory_properties(PROPERTIES TEST_INCLUDE_FILE "${CMAKE_CURRENT_BINARY_DIR}/dtkSetTestEnvironment.cmake")
369

370
install(FILES
371
  "${CMAKE_CURRENT_BINARY_DIR}/install/dtkConfig.cmake"
372
  "${CMAKE_CURRENT_BINARY_DIR}/dtkConfigVersion.cmake"
373
  "${CMAKE_CURRENT_BINARY_DIR}/dtkSetTestEnvironment.cmake"
374 375 376 377
  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/dtkCodeCoverage.cmake"
  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/dtkWrap.cmake"
  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindSIP.cmake"
  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindSIP.py"
378
  DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/dtk)
379

380
install(EXPORT dtkDepends DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/dtk)
381

Julien Wintz's avatar
Julien Wintz committed
382 383 384 385
## ###################################################################
## Beautifying
## ###################################################################

386 387 388
mark_as_advanced(dtk_VERSION_MAJOR)
mark_as_advanced(dtk_VERSION_MINOR)
mark_as_advanced(dtk_VERSION_BUILD)
Julien Wintz's avatar
Julien Wintz committed
389

390
mark_as_advanced(Qt5_DIR)
Julien Wintz's avatar
Julien Wintz committed
391 392 393 394 395 396
mark_as_advanced(Qt5Concurrent_DIR)
mark_as_advanced(Qt5Core_DIR)
mark_as_advanced(Qt5Gui_DIR)
mark_as_advanced(Qt5Network_DIR)
mark_as_advanced(Qt5Qml_DIR)
mark_as_advanced(Qt5Quick_DIR)
Julien Wintz's avatar
Julien Wintz committed
397
mark_as_advanced(Qt5QuickTest_DIR)
398
mark_as_advanced(Qt5Script_DIR)
399
mark_as_advanced(Qt5Svg_DIR)
400
mark_as_advanced(Qt5Test_DIR)
Julien Wintz's avatar
Julien Wintz committed
401
mark_as_advanced(Qt5Widgets_DIR)
402
mark_as_advanced(Qt5Xml_DIR)
Julien Wintz's avatar
Julien Wintz committed
403 404 405 406 407 408 409

mark_as_advanced(CMAKE_AR)
mark_as_advanced(CMAKE_BUILD_TYPE)
mark_as_advanced(CMAKE_INSTALL_PREFIX)
mark_as_advanced(CMAKE_OSX_ARCHITECTURES)
mark_as_advanced(CMAKE_OSX_DEPLOYMENT_TARGET)
mark_as_advanced(CMAKE_OSX_SYSROOT)
WINTZ Julien's avatar
WINTZ Julien committed
410
mark_as_advanced(CTEST_MEMORYCHECK_COMMAND)
Julien Wintz's avatar
Julien Wintz committed
411

412
mark_as_advanced(DTK_ENABLE_COVERAGE)
413
mark_as_advanced(DTK_ENABLE_MEMCHECK)
414
mark_as_advanced(DTK_COVERAGE_USE_COBERTURA)
415
mark_as_advanced(DTK_PYTHON_VERSION)
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
416

417 418
mark_as_advanced(CCACHE_FOUND)

419 420
######################################################################
### CMakeLists.txt ends here