plugin.cmake 26.9 KB
Newer Older
1 2 3 4 5 6 7
# This module provides the following macro:
#
# openflipper_plugin ( [DIRS dir1 dir2 ...]
#                      [DEPS dep1 dep2 ...]
#                      [OPTDEPS dep1 dep2 ...]
#                      [LDFLAGSADD flag1 flag2 ...]
#                      [CFLAGSADD flag1 flag2 ...]
8
#                      [CDEFINITIONSADD definition1 definition2 ...]
9 10 11 12 13 14 15 16 17
#                      [LIBRARIES lib1 lib2 ...]
#                      [LIBDIRS dir1 dir2 ...]
#                      [INCDIRS dir1 dir2 ...]
#                      [ADDSRC file1 file2 ...]
#                      [INSTALLDATA dir1 dir2 ...]
#                      [TRANSLATION_LANGUAGES lang1 lang2 ...]
#                      [TRANSLATION_ADDFILES file1 file2 ...]
#                      [LICENSEMANAGER])
#
18 19 20 21 22 23 24 25 26 27 28
# DIRS            = additional directories with source files
# DEPS            = required dependencies for find_package macro
# OPTDEPS         = optional dependencies for find_package macro, if found, a define ENABLE_<Depname> will be added automatically
# LDFLAGSADD      = flags added to the link command
# CFLAGSADD       = flags added to the compile command
# CDEFINITIONSADD = definitions added to the compile command
# LIBRARIES       = libraries added to link command
# LIBDIRS         = additional link directories
# INCDIRS         = additional include directories
# ADDSRC          = additional source files
# INSTALLDATA     = directories that will be installed into the openflipper data directory
29 30 31 32 33 34 35
#
# TRANSLATION_LANGUAGES = language codes for translation
# TRANSLATION_ADDFILES  = additional files that should be included into the translation files
#
# LICENSEMANAGER = Compile plugin with license management
#
# Plugins can implement a acg_list_filter ("listname") macro to filter out
Matthias Möller's avatar
Matthias Möller committed
36
# unneeded headers, sources and ui files from the autogenerated
37 38
# build sources lists (see common.cmake drop_templates macro)
#
Jan Möbius's avatar
Jan Möbius committed
39 40 41 42 43
# Translations
# Create a subdirectory called translations in your Plugin directory
# The *.ts files there will be used for the translations
#
# Special DEPS:
Matthias Möller's avatar
Matthias Möller committed
44
# CUDA:
Jan Möbius's avatar
Jan Möbius committed
45 46 47 48 49
# If your plugin requires cuda, add "CUDA" to the list of dependencies
# and create a subdir called Cuda in your plugin directory
# The files in this directory will be compiled by nvcc and linked
# into the plugin
#
50 51 52
# The variables PLUGIN_${plugin}_MISSING_DEPS indicate whether any mandatory
# dependencies of the respective plugins are missing.
#
53 54 55 56 57 58 59 60 61 62 63 64

include (ACGCommon)

# get plugin name from directory name
macro (_get_plugin_name var)
  string (REGEX MATCH "Plugin-.+[/\\]?$" _dir ${CMAKE_CURRENT_SOURCE_DIR})
  string (REPLACE "Plugin-" "" ${var} ${_dir})
endmacro ()

# parse plugin macro parameter
macro (_get_plugin_parameters _prefix)
    set (_current_var _foo)
65
    set (_supported_var DIRS DEPS OPTDEPS LDFLAGSADD CFLAGSADD CDEFINITIONSADD LIBRARIES LIBDIRS INCDIRS ADDSRC INSTALLDATA TRANSLATION_LANGUAGES TRANSLATION_ADDFILES)
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    set (_supported_flags LICENSEMANAGER)
    foreach (_val ${_supported_var})
        set (${_prefix}_${_val})
    endforeach ()
    foreach (_val ${_supported_flags})
        set (${_prefix}_${_val} 0)
    endforeach ()

    foreach (_val ${ARGN})
        set (_found FALSE)
        foreach (_find ${_supported_var})
            if ("${_find}" STREQUAL "${_val}")
                set (_found TRUE)
            endif ()
        endforeach ()

        foreach (_find ${_supported_flags})
            if ("${_find}" STREQUAL "${_val}")
                set (${_prefix}_${_val} 1)
            endif ()
        endforeach ()

        if (_found)
            set (_current_var ${_prefix}_${_val})
        else ()
            list (APPEND ${_current_var} ${_val})
        endif ()
    endforeach ()

endmacro ()

# check dependencies
98 99 100 101
# _prefix    : prefix used ( usually the plugin name )
# _optional : if we are currently pars
macro (_check_plugin_deps _prefix _optional )

102
    set (${_prefix}_HAS_DEPS TRUE)
103 104 105 106

    # This will contain the final list of all dependencies
    list (APPEND FULL_DEPENDENCY_LIST "")

Matthias Möller's avatar
Matthias Möller committed
107
    #======================================================================================
108
    # Collect dependencies of dependencies
Matthias Möller's avatar
Matthias Möller committed
109
    # Recursive dependencies will be added here.
110 111 112 113
    # The base package name will be used and the variables
    # PACKAGE_DEPS     : Mandatory recursive dependencies
    # PACKAGE_OPT_DEPS : Optional recursive dependencies
    #======================================================================================
114
    foreach (_val ${ARGN})
115
       string (TOUPPER ${_val} _VAL)
Matthias Möller's avatar
Matthias Möller committed
116

117 118 119 120 121 122
       # First we try to find the dependencies directly
       find_package(${_val})

       # This will contain the list of all dependencies of the current base dependency ( including recursive dependencies for one level )
       set (CURRENT_DEPENDENCY_LIST "")

Matthias Möller's avatar
Matthias Möller committed
123
       # Flag if all dependencies were found (Only mandatory ones)
124 125 126 127 128 129 130 131 132 133
       set (ALL_REQUIRED_DEPENDENCIES_FOUND TRUE)

       # Recursive dependencies which are not optional will also be added by default (Not optional, so error if not available!)
       if  ( DEFINED ${_VAL}_DEPS )

          foreach (_rec_dep ${${_VAL}_DEPS})

            string (TOUPPER ${_rec_dep} _REC_DEP)

            find_package(${_rec_dep})
Matthias Möller's avatar
Matthias Möller committed
134

135 136 137 138 139 140 141 142
            if ( ${_REC_DEP}_FOUND )
              list (APPEND CURRENT_DEPENDENCY_LIST ${_rec_dep} )
              add_definitions( -DENABLE_${_REC_DEP} )
            else()
              set (ALL_REQUIRED_DEPENDENCIES_FOUND FALSE)
              acg_set (_${_prefix}_MISSING_DEPS "${_${_prefix}_MISSING_DEPS} ${_VAL}_MISSING_MANDATORY_RECURSIVE_DEP_${_REC_DEP}")
            endif()
          endforeach()
Matthias Möller's avatar
Matthias Möller committed
143

144 145 146 147 148 149 150 151 152 153 154 155 156
       endif()


       # optional dependencies will be added if available and compiler flags will be set accordingly
       if  ( DEFINED ${_VAL}_OPT_DEPS )

          foreach (_rec_dep ${${_VAL}_OPT_DEPS})

            string (TOUPPER ${_rec_dep} _REC_DEP)

            find_package(${_rec_dep})

            # Optional so add if we found the dependency or we skip it.
Matthias Möller's avatar
Matthias Möller committed
157
            # Defines will be added due to the optional status
158 159 160
            if ( ${_REC_DEP}_FOUND )
              list (APPEND CURRENT_DEPENDENCY_LIST ${_rec_dep} )
              add_definitions( -DENABLE_${_REC_DEP} )
161 162 163 164
            elseif ( ${_rec_dep}_FOUND )
             # Lower case definition workaround
		list (APPEND CURRENT_DEPENDENCY_LIST ${_rec_dep} )
                add_definitions( -DENABLE_${_REC_DEP} )
165 166 167
            else()
              add_definitions( -DDISABLE_${_REC_DEP} )
	    endif()
168

169 170 171 172 173 174
          endforeach()
       endif()

       if ( ${_optional} STREQUAL "TRUE"  )

         if ( ${_VAL}_FOUND )
175 176 177 178 179 180

           # Optional dependency found and recursive found, so add definition to enable it
           if ( ${_optional} STREQUAL "TRUE" )
             add_definitions(-DENABLE_${_VAL})
           endif()

181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
           if ( ALL_REQUIRED_DEPENDENCIES_FOUND )
             # All found so add package dependencies
             list (APPEND FULL_DEPENDENCY_LIST ${CURRENT_DEPENDENCY_LIST})
             # Add package itself
             list (APPEND FULL_DEPENDENCY_LIST ${_val})
           else()
	     message("Missing recursive dependencies when optional")
           endif()

         else()
           message("Info: OPTIONAL Dependency  ${_VAL} for  ${_prefix}  not found .. proceeding without it!")

         endif()

       else()

         if ( ALL_REQUIRED_DEPENDENCIES_FOUND )
           # All found so add package dependencies
           list (APPEND FULL_DEPENDENCY_LIST ${CURRENT_DEPENDENCY_LIST})
           # Add package itself
           list (APPEND FULL_DEPENDENCY_LIST ${_val})
         else()
    	   acg_set (_${_prefix}_MISSING_DEPS "${_${_prefix}_MISSING_DEPS} ${_VAL}_BECAUSE_OF_MISSING_RECURSIVE_DEPENDENCY")
           set (${_prefix}_HAS_DEPS FALSE)
         endif()

       endif()

    endforeach()

    foreach (_val ${FULL_DEPENDENCY_LIST})
212 213 214 215
        string (TOUPPER ${_val} _VAL)

        find_package(${_val})

216 217 218
        #======================================================================================
        # Global dependency tracking
        #======================================================================================
Jan Möbius's avatar
Jan Möbius committed
219
        # Get our current list of all dependencies used by plugins
220 221
	get_property( global_dependency_list GLOBAL PROPERTY GLOBAL_PLUGIN_DEPENDENCIES_LIST)

Jan Möbius's avatar
Jan Möbius committed
222
	#Add the new entry to the list
223
        list (APPEND global_dependency_list ${_val} )
Jan Möbius's avatar
Jan Möbius committed
224

Jan Möbius's avatar
Jan Möbius committed
225
        # Remove it again, if it was a duplicate
Jan Möbius's avatar
Jan Möbius committed
226
        list(REMOVE_DUPLICATES global_dependency_list)
Matthias Möller's avatar
Matthias Möller committed
227

Jan Möbius's avatar
Jan Möbius committed
228
        # Store the list in the global property
229 230
        set_property( GLOBAL PROPERTY GLOBAL_PLUGIN_DEPENDENCIES_LIST ${global_dependency_list} )

231 232 233 234
        #======================================================================================
        # Collect all dependencies (local and global)
        #======================================================================================

235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
        if (${_val}_FOUND OR ${_VAL}_FOUND)
          foreach (_name ${_val} ${_VAL})
            if (DEFINED ${_name}_INCLUDE_PATH)
              list (APPEND ${_prefix}_DEPS_INCDIRS "${${_name}_INCLUDE_PATH}")
            endif ()
            if (DEFINED ${_name}_INCLUDE_DIRS)
              list (APPEND ${_prefix}_DEPS_INCDIRS "${${_name}_INCLUDE_DIRS}")
            endif ()
            if (DEFINED ${_name}_INCLUDE_DIR)
              list (APPEND ${_prefix}_DEPS_INCDIRS "${${_name}_INCLUDE_DIR}")
            endif ()
            if (DEFINED ${_name}_LIBRARY_DIRS)
              list (APPEND ${_prefix}_DEPS_LIBDIRS "${${_name}_LIBRARY_DIRS}")
            endif ()
            if (DEFINED ${_name}_LIBRARY_DIR)
              list (APPEND ${_prefix}_DEPS_LIBDIRS "${${_name}_LIBRARY_DIR}")
            endif ()
            if (DEFINED ${_name}_LIBRARIES)
              list (APPEND ${_prefix}_DEPS_LIBRARIES "${${_name}_LIBRARIES}")
            endif ()
            if (DEFINED ${_name}_LIBRARY)
              list (APPEND ${_prefix}_DEPS_LIBRARIES "${${_name}_LIBRARY}")
            endif ()
            if (DEFINED ${_name}_LINKER_FLAGS)
259 260
#              list (APPEND ${_prefix}_DEPS_LINKER_FLAGS "${${_name}_LINKER_FLAGS}")
              # this variable is used as a string later on (not as a list!!!)
Matthias Möller's avatar
Matthias Möller committed
261
              set( ${_prefix}_DEPS_LINKER_FLAGS "${${_prefix}_DEPS_LINKER_FLAGS} ${${_name}_LINKER_FLAGS}")
262
            endif ()
263 264 265 266 267
            if (DEFINED ${_name}_COMPILER_FLAGS)
#              list (APPEND ${_prefix}_DEPS_COMPILER_FLAGS "${${_name}_COMPILER_FLAGS}")
              # this variable is used as a string later on (not as a list!!!)
              set( ${_prefix}_DEPS_COMPILER_FLAGS "${${_prefix}_DEPS_COMPILER_FLAGS} ${${_name}_COMPILER_FLAGS}")
            endif ()
268
            if (DEFINED ${_name}_COMPILER_DEFINITIONS)
Jan Möbius's avatar
Jan Möbius committed
269 270
              list (APPEND ${_prefix}_DEPS_COMPILE_DEFINITIONS "${${_name}_COMPILER_DEFINITIONS}")
              list(REMOVE_DUPLICATES ${_prefix}_DEPS_COMPILE_DEFINITIONS )
271 272
            endif ()
            if (DEFINED ${_name}_COMPILE_DEFINITIONS)
Jan Möbius's avatar
Jan Möbius committed
273 274
              list (APPEND ${_prefix}_DEPS_COMPILE_DEFINITIONS "${${_name}_COMPILE_DEFINITIONS}")
              list(REMOVE_DUPLICATES ${_prefix}_DEPS_COMPILE_DEFINITIONS )
275
            endif ()
276 277 278 279 280 281 282 283 284
          endforeach ()
        else ()
            set (${_prefix}_HAS_DEPS FALSE)
            acg_set (_${_prefix}_MISSING_DEPS "${_${_prefix}_MISSING_DEPS} ${_val}")
        endif ()
    endforeach ()
endmacro ()

macro (_plugin_licensemanagement)
285
  acg_append_files (headers "LicenseManager.hh" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
286

287
  if ( OPENFLIPPER_ENABLE_LICENSE_KEY_GENERATOR )
288 289 290
    acg_append_files (keygen_hdr "*.hh" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager/keyGen")
    acg_append_files (keygen_src "*.cc" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager/keyGen")
    acg_append_files (keygen_ui  "*.ui" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager/keyGen")
Matthias Möller's avatar
Matthias Möller committed
291

292
    # genereate uic and moc targets
Matthias Möller's avatar
Matthias Möller committed
293 294 295 296 297 298 299
    if (QT5_FOUND)
      acg_qt5_autouic (keygen_uic ${keygen_ui})
      acg_qt5_automoc (keygen_moc ${keygen_hdr})
    else ()
      acg_qt4_autouic (keygen_uic ${keygen_ui})
      acg_qt4_automoc (keygen_moc ${keygen_hdr})
    endif()
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327

    add_executable (Plugin-${plugin}-keygen ${keygen_uic} ${keygen_moc} ${keygen_hdr} ${keygen_src})

    target_link_libraries (
      Plugin-${plugin}-keygen
      ${QT_LIBRARIES}
    )

    # create our output directroy
    if (NOT EXISTS ${CMAKE_BINARY_DIR}/LicenseManagement)
      file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/LicenseManagement)
    endif ()

    if (WIN32)
      # copy exe file to "Build" directory
      # Visual studio will create this file in a subdirectory so we can't use
      # RUNTIME_OUTPUT_DIRECTORY directly here
      add_custom_command (TARGET Plugin-${plugin}-keygen POST_BUILD
                          COMMAND ${CMAKE_COMMAND} -E
                          copy_if_different
                            ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Plugin-${plugin}-keygen.exe
                          ${CMAKE_BINARY_DIR}/LicenseManagement/Plugin-${plugin}-keygen.exe)
    else ()
      set_target_properties (
        Plugin-${plugin}-keygen PROPERTIES
        RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/LicenseManagement"
      )
    endif ()
328 329 330 331 332
  endif()
  if ( OPENFLIPPER_ENABLE_LICENSE_MANAGER )
    acg_append_files (headers "LicenseManagerActive.hh" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
    acg_append_files (sources "*.cc" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
  # acg_append_files (ui "*.ui" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
333 334
  else(OPENFLIPPER_ENABLE_LICENSE_MANAGER)
    acg_append_files (headers "LicenseManagerDisabled.hh" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
335 336 337 338 339 340 341 342 343 344 345 346 347 348
  endif()
endmacro ()

# main function
function (_build_openflipper_plugin plugin)

  acg_set (OPENFLIPPER_${_PLUGIN}_BUILD "0")

  # get upper plugin name
  string (TOUPPER ${plugin} _PLUGIN)

  #============================================================================================
  # parse parameters
  #============================================================================================
Matthias Möller's avatar
Matthias Möller committed
349

350 351 352 353 354 355 356 357 358
  _get_plugin_parameters (${_PLUGIN} ${ARGN})

  #============================================================================================
  # Collect dependencies
  #============================================================================================

  # check dependencies
  acg_unset (_${_PLUGIN}_MISSING_DEPS)
  set (${_PLUGIN}_HAS_DEPS)
359
  _check_plugin_deps (${_PLUGIN} TRUE ${${_PLUGIN}_OPTDEPS})
360 361 362

  acg_unset (_${_PLUGIN}_MISSING_DEPS)
  set (${_PLUGIN}_HAS_DEPS)
363
  _check_plugin_deps (${_PLUGIN} FALSE ${${_PLUGIN}_DEPS})
364

Jan Möbius's avatar
Jan Möbius committed
365

366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
  #============================================================================================
  # Remember Lib dirs for bundle generation
  #============================================================================================

  # On Windows we collect the library paths in a global property.
  # These paths will be used in the toplevel cmakefile
  # to configure the fixup_bundle to copy the required libs to the bundle.
  if (WIN32)
    set(WINDOWS_COPY_LIBDIRS "")
    # Get the required directories and remeber them to build the bundle later
    list(APPEND WINDOWS_COPY_LIBDIRS  ${${_PLUGIN}_DEPS_LIBDIRS} )
    # Remove duplicates from the list
    list(REMOVE_DUPLICATES WINDOWS_COPY_LIBDIRS)
    # Has to be a global property because we need it in the main cmakefile
    set_property(GLOBAL APPEND PROPERTY WINDOWS_LIBRARY_DIR_LIST "${WINDOWS_COPY_LIBDIRS}")
  endif(WIN32)

  if (${_PLUGIN}_HAS_DEPS)
    include_directories (
      .
      ${CMAKE_SOURCE_DIR}
387
      ${OPENMESH_INCLUDE_DIRS}
388
      ${OPENVOLUMEMESH_INCLUDE_DIR}
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
      ${CMAKE_CURRENT_SOURCE_DIR}
      ${CMAKE_CURRENT_BINARY_DIR}
      ${${_PLUGIN}_DEPS_INCDIRS}
      ${${_PLUGIN}_INCDIRS}
      ${OPENGL_INCLUDE_DIR}
      ${GLEW_INCLUDE_DIR}
      ${GLUT_INCLUDE_DIR}
      ${CMAKE_BINARY_DIR}/OpenFlipper/PluginLib
    )

    # Linking for apple is special here as the linker pulls in the dependencies, we have to set them like in PluginLib!
    if( APPLE )

      # search all ObjectTypes in the ObjectType directory for additional build information
      file (
         GLOB _plugin_buildinfos
         RELATIVE "${CMAKE_SOURCE_DIR}"
         "${CMAKE_SOURCE_DIR}/ObjectTypes/*/CMakeLists.txt"
      )

Matthias Möller's avatar
Matthias Möller committed
409

410 411 412 413 414 415 416 417
      # include all cmake files found for objecttypes here
      foreach ( _buildInfo ${_plugin_buildinfos})
        include ("${CMAKE_SOURCE_DIR}/${_buildInfo}")
      endforeach ()

      link_directories (
        ${${_PLUGIN}_DEPS_LIBDIRS}
        ${${_PLUGIN}_LIBDIRS}
Matthias Möller's avatar
Matthias Möller committed
418
        ${ADDITIONAL_PLUGINLIB_LINK_DIRS}
419
      )
Matthias Möller's avatar
Matthias Möller committed
420

421 422 423 424 425 426
    else (APPLE)
       link_directories (
         ${${_PLUGIN}_DEPS_LIBDIRS}
         ${${_PLUGIN}_LIBDIRS}
       )
    endif(APPLE)
Matthias Möller's avatar
Matthias Möller committed
427 428 429

    set (directories
       .
430 431 432 433 434 435
       ${${_PLUGIN}_DIRS}
    )

    #============================================================================================
    # User Documentation build
    #============================================================================================
Matthias Möller's avatar
Matthias Möller committed
436

437 438 439 440 441
    # Only build the documentation if a userdoc subdirectory exists for the plugin
    if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/userDoc)

      set(plugin_html_doc_dir "${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_DATADIR}/Doc/UserHTML/Plugin-${plugin}")
      set(plugin_qt_help_dir "${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_DATADIR}/Help")
Matthias Möller's avatar
Matthias Möller committed
442

443 444
      find_package(Doxygen)

445
      if ( DOXYGEN_FOUND )
446

Matthias Möller's avatar
Matthias Möller committed
447
        # Create user documentation target with our template doxy file
448
        acg_create_doc_target( doc-User-${plugin} "${CMAKE_SOURCE_DIR}/OpenFlipper/Documentation/PluginDoxyTemplate" )
449 450 451 452 453 454 455 456 457 458 459 460

        # make doc builds this plugin's documentation as well
        add_dependencies(doc-UserHelp doc-User-${plugin})

        # Create directories in order to avoid doxygen warnings
        if(NOT (IS_DIRECTORY ${plugin_html_doc_dir}) )
           file(MAKE_DIRECTORY ${plugin_html_doc_dir} )
        endif()

        # Create directories in order to avoid doxygen warnings
        if(NOT (IS_DIRECTORY ${plugin_qt_help_dir}) )
           file(MAKE_DIRECTORY ${plugin_qt_help_dir} )
Matthias Möller's avatar
Matthias Möller committed
461
        endif()
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492

      endif()

    endif()

    #============================================================================================
    # Binary build
    #============================================================================================


    # collect all header,source and ui files
    acg_append_files (headers "*.hh" ${directories})
    acg_append_files (sources "*.cc" ${directories})
    acg_append_files (sources "*.cpp" ${directories})
    acg_append_files (sources "*.c" ${directories})
    acg_append_files (ui "*.ui" ${directories})
    acg_append_files (qrc "*.qrc" ${directories})

    # remove template cc files from source file list
    acg_drop_templates (sources)

    # filter header,source and ui files lists if acg_list_filter macro has been defined
    if (COMMAND acg_list_filter)
      acg_list_filter (headers)
      acg_list_filter (sources)
      acg_list_filter (ui)
    endif ()

    set(${_PLUGIN}_LICENSE_DEFS "")
    if (${_PLUGIN}_LICENSEMANAGER )
      _plugin_licensemanagement ()
Matthias Möller's avatar
Matthias Möller committed
493

494 495 496 497 498 499
      if ( OPENFLIPPER_ENABLE_LICENSE_MANAGER )
	   set(${_PLUGIN}_LICENSE_DEFS "-DWITH_LICENSE_MANAGER")
      endif()
    endif ()

    # genereate uic and moc targets
Matthias Möller's avatar
Matthias Möller committed
500 501 502 503 504 505 506 507 508 509 510 511
    if (QT5_FOUND)
      acg_qt5_autouic (uic_targets ${ui})
      acg_qt5_automoc (moc_targets ${headers})
      acg_qt5_autoqrc (qrc_targets ${qrc})
    else ()
      acg_qt4_autouic (uic_targets ${ui})
      acg_qt4_automoc (moc_targets ${headers})
      acg_qt4_autoqrc (qrc_targets ${qrc})
    endif ()



Jan Möbius's avatar
Jan Möbius committed
512
    add_library (Plugin-${plugin} MODULE ${uic_targets} ${sources} ${headers} ${moc_targets} ${qrc_targets} ${${_PLUGIN}_ADDSRC})
513 514 515 516 517 518

    # add this plugin to build plugin list for dependency tracking
    acg_set (OPENFLIPPER_PLUGINS "${OPENFLIPPER_PLUGINS};Plugin-${plugin}")
    acg_set (OPENFLIPPER_${_PLUGIN}_BUILD "1")

    # append compiler and linker flags from plugin dependencies
519

Jan Möbius's avatar
Jan Möbius committed
520 521
    list(APPEND ${_PLUGIN}_DEPS_COMPILE_DEFINITIONS ${${_PLUGIN}_CDEFINITIONSADD} )

522 523
    set_target_properties (
      Plugin-${plugin} PROPERTIES
524
      COMPILE_FLAGS "${${_PLUGIN}_CFLAGSADD} ${${_PLUGIN}_LICENSE_DEFS} ${${_PLUGIN}_DEPS_COMPILER_FLAGS}"
Matthias Möller's avatar
Matthias Möller committed
525
      COMPILE_DEFINITIONS  "${${_PLUGIN}_DEPS_COMPILE_DEFINITIONS}"
526 527
      LINK_FLAGS "${${_PLUGIN}_LDFLAGSADD} ${${_PLUGIN}_DEPS_LINKER_FLAGS}"
    )
Matthias Möller's avatar
Matthias Möller committed
528

529 530 531 532 533 534
    if (WIN32)
      # Visual studio requires our plugins to link with GLUT
      find_package (GLUT)
      # generate dllinport defines
      add_definitions (-DACGDLL -DUSEACG -DPLUGINLIBDLL -DUSEPLUGINLIBDLL)
      target_link_libraries (Plugin-${plugin}
535
    	${OPENMESH_LIBRARIES}
536
        ${OPENVOLUMEMESH_LIBRARY}
537
        ACG
538
        OpenFlipperPluginLib
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
        ${GLUT_LIBRARIES}
      )

      # copy plugin dll file to "Build" directory
      # Visual studio will create this file in a subdirectory so we can't use
      # LIBRARY_OUTPUT_DIRECTORY directly here
      if (NOT EXISTS ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_PLUGINDIR})
        file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Build/${ACG_PROJEC_PLUGINDIR})
      endif ()
      add_custom_command (TARGET Plugin-${plugin} POST_BUILD
                          COMMAND ${CMAKE_COMMAND} -E
                          copy_if_different
                            ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Plugin-${plugin}.dll
                            ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_PLUGINDIR}/Plugin-${plugin}.dll
                          )
Matthias Möller's avatar
Matthias Möller committed
554
    elseif (APPLE)
555 556 557

      target_link_libraries (
         Plugin-${plugin}
558
	 OpenFlipperPluginLib
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
	 ${QT_LIBRARIES}
      )
      # copy plugin so file to application bundle inside "Build" directory
      if (NOT EXISTS ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_PLUGINDIR})
        file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_PLUGINDIR})
      endif ()
      add_custom_command (TARGET Plugin-${plugin} POST_BUILD
                          COMMAND ${CMAKE_COMMAND} -E
                          copy_if_different
                            ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/libPlugin-${plugin}.so
                            ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_PLUGINDIR}/libPlugin-${plugin}.so
                          )
    else ()
      # directly generate plugin in plugin directory
      set_target_properties (
        Plugin-${plugin} PROPERTIES
        LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_PLUGINDIR}"
      )
    endif ()
Matthias Möller's avatar
Matthias Möller committed
578

579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
    target_link_libraries (Plugin-${plugin}
      ${${_PLUGIN}_DEPS_LIBRARIES}
      ${${_PLUGIN}_LIBRARIES}
    )

    # no install on mac, because the whole bundle will be installed in the
    # toplevel CMakeLists.txt
    if (NOT APPLE)
      install (
        TARGETS Plugin-${plugin}
        DESTINATION ${ACG_PROJECT_PLUGINDIR}
      )
    endif ()

    foreach (_dir ${${_PLUGIN}_INSTALLDATA})
      acg_copy_after_build (Plugin-${plugin} "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}" "${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_DATADIR}/${_dir}")
      if (NOT APPLE)
        acg_install_dir ("${CMAKE_CURRENT_SOURCE_DIR}/${_dir}" "${ACG_PROJECT_DATADIR}/${_dir}")
      endif ()
    endforeach ()
Matthias Möller's avatar
Matthias Möller committed
599

Jan Möbius's avatar
Jan Möbius committed
600 601 602
    #============================================================================================
    # CUDA Integration
    # This block takes all cuda files from a plugins subdirectory called "Cuda"
Matthias Möller's avatar
Matthias Möller committed
603
    # The files will be compiled by nvcc and linked to one library containing all cuda parts of
Jan Möbius's avatar
Jan Möbius committed
604 605
    # the plugin. This static library is than linked into the plugin
    #============================================================================================
Matthias Möller's avatar
Matthias Möller committed
606

Jan Möbius's avatar
Jan Möbius committed
607 608 609
    # Check if cuda is in the list of dependencies:
    list(FIND ${_PLUGIN}_DEPS "CUDA" FIND_RESULT)
    if ( NOT FIND_RESULT EQUAL -1 )
Matthias Möller's avatar
Matthias Möller committed
610

Jan Möbius's avatar
Jan Möbius committed
611 612 613 614 615
      # Required but maybe it is not found
      # finder is automatically called before this
      if ( CUDA_FOUND )
        #Setup options
        CUDA_ADD_CUDA_INCLUDE_ONCE()
Matthias Möller's avatar
Matthias Möller committed
616

Jan Möbius's avatar
Jan Möbius committed
617 618 619 620 621 622 623 624
        # Clear out the directory defines to prevent nvcc from getting them
        # TODO : Create an additional flag variable for CUDA
        get_directory_property( CURRENT_DEFINITIONS COMPILE_DEFINITIONS )
        set_directory_properties( PROPERTIES COMPILE_DEFINITIONS "" )

        get_directory_property( CURRENT_DEFINITIONS_A COMPILE_DEFINITIONS )

        # Get all cuda sources
625
        file(GLOB_RECURSE ${_PLUGIN}_CUDA_SRCS Cuda/*.cu Cuda/*.c)
Matthias Möller's avatar
Matthias Möller committed
626

627 628
        # Add cuda include dirs to global build target
        include_directories(${CUDA_INCLUDE_DIRS})
Matthias Möller's avatar
Matthias Möller committed
629

Jan Möbius's avatar
Jan Möbius committed
630 631 632
        # Force to -fPIC such that we can correctly link against the lib lateron in the plugin
        list ( APPEND CMAKE_CXX_FLAGS "-fPIC" )
        list ( APPEND CMAKE_CC_FLAGS "-fPIC" )
Matthias Möller's avatar
Matthias Möller committed
633

Jan Möbius's avatar
Jan Möbius committed
634
        # Prepare the files
635
        if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
636
        	CUDA_COMPILE(${_PLUGIN}_CUDA_GENERATED_FILES ${${_PLUGIN}_CUDA_SRCS} OPTIONS -g -G --device-emulation -Xcompiler)
637
        else()
638
        	CUDA_COMPILE(${_PLUGIN}_CUDA_GENERATED_FILES ${${_PLUGIN}_CUDA_SRCS} OPTIONS -O2)
639
        endif()
Matthias Möller's avatar
Matthias Möller committed
640

Jan Möbius's avatar
Jan Möbius committed
641 642
        # Create the library containing all cuda files
        CUDA_ADD_LIBRARY(${_PLUGIN}_cuda_lib STATIC ${${_PLUGIN}_CUDA_GENERATED_FILES} )
Matthias Möller's avatar
Matthias Möller committed
643

Jan Möbius's avatar
Jan Möbius committed
644 645
        # Link the cuda plugin library to the plugin itself
        target_link_libraries(Plugin-${plugin} ${_PLUGIN}_cuda_lib)
Matthias Möller's avatar
Matthias Möller committed
646

Jan Möbius's avatar
Jan Möbius committed
647
        # reset to original compile definitions
648
        set_directory_properties( PROPERTIES COMPILE_DEFINITIONS "${CURRENT_DEFINITIONS}" )
Jan Möbius's avatar
Jan Möbius committed
649 650 651 652 653 654 655

      endif( CUDA_FOUND )
    endif()

    #============================================================================================
    # Translations
    #============================================================================================
656 657 658 659 660 661 662 663

    if ( ${_PLUGIN}_TRANSLATION_LANGUAGES)
      set (trans_files ${sources} )
      list (APPEND trans_files ${ui})
      list (APPEND trans_files ${headers})
      list (APPEND trans_files ${${_PLUGIN}_TRANSLATION_ADDFILES})
      acg_add_translations(Plugin-${plugin} ${${_PLUGIN}_TRANSLATION_LANGUAGES} "${trans_files}" )
    endif ()
664
    set(PLUGIN_${plugin}_MISSING_DEPS FALSE PARENT_SCOPE)
665 666 667 668

  else ()
    message (STATUS "[WARNING] One or more dependencies for plugin ${plugin} not found. Skipping plugin.")
    message (STATUS "Missing dependencies :${_${_PLUGIN}_MISSING_DEPS}")
669
    set(PLUGIN_${plugin}_MISSING_DEPS TRUE PARENT_SCOPE)
670
  endif ()
Matthias Möller's avatar
Matthias Möller committed
671

672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
endfunction ()

macro (openflipper_plugin)
  _get_plugin_name (_plugin)

  string (TOUPPER ${_plugin} _PLUGIN)

  # add option to disable plugin build
  option (
    DISABLE_PLUGIN_${_PLUGIN}
    "Disable building of plugin \"${_plugin}\""
        OFF
  )

  if (NOT DISABLE_PLUGIN_${_PLUGIN})
    _build_openflipper_plugin (${_plugin} ${ARGN})
  endif ()
endmacro ()