plugin.cmake 12.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
# This module provides the following macro:
#
# openflipper_plugin ( [DIRS dir1 dir2 ...]
#                      [DEPS dep1 dep2 ...]
#                      [OPTDEPS dep1 dep2 ...]
#                      [LDFLAGSADD flag1 flag2 ...]
#                      [CFLAGSADD flag1 flag2 ...]
#                      [LIBRARIES lib1 lib2 ...]
#                      [LIBDIRS dir1 dir2 ...]
#                      [INCDIRS dir1 dir2 ...]
#                      [ADDSRC file1 file2 ...]
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
12
#                      [INSTALLDATA dir1 dir2 ...]
Jan Möbius's avatar
Jan Möbius committed
13
14
#                      [TRANSLATION_LANGUAGES lang1 lang2 ...]
#                      [TRANSLATION_ADDFILES file1 file2 ...]
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
15
#                      [LICENSEMANAGER])
16
17
18
19
20
21
22
23
24
25
26
27
#
# DIRS        = additional directories with source files
# DEPS        = required dependencies for find_package macro
# OPTDEPS     = optional dependencies for find_package macro
# LDFLAGSADD  = flags added to the link command
# CFLAGSADD   = flags 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
#
Jan Möbius's avatar
Jan Möbius committed
28
29
30
# TRANSLATION_LANGUAGES = language codes for translation
# TRANSLATION_ADDFILES  = additional files that should be included into the translation files
#
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
31
32
# LICENSEMANAGER = Compile plugin with license management
#
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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)
#

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)
Jan Möbius's avatar
Jan Möbius committed
49
    set (_supported_var DIRS DEPS OPTDEPS LDFLAGSADD CFLAGSADD LIBRARIES LIBDIRS INCDIRS ADDSRC INSTALLDATA TRANSLATION_LANGUAGES TRANSLATION_ADDFILES)
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
50
    set (_supported_flags LICENSEMANAGER)
51
52
53
    foreach (_val ${_supported_var})
        set (${_prefix}_${_val})
    endforeach ()
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
54
55
56
57
    foreach (_val ${_supported_flags})
        set (${_prefix}_${_val} 0)
    endforeach ()

58
59
60
61
62
63
64
    foreach (_val ${ARGN})
        set (_found FALSE)
        foreach (_find ${_supported_var})
            if ("${_find}" STREQUAL "${_val}")
                set (_found TRUE)
            endif ()
        endforeach ()
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
65
66
67
68
69
70
71

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

72
73
74
75
76
77
        if (_found)
            set (_current_var ${_prefix}_${_val})
        else ()
            list (APPEND ${_current_var} ${_val})
        endif ()
    endforeach ()
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
78

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

# check dependencies
macro (_check_plugin_deps _prefix)
    set (${_prefix}_HAS_DEPS TRUE)
    foreach (_val ${ARGN})
        string (TOUPPER ${_val} _VAL)

        find_package(${_val})

        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)
              list (APPEND ${_prefix}_DEPS_LINKER_FLAGS "${${_name}_LINKER_FLAGS}")
            endif ()
          endforeach ()
        else ()
            set (${_prefix}_HAS_DEPS FALSE)
            acg_set (_${_prefix}_MISSING_DEPS "${_${_prefix}_MISSING_DEPS} ${_val}")
        endif ()
    endforeach ()
endmacro ()

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
123
124
125
macro (_plugin_licensemanagement)
  acg_append_files (headers "*.hh" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
  acg_append_files (sources "*.cc" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
Jan Möbius's avatar
Jan Möbius committed
126
#  acg_append_files (ui "*.ui" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager")
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
127
128
129

  acg_append_files (keygen_hdr "*.hh" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager/keyGen")
  acg_append_files (keygen_src "*.cc" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager/keyGen")
Jan Möbius's avatar
Jan Möbius committed
130
131
132
133
  acg_append_files (keygen_ui  "*.ui" "${CMAKE_SOURCE_DIR}/OpenFlipper/LicenseManager/keyGen")
  
  # genereate uic and moc targets
  acg_qt4_autouic (keygen_uic ${keygen_ui})
Jan Möbius's avatar
Jan Möbius committed
134
  acg_qt4_automoc (keygen_moc ${keygen_hdr})
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
135

Jan Möbius's avatar
Jan Möbius committed
136
  add_executable (Plugin-${plugin}-keygen ${keygen_uic} ${keygen_moc} ${keygen_hdr} ${keygen_src})
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
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

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

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


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

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

  if (${_PLUGIN}_HAS_DEPS)
    include_directories (
      .
      ${CMAKE_SOURCE_DIR}
      ${CMAKE_SOURCE_DIR}/OpenMesh/src
      ${CMAKE_CURRENT_SOURCE_DIR}
      ${CMAKE_CURRENT_BINARY_DIR}
      ${${_PLUGIN}_DEPS_INCDIRS}
      ${${_PLUGIN}_INCDIRS}
      ${OPENGL_INCLUDE_DIR}
      ${GLEW_INCLUDE_DIR}
      ${GLUT_INCLUDE_DIR}
    )

    link_directories (
      ${${_PLUGIN}_DEPS_LIBDIRS}
      ${${_PLUGIN}_LIBDIRS}
    )

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

    # collect all header,source and ui files
    acg_append_files (headers "*.hh" ${directories})
    acg_append_files (sources "*.cc" ${directories})
    acg_append_files (sources "*.c" ${directories})
    acg_append_files (ui "*.ui" ${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 ()

Jan Möbius's avatar
Jan Möbius committed
226
    if (${_PLUGIN}_LICENSEMANAGER)
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
227
228
229
      _plugin_licensemanagement ()
    endif ()

230
231
232
233
234
235
236
237
238
239
240
241
242
    # genereate uic and moc targets
    acg_qt4_autouic (uic_targets ${ui})
    acg_qt4_automoc (moc_targets ${headers})

    add_library (Plugin-${plugin} MODULE ${uic_targets} ${sources} ${headers} ${moc_targets} ${${_PLUGIN}_ADDSRC})

    # 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
    set_target_properties (
      Plugin-${plugin} PROPERTIES
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
243
      COMPILE_FLAGS ""
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
      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
      add_definitions (-DACGDLL -DUSEACG -DPLUGINLIBDLL -DUSEPLUGINLIBDLL)
      target_link_libraries (Plugin-${plugin}
	OpenMeshCore
        OpenMeshTools
        ACG
        PluginLib
        ${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}
	 PluginLib
	 ${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}
    )

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

Jan Möbius's avatar
Jan Möbius committed
318
    if ( ${_PLUGIN}_TRANSLATION_LANGUAGES)
319
      set (trans_files ${ui} )
Jan Möbius's avatar
Jan Möbius committed
320
321
322
      list (APPEND trans_files ${sources})
      list (APPEND trans_files ${headers})
      list (APPEND trans_files ${${_PLUGIN}_TRANSLATION_ADDFILES})
323
      acg_add_translations(Plugin-${plugin} ${${_PLUGIN}_TRANSLATION_LANGUAGES} ${trans_files})
Jan Möbius's avatar
Jan Möbius committed
324
325
    endif ()

326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
  else ()
    message (STATUS "[WARNING] One or more dependencies for plugin ${plugin} not found. Skipping plugin.")
    message (STATUS "Missing dependencies :${_${_PLUGIN}_MISSING_DEPS}")
  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
  )

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