ParaViewBranding.cmake 13.4 KB
Newer Older
1 2 3
###############################################################################
# This file defines the macros that ParaView-based clients can use of creating
# custom ParaView client builds with custom branding and configuration.
4
#
5 6 7
# build_paraview_client(
#   # The name for this client. This is the name used for the executable created.
#   paraview
8 9 10 11
#
#   # Optional name for the application (If none is specified then the
#   # client-name is used.
#   APPLICATION_NAME "ParaView"
12
#
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
13
#   # This is the title bar text (optional).
14
#
15
#   TITLE "Kitware ParaView"
16
#
17 18
#   # This is the organization name.
#   ORGANIZATION "Kitware Inc."
19
#
20 21
#   # PNG Image to be used for the Splash screen. If none is provided,
#   # splash screen is not shown/used.
22
#   SPLASH_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/Splash.png"
23
#
24 25 26 27
#   # Provide version information for the client.
#   VERSION_MAJOR ${PARAVIEW_VERSION_MAJOR}
#   VERSION_MINOR ${PARAVIEW_VERSION_MINOR}
#   VERSION_PATCH ${PARAVIEW_VERSION_PATCH}
28
#
29 30
#   # Icon to be used for the Mac bundle.
#   BUNDLE_ICON   "${CMAKE_CURRENT_SOURCE_DIR}/Icon.icns"
31
#
32 33 34 35 36 37 38
#   # Icon to be used for the Windows application.
#   APPLICATION_ICON "${CMAKE_CURRENT_SOURCE_DIR}/Icon.ico"
#
#   # Name of the class to use for the main window. If none is specified,
#   # default QMainWindow will be used.
#   PVMAIN_WINDOW QMainWindow-subclass
#   PVMAIN_WINDOW_INCLUDE QMainWindow-subclass-header
39
#
40 41 42 43 44 45 46 47
#   # Next specify the plugins that are needed to be built and loaded on startup
#   # for this client to work. These must be specified in the order that they
#   # should be loaded. The name is the name of the plugin specified in the
#   # add_paraview_plugin call.
#   # Currently, only client-based plugins are supported. i.e. no effort is made
#   # to load the plugins on the server side when a new server connection is made.
#   # That may be added in future, if deemed necessary.
#   REQUIRED_PLUGINS PointSpritePlugin
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
#   # Next specify the plugin that are not required, but if available, should be
#   # loaded on startup. These must be specified in the order that they
#   # should be loaded. The name is the name of the plugin specified in the
#   # add_paraview_plugin call.
#   # Currently, only client-based plugins are supported. i.e. no effort is made
#   # to load the plugins on the server side when a new server connection is made.
#   # That may be added in future, if deemed necessary.
#   OPTIONAL_PLUGINS ClientGraphView ClientTreeView
#
#   # Extra targets that this executable depends on. Useful only if you are
#   # building extra libraries for your application.
#   EXTRA_DEPENDENCIES blah1 blah2
#
#   # GUI Configuration XMLs that are used to configure the client eg. readers,
#   # writers, sources menu, filters menu etc.
#   GUI_CONFIGURATION_XMLS <list of xml files>
#
#   # The Qt compressed help file (*.qch) which provides the documentation for the
#   # application. *.qch files are typically generated from *.qhp files using
#   # the qhelpgenerator executable.
#   COMPRESSED_HELP_FILE MyApp.qch
#
#   # Additional source files.
#   SOURCES <list of source files>
73
#
74 75 76 77 78
#   # If this option is present, then this macro will create a library named
#   # pq{Name}Initializer with all the source components generated by this macro
#   # that the executable links against. Otherwise, for sake of simplicity no
#   # extra library is created.
#   MAKE_INITIALIZER_LIBRARY
79 80 81 82 83 84 85 86 87
#
#   # Optionally specify install destinations.  See CMake install() command
#   # documentation for meaning of RUNTIME, LIBRARY, ARCHIVE, and BUNDLE.
#   INSTALL_RUNTIME_DIR "bin"
#   INSTALL_LIBRARY_DIR "lib/<appname>-<major>.<minor>"
#   INSTALL_ARCHIVE_DIR "lib/<appname>-<major>.<minor>"
#   INSTALL_BUNDLE_DIR  "bin" # default is the INSTALL_RUNTIME_DIR
#
#   # Deprecated.  Use INSTALL_RUNTIME_DIR and INSTALL_BUNDLE_DIR instead.
88 89
#   INSTALL_BIN_DIR "bin"
#
90
#   # Deprecated.  Use INSTALL_LIBRARY_DIR and INSTALL_ARCHIVE_DIR instead.
91
#   INSTALL_LIB_DIR "lib"
92
#   )
93
#
94
###############################################################################
95
include(pvForwardingExecutable)
96

97
FUNCTION(build_paraview_client BPC_NAME)
98
  PV_PARSE_ARGUMENTS(BPC
99
    "APPLICATION_NAME;TITLE;ORGANIZATION;SPLASH_IMAGE;VERSION_MAJOR;VERSION_MINOR;VERSION_PATCH;BUNDLE_ICON;APPLICATION_ICON;REQUIRED_PLUGINS;OPTIONAL_PLUGINS;PVMAIN_WINDOW;PVMAIN_WINDOW_INCLUDE;EXTRA_DEPENDENCIES;GUI_CONFIGURATION_XMLS;COMPRESSED_HELP_FILE;SOURCES;INSTALL_RUNTIME_DIR;INSTALL_LIBRARY_DIR;INSTALL_ARCHIVE_DIR;INSTALL_BUNDLE_DIR;INSTALL_BIN_DIR;INSTALL_LIB_DIR"
100
    "MAKE_INITIALIZER_LIBRARY"
101 102 103 104 105
    ${ARGN}
    )

  # Version numbers are required. Throw an error is not set correctly.
  IF (NOT DEFINED BPC_VERSION_MAJOR OR NOT DEFINED BPC_VERSION_MINOR OR NOT DEFINED BPC_VERSION_PATCH)
106
    MESSAGE(ERROR
107
      "VERSION_MAJOR, VERSION_MINOR and VERSION_PATCH must be specified")
108
  ENDIF ()
109 110

  # If no title is provided, make one up using the name.
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
111 112 113 114 115
  if(DEFINED BPC_TITLE)
    set (BPC_HAS_TITLE 1)
  else()
    set (BPC_HAS_TITLE 0)
  endif()
116 117 118
  pv_set_if_not_set(BPC_TITLE "${BPC_NAME}")
  pv_set_if_not_set(BPC_APPLICATION_NAME "${BPC_NAME}")
  pv_set_if_not_set(BPC_ORGANIZATION "Humanity")
119 120 121 122 123 124 125 126 127 128 129 130 131
  if(NOT DEFINED BPC_INSTALL_RUNTIME_DIR AND DEFINED BPC_INSTALL_BIN_DIR)
    set(BPC_INSTALL_RUNTIME_DIR "${BPC_INSTALL_BIN_DIR}")
  endif()
  if(NOT DEFINED BPC_INSTALL_LIBRARY_DIR AND DEFINED BPC_INSTALL_LIB_DIR)
    set(BPC_INSTALL_LIBRARY_DIR "${BPC_INSTALL_LIB_DIR}")
  endif()
  if(NOT DEFINED BPC_INSTALL_BUNDLE_DIR AND DEFINED BPC_INSTALL_BIN_DIR)
    set(BPC_INSTALL_BUNDLE_DIR "${BPC_INSTALL_BIN_DIR}")
  endif()
  pv_set_if_not_set(BPC_INSTALL_RUNTIME_DIR "bin")
  pv_set_if_not_set(BPC_INSTALL_LIBRARY_DIR
      "lib/${BPC_NAME}-${BPC_VERSION_MAJOR}.${BPC_VERSION_MINOR}")
  pv_set_if_not_set(BPC_INSTALL_ARCHIVE_DIR
132
      "lib/${BPC_NAME}-${BPC_VERSION_MAJOR}.${BPC_VERSION_MINOR}")
133
  pv_set_if_not_set(BPC_INSTALL_BUNDLE_DIR "${BPC_INSTALL_RUNTIME_DIR}")
134

135
  SET (branding_source_dir "${ParaView_CMAKE_DIR}")
136 137 138 139 140 141

  # If APPLICATION_ICON is specified, use that for the windows executable.
  IF (WIN32 AND BPC_APPLICATION_ICON)
    FILE (WRITE "${CMAKE_CURRENT_BINARY_DIR}/Icon.rc"
      "// Icon with lowest ID value placed first to ensure application icon\n"
      "// remains consistent on all systems.\n"
142
      "IDI_ICON1 ICON \"${BPC_APPLICATION_ICON}\"")
143
    SET(exe_icon "${CMAKE_CURRENT_BINARY_DIR}/Icon.rc")
144
  ENDIF ()
145

146 147 148 149
  # executable_flags are used to pass options to add_executable(..) call such as
  # WIN32 or MACOSX_BUNDLE
  set (executable_flags)

150 151 152
  # If BPC_BUNDLE_ICON is set, setup the macosx bundle.
  IF (APPLE)
    IF (BPC_BUNDLE_ICON)
153 154
      GET_FILENAME_COMPONENT(bundle_icon_file "${BPC_BUNDLE_ICON}" NAME)
      SET(apple_bundle_sources ${bundle_icon_file})
155 156 157 158
      SET_SOURCE_FILES_PROPERTIES(
        ${BPC_BUNDLE_ICON}
        PROPERTIES
        MACOSX_PACKAGE_LOCATION Resources
159 160 161 162 163 164 165 166 167 168
        )
    ENDIF ()
    IF (IS_DIRECTORY "${QT_QTGUI_LIBRARY_RELEASE}")
      GET_FILENAME_COMPONENT(qt_menu_nib
        "${QT_QTGUI_LIBRARY_RELEASE}/Resources/qt_menu.nib"
        REALPATH)
    ELSE ()
      GET_FILENAME_COMPONENT(qt_menu_nib
        "${QT_LIBRARY_DIR}/Resources/qt_menu.nib"
        REALPATH)
169
    ENDIF ()
170

171 172 173 174 175 176 177 178 179
    set(qt_menu_nib_sources
      "${qt_menu_nib}/classes.nib"
      "${qt_menu_nib}/info.nib"
      "${qt_menu_nib}/keyedobjects.nib"
      )
    SET_SOURCE_FILES_PROPERTIES(
      ${qt_menu_nib_sources}
      PROPERTIES
      MACOSX_PACKAGE_LOCATION Resources/qt_menu.nib
180 181
      )
    SET(executable_flags MACOSX_BUNDLE)
182
  ENDIF ()
183 184 185

  IF(WIN32)
    LINK_DIRECTORIES(${QT_LIBRARY_DIR})
186
    set (executable_flags WIN32)
187
  ENDIF()
188

189 190
  pv_set_if_not_set(BPC_PVMAIN_WINDOW "QMainWindow")
  pv_set_if_not_set(BPC_PVMAIN_WINDOW_INCLUDE "QMainWindow")
191 192 193 194

  SET (BPC_HAS_GUI_CONFIGURATION_XMLS 0)
  IF (BPC_GUI_CONFIGURATION_XMLS)
    SET (BPC_HAS_GUI_CONFIGURATION_XMLS 1)
195
  ENDIF ()
196

197 198
  set (ui_resources)
  set (ui_resource_init "")
199

200 201 202
  # If a splash image is specified, put that in a Qt resource file
  # and pass the name along to branded_paraview_initializer.cxx.
  if(DEFINED BPC_SPLASH_IMAGE)
203 204 205 206 207 208
    # We name the splash image as "SplashImage.img". That way, the
    # pqAboutDialog and other UI components can automatically pick
    # it up.
    set(splash_img "${CMAKE_CURRENT_BINARY_DIR}/SplashImage.img")
    configure_file("${BPC_SPLASH_IMAGE}" "${splash_img}" COPYONLY)
    set(BPC_SPLASH_RESOURCE ":/${BPC_NAME}/SplashImage.img")
209 210
    # Generate a resource file for the splash image.
    set(splash_qrc "${CMAKE_CURRENT_BINARY_DIR}/${BPC_NAME}_splash.qrc")
211
    generate_qt_resource_from_files("${splash_qrc}" "/${BPC_NAME}" ${splash_img})
212
    list(APPEND ui_resources "${splash_qrc}")
213
    set(ui_resource_init
214 215
      "${ui_resource_init}  Q_INIT_RESOURCE(${BPC_NAME}_splash);\n")
  endif()
216 217 218 219 220 221 222 223 224 225

  if (BPC_GUI_CONFIGURATION_XMLS)
    set (outfile "${CMAKE_CURRENT_BINARY_DIR}/${BPC_NAME}_configuration.qrc")
    GENERATE_QT_RESOURCE_FROM_FILES("${outfile}"
      "/${BPC_NAME}/Configuration"
      "${BPC_GUI_CONFIGURATION_XMLS}")
    list(APPEND ui_resources "${outfile}")
    set(ui_resource_init
      "${ui_resource_init}  Q_INIT_RESOURCE(${BPC_NAME}_configuration);\n")
  endif ()
226 227 228 229

  IF (BPC_COMPRESSED_HELP_FILE)
    # If a help collection file is specified, create a resource from it so that
    # when the ParaView help system can locate it at runtime and show the
230
    # appropriate help when the user asks for it. The
231 232
    set (outfile "${CMAKE_CURRENT_BINARY_DIR}/${BPC_NAME}_help.qrc")
    GENERATE_QT_RESOURCE_FROM_FILES("${outfile}"
233
      "/${BPC_APPLICATION_NAME}/Documentation"
234
      "${BPC_COMPRESSED_HELP_FILE};")
235 236
    SET_SOURCE_FILES_PROPERTIES(${outfile}
      PROPERTIES OBJECT_DEPENDS "${BPC_COMPRESSED_HELP_FILE}")
237
    SET (ui_resources ${ui_resources} "${outfile}")
238 239
    set (ui_resource_init
      "${ui_resource_init}  Q_INIT_RESOURCE(${BPC_NAME}_help);\n")
240
  ENDIF ()
241

242
  INCLUDE(ParaViewQt)
243
  pv_find_package_qt(qt_targets REQUIRED QUIET
244
    QT5_COMPONENTS Widgets)
245
  pv_qt_add_resources(rcs_sources ${ui_resources})
246 247 248 249 250 251 252 253

  SOURCE_GROUP("Resources" FILES
    ${ui_resources}
    ${exe_icon}
    )
  SOURCE_GROUP("Generated" FILES
    ${rcs_sources}
    )
254 255
  CONFIGURE_FILE(${branding_source_dir}/branded_paraview_main.cxx.in
                 ${CMAKE_CURRENT_BINARY_DIR}/${BPC_NAME}_main.cxx @ONLY)
256 257 258 259
  CONFIGURE_FILE(${branding_source_dir}/branded_paraview_initializer.cxx.in
                 ${CMAKE_CURRENT_BINARY_DIR}/pq${BPC_NAME}Initializer.cxx @ONLY)
  CONFIGURE_FILE(${branding_source_dir}/branded_paraview_initializer.h.in
                 ${CMAKE_CURRENT_BINARY_DIR}/pq${BPC_NAME}Initializer.h @ONLY)
260

261 262 263 264 265 266 267 268
  # If BPC_MAKE_INITIALIZER_LIBRARY is set, then we are creating a separate
  # library for the initializer, otherwise we don't create a separate library to
  # keep things simple.
  SET (EXE_SRCS pq${BPC_NAME}Initializer.cxx
               ${rcs_sources}
               ${BPC_SOURCES})

  IF (BPC_MAKE_INITIALIZER_LIBRARY)
269 270
    ADD_LIBRARY(pq${BPC_NAME}Initializer SHARED
                ${EXE_SRCS}
271 272 273
                )
    SET (EXE_SRCS)
    TARGET_LINK_LIBRARIES(pq${BPC_NAME}Initializer
274 275 276 277
      LINK_PRIVATE
        pqApplicationComponents
        vtkPVServerManagerApplication
        ${BPC_EXTRA_DEPENDENCIES}
278
        ${qt_targets}
279
      )
280

281 282 283
    IF (PV_INSTALL_LIB_DIR)
      INSTALL(TARGETS pq${BPC_NAME}Initializer
            DESTINATION ${PV_INSTALL_LIB_DIR}
284
            COMPONENT Runtime)
285 286
    ENDIF ()
  ENDIF ()
287

288
  SET (PV_EXE_LIST ${BPC_NAME})
289

290
  # needed to set up shared forwarding correctly.
291
  pv_add_executable_with_forwarding2(pv_exe_suffix
292 293
                 "${PARAVIEW_LIBRARY_DIRS}"
                 "../${PARAVIEW_INSTALL_LIB_DIR}"
294
                 "${BPC_INSTALL_LIBRARY_DIR}"
295 296
                 ${BPC_NAME}
                 ${executable_flags}
297
                 ${BPC_NAME}_main.cxx
298
                 ${exe_icon}
299 300 301
                 ${apple_bundle_sources}
                 ${EXE_SRCS}
                 )
302
  TARGET_LINK_LIBRARIES(${BPC_NAME}
303 304 305
      LINK_PRIVATE
        pqApplicationComponents
        vtkPVServerManagerApplication
306
        vtksys
307
        ${qt_targets}
308
        ${BPC_EXTRA_DEPENDENCIES}
309
    )
310

311
  IF (BPC_MAKE_INITIALIZER_LIBRARY)
312
    TARGET_LINK_LIBRARIES(${BPC_NAME}
313 314
      LINK_PRIVATE
        pq${BPC_NAME}Initializer)
315
  ENDIF ()
316

317 318 319 320 321
  if (MINGW)
    # needed for dupenv_s
    target_link_libraries (${BPC_NAME} LINK_PRIVATE msvcr90)
  endif ()

322 323
  if (pv_exe_suffix)
    install(TARGETS ${BPC_NAME}
324
            RUNTIME DESTINATION "${BPC_INSTALL_LIBRARY_DIR}"
325
            COMPONENT Runtime)
326 327
  endif()
  install(TARGETS ${BPC_NAME}${pv_exe_suffix}
328 329 330 331
          RUNTIME DESTINATION "${BPC_INSTALL_RUNTIME_DIR}"
          LIBRARY DESTINATION "${BPC_INSTALL_LIBRARY_DIR}"
          ARCHIVE DESTINATION "${BPC_INSTALL_ARCHIVE_DIR}"
          BUNDLE DESTINATION  "${BPC_INSTALL_BUNDLE_DIR}"
332
          COMPONENT Runtime)
333

334 335
  IF (APPLE)
    IF (BPC_BUNDLE_ICON)
336
      SET_TARGET_PROPERTIES(${BPC_NAME} PROPERTIES
337
        MACOSX_BUNDLE_ICON_FILE ${bundle_icon_file})
338
    ENDIF ()
339
    SET_TARGET_PROPERTIES(${BPC_NAME} PROPERTIES
340
      MACOSX_BUNDLE_BUNDLE_NAME "${BPC_APPLICATION_NAME}")
341 342 343 344 345
    string(TOLOWER ${BPC_ORGANIZATION} BPC_ORGANIZATION_LOWER)
    SET_TARGET_PROPERTIES(${BPC_NAME} PROPERTIES
      MACOSX_BUNDLE_GUI_IDENTIFIER "org.${BPC_ORGANIZATION_LOWER}.${BPC_APPLICATION_NAME}")
    SET_TARGET_PROPERTIES(${BPC_NAME} PROPERTIES
      MACOSX_BUNDLE_SHORT_VERSION_STRING "${BPC_VERSION_MAJOR}.${BPC_VERSION_MINOR}.${BPC_VERSION_PATCH}")
346 347 348 349
    if (NOT PARAVIEW_DO_UNIX_STYLE_INSTALLS)
      set_target_properties("${BPC_NAME}" PROPERTIES
        INSTALL_RPATH "@executable_path/../Libraries;@executable_path/../Plugins")
    endif ()
350 351
  ENDIF ()
ENDFUNCTION()