InstallSupportFiles.cmake 12.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Get the translation files coming with Qt, and install them in the bundle
# They are loaded by Monteverdi.
function(get_qt_translation_files RESULT)
    # These files are the "qt_<localename>.qm" files
    # They are located in QT_TRANSLATIONS_DIR, which comes from FindQt4
    file(GLOB translation_files ${QT_TRANSLATIONS_DIR}/qt_*)

    # We need to remove the "qt_help_<localename>.qm" files from this list
    foreach(translation_item ${translation_files})
      if(${translation_item} MATCHES "qt_help")
        list(REMOVE_ITEM translation_files ${translation_item})
      endif()
    endforeach()

    set(${RESULT} ${translation_files} PARENT_SCOPE)
  endfunction()


function(func_install_xdk_files)

  #The list of REQ_SHARE_DIR is made up from <mxe-target-dir>/share/
  #It may vary in future. I prefer not to glob on the share dir and
  #end up distributing man, info etc.. which ar irrelvant for windows
24
25
26
27

  #TODO: cleaup this function. current
  # code is bit of picking each .lib and .dll for now
  # see opencv, itk, 
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  foreach(REQ_SHARE_DIR
      aclocal
      Armadillo
      applications
      cmake
      dbus-1
      fontconfig
      libgta
      locale
      xml
      applications
      cmake
      icons
      OpenCV
      pixmaps
      pkgconfig
      )
    if(EXISTS "${DEPENDENCIES_INSTALL_DIR}/share/${REQ_SHARE_DIR}")
      func_install_without_message("${DEPENDENCIES_INSTALL_DIR}/share/${REQ_SHARE_DIR}" "share")
    endif()
  endforeach()

50
51
52
  file(GLOB ITK_CMAKE_DIRS "${DEPENDENCIES_INSTALL_DIR}/lib/cmake/ITK*")
  foreach(ITK_CMAKE_DIR ${ITK_CMAKE_DIRS})
      func_install_without_message("${ITK_CMAKE_DIR}" "lib/cmake")
53
54
55
56
57
  endforeach()

  set(QT_REQ_DIRS)
  if(WIN32)
    #only affects windows due to regex on dll
58
59
60
61
62
63
    #.lib are not taken when processing dependencies. 
    # We just get .dlls which is enough for binary package
    # For XDK, we need .lib files when building OTB using xdk
    # For Linux. we get .so.X.Y.Z by finding the 'target'
    # of any .so file. So there is no need for such a copy on
    # Linux and OSX 
64
65
66
67
68
69
70
71
72
    if(MSVC)
      file(GLOB LIB_FILES "${DEPENDENCIES_INSTALL_DIR}/lib/*.lib")
    else()
      file(GLOB LIB_FILES "${DEPENDENCIES_INSTALL_DIR}/lib/*dll.*")
    endif()

    foreach(LIB_FILE ${LIB_FILES})
      pkg_install_rule(${LIB_FILE})
    endforeach()
73
    
74
75
76
77
78
79
80
81
    #qt/bin is also a special case for mxe.
    file(GLOB QT_EXTRA_DLL_FILES "${DEPENDENCIES_INSTALL_DIR}/qt/bin/*.dll")
    install(FILES ${QT_EXTRA_DLL_FILES} DESTINATION ${PKG_STAGE_DIR}/bin)

    #list(APPEND QT_REQ_DIRS lib)
    list(APPEND QT_REQ_DIRS include)
    list(APPEND QT_REQ_DIRS imports)

82
83
    #mxe installs qt in a separate directory under install prefix. So..
    set(QT_INSTALL_DIR "${DEPENDENCIES_INSTALL_DIR}/qt")
84
  else()
85
    set(QT_INSTALL_DIR "${DEPENDENCIES_INSTALL_DIR}")
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

  endif(WIN32)

  list(APPEND QT_REQ_DIRS mkspecs)
  list(APPEND QT_REQ_DIRS plugins)
  list(APPEND QT_REQ_DIRS translations)
  foreach(QT_REQ_DIR ${QT_REQ_DIRS} )
    if(EXISTS "${QT_INSTALL_DIR}/${QT_REQ_DIR}")
      func_install_without_message("${QT_INSTALL_DIR}/${QT_REQ_DIR}" "")
    endif()
  endforeach()

  # #install ${DEPENDENCIES_INSTALL_DIR}/include directory. Attention to OTB includes
  file(GLOB ALL_IN_INCLUDE_DIR "${DEPENDENCIES_INSTALL_DIR}/include/*")
  foreach(INCLUDE_DIR_ITEM ${ALL_IN_INCLUDE_DIR})
    get_filename_component(INCLUDE_DIR_ITEM_name ${INCLUDE_DIR_ITEM} NAME)
    get_filename_component(INCLUDE_DIR_ITEM_name_we ${INCLUDE_DIR_ITEM} NAME_WE)
    if(NOT "${INCLUDE_DIR_ITEM_name_we}" MATCHES "OTB|otb")
      if( IS_DIRECTORY ${INCLUDE_DIR_ITEM})
        install(CODE
          "message(STATUS \"Installing: ${CMAKE_INSTALL_PREFIX}/${PKG_STAGE_DIR}/include/${INCLUDE_DIR_ITEM_name}/\")" )
        install(
          DIRECTORY   "${INCLUDE_DIR_ITEM}"
          DESTINATION "${PKG_STAGE_DIR}/include/"
          MESSAGE_NEVER
          )
      else()
        install(
          FILES   "${INCLUDE_DIR_ITEM}"
          DESTINATION "${PKG_STAGE_DIR}/include/"
          )
      endif() #if( IS_DIRECTORY
    endif() #if (NOT
  endforeach()

endfunction() #func_install_xdk_files

function(func_install_support_files)

  #a convenient cmake var for storing <prefix>/bin
  set(PKG_STAGE_BIN_DIR "${PKG_STAGE_DIR}/bin")

  #<prefix>/share for gdal data files
  set(PKG_SHARE_DEST_DIR ${PKG_STAGE_DIR}/share)

  set(PKG_SHARE_SOURCE_DIR ${DEPENDENCIES_INSTALL_DIR}/share)

  set(GDAL_DATA ${PKG_SHARE_SOURCE_DIR}/gdal)
  #MSVC install gdal-data in in a different directory. So we don't spoil it
  if(MSVC)
    set(GDAL_DATA ${DEPENDENCIES_INSTALL_DIR}/data)
  endif()

  # Just check if required variables are defined.
  foreach(req
      DEPENDENCIES_INSTALL_DIR
      PKG_STAGE_DIR
      PACKAGE_SUPPORT_FILES_DIR
      OTB_INSTALL_DIR
      )
    if(NOT DEFINED ${req})
      message(FATAL_ERROR "you must set ${req} before calling this method")
    endif()
    set(vars "${vars}  ${req}=[${${req}}]\n")
  endforeach(req)

  # one for debugging..
  # install(CODE "message(\"CMake/PackageHelper.cmake:install_supoport_files(${outdir})\n${vars}\n\")")
  if(NOT PKG_GENERATE_XDK)
    func_install_otb_support_files()

    #check if monteverdi executable is built?
    if(EXISTS "${OTB_INSTALL_DIR}/bin/monteverdi${EXE_EXT}")
      func_install_monteverdi_support_files()
    endif()

  endif() #NOT PKG_GENERATE_XDK

  ####################### install GDAL data ############################
  if(NOT EXISTS "${GDAL_DATA}/epsg.wkt")
    message(FATAL_ERROR
      "Cannot generate package without GDAL_DATA : ${GDAL_DATA} ${DEPENDENCIES_INSTALL_DIR}")
  endif()


171
172
173
174
175
176
  # install(
  #   DIRECTORY ${GDAL_DATA}
  #   DESTINATION ${PKG_SHARE_DEST_DIR}
  #   )

  func_install_without_message("${GDAL_DATA}" "share" )
177
  ####################### install GeoTIFF data ########################
178
179
180
  #install( DIRECTORY ${PKG_SHARE_SOURCE_DIR}/epsg_csv DESTINATION ${PKG_SHARE_DEST_DIR}  )

  func_install_without_message("${PKG_SHARE_SOURCE_DIR}/epsg_csv" "share" )
181
182

  ####################### install OSSIM data ##########################
183
184
185
  #install( DIRECTORY ${PKG_SHARE_SOURCE_DIR}/ossim DESTINATION ${PKG_SHARE_DEST_DIR})

  func_install_without_message("${PKG_SHARE_SOURCE_DIR}/ossim" "share" )
186
187
188

  ####################### install proj share ##########################
  if(EXISTS ${PKG_SHARE_SOURCE_DIR}/proj)
189
190
    #install(DIRECTORY ${PKG_SHARE_SOURCE_DIR}/proj DESTINATION ${PKG_SHARE_DEST_DIR})
    func_install_without_message("${PKG_SHARE_SOURCE_DIR}/proj" "share" )
191
192
193
  endif()
  
  ####################### Install copyrights ##########################
194
195
196
197
  #install license for windows package
  #install(DIRECTORY ${PKG_SHARE_SOURCE_DIR}/copyright DESTINATION ${PKG_SHARE_DEST_DIR} )
  func_install_without_message("${PKG_SHARE_SOURCE_DIR}/copyright" "share" )
  install(FILES ${PKG_SHARE_SOURCE_DIR}/copyright/LICENSE DESTINATION ${PKG_STAGE_DIR})
198
199

  ####################### Install VERSION ##########################
200
201
202

  set(PKG_VERSION_FILE
    "${OTB_INSTALL_DIR}/share/doc/${PKG_OTB_VERSION_MAJOR}.${PKG_OTB_VERSION_MINOR}/VERSION")
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
  if(EXISTS ${PKG_VERSION_FILE} )
    install(FILES ${PKG_VERSION_FILE} DESTINATION ${PKG_STAGE_DIR})
  endif()

endfunction()

function(func_install_otb_support_files)
  foreach(req
      PKG_STAGE_DIR
      OTB_INSTALL_DIR
      DEPENDENCIES_INSTALL_DIR
      )
    if(NOT DEFINED ${req})
      message(FATAL_ERROR "you must set ${req} before calling this method")
    endif()
    set(vars "${vars}  ${req}=[${${req}}]\n")
  endforeach(req)

  #a convenient cmake var for storing <prefix>/bin
  set(PKG_STAGE_BIN_DIR "${PKG_STAGE_DIR}/bin")

  #<prefix>/share for gdal data files
  set(PKG_SHARE_DEST_DIR ${PKG_STAGE_DIR}/share)

  set(PKG_SHARE_SOURCE_DIR ${DEPENDENCIES_INSTALL_DIR}/share)

  #For Unixes we make them in the *pkgsetup.in
Rashad Kanavath's avatar
Rashad Kanavath committed
230
  ##################### install environment setup file ##########################
231
  if(WIN32)
Rashad Kanavath's avatar
Rashad Kanavath committed
232
233
234
235
236
237
238
239
    install(
      FILES ${PACKAGE_SUPPORT_FILES_DIR}/otbenv.cmd
      DESTINATION ${PKG_STAGE_DIR}
      )

    install(
      FILES ${PACKAGE_SUPPORT_FILES_DIR}/otbenv.profile
      DESTINATION ${PKG_STAGE_DIR}
240
      RENAME otbenv.sh
Rashad Kanavath's avatar
Rashad Kanavath committed
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
    endforeach()

    #we need startup files for mapla monteverdi in the root directory
    #For Unixes, we make them inside pkgsetup script!
    foreach(exe_file mapla monteverdi)
      install(
        PROGRAMS ${PACKAGE_SUPPORT_FILES_DIR}/${exe_file}.bat
        DESTINATION "${PKG_STAGE_DIR}"
        )
    endforeach()
  endif()

  ####################### install cli and gui scripts ###########################
  file(GLOB PKG_APP_SCRIPTS
    ${OTB_INSTALL_DIR}/bin/otbcli*
    ${OTB_INSTALL_DIR}/bin/otbgui*) #

  list(LENGTH PKG_APP_SCRIPTS PKG_APP_SCRIPTS_LENGTH)
  if (PKG_APP_SCRIPTS_LENGTH LESS 1)
    message(WARNING "PKG_APP_SCRIPTS is empty: ${PKG_APP_SCRIPTS}")
  endif()

  ##################### install cli and gui scripts #######################
  install(PROGRAMS ${PKG_APP_SCRIPTS}  DESTINATION ${PKG_STAGE_BIN_DIR})


endfunction()

function(func_install_monteverdi_support_files)

  #name/ext of qt's sqlite plugin. Varies with platform/OS
  if(WIN32)
    set(PKG_QTSQLITE_FILENAME "qsqlite4.dll")
  elseif(APPLE)
    set(PKG_QTSQLITE_FILENAME "libqsqlite.dylib")
  elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
    set(PKG_QTSQLITE_FILENAME "libqsqlite.so")
  else()
    message(FATAL_ERROR "func_install_monteverdi_support_files: Unknown OS/Platform")
  endif()

  #root folder where qt plugins are installed
  set(PKG_QTPLUGINS_DIR "${PKG_STAGE_DIR}/lib/qt4/plugins")

  #qt4's distributes some translation of common message string used in Qt.
  #This are provided with any qt installation. We reuse them in otb package
  #so as not to reinvent the wheels.
  set(PKG_QT_TRANSLATIONS_DIR "${PKG_STAGE_DIR}/lib/qt4/translations")

  #<prefix>/share for otb i18n directory. This is different from qt's i18N directory
  #which is <prefix>/share/qt4/translations.
  #set(PKG_xxOTB_Ixxx18N_DIR "${PKG_STAGE_DIR}/${PKG_OTB_INSTALL_DATA_DIR}/i18n")
  # we find this value by parsing ConfigureMonteverdi.h
  set(ConfigureMonteverdi_H "${OTB_BINARY_DIR}/Modules/Visualization/MonteverdiCore/ConfigureMonteverdi.h")
  if(NOT EXISTS "${ConfigureMonteverdi_H}")
    message(FATAL_ERROR "${ConfigureMonteverdi_H} does not exists. Cannot continue")
  endif()

  file(
    STRINGS "${ConfigureMonteverdi_H}"
    ConfigureMonteverdi_H_CONTENTS
    REGEX "^#define.Monteverdi_INSTALL_DATA_DIR")

  string(REGEX REPLACE
    "^#define.Monteverdi_INSTALL_DATA_DIR" ""
    ConfigureMonteverdi_H_CONTENTS
    ${ConfigureMonteverdi_H_CONTENTS} )

  if(NOT ConfigureMonteverdi_H_CONTENTS)
    message(FATAL_ERROR "Parse error in ${ConfigureMonteverdi_H}. Cannot continue")
  endif()

  string(
    REGEX REPLACE "\"" ""
    PKG_OTB_INSTALL_DATA_DIR
    "${ConfigureMonteverdi_H_CONTENTS}")

  if(NOT PKG_OTB_INSTALL_DATA_DIR)
    message(FATAL_ERROR "parse error in ${ConfigureMonteverdi_H_CONTENTS}. Cannot continue")
  endif()
  
  string(STRIP "${PKG_OTB_INSTALL_DATA_DIR}" PKG_OTB_INSTALL_DATA_DIR)

  set(PKG_OTB_TRANSLATIONS_DIRNAME "${PKG_OTB_INSTALL_DATA_DIR}/i18n")

  # Just check if required variables are defined.
  foreach(req
      PACKAGE_OTB_SRC_DIR
      PACKAGE_SUPPORT_FILES_DIR
      QT_PLUGINS_DIR
      PKG_STAGE_BIN_DIR
      PKG_QTSQLITE_FILENAME
      PKG_QTPLUGINS_DIR
      PKG_QT_TRANSLATIONS_DIR
      PKG_OTB_TRANSLATIONS_DIRNAME
      )
    if(NOT DEFINED ${req} OR "${${req}}" STREQUAL "")
      message(FATAL_ERROR "you must set ${req} before calling this method")
    endif()
    set(vars "${vars}  ${req}=[${${req}}]\n")
  endforeach(req)

  #install icon file for .app file. Monteverdi and Mapla has same icon!
  if(APPLE)
    install(FILES ${PACKAGE_SUPPORT_FILES_DIR}/Monteverdi.icns
      DESTINATION ${PKG_STAGE_DIR})
  endif()

  ####################### install sqldriver plugin ########################
  install(FILES ${QT_PLUGINS_DIR}/sqldrivers/${PKG_QTSQLITE_FILENAME}
    DESTINATION ${PKG_QTPLUGINS_DIR}/sqldrivers)

  ####################### install qt4 translations ###########################
  #get all translations already distributed with qt4
  get_qt_translation_files(QT_TRANSLATIONS_FILES)

  #install all files in ${QT_TRANSLATIONS_FILES}
  install(FILES ${QT_TRANSLATIONS_FILES}  DESTINATION ${PKG_QT_TRANSLATIONS_DIR})

  ####################### install monteverdi translations #####################
  #translation of monteverdi specific strings
  if(NOT EXISTS "${OTB_INSTALL_DIR}/${PKG_OTB_TRANSLATIONS_DIRNAME}")
    message(FATAL_ERROR "Error ${OTB_INSTALL_DIR}/${PKG_OTB_TRANSLATIONS_DIRNAME} not exists")
  endif()
  
  file(GLOB APP_TS_FILES ${PACKAGE_OTB_SRC_DIR}/i18n/*.ts) # qm files
  foreach(APP_TS_FILE ${APP_TS_FILES})
    get_filename_component(APP_TS_FILENAME ${APP_TS_FILE} NAME_WE)
    install(FILES ${OTB_INSTALL_DIR}/${PKG_OTB_TRANSLATIONS_DIRNAME}/${APP_TS_FILENAME}.qm
      DESTINATION ${PKG_STAGE_DIR}/${PKG_OTB_TRANSLATIONS_DIRNAME}
      )
  endforeach()
  
endfunction()