Projectkk2glider/issue 4086 usb and serial (#4097)
[opentx.git] / companion / src / CMakeLists.txt
blobd00bac1816cef732a176e621dda2a5613e5ce8a1
1  if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
2   set(C9X_NAME_SUFFIX ${VERSION_MAJOR}${VERSION_MINOR})
3   set(COMPANION_NAME "companion${C9X_NAME_SUFFIX}")
4   set(SIMULATOR_NAME "simulator${C9X_NAME_SUFFIX}")
5   set(SIMULATOR_LIB_PATH ${CMAKE_INSTALL_PREFIX}/lib/companion${C9X_NAME_SUFFIX})
6 else(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
7   set(COMPANION_NAME "companion")
8   set(SIMULATOR_NAME "simulator")
9 endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
11 # This the name that the user will see in the generated DMG and what the application
12 # will be called under /Applications. We include the version string to make installing
13 # different versions for different eeproms easier, i.e. without manually renaming
14 set(COMPANION_OSX_APP_BUNDLE_NAME "OpenTX Companion ${VERSION_MAJOR}.${VERSION_MINOR}")
16 # On OS X we copy dfu-util to the application bundle. This the path from which we copy
17 # the binary (default homebrew path)
18 set(DFU_UTIL_PATH "/usr/local/bin/dfu-util")
20 option(ALLOW_NIGHTLY_BUILDS "Allow nightly builds download / update") # Disabled by default
21 if(ALLOW_NIGHTLY_BUILDS)
22   add_definitions(-DALLOW_NIGHTLY_BUILDS)
23 endif(ALLOW_NIGHTLY_BUILDS)
25 option(DEBUG_STORAGE_IMPORT "Turn on debug output for storage import") # Disabled by default
26 if(DEBUG_STORAGE_IMPORT)
27   add_definitions(-DDEBUG_STORAGE_IMPORT)
28   message(STATUS "Storage import debugging enabled")
29 endif()
30 if(DEBUG)
31   add_definitions(-DDEBUG)
32 endif()
34 option(TABLE_LAYOUT "Use QTableWidget for grid layouts") # Disabled by default
35 if(TABLE_LAYOUT)
36   add_definitions(-DTABLE_LAYOUT)
37   message(STATUS "Using QTableWidget")
38 endif()
40 if(SDL_FOUND)
41   include_directories(${SDL_INCLUDE_DIR})
42   add_definitions(-DSIMU_AUDIO)
43   add_definitions(-DJOYSTICKS)
44 endif()
46 message(STATUS "Looking for QT lupdate ")
47 find_package(Lupdate)
48 if(LUPDATE_FOUND)
49   message("QT lupdate: " ${LUPDATE_EXECUTABLE})
50 else()
51   message("QT lupdate not found!")
52 endif()
54 add_definitions(-DQXT_STATIC)
56 if(MSVC)
57   set(CMAKE_CXX_FLAGS "/EHsc /LD")
58   SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS,5.01")
59   include_directories(${PROJECT_SOURCE_DIR}/winbuild C:/Programs/pthreads/Pre-built.2/include C:/Programs/msinttypes C:/Programs/dirent/include)
60   link_directories(C:/Programs/pthreads/Pre-built.2/lib/)
61   set(PTHREAD_LIBRARY pthreadVC2.lib)
62 else()
63   set(PTHREAD_LIBRARY pthread)
64   add_definitions(-Wall)
65   link_directories(/usr/local/lib)
66 endif()
68 set(RADIO_SRC_DIRECTORY ${PROJECT_SOURCE_DIR}/radio/src)
69 set(SIMU_SRC_DIRECTORY ${PROJECT_SOURCE_DIR}/companion/src/simulation)
70 set(COMPANION_SRC_DIRECTORY ${PROJECT_SOURCE_DIR}/companion/src)
72 include_directories(
73   ${CMAKE_BINARY_DIR}
74   ${CMAKE_CURRENT_BINARY_DIR}
75   ${COMPANION_SRC_DIRECTORY}
76   ${COMPANION_SRC_DIRECTORY}/shared
77   ${SIMU_SRC_DIRECTORY}
78   ${COMPANION_SRC_DIRECTORY}/thirdparty/qxtcommandoptions
79   ${COMPANION_SRC_DIRECTORY}/thirdparty/qcustomplot
80   ${COMPANION_SRC_DIRECTORY}/thirdparty/miniz
81   ${COMPANION_SRC_DIRECTORY}/storage
84 add_subdirectory(shared)
85 add_subdirectory(modeledit)
86 add_subdirectory(generaledit)
87 add_subdirectory(simulation)
88 add_subdirectory(storage)
89 add_subdirectory(thirdparty/qcustomplot)
90 add_subdirectory(thirdparty/qxtcommandoptions)
92 set(common_SRCS
93   eeprominterface.cpp
94   firmwares/er9x/er9xeeprom.cpp
95   firmwares/er9x/er9xinterface.cpp
96   firmwares/ersky9x/ersky9xeeprom.cpp
97   firmwares/ersky9x/ersky9xinterface.cpp
98   firmwares/opentx/opentxeeprom.cpp
99   firmwares/opentx/opentxinterface.cpp
100   )
102 qt5_wrap_cpp(common_SRCS)
104 add_library(common ${common_SRCS})
105 qt5_use_modules(common Core Xml Widgets)
107 set(companion_SRCS
108   helpers.cpp
109   helpers_html.cpp
110   mdichild.cpp
111   modelslist.cpp
112   apppreferencesdialog.cpp
113   fwpreferencesdialog.cpp
114   burnconfigdialog.cpp
115   multimodelprinter.cpp
116   comparedialog.cpp
117   contributorsdialog.cpp
118   releasenotesdialog.cpp
119   releasenotesfirmwaredialog.cpp
120   customizesplashdialog.cpp
121   radiointerface.cpp
122   progresswidget.cpp
123   progressdialog.cpp
124   process_copy.cpp
125   process_flash.cpp
126   process_sync.cpp
127   flashfirmwaredialog.cpp
128   flasheepromdialog.cpp
129   printdialog.cpp
130   modelprinter.cpp
131   fusesdialog.cpp
132   logsdialog.cpp
133   downloaddialog.cpp
134   splashlibrarydialog.cpp
135   mainwindow.cpp
136   companion.cpp
137   radionotfound.cpp
138   wizarddata.cpp
139   wizarddialog.cpp
140   )
142 set(companion_MOC_HDRS
143   apppreferencesdialog.h
144   fwpreferencesdialog.h
145   burnconfigdialog.h
146   comparedialog.h
147   printdialog.h
148   fusesdialog.h
149   logsdialog.h
150   contributorsdialog.h
151   releasenotesdialog.h
152   releasenotesfirmwaredialog.h
153   customizesplashdialog.h
154   splashlibrarydialog.h
155   splashlabel.h
156   progresswidget.h
157   progressdialog.h
158   process_copy.h
159   process_flash.h
160   process_sync.h
161   flashfirmwaredialog.h
162   flasheepromdialog.h
163   downloaddialog.h
164   modelslist.h
165   mdichild.h
166   mainwindow.h
167   radionotfound.h
168   helpers.h
169   wizarddialog.h
170   modelprinter.h
171   multimodelprinter.h
172   )
174 set(companion_UIS
175   mdichild.ui
176   comparedialog.ui
177   fusesdialog.ui
178   logsdialog.ui
179   apppreferencesdialog.ui
180   fwpreferencesdialog.ui
181   burnconfigdialog.ui
182   downloaddialog.ui
183   printdialog.ui
184   htmldialog.ui
185   customizesplashdialog.ui
186   splashlibrarydialog.ui
187   progresswidget.ui
188   progressdialog.ui
189   flashfirmwaredialog.ui
190   flasheepromdialog.ui
191   radionotfound.ui
192   )
194 set(companion_RESOURCES
195   companion.qrc
196   ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc
197   )
199 configure_file(${COMPANION_SRC_DIRECTORY}/version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
200 configure_file(${COMPANION_SRC_DIRECTORY}/translations.qrc.in ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc @ONLY)
201 configure_file(${COMPANION_SRC_DIRECTORY}/companion.desktop.in ${CMAKE_CURRENT_BINARY_DIR}/companion.desktop @ONLY)
202 configure_file(${COMPANION_SRC_DIRECTORY}/simulator.desktop.in ${CMAKE_CURRENT_BINARY_DIR}/simulator.desktop @ONLY)
204 if(WIN32)
205   set(companion_SRCS ${companion_SRCS} icon.rc)
206   if(NOT MSVC)
207     set(CMAKE_EXE_LINKER_FLAGS -mwindows)
208   endif()
209 endif()
211 include_directories(${CMAKE_BINARY_DIR})
212 include_directories(${CMAKE_SOURCE_DIR})
214 set(LANGUAGES he pl pt ru de fr es it sv cs fi nl)
215 foreach(language ${LANGUAGES})
216   set(companion_TS ${companion_TS} translations/companion_${language}.ts)
217 endforeach(language)
219 qt5_wrap_ui(companion_SRCS ${companion_UIS})
220 qt5_wrap_cpp(companion_SRCS ${companion_MOC_HDRS})
221 qt5_add_translation(companion_QM ${companion_TS})
222 qt5_add_resources(companion_RCC ${companion_RESOURCES})
223 add_custom_target(gen_qrc DEPENDS ${companion_RCC})
225 add_definitions(-DQT_TRANSLATIONS_DIR="${QT_TRANSLATIONS_DIR}")
227 add_executable(${COMPANION_NAME} MACOSX_BUNDLE WIN32 ${companion_SRCS} ${companion_RCC} ${companion_QM})
229 add_dependencies(${COMPANION_NAME} gen_qrc)
230 qt5_use_modules(${COMPANION_NAME} Core Widgets Network)
231 target_link_libraries(${COMPANION_NAME} PRIVATE generaledit modeledit simulation common qcustomplot shared storage ${PTHREAD_LIBRARY} ${SDL_LIBRARY})
233 ############# Standalone simu ###############
235 set(simu_SRCS
236   modeledit/node.cpp
237   modeledit/edge.cpp # TODO not needed
238   simulator.cpp
239   )
241 set(simu_MOC_HDRS
242   modeledit/node.h
243   )
245 qt5_wrap_cpp(simu_SRCS ${simu_MOC_HDRS} )
247 if(WIN32)
248   set(simu_SRCS ${simu_SRCS} icon.rc)
249 endif()
252 add_executable(${SIMULATOR_NAME} MACOSX_BUNDLE WIN32 ${simu_SRCS} ${companion_RCC})
254 add_dependencies(${SIMULATOR_NAME} gen_qrc)
255 # TODO not the same link command than companion?
256 target_link_libraries(${SIMULATOR_NAME} PRIVATE simulation common storage qxtcommandoptions ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY} ${PTHREAD_LIBRARY} ${SDL_LIBRARY} ${OPENTX_SIMULATOR_LIBS})
258 ############# Packaging ####################
259 message(STATUS ${CMAKE_BINARY_DIR} ${CMAKE_INSTALL_PREFIX}/bin)
260 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
261   install(TARGETS ${COMPANION_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
262   install(TARGETS ${SIMULATOR_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
263   install(DIRECTORY ${CMAKE_BINARY_DIR}/ DESTINATION ${SIMULATOR_LIB_PATH} USE_SOURCE_PERMISSIONS
264     FILES_MATCHING PATTERN "libopentx-*${CMAKE_SHARED_LIBRARY_SUFFIX}"
265     PATTERN "CMakeFiles" EXCLUDE
266     PATTERN "_CPack_Packages" EXCLUDE
267     PATTERN "companion" EXCLUDE
268     PATTERN "radio" EXCLUDE
269   )
270   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/companion.desktop DESTINATION share/applications RENAME companion${C9X_NAME_SUFFIX}.desktop)
271   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/simulator.desktop DESTINATION share/applications RENAME simulator${C9X_NAME_SUFFIX}.desktop)
272   if(${CMAKE_INSTALL_PREFIX} MATCHES "/usr/local")
273     install(FILES images/linuxicons/16x16/companion.png DESTINATION /usr/share/icons/hicolor/16x16/apps RENAME companion${C9X_NAME_SUFFIX}.png)
274     install(FILES images/linuxicons/22x22/companion.png DESTINATION /usr/share/icons/hicolor/22x22/apps RENAME companion${C9X_NAME_SUFFIX}.png)
275     install(FILES images/linuxicons/24x24/companion.png DESTINATION /usr/share/icons/hicolor/24x24/apps RENAME companion${C9X_NAME_SUFFIX}.png)
276     install(FILES images/linuxicons/32x32/companion.png DESTINATION /usr/share/icons/hicolor/32x32/apps RENAME companion${C9X_NAME_SUFFIX}.png)
277     install(FILES images/linuxicons/48x48/companion.png DESTINATION /usr/share/icons/hicolor/48x48/apps RENAME companion${C9X_NAME_SUFFIX}.png)
278     install(FILES images/linuxicons/128x128/companion.png DESTINATION /usr/share/icons/hicolor/128x128/apps RENAME companion${C9X_NAME_SUFFIX}.png)
279     install(FILES images/linuxicons/256x256/companion.png DESTINATION /usr/share/icons/hicolor/256x256/apps RENAME companion${C9X_NAME_SUFFIX}.png)
280     install(FILES images/linuxicons/512x512/companion.png DESTINATION /usr/share/icons/hicolor/512x512/apps RENAME companion${C9X_NAME_SUFFIX}.png)
281     install(FILES images/linuxicons/scalable/companion.svg DESTINATION /usr/share/icons/hicolor/scalable/apps RENAME companion${C9X_NAME_SUFFIX}.svg)
282     install(FILES ../targets/linux/45-companion-taranis.rules DESTINATION /lib/udev/rules.d RENAME 45-companion${C9X_NAME_SUFFIX}-taranis.rules)
283   else()
284     install(FILES images/linuxicons/16x16/companion.png DESTINATION share/icons/hicolor/16x16/apps RENAME companion${C9X_NAME_SUFFIX}.png)
285     install(FILES images/linuxicons/22x22/companion.png DESTINATION share/icons/hicolor/22x22/apps RENAME companion${C9X_NAME_SUFFIX}.png)
286     install(FILES images/linuxicons/24x24/companion.png DESTINATION share/icons/hicolor/24x24/apps RENAME companion${C9X_NAME_SUFFIX}.png)
287     install(FILES images/linuxicons/32x32/companion.png DESTINATION share/icons/hicolor/32x32/apps RENAME companion${C9X_NAME_SUFFIX}.png)
288     install(FILES images/linuxicons/48x48/companion.png DESTINATION share/icons/hicolor/48x48/apps RENAME companion${C9X_NAME_SUFFIX}.png)
289     install(FILES images/linuxicons/128x128/companion.png DESTINATION share/icons/hicolor/128x128/apps RENAME companion${C9X_NAME_SUFFIX}.png)
290     install(FILES images/linuxicons/256x256/companion.png DESTINATION share/icons/hicolor/256x256/apps RENAME companion${C9X_NAME_SUFFIX}.png)
291     install(FILES images/linuxicons/512x512/companion.png DESTINATION share/icons/hicolor/512x512/apps RENAME companion${C9X_NAME_SUFFIX}.png)
292     install(FILES images/linuxicons/scalable/companion.svg DESTINATION share/icons/hicolor/scalable/apps RENAME companion${C9X_NAME_SUFFIX}.svg)
293     install(FILES ../targets/linux/45-companion-taranis.rules DESTINATION lib/udev/rules.d RENAME 45-companion${C9X_NAME_SUFFIX}-taranis.rules)
294   endif()
295   # Linux specific code
296   set(OperatingSystem "Linux")
297 elseif(WIN32)
298   get_target_property(QtCore_LOCATION Qt5::Core LOCATION)
299   get_filename_component(QT_DLL_DIR ${QtCore_LOCATION} PATH)
300   get_filename_component(SDL_DIR ${SDL_LIBRARY} PATH)
301   install(FILES ${QT_DLL_DIR}/icudt54.dll ${QT_DLL_DIR}/icuin54.dll ${QT_DLL_DIR}/icuuc54.dll ${QT_DLL_DIR}/Qt5Core.dll ${QT_DLL_DIR}/Qt5Gui.dll ${QT_DLL_DIR}/Qt5Widgets.dll ${QT_DLL_DIR}/Qt5Xml.dll ${QT_DLL_DIR}/Qt5Network.dll ${QT_DLL_DIR}/Qt5PrintSupport.dll ${QT_DLL_DIR}/Qt5Multimedia.dll ${SDL_DIR}/SDL.dll DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>)
302   install(FILES ${QT_DLL_DIR}/icudt54.dll ${QT_DLL_DIR}/icuin54.dll ${QT_DLL_DIR}/icuuc54.dll ${QT_DLL_DIR}/Qt5Cored.dll ${QT_DLL_DIR}/Qt5Guid.dll ${QT_DLL_DIR}/Qt5Widgetsd.dll ${QT_DLL_DIR}/Qt5Xmld.dll ${QT_DLL_DIR}/Qt5Networkd.dll ${QT_DLL_DIR}/Qt5PrintSupportd.dll ${QT_DLL_DIR}/Qt5Multimediad.dll ${SDL_DIR}/SDL.dll DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>)
303 endif()
305 if(WIN32)
306   if(MSVC)
307     set(COMPANION_NSI_IN_FILE companion-vs.nsi.in)
308     set(SIMULATOR_NSI_IN_FILE simulator-vs.nsi.in)
309   else()
310     set(COMPANION_NSI_IN_FILE companion-msys.nsi.in)
311     set(SIMULATOR_NSI_IN_FILE simulator-msys.nsi.in)
312   endif()
314   set(SYSDIR "$ENV{windir}/system32")
315   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../targets/windows/${COMPANION_NSI_IN_FILE} ${PROJECT_BINARY_DIR}/companion/companion.nsi @ONLY)
316   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../targets/windows/${SIMULATOR_NSI_IN_FILE} ${PROJECT_BINARY_DIR}/companion/simulator.nsi @ONLY)
318   find_program(NSIS_EXE makensis.exe PATHS
319     "C:/Program Files/NSIS"
320     "C:/Program Files (x86)/NSIS"
321     "C:/Programs/NSIS"
322     )
324   add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/companion/companion-windows.exe
325     COMMAND "${NSIS_EXE}" ARGS ${PROJECT_BINARY_DIR}/companion/companion.nsi
326     DEPENDS companion simulator opentx-simulators ${PROJECT_BINARY_DIR}/companion/companion.nsi
327     COMMENT "Companion Windows NSIS Installer")
329   add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/companion/simulator-install.exe
330     COMMAND "${NSIS_EXE}" ARGS ${PROJECT_BINARY_DIR}/companion/simulator.nsi
331     DEPENDS simulator ${PROJECT_BINARY_DIR}/companion/simulator.nsi
332     COMMENT "Simulator Windows NSIS Installer")
334   add_custom_target(installer
335     DEPENDS ${PROJECT_BINARY_DIR}/companion/companion-windows.exe
336     DEPENDS ${PROJECT_BINARY_DIR}/companion/simulator-windows.exe
337     SOURCES ${PROJECT_BINARY_DIR}/companion/companion.nsi
338     SOURCES ${PROJECT_BINARY_DIR}/companion/simulator.nsi
339     )
340 endif()
342 if(LUPDATE_FOUND)
343   add_custom_target(translations
344     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
345     COMMAND ${LUPDATE_EXECUTABLE} ${CMAKE_SOURCE_DIR} -no-obsolete -ts ${companion_TS}
346     )
347 else()
348   add_custom_target(translations
349     COMMAND echo "Sorry, QT lupdate was not found."
350     )
351 endif()
353 set(CPACK_PACKAGE_NAME "companion${C9X_NAME_SUFFIX}")
354 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Models and settings editor for the OpenTX open source firmware")
355 string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE)
357 # The file stripping is deliberately disabled, with the stripped file we get
358 # very poor trace-backs from the users when they report Companion crash
359 set(CPACK_STRIP_FILES FALSE)
361 set(plugin_dest_dir bin)
362 set(qtconf_dest_dir bin)
363 set(APPS "\${CMAKE_INSTALL_PREFIX}/bin/${COMPANION_NAME}")
364 IF(APPLE)
365   set(plugin_dest_dir ${COMPANION_NAME}.app/Contents/Plugins)
366   set(qtconf_dest_dir ${COMPANION_NAME}.app/Contents/Resources)
367   set(translations_dest_dir ${COMPANION_NAME}.app/Contents/translations)
368   set(APPS "\${CMAKE_INSTALL_PREFIX}/${COMPANION_NAME}.app")
369   set_target_properties(${COMPANION_NAME} PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Companion ${VERSION_MAJOR}.${VERSION_MINOR}")
370   set_target_properties(${SIMULATOR_NAME} PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Simulator ${VERSION_MAJOR}.${VERSION_MINOR}")
371 ENDIF(APPLE)
372 IF(WIN32)
373   set(APPS "\${CMAKE_INSTALL_PREFIX}/bin/QtTest.exe")
374 ENDIF(WIN32)
377 INSTALL(TARGETS ${COMPANION_NAME}
378     BUNDLE DESTINATION . COMPONENT Runtime
379     RUNTIME DESTINATION bin COMPONENT Runtime
380     )
382 # Qt5 + Cmake + Mac is poorly documented. A lot of this is guesswork
383 # and trial and error. Do not hesitate to fix it for the better
384 if(APPLE)
385   set(APPS "\${CMAKE_INSTALL_PREFIX}/${COMPANION_NAME}.app")
387   file(GLOB simulator_plugins "${CMAKE_BINARY_DIR}/libopentx-*${CMAKE_SHARED_LIBRARY_SUFFIX}")
388   set(companion_res_dir ${COMPANION_NAME}.app/Contents/Resources)
389   install(FILES ${simulator_plugins} DESTINATION "${companion_res_dir}" COMPONENT Runtime)
391   # Write qt.conf to tell qt where to find it plugins
392   file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
393     "[Paths]\nPlugins = Plugins\n")
394     install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
395     DESTINATION "${companion_res_dir}"
396     COMPONENT Runtime)
398   # menu file
399   install(DIRECTORY ${PROJECT_SOURCE_DIR}/companion/targets/mac/qt_menu.nib DESTINATION "${companion_res_dir}" COMPONENT Runtime)
401   # translations file
402   install(FILES ${companion_QM} DESTINATION "${translations_dest_dir}" COMPONENT Runtime)
404   # manually add the cocoa plugin
405   get_target_property(QPA_PLUGIN Qt5::QCocoaIntegrationPlugin LOCATION)
406   install(FILES ${QPA_PLUGIN} DESTINATION "${plugin_dest_dir}/platforms/" COMPONENT Runtime)
407   set(bundle_qt_libs "\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/platforms/libqcocoa.dylib")
409   # Add icon
410   set(MACOSX_BUNDLE_ICON_FILE iconmac.icns)
411   set(MAC_ICON_FILE ${COMPANION_SRC_DIRECTORY}/images/${MACOSX_BUNDLE_ICON_FILE})
412   SET_SOURCE_FILES_PROPERTIES(${MAC_ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
413   set(${COMPANION_SOURCES} ${COMPANION_SOURCES} ${PROJECT_SOURCE_DIR}/images/${MACOSX_BUNDLE_ICON_FILE})
414   install(FILES ${MAC_ICON_FILE} DESTINATION ${companion_res_dir} COMPONENT Runtime)
416   # Copy dfu-util, resolve symlink first
417   get_filename_component(DFU_UTIL_ABSOLUTE_PATH ${DFU_UTIL_PATH} REALPATH)
418   install(FILES ${DFU_UTIL_ABSOLUTE_PATH} DESTINATION ${companion_res_dir} COMPONENT Runtime)
419   set(bundle_dfu_util_path "\${CMAKE_INSTALL_PREFIX}/${companion_res_dir}/dfu-util")
421   # These needs to be relative to CMAKE_INSTALL_PREFIX
422   get_target_property(QT_LIBRARY_DIR Qt5::Core LOCATION)
423   get_filename_component(QT_LIBRARY_DIR ${QT_LIBRARY_DIR} PATH)
424   get_filename_component(QT_LIBRARY_DIR "${QT_LIBRARY_DIR}/.." ABSOLUTE)
426   # Include depencies (adding frameworks, fixing the embbeded libraries)
427   # I get write errors without setting BU_CHMOD_BUNDLE_ITEMS even though it is
428   # technically a hack (that is already is in the Bundle library ....)
429   install(CODE "
430    include(BundleUtilities)
431    file(GLOB bundle_simulator_libs \"\${CMAKE_INSTALL_PREFIX}/${companion_res_dir}/libopentx-*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
432    set(BU_CHMOD_BUNDLE_ITEMS on)
433    fixup_bundle(\"${APPS}\"   \"\${bundle_simulator_libs};${bundle_qt_libs};${bundle_dfu_util_path}\"   \"${QT_LIBRARY_DIR}\")
434    file(RENAME \"\${CMAKE_INSTALL_PREFIX}/${COMPANION_NAME}.app\" \"\${CMAKE_INSTALL_PREFIX}/${COMPANION_OSX_APP_BUNDLE_NAME}.app\")
435    " COMPONENT Runtime)
436 endif()
438 find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
440 if(DPKG_PROGRAM)
441   set(CPACK_GENERATOR "DEB")
442   execute_process(
443     COMMAND ${DPKG_PROGRAM} --print-architecture
444     OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
445     OUTPUT_STRIP_TRAILING_WHITESPACE
446   )
447   set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
448   set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Bertrand Songis <bsongis-nosp@m-gmail.com>")
449   set(CPACK_DEBIAN_PACKAGE_VERSION ${VERSION})
450   set(CPACK_DEBIAN_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
451   set(CPACK_DEBIAN_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
452   set(CPACK_DEBIAN_ARCHITECTURE $(CMAKE_SYSTEM_PROCESSOR))
453   set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
454 elseif(APPLE)
455   set(CPACK_GENERATOR "DragNDrop")
456 # set(CPACK_GENERATOR "TGZ")  # for quick testing
457   set(CPACK_BINARY_DRAGNDROP ON)
458   set(CPACK_DMG_BACKGROUND_IMAGE ${COMPANION_SRC_DIRECTORY}/images/splash22_3_dmg.png)
459   set(CPACK_DMG_VOLUME_NAME "OpenTX Companion")
460   set(CPACK_DMG_DS_STORE ${PROJECT_SOURCE_DIR}/companion/targets/mac/DS_Store)
461   set(CPACK_PACKAGE_FILE_NAME "opentx-${CPACK_PACKAGE_NAME_LOWERCASE}-${VERSION}")
462 else(DPKG_PROGRAM)
463   set(CPACK_GENERATOR "RPM")
464   set(CPACK_RPM_PACKAGE_VERSION ${VERSION})
465   set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
466   set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}-${VERSION}-${CMAKE_SYSTEM_PROCESSOR}")
467   set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/lib /lib/udev /lib/udev/rules.d")
468 endif(DPKG_PROGRAM)
470 include(CPack)