plugin.cmake 33 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3
# This module provides the following macro:
#
# openflipper_plugin ( [DIRS dir1 dir2 ...]
Jan Möbius's avatar
Jan Möbius committed
4 5
#                      [TYPES type1 type2 ...] 
#                      [OPT_TYPES type1 type2 ...] 
Jan Möbius's avatar
Jan Möbius committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#                      [DEPS dep1 dep2 ...]
#                      [OPTDEPS dep1 dep2 ...]
#                      [LDFLAGSADD flag1 flag2 ...]
#                      [CFLAGSADD flag1 flag2 ...]
#                      [CDEFINITIONSADD definition1 definition2 ...]
#                      [LIBRARIES lib1 lib2 ...]
#                      [ADD_CORE_APP_LIBRARIES lib1 lib2 ...]
#                      [LIBDIRS dir1 dir2 ...]
#                      [INCDIRS dir1 dir2 ...]
#                      [ADDSRC file1 file2 ...]
#                      [INSTALLDATA dir1 dir2 ...]
#                      [TRANSLATION_LANGUAGES lang1 lang2 ...]
#                      [TRANSLATION_ADDFILES file1 file2 ...]
#                      [LICENSEMANAGER])
#

# DIRS                   = additional directories with source files
Jan Möbius's avatar
Jan Möbius committed
23 24
# TYPES                  = List of datatypes required by this plugin (uppercase)
# OPT_TYPES              = List of optional datatypes for this plugin (uppercase)
Jan Möbius's avatar
Jan Möbius committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
# 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
# ADD_CORE_APP_LIBRARIES = libraries added to be linked to the core app
# LIBDIRS                = additional link directories
# INCDIRS                = additional include directories
# ADDSRC                 = additional source files
# INSTALLDATA            = directories that will be installed into the openflipper data directory
# GLEWDEFINITIONS = Checks glew if it defines the given definitions
#
# 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
# unneeded headers, sources and ui files from the autogenerated
# build sources lists (see common.cmake drop_templates macro)
#
# Translations
# Create a subdirectory called translations in your Plugin directory
# The *.ts files there will be used for the translations
#
# Special DEPS:
# CUDA:
# 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
#
# The variables PLUGIN_${plugin}_MISSING_DEPS indicate whether any mandatory
# dependencies of the respective plugins are missing.
#

if(OPENFLIPPER_PLUGIN_INCLUDED)
  return()
endif(OPENFLIPPER_PLUGIN_INCLUDED)
set(OPENFLIPPER_PLUGIN_INCLUDED TRUE PARENT_SCOPE)

include (ACGCommon)
include (MSVCMacros)

# 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)
Jan Möbius's avatar
Jan Möbius committed
79
    set (_supported_var DIRS TYPES OPT_TYPES DEPS OPTDEPS LDFLAGSADD CFLAGSADD CDEFINITIONSADD
Jan Möbius's avatar
Jan Möbius committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 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 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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 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
      LIBRARIES ADD_CORE_APP_LIBRARIES LIBDIRS INCDIRS ADDSRC INSTALLDATA GLEWDEFINITIONS TRANSLATION_LANGUAGES TRANSLATION_ADDFILES)
    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
# _prefix    : prefix used ( usually the plugin name )
# _optional : if we are currently pars
macro (_check_plugin_deps _prefix _optional )


    set (${_prefix}_HAS_DEPS TRUE)

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

    #======================================================================================
    # Collect dependencies of dependencies
    # Recursive dependencies will be added here.
    # The base package name will be used and the variables
    # PACKAGE_DEPS     : Mandatory recursive dependencies
    # PACKAGE_OPT_DEPS : Optional recursive dependencies
    #======================================================================================
    foreach (_val ${ARGN})
       string (TOUPPER ${_val} _VAL)

       # First we try to find the dependencies directly
       if (NOT ${_VAL}_FOUND AND NOT ${_val}_FOUND)
       #  MESSAGE(STATUS "Looking for _val \"${_val}\"")
         find_package(${_val})
         list(APPEND LOADED_PACKAGES_ "${_val}")
       #else()
       #  MESSAGE(STATUS "Skipping _val \"${_val}\"")
       endif ()

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

       # Flag if all dependencies were found (Only mandatory ones)
       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)

            if (NOT ${_REC_DEP}_FOUND AND NOT ${_rec_dep}_FOUND)
            #  MESSAGE(STATUS "Looking for _rec_dep \"${_rec_dep}\"")
              find_package(${_rec_dep})
              list(APPEND LOADED_PACKAGES_ "${_rec_dep}")
            #else()
            #  MESSAGE(STATUS "Skipping _rec_dep \"${_rec_dep}\"")
            endif ()

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

       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)

            if (NOT ${_REC_DEP}_FOUND AND NOT ${_rec_dep}_FOUND)
            #  MESSAGE(STATUS "Looking for _rec_dep \"${_rec_dep}\"")
              find_package(${_rec_dep})
              list(APPEND LOADED_PACKAGES_ "${_rec_dep}")
            #else()
            #  MESSAGE(STATUS "Skipping _rec_dep \"${_rec_dep}\"")
            endif ()

            # Optional so add if we found the dependency or we skip it.
            # Defines will be added due to the optional status
            if ( ${_REC_DEP}_FOUND )
              list (APPEND CURRENT_DEPENDENCY_LIST ${_rec_dep} )
              add_definitions( -DENABLE_${_REC_DEP} )
            elseif ( ${_rec_dep}_FOUND )
             # Lower case definition workaround
		list (APPEND CURRENT_DEPENDENCY_LIST ${_rec_dep} )
                add_definitions( -DENABLE_${_REC_DEP} )
            else()
              add_definitions( -DDISABLE_${_REC_DEP} )
	    endif()

          endforeach()
       endif()

       if ( ${_optional} STREQUAL "TRUE"  )

         if ( ${_VAL}_FOUND )

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

           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})
        string (TOUPPER ${_val} _VAL)

        if (NOT ${_VAL}_FOUND AND NOT ${_val}_FOUND)
        #  MESSAGE(STATUS "Looking for _val \"${_val}\"")
          find_package(${_val})
          list(APPEND LOADED_PACKAGES_ "${_val}")
        #else()
        #  MESSAGE(STATUS "Skipping _val \"${_val}\"")
        endif ()

        #======================================================================================
        # Global dependency tracking
        #======================================================================================
        # Get our current list of all dependencies used by plugins
	get_property( global_dependency_list GLOBAL PROPERTY GLOBAL_PLUGIN_DEPENDENCIES_LIST)

	#Add the new entry to the list
        list (APPEND global_dependency_list ${_val} )

        # Remove it again, if it was a duplicate
        list(REMOVE_DUPLICATES global_dependency_list)

        # Store the list in the global property
        set_property( GLOBAL PROPERTY GLOBAL_PLUGIN_DEPENDENCIES_LIST ${global_dependency_list} )

        #======================================================================================
        # Collect all dependencies (local and global)
        #======================================================================================

        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}_INCLUDES)
              list (APPEND ${_prefix}_DEPS_INCDIRS "${${_name}_INCLUDES}")
            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)
#              list (APPEND ${_prefix}_DEPS_LINKER_FLAGS "${${_name}_LINKER_FLAGS}")
              # this variable is used as a string later on (not as a list!!!)
              set( ${_prefix}_DEPS_LINKER_FLAGS "${${_prefix}_DEPS_LINKER_FLAGS} ${${_name}_LINKER_FLAGS}")
            endif ()
            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 ()
            if (DEFINED ${_name}_COMPILER_DEFINITIONS)
              list (APPEND ${_prefix}_DEPS_COMPILE_DEFINITIONS "${${_name}_COMPILER_DEFINITIONS}")
              list(REMOVE_DUPLICATES ${_prefix}_DEPS_COMPILE_DEFINITIONS )
            endif ()
            if (DEFINED ${_name}_COMPILE_DEFINITIONS)
              list (APPEND ${_prefix}_DEPS_COMPILE_DEFINITIONS "${${_name}_COMPILE_DEFINITIONS}")
              list(REMOVE_DUPLICATES ${_prefix}_DEPS_COMPILE_DEFINITIONS )
            endif ()
          endforeach ()
        else ()
            set (${_prefix}_HAS_DEPS FALSE)
            acg_set (_${_prefix}_MISSING_DEPS "${_${_prefix}_MISSING_DEPS} ${_val}")
        endif ()
    endforeach ()

Jan Möbius's avatar
Jan Möbius committed
326 327 328 329 330 331
    
    if ( NOT ${_optional} STREQUAL "TRUE"  )
   
      if  ( DEFINED ${_prefix}_TYPES )

          foreach (_TYPE ${${_prefix}_TYPES})
332
             if ( TARGET ${_TYPE} )
Jan Möbius's avatar
Jan Möbius committed
333 334
               list(APPEND ${_prefix}_TYPE_INCLUDES "${${_TYPE}_INCLUDE}")
               list(APPEND ${_prefix}_TYPE_DEPENDENCIES "${_TYPE}")
335
               list(APPEND ${_prefix}_TYPE_DEFINITIONS "-DENABLE_${_TYPE}_SUPPORT")
Jan Möbius's avatar
Jan Möbius committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
             else()
               acg_set (_${_prefix}_MISSING_DEPS "${_${_prefix}_MISSING_DEPS} TYPE_${_TYPE} ")
               set (${_prefix}_HAS_DEPS FALSE)
             endif()

          endforeach()
      endif()
    endif()

    # Optional types
    if ( ${_optional} STREQUAL "TRUE"  )
      if  ( DEFINED ${_prefix}_OPT_TYPES )

          foreach (_TYPE ${${_prefix}_OPT_TYPES})

351
             if ( TARGET ${_TYPE} )
Jan Möbius's avatar
Jan Möbius committed
352 353
               list(APPEND ${_prefix}_TYPE_INCLUDES "${${_TYPE}_INCLUDE}")
               list(APPEND ${_prefix}_TYPE_DEPENDENCIES "${_TYPE}")
354
               list(APPEND ${_prefix}_TYPE_DEFINITIONS "-DENABLE_${_TYPE}_SUPPORT")
Jan Möbius's avatar
Jan Möbius committed
355
             else()
356
               message("Optional Datatype ${_TYPE} not available, proceeding without it")
Jan Möbius's avatar
Jan Möbius committed
357 358 359 360 361 362 363
             endif()

          endforeach()
      endif()
    endif()


Jan Möbius's avatar
Jan Möbius committed
364 365 366 367 368 369 370 371 372 373 374 375
    set(LOADED_PACKAGES ${LOADED_PACKAGES} ${LOADED_PACKAGES_})
    set(LOADED_PACKAGES ${LOADED_PACKAGES} PARENT_SCOPE)
endmacro ()

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

  if ( OPENFLIPPER_ENABLE_LICENSE_KEY_GENERATOR )
    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")

376
    add_executable (Plugin-${plugin}-keygen ${keygen_ui} ${keygen_hdr} ${keygen_src})
Jan Möbius's avatar
Jan Möbius committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405

    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 ()
  endif()
  if ( OPENFLIPPER_ENABLE_LICENSE_MANAGER )
    acg_append_files (headers "LicenseManagerActive.hh" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
406
    acg_append_files (sources "LicenseManagerActive.cc" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
Jan Möbius's avatar
Jan Möbius committed
407 408 409
  # acg_append_files (ui "*.ui" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
  else(OPENFLIPPER_ENABLE_LICENSE_MANAGER)
    acg_append_files (headers "LicenseManagerDisabled.hh" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
410
    acg_append_files (sources "LicenseManagerDisabled.cc" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
Jan Möbius's avatar
Jan Möbius committed
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 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 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
  endif()
endmacro ()

#======================================================
# check dependencies in GLEW library
# _prefix    : prefix used ( usually the plugin name )
#======================================================
macro (_check_plugin_glew_deps _prefix )

 foreach (_extension ${${_prefix}_GLEWDEFINITIONS})

   acg_test_glew_definition( ${_extension} ${_prefix}_GLEW_HAS_DEFINITION_${_extension}  )

   # If the dependency is not found, we disable the plugin
   if(NOT ${_prefix}_GLEW_HAS_DEFINITION_${_extension} )
      set (${_prefix}_HAS_DEPS FALSE)
      acg_set (_${_prefix}_MISSING_DEPS "${_${_prefix}_MISSING_DEPS} GLEW extension ${_extension}")
   endif()

 endforeach()

endmacro ()



#======================================================
# main function
#======================================================
function (_build_openflipper_plugin plugin)
  acg_set (OPENFLIPPER_${_PLUGIN}_BUILD "0")

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

  #============================================================================================
  # parse parameters
  #============================================================================================

  _get_plugin_parameters (${_PLUGIN} ${ARGN})

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

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

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

  #============================================================================================
  # Additional libraries to be linked to the core app
  #============================================================================================

  get_property( global_core_app_libraries GLOBAL PROPERTY GLOBAL_CORE_APP_LIBRARIES)
  foreach (_val ${${_PLUGIN}_ADD_CORE_APP_LIBRARIES})
    list(APPEND global_core_app_libraries ${_val})
    list(REMOVE_DUPLICATES global_core_app_libraries)
  endforeach ()
  set_property( GLOBAL PROPERTY GLOBAL_CORE_APP_LIBRARIES ${global_core_app_libraries} )

  # CHECK for GLEW definitions
  #============================================================================================

  _check_plugin_glew_deps (${_PLUGIN})

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

    # Find all packages and include their Paths here as they would be in the toplevel
    file(GLOB OF_PACKAGES RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/Package*" )

    foreach ( OF_PACKAGE ${OF_PACKAGES})
      list(APPEND PACKAGE_INCLUDES "${CMAKE_SOURCE_DIR}/${OF_PACKAGES}")
    endforeach ()

    # search all lib directories in packages for OpenFlipper
  
    file (
        GLOB PACKAGE_DIRS
          "${CMAKE_SOURCE_DIR}/Package-*"
    )

Jan Möbius's avatar
Jan Möbius committed
513 514
    # ${CMAKE_BINARY_DIR}/OpenFlipper/libs_required/ACG  : Required due to ui files creating headers there

Jan Möbius's avatar
Jan Möbius committed
515 516 517
    
    

Jan Möbius's avatar
Jan Möbius committed
518 519 520 521
    include_directories (
      .
      ${PACKAGE_DIRS}
      ${CMAKE_SOURCE_DIR}
Jan Möbius's avatar
Jan Möbius committed
522
      ${ACG_INCLUDE_DIR}
Jan Möbius's avatar
Jan Möbius committed
523 524 525
      ${OPENMESH_INCLUDE_DIRS}
      ${CMAKE_CURRENT_SOURCE_DIR}
      ${CMAKE_CURRENT_BINARY_DIR}
Jan Möbius's avatar
Jan Möbius committed
526
      ${CMAKE_BINARY_DIR}/OpenFlipper/libs_required/ACG
Jan Möbius's avatar
Jan Möbius committed
527 528 529 530 531 532 533
      ${${_PLUGIN}_DEPS_INCDIRS}
      ${${_PLUGIN}_INCDIRS}
      ${OPENGL_INCLUDE_DIR}
      ${GLEW_INCLUDE_DIR}
      ${GLUT_INCLUDE_DIR}
      ${CMAKE_BINARY_DIR}/OpenFlipper/PluginLib
      ${PACKAGE_INCLUDES}
Jan Möbius's avatar
Jan Möbius committed
534
      ${${_PLUGIN}_TYPE_INCLUDES}
Jan Möbius's avatar
Jan Möbius committed
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
    )

    # 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"
         "${CMAKE_SOURCE_DIR}/Package*/ObjectTypes/*/CMakeLists.txt"
      )


      # 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}
        ${ADDITIONAL_PLUGINLIB_LINK_DIRS}
      )

    else (APPLE)
       link_directories (
         ${${_PLUGIN}_DEPS_LIBDIRS}
         ${${_PLUGIN}_LIBDIRS}
       )
    endif(APPLE)

    set (directories
       .
       ${${_PLUGIN}_DIRS}
    )

    #============================================================================================
    # User Documentation build
    #============================================================================================

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

      if (NOT DOXYGEN_FOUND)
        find_package(Doxygen)
      endif ()

      if ( DOXYGEN_FOUND )

        # Create user documentation target with our template doxy file
        acg_create_doc_target( doc-User-${plugin} "${CMAKE_SOURCE_DIR}/OpenFlipper/Documentation/PluginDoxyTemplate" )

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

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

      if ( OPENFLIPPER_ENABLE_LICENSE_MANAGER )
	   set(${_PLUGIN}_LICENSE_DEFS "-DWITH_LICENSE_MANAGER")
      endif()
    endif ()

640 641
    add_definitions(${${_PLUGIN}_TYPE_DEFINITIONS})

Jan Möbius's avatar
Jan Möbius committed
642
    add_library (Plugin-${plugin} MODULE ${ui} ${sources} ${headers} ${qrc} ${${_PLUGIN}_ADDSRC})
Jan Möbius's avatar
Jan Möbius committed
643 644 645 646 647 648 649 650 651
    #group projects by parent folder name on MSVC (used for e.g. plugincollection)
    get_filename_component(PARENT_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
    get_filename_component(PARENT_DIR_NAME "${PARENT_DIR}" NAME)
    GROUP_PROJECT(Plugin-${plugin} ${PARENT_DIR_NAME})
    # add this plugin to build plugin list for dependency tracking
    acg_set (OPENFLIPPER_PLUGINS "${OPENFLIPPER_PLUGINS};Plugin-${plugin}")
    acg_set (OPENFLIPPER_${_PLUGIN}_BUILD "1")

    if (STATIC_PLUGIN_${_PLUGIN})
Jan Möbius's avatar
Jan Möbius committed
652
        add_library (Plugin-Static-${plugin} STATIC ${ui} ${sources} ${headers} ${qrc} ${${_PLUGIN}_ADDSRC})
Jan Möbius's avatar
Jan Möbius committed
653 654 655 656 657 658 659 660 661 662 663 664
        set_target_properties(Plugin-Static-${plugin} PROPERTIES COMPILE_DEFINITIONS "QT_STATICPLUGIN")
        get_target_property(PLUGIN_OUTPUT_FILENAME Plugin-${plugin} LOCATION)
        get_filename_component(PLUGIN_OUTPUT_FILENAME "${PLUGIN_OUTPUT_FILENAME}" NAME)
        acg_set (OPENFLIPPER_STATIC_PLUGINS "${OPENFLIPPER_STATIC_PLUGINS};Plugin-Static-${plugin}")
        acg_set (OPENFLIPPER_STATIC_PLUGIN_NAMES "${OPENFLIPPER_STATIC_PLUGIN_NAMES};${STATIC_PLUGIN_${_PLUGIN}}")
        acg_set (OPENFLIPPER_STATIC_PLUGIN_FILES "${OPENFLIPPER_STATIC_PLUGIN_FILES};${PLUGIN_OUTPUT_FILENAME}")
    endif ()

    # append compiler and linker flags from plugin dependencies

    list(APPEND ${_PLUGIN}_DEPS_COMPILE_DEFINITIONS ${${_PLUGIN}_CDEFINITIONSADD} )

665
    string(REPLACE ";" " " ${_PLUGIN}_CFLAGSADD_STR "${${_PLUGIN}_CFLAGSADD}")
Jan Möbius's avatar
Jan Möbius committed
666 667 668 669 670 671 672 673 674 675 676 677

    set_target_properties (
      Plugin-${plugin} PROPERTIES
      COMPILE_FLAGS "${${_PLUGIN}_CFLAGSADD_STR} ${${_PLUGIN}_LICENSE_DEFS} ${${_PLUGIN}_DEPS_COMPILER_FLAGS}"
      COMPILE_DEFINITIONS  "${${_PLUGIN}_DEPS_COMPILE_DEFINITIONS}"
      LINK_FLAGS "${${_PLUGIN}_LDFLAGSADD} ${${_PLUGIN}_DEPS_LINKER_FLAGS}"
    )

    if (WIN32)
      # Visual studio requires our plugins to link with GLUT
      find_package (GLUT)
      # generate dllinport defines
678
      add_definitions (-DACGDLL -DUSEACG -DPLUGINLIBDLL -DUSEPLUGINLIBDLL -DFREEGLUT_LIB_PRAGMAS=0)
Jan Möbius's avatar
Jan Möbius committed
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
      target_link_libraries (Plugin-${plugin}
    	${OPENMESH_LIBRARIES}
        ACG
        OpenFlipperPluginLib
        ${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
                          )
    elseif (APPLE)

      target_link_libraries (
         Plugin-${plugin}
	 OpenFlipperPluginLib
	 ${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 ()

    target_link_libraries (Plugin-${plugin}
      ${${_PLUGIN}_DEPS_LIBRARIES}
      ${${_PLUGIN}_LIBRARIES}
Jan Möbius's avatar
Jan Möbius committed
726
      ${${_PLUGIN}_TYPE_DEPENDENCIES}
Jan Möbius's avatar
Jan Möbius committed
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
    )

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

    set(INSTALLDATA_DIRS)
    foreach (_dir ${${_PLUGIN}_INSTALLDATA})
      list(APPEND INSTALLDATA_DIRS "${_dir}")
      if (NOT APPLE)
        acg_install_dir ("${CMAKE_CURRENT_SOURCE_DIR}/${_dir}" "${ACG_PROJECT_DATADIR}/${_dir}")
      endif ()
    endforeach ()
    set(INSTALLDATA_DIRS ${INSTALLDATA_DIRS} PARENT_SCOPE)

    #============================================================================================
    # CUDA Integration
    # This block takes all cuda files from a plugins subdirectory called "Cuda"
    # The files will be compiled by nvcc and linked to one library containing all cuda parts of
    # the plugin. This static library is than linked into the plugin
    #============================================================================================

    # Check if cuda is in the list of dependencies:
    list(FIND ${_PLUGIN}_DEPS "CUDA" FIND_RESULT)
    if ( NOT FIND_RESULT EQUAL -1 )

      # Required but maybe it is not found
      # finder is automatically called before this
      if ( CUDA_FOUND )
        #Setup options
        CUDA_ADD_CUDA_INCLUDE_ONCE()

        # 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
        file(GLOB_RECURSE ${_PLUGIN}_CUDA_SRCS Cuda/*.cu Cuda/*.c)

        # Add cuda include dirs to global build target
        include_directories(${CUDA_INCLUDE_DIRS})

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

        # Prepare the files
        if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
        	CUDA_COMPILE(${_PLUGIN}_CUDA_GENERATED_FILES ${${_PLUGIN}_CUDA_SRCS} OPTIONS -g -G --device-emulation -Xcompiler)
        else()
        	CUDA_COMPILE(${_PLUGIN}_CUDA_GENERATED_FILES ${${_PLUGIN}_CUDA_SRCS} OPTIONS -O2)
        endif()

        # Create the library containing all cuda files
        CUDA_ADD_LIBRARY(${_PLUGIN}_cuda_lib STATIC ${${_PLUGIN}_CUDA_GENERATED_FILES} )

        # Link the cuda plugin library to the plugin itself
        target_link_libraries(Plugin-${plugin} ${_PLUGIN}_cuda_lib)

        # reset to original compile definitions
        set_directory_properties( PROPERTIES COMPILE_DEFINITIONS "${CURRENT_DEFINITIONS}" )

      endif( CUDA_FOUND )
    endif()

    #============================================================================================
    # Translations
    #============================================================================================

    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 ()
    set(PLUGIN_${plugin}_MISSING_DEPS FALSE PARENT_SCOPE)

  else ()
    message (STATUS "[WARNING] One or more dependencies for plugin ${plugin} not found. Skipping plugin.")
    message (STATUS "Missing dependencies :${_${_PLUGIN}_MISSING_DEPS}")
    set(PLUGIN_${plugin}_MISSING_DEPS TRUE PARENT_SCOPE)
  endif ()

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
  )

  set (
    STATIC_PLUGIN_${_PLUGIN}
    ""
    CACHE
    STRING
    "Set this variable to the name of the plugin class in order to link it statically into the OpenFlipper binary."
  )

  if (NOT DISABLE_PLUGIN_${_PLUGIN})
    #group the files in msvc
    RECURSE_GROUPS( ${CMAKE_CURRENT_SOURCE_DIR} )
    _build_openflipper_plugin (${_plugin} ${ARGN})
    set(LOADED_PACKAGES ${LOADED_PACKAGES} PARENT_SCOPE)
    set(INSTALLDATA_DIRS ${INSTALLDATA_DIRS} PARENT_SCOPE)
  endif ()
endmacro ()

# No stupid abundance of "Boost version" messages, please.
SET (Boost_FIND_QUIETLY TRUE PARENT_SCOPE)