Update CREDITS.txt
[opentx.git] / companion / src / CMakeLists.txt
blob9343d71b9efe53d46e39b1ece2873a76a95b16ee
1 set(SIMULATOR_INSTALL_PREFIX "" CACHE STRING "Alternative simulator library search path")
3 if(${CMAKE_SYSTEM_NAME} MATCHES "(Linux|FreeBSD)")
4   set(C9X_NAME_SUFFIX ${VERSION_MAJOR}${VERSION_MINOR})
5   set(COMPANION_NAME "companion${C9X_NAME_SUFFIX}")
6   set(SIMULATOR_NAME "simulator${C9X_NAME_SUFFIX}")
7   if (NOT ${SIMULATOR_INSTALL_PREFIX} STREQUAL "")
8     set(SIMULATOR_LIB_PATH ${SIMULATOR_INSTALL_PREFIX}/lib/companion${C9X_NAME_SUFFIX})
9   else()
10     set(SIMULATOR_LIB_PATH ${CMAKE_INSTALL_PREFIX}/lib/companion${C9X_NAME_SUFFIX})
11   endif()
12   message(STATUS "Simulators library search path: " ${SIMULATOR_LIB_PATH})
13   set(SIMULATOR_LIB_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/lib/companion${C9X_NAME_SUFFIX})
14 else()
15   set(COMPANION_NAME "companion")
16   set(SIMULATOR_NAME "simulator")
17 endif()
19 # This the name that the user will see in the generated DMG and what the application
20 # will be called under /Applications. We include the version string to make installing
21 # different versions for different eeproms easier, i.e. without manually renaming
22 set(COMPANION_OSX_APP_BUNDLE_NAME "OpenTX Companion ${VERSION_MAJOR}.${VERSION_MINOR}")
24 # On OS X we copy dfu-util to the application bundle. This the path from which we copy
25 # the binary (default homebrew path)
26 set(DFU_UTIL_PATH "/usr/local/bin/dfu-util")
27 set(AVRDUDE_PATH "/usr/local/bin/avrdude")
28 set(AVRDUDE_CONF "/usr/local/etc/avrdude.conf")
30 option(ALLOW_NIGHTLY_BUILDS "Allow nightly builds download / update") # Disabled by default
31 if(ALLOW_NIGHTLY_BUILDS)
32   add_definitions(-DALLOW_NIGHTLY_BUILDS)
33 endif(ALLOW_NIGHTLY_BUILDS)
35 option(DEBUG_STORAGE_IMPORT "Turn on debug output for storage import") # Disabled by default
36 if(DEBUG_STORAGE_IMPORT)
37   add_definitions(-DDEBUG_STORAGE_IMPORT)
38   message(STATUS "Storage import debugging enabled")
39 endif()
40 if(DEBUG)
41   add_definitions(-DDEBUG)
42 endif()
44 option(TABLE_LAYOUT "Use QTableWidget for grid layouts") # Disabled by default
45 if(TABLE_LAYOUT)
46   add_definitions(-DTABLE_LAYOUT)
47   message(STATUS "Using QTableWidget")
48 endif()
50 if(WIN32)
51   option(WIN_DO_FULL_INSTALL "'install' target will perform a full installation into CMAKE_INSTALL_PREFIX path, otherwise only supporting DLLs are copied to binaries folder (default)" OFF)
52   option(WIN_USE_CONSOLE "Open a Windows command console for Simulator debug output." OFF)
53   if(WIN_USE_CONSOLE)
54     add_definitions(-DWIN_USE_CONSOLE_STDIO)
55   endif()
56 endif()
58 if(SDL_FOUND)
59   include_directories(${SDL_INCLUDE_DIR})
60   add_definitions(-DJOYSTICKS)
61 endif()
63 add_definitions(${APP_COMMON_DEFINES})  # set in top-level CMakeLists
65 if(NOT MSVC)
66   set(WARNING_FLAGS "${WARNING_FLAGS} -Wall")
67   if(WARNINGS_AS_ERRORS)
68     set(WARNING_FLAGS "${WARNING_FLAGS} -Werror")
69   endif()
70 else()
71   # silence lots of warnings regarding "insecure" use of functions (sprintf, strcpy, etc)
72   set(WARNING_FLAGS "${WARNING_FLAGS} /D_CRT_SECURE_NO_WARNINGS")
73   if(WARNINGS_AS_ERRORS)
74     set(WARNING_FLAGS "${WARNING_FLAGS} /WX")
75   endif()
76 endif()
78 if(WIN32)
79   include_directories(SYSTEM ${WIN_INCLUDE_DIRS})
80   if(NOT WIN_USE_CONSOLE)
81     set(WIN_EXECUTABLE_TYPE WIN32)  # GUI (WinMain) app
82   endif()
83   if(MSVC)
84     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /LD /MP")
85     if(NOT WIN_USE_CONSOLE)
86       set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS,5.01")  # is this even needed?
87     endif()
88   elseif(MINGW)
89     # struct packing breaks on MinGW w/out -mno-ms-bitfields: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991 & http://stackoverflow.com/questions/24015852/struct-packing-and-alignment-with-mingw
90     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-ms-bitfields")
91   endif()
92 else()
93   set(PTHREAD_LIBRARY pthread)
94   link_directories(/usr/local/lib)
95 endif()
97 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
99 use_cxx11()  # ensure gnu++11 in CXX_FLAGS with CMake < 3.1
101 include_directories(
102   ${CMAKE_BINARY_DIR}
103   ${CMAKE_CURRENT_BINARY_DIR}
104   ${CMAKE_SOURCE_DIR}
105   ${COMPANION_SRC_DIRECTORY}
106   ${COMPANION_SRC_DIRECTORY}/shared
107   ${SIMU_SRC_DIRECTORY}
108   ${COMPANION_SRC_DIRECTORY}/thirdparty/qcustomplot
109   ${COMPANION_SRC_DIRECTORY}/thirdparty/miniz
110   ${COMPANION_SRC_DIRECTORY}/storage
113 ############# Do macro replacements on input files #############
114 configure_file(${COMPANION_SRC_DIRECTORY}/version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
115 configure_file(${COMPANION_SRC_DIRECTORY}/companion.desktop.in ${CMAKE_CURRENT_BINARY_DIR}/companion.desktop @ONLY)
116 configure_file(${COMPANION_SRC_DIRECTORY}/simulator.desktop.in ${CMAKE_CURRENT_BINARY_DIR}/simulator.desktop @ONLY)
118 ############# Translations ###############
120 ### Generate .qm files and assemble resource (qrc) file.
122 # available Companion translations (src/translations/*.ts)
123 set(LANGUAGES cs de en es fi fr it pl sv zh_CN)
124 foreach(language ${LANGUAGES})
125   list(APPEND companion_TS translations/companion_${language}.ts)
126 endforeach(language)
127 # .ts -> .qm
128 qt5_add_translation(companion_QM ${companion_TS})
130 # add Qt translations if found
131 if(QT_TRANSLATIONS_DIR)
132   # Some languages have all translations in one qt_*.qm file and others break them up into modules, in which case we need qt_base_*.qm
133   file(GLOB qtbase_QM "${QT_TRANSLATIONS_DIR}/qtbase_*.qm")
134   file(GLOB qt_QM "${QT_TRANSLATIONS_DIR}/qt_??.qm")  # don't want to match "qt_help_*.qm"
135   list(APPEND qt_QM "${QT_TRANSLATIONS_DIR}/qt_zh_CN.qm" "${QT_TRANSLATIONS_DIR}/qt_zh_TW.qm")  # exceptions not matched by the GLOB
136 else()
137   message(STATUS "QT_TRANSLATIONS_DIR not found, unable to package pre-built Qt translations with application.")
138 endif()
140 set(TRANSLATIONS_QRC "${CMAKE_CURRENT_BINARY_DIR}/translations.qrc")
142 # Dynamically create translations.qrc file (XML) from all collected translation files.
143 foreach(qm_file ${companion_QM} ${qt_QM} ${qtbase_QM})
144   get_filename_component(qm_file_name ${qm_file} NAME)
145   # Add file with full path and file name (w/out path) as alias to be used in actual code
146   set(TRANSLATION_FILES_LIST "${TRANSLATION_FILES_LIST}    <file alias=\"${qm_file_name}\">${qm_file}</file>\n")
147 endforeach()
148 configure_file(${COMPANION_SRC_DIRECTORY}/translations.qrc.in ${TRANSLATIONS_QRC} @ONLY)
150 ### Add optional "translations" target for updating .ts files
151 if(QT_LUPDATE_EXECUTABLE)
152   add_custom_target(translations
153     WORKING_DIRECTORY ${COMPANION_SRC_DIRECTORY}
154     COMMAND ${QT_LUPDATE_EXECUTABLE} ${CMAKE_SOURCE_DIR} -no-obsolete -ts ${companion_TS}
155     )
156 else()
157   message(STATUS "Qt lupdate not found, 'translations' target will not be availabe.")
158 endif()
160 ############# Common lib ###############
162 set(common_SRCS
163   appdebugmessagehandler.cpp
164   customdebug.cpp
165   helpers.cpp
166   translations.cpp
167   modeledit/node.cpp  # used in simulator
168   modeledit/edge.cpp  # used by node
169   )
171 set(common_MOC_HDRS
172   appdebugmessagehandler.h
173   helpers.h
174   modeledit/node.h
175   )
177 set(common_RESOURCES
178   companion.qrc
179   ${TRANSLATIONS_QRC}
180   )
182 qt5_wrap_cpp(common_SRCS ${common_MOC_HDRS})
183 qt5_add_resources(common_RCC ${common_RESOURCES})
185 add_library(common ${common_SRCS} ${common_RCC})
187 target_link_libraries(common
188   firmwares
189   storage
190   simulation
191   maxLibQtWidgets
192   Qt5::Core
193   Qt5::Xml
194   Qt5::Widgets
195   ${PTHREAD_LIBRARY}
196   ${SDL_LIBRARY}
197   ${WIN_LINK_LIBRARIES}
198   )
200 set(CPN_COMMON_LIB common)
202 ############# Supporting libraries ###############
204 add_subdirectory(firmwares)
205 add_subdirectory(shared)
206 add_subdirectory(modeledit)
207 add_subdirectory(generaledit)
208 add_subdirectory(simulation)
209 add_subdirectory(storage)
210 add_subdirectory(thirdparty/qcustomplot)
211 add_subdirectory(thirdparty/maxlibqt/src/widgets)
213 ############# Companion ###############
215 set(companion_SRCS
216   helpers_html.cpp
217   mdichild.cpp
218   modelslist.cpp
219   apppreferencesdialog.cpp
220   fwpreferencesdialog.cpp
221   burnconfigdialog.cpp
222   multimodelprinter.cpp
223   comparedialog.cpp
224   creditsdialog.cpp
225   releasenotesdialog.cpp
226   releasenotesfirmwaredialog.cpp
227   customizesplashdialog.cpp
228   radiointerface.cpp
229   progresswidget.cpp
230   progressdialog.cpp
231   process_copy.cpp
232   process_flash.cpp
233   process_sync.cpp
234   flashfirmwaredialog.cpp
235   flasheepromdialog.cpp
236   printdialog.cpp
237   modelprinter.cpp
238   fusesdialog.cpp
239   logsdialog.cpp
240   downloaddialog.cpp
241   splashlibrarydialog.cpp
242   mainwindow.cpp
243   companion.cpp
244   radionotfound.cpp
245   wizarddata.cpp
246   wizarddialog.cpp
247   )
249 set(companion_MOC_HDRS
250   apppreferencesdialog.h
251   fwpreferencesdialog.h
252   burnconfigdialog.h
253   comparedialog.h
254   printdialog.h
255   fusesdialog.h
256   logsdialog.h
257   creditsdialog.h
258   releasenotesdialog.h
259   releasenotesfirmwaredialog.h
260   customizesplashdialog.h
261   splashlibrarydialog.h
262   splashlabel.h
263   progresswidget.h
264   progressdialog.h
265   process_copy.h
266   process_flash.h
267   process_sync.h
268   flashfirmwaredialog.h
269   flasheepromdialog.h
270   downloaddialog.h
271   mdichild.h
272   mainwindow.h
273   radionotfound.h
274   wizarddialog.h
275   modelprinter.h
276   multimodelprinter.h
277   modelslist.h
278   )
280 set(companion_UIS
281   mdichild.ui
282   comparedialog.ui
283   fusesdialog.ui
284   logsdialog.ui
285   apppreferencesdialog.ui
286   fwpreferencesdialog.ui
287   burnconfigdialog.ui
288   downloaddialog.ui
289   printdialog.ui
290   htmldialog.ui
291   customizesplashdialog.ui
292   splashlibrarydialog.ui
293   progresswidget.ui
294   progressdialog.ui
295   flashfirmwaredialog.ui
296   flasheepromdialog.ui
297   radionotfound.ui
298   )
300 if(WIN32)
301   set(icon_RC icon.rc)
302 endif()
304 qt5_wrap_ui(companion_SRCS ${companion_UIS})
305 qt5_wrap_cpp(companion_SRCS ${companion_MOC_HDRS})
307 add_executable(${COMPANION_NAME} MACOSX_BUNDLE ${WIN_EXECUTABLE_TYPE} ${companion_SRCS} ${icon_RC})
308 qt5_use_modules(${COMPANION_NAME} Core Widgets Network)
309 target_link_libraries(${COMPANION_NAME} PRIVATE generaledit modeledit qcustomplot shared ${CPN_COMMON_LIB})
311 PrintTargetReport("${COMPANION_NAME}")
313 ############# Standalone simulator ###############
315 set(simu_SRCS simulator.cpp )
317 add_executable(${SIMULATOR_NAME} MACOSX_BUNDLE ${WIN_EXECUTABLE_TYPE} ${simu_SRCS} ${icon_RC})
318 target_link_libraries(${SIMULATOR_NAME} PRIVATE ${CPN_COMMON_LIB})
320 ############# Install ####################
322 # Generate list of simulator plugins, used by all platforms
323 file(GLOB simulator_plugins "${CMAKE_BINARY_DIR}/*opentx-*simulator${CMAKE_SHARED_LIBRARY_SUFFIX}")
324 # the current flavour is not automatically added if build in the current cmake iteration, so always
325 # add its library name to be sure
326 string(TOLOWER ${PCB} FLAVOUR)
327 if(POLICY CMP0026)
328   cmake_policy(SET CMP0026 OLD)  # https://cmake.org/cmake/help/v3.0/policy/CMP0026.html
329 endif()
330 get_property(current_plugin TARGET opentx-${FLAVOUR}-simulator PROPERTY LOCATION)
331 list(APPEND simulator_plugins "${current_plugin}")
333 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
335   message(STATUS "install " ${CMAKE_BINARY_DIR} " to " ${CMAKE_INSTALL_PREFIX}/bin)
336   install(TARGETS ${COMPANION_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
337   install(TARGETS ${SIMULATOR_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
338   install(FILES ${simulator_plugins} DESTINATION "${SIMULATOR_LIB_INSTALL_PATH}")
339   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/companion.desktop DESTINATION share/applications RENAME companion${C9X_NAME_SUFFIX}.desktop)
340   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/simulator.desktop DESTINATION share/applications RENAME simulator${C9X_NAME_SUFFIX}.desktop)
341   if(${CMAKE_INSTALL_PREFIX} MATCHES "/usr/local")
342     set(INSTALL_TEMP_SHR_PFX "/usr/")
343     set(INSTALL_TEMP_LIB_PFX "/")
344   endif()
345   install(FILES images/linuxicons/16x16/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/16x16/apps RENAME companion${C9X_NAME_SUFFIX}.png)
346   install(FILES images/linuxicons/22x22/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/22x22/apps RENAME companion${C9X_NAME_SUFFIX}.png)
347   install(FILES images/linuxicons/24x24/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/24x24/apps RENAME companion${C9X_NAME_SUFFIX}.png)
348   install(FILES images/linuxicons/32x32/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/32x32/apps RENAME companion${C9X_NAME_SUFFIX}.png)
349   install(FILES images/linuxicons/48x48/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/48x48/apps RENAME companion${C9X_NAME_SUFFIX}.png)
350   install(FILES images/linuxicons/128x128/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/128x128/apps RENAME companion${C9X_NAME_SUFFIX}.png)
351   install(FILES images/linuxicons/256x256/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/256x256/apps RENAME companion${C9X_NAME_SUFFIX}.png)
352   install(FILES images/linuxicons/512x512/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/512x512/apps RENAME companion${C9X_NAME_SUFFIX}.png)
353   install(FILES images/linuxicons/scalable/companion.svg DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/scalable/apps RENAME companion${C9X_NAME_SUFFIX}.svg)
354   install(FILES ../targets/linux/45-companion-taranis.rules DESTINATION ${INSTALL_TEMP_LIB_PFX}lib/udev/rules.d RENAME 45-companion${C9X_NAME_SUFFIX}-taranis.rules)
355   install(FILES ../targets/linux/45-usbasp.rules DESTINATION ${INSTALL_TEMP_LIB_PFX}lib/udev/rules.d RENAME 45-companion${C9X_NAME_SUFFIX}-usbasp.rules)
356   # Linux specific code
357   set(OperatingSystem "Linux")
359 elseif(WIN32)
361   set(QT_DLL_DIR ${QT_LIB_DIR})
362   set(INSTALL_TEMP_QTDLL_FILES Qt5Core Qt5Gui Qt5Widgets Qt5Xml Qt5Network Qt5PrintSupport Qt5Multimedia Qt5Svg)
363   set(INSTALL_TEMP_ICUDLL_FILES icudt54.dll icuin54.dll icuuc54.dll)
364   if(CMAKE_BUILD_TYPE STREQUAL "Debug")
365     set(INSTALL_TEMP_QTDLL_SFX "d")
366   endif()
368   if(NOT WIN_DO_FULL_INSTALL)
369     # Just copy supporting DLLs to build folder
370     set(INSTALL_DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
371     message(STATUS "Partial install to " ${INSTALL_DESTINATION})
372   else()
373     # Full Windows installation with all supporting files
374     set(INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}")
375     message(STATUS "Full install to " ${INSTALL_DESTINATION})
376     # companion & simulator binaries
377     install(TARGETS ${COMPANION_NAME} DESTINATION ${INSTALL_DESTINATION})
378     install(TARGETS ${SIMULATOR_NAME} DESTINATION ${INSTALL_DESTINATION})
379     install(FILES ${simulator_plugins} DESTINATION "${INSTALL_DESTINATION}")
380     # supporting utilities
381     set(INSTALL_TEMP_FILES avrdude.exe avrdude.conf dfu-util.exe libusb0.dll libusb-1.0.dll)
382     foreach(tmpfile ${INSTALL_TEMP_FILES})
383       install(FILES "${COMPANION_SRC_DIRECTORY}/../targets/windows/${tmpfile}" DESTINATION ${INSTALL_DESTINATION})
384     endforeach()
385   endif()  # WIN_DO_FULL_INSTALL
387   # Qt dlls
388   foreach(tmpfile ${INSTALL_TEMP_QTDLL_FILES})
389     install(FILES ${QT_DLL_DIR}/${tmpfile}${INSTALL_TEMP_QTDLL_SFX}.dll DESTINATION ${INSTALL_DESTINATION})
390   endforeach()
391   install(FILES ${QT_DLL_DIR}/../plugins/platforms/qwindows${INSTALL_TEMP_QTDLL_SFX}.dll DESTINATION ${INSTALL_DESTINATION}/platforms)
392   # ICU dlls
393   foreach(tmpfile ${INSTALL_TEMP_ICUDLL_FILES})
394     # Qt5.7+ doesn't use icu dlls anymore, hence optional
395     install(FILES ${QT_DLL_DIR}/${tmpfile}.dll DESTINATION ${INSTALL_DESTINATION} OPTIONAL)
396   endforeach()
397   # SDL dll
398   if(SDL_FOUND AND SDL_LIBRARY_PATH AND EXISTS "${SDL_LIBRARY_PATH}/SDL.dll")
399     set(SDL_DIR ${SDL_LIBRARY_PATH})  # this is also used by NSIS installer script
400     install(FILES ${SDL_DIR}/SDL.dll DESTINATION ${INSTALL_DESTINATION})
401   elseif(SDL_FOUND)
402     message(WARNING "Installer: SDL.dll not found!")
403   endif()
404   # C++/system dlls, depends on compiler
405   if(MSVC)
406     string(REPLACE "\\" "/" WIN_SYSDIR "$ENV{windir}")
407     set(WIN_SYSDIR "${WIN_SYSDIR}/SysWOW64")  # This would be "system32" for a 64-bit build or on x86... but how to tell?
408     if(IS_DIRECTORY "${WIN_SYSDIR}")
409       install(FILES "${WIN_SYSDIR}/msvcp140.dll" "${WIN_SYSDIR}/vcruntime140.dll" DESTINATION ${INSTALL_DESTINATION} OPTIONAL)
410     endif()
411     if(WIN_PTHREAD_DLL)
412       install(FILES "${WIN_PTHREAD_DLL}" DESTINATION ${INSTALL_DESTINATION})
413     endif()
414   elseif(MINGW)
415     get_filename_component(MINGW_DIR ${CMAKE_CXX_COMPILER} PATH)
416     if(IS_DIRECTORY ${MINGW_DIR})
417       install(FILES "${MINGW_DIR}/libgcc_s_dw2-1.dll" "${MINGW_DIR}/libstdc++-6.dll" "${MINGW_DIR}/libwinpthread-1.dll" DESTINATION ${INSTALL_DESTINATION})
418       set(MINGW_DIR "${MINGW_DIR}/../opt/bin")
419       # SSL support
420       install(FILES "${MINGW_DIR}/libeay32.dll" "${MINGW_DIR}/ssleay32.dll" DESTINATION ${INSTALL_DESTINATION} OPTIONAL)
421     endif()
422   endif()
424 endif() # WIN32 install
426 ############# Packaging ####################
428 # Create Windows installer with NSIS (only works for MSVC for now)
429 if(WIN32)
430   if(MSVC)
431     set(COMPANION_NSI_IN_FILE companion-vs.nsi.in)
432     set(SIMULATOR_NSI_IN_FILE simulator-vs.nsi.in)
433   else()
434     set(COMPANION_NSI_IN_FILE companion-msys.nsi.in)
435     set(SIMULATOR_NSI_IN_FILE simulator-msys.nsi.in)
436   endif()
438   set(SYSDIR "$ENV{windir}/system32")
439   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../targets/windows/${COMPANION_NSI_IN_FILE} ${PROJECT_BINARY_DIR}/companion/companion.nsi @ONLY)
440   #configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../targets/windows/${SIMULATOR_NSI_IN_FILE} ${PROJECT_BINARY_DIR}/companion/simulator.nsi @ONLY)
442   find_program(NSIS_EXE makensis.exe PATHS
443     "C:/Program Files/NSIS"
444     "C:/Program Files (x86)/NSIS"
445     "C:/Programs/NSIS"
446     )
448   add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/companion/companion-windows.exe
449     COMMAND "${NSIS_EXE}" ARGS ${PROJECT_BINARY_DIR}/companion/companion.nsi
450     DEPENDS companion simulator opentx-simulators ${PROJECT_BINARY_DIR}/companion/companion.nsi
451     COMMENT "Companion Windows NSIS Installer")
453 #  add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/companion/simulator-install.exe
454 #    COMMAND "${NSIS_EXE}" ARGS ${PROJECT_BINARY_DIR}/companion/simulator.nsi
455 #    DEPENDS simulator ${PROJECT_BINARY_DIR}/companion/simulator.nsi
456 #    COMMENT "Simulator Windows NSIS Installer")
458   add_custom_target(installer
459     DEPENDS ${PROJECT_BINARY_DIR}/companion/companion-windows.exe
460 #    DEPENDS ${PROJECT_BINARY_DIR}/companion/simulator-windows.exe
461     SOURCES ${PROJECT_BINARY_DIR}/companion/companion.nsi
462 #    SOURCES ${PROJECT_BINARY_DIR}/companion/simulator.nsi
463     )
464 endif()
466 set(CPACK_PACKAGE_NAME "companion${C9X_NAME_SUFFIX}")
467 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Models and settings editor for the OpenTX open source firmware")
468 string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE)
470 # The file stripping is deliberately disabled, with the stripped file we get
471 # very poor trace-backs from the users when they report Companion crash
472 set(CPACK_STRIP_FILES FALSE)
474 # Qt5 + Cmake + Mac is poorly documented. A lot of this is guesswork
475 # and trial and error. Do not hesitate to fix it for the better
476 IF(APPLE)
477   set(plugin_dest_dir ${COMPANION_NAME}.app/Contents/Plugins)
478   set(qtconf_dest_dir ${COMPANION_NAME}.app/Contents/Resources)
479   set(APPS "\${CMAKE_INSTALL_PREFIX}/${COMPANION_NAME}.app")
480   set(companion_res_dir ${COMPANION_NAME}.app/Contents/Resources)
482   set_target_properties(${COMPANION_NAME} PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Companion ${VERSION_MAJOR}.${VERSION_MINOR}")
483   set_target_properties(${SIMULATOR_NAME} PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Simulator ${VERSION_MAJOR}.${VERSION_MINOR}")
485   # Use a non standard Info.plist that adds Retina support flags
486   set_target_properties(${COMPANION_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/companion/targets/mac/MacOSXBundleInfo.plist.in)
487   set_target_properties(${SIMULATOR_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/companion/targets/mac/MacOSXBundleInfo.plist.in)
489   INSTALL(TARGETS ${COMPANION_NAME}
490       BUNDLE DESTINATION . COMPONENT Runtime
491       RUNTIME DESTINATION bin COMPONENT Runtime
492       )
494   install(FILES ${simulator_plugins} DESTINATION "${companion_res_dir}" COMPONENT Runtime)
496   # Write qt.conf to tell qt where to find it plugins
497   file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
498     "[Paths]\nPlugins = Plugins\n")
499   install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
500     DESTINATION "${companion_res_dir}"
501     COMPONENT Runtime)
503   # menu file
504   install(DIRECTORY ${PROJECT_SOURCE_DIR}/companion/targets/mac/qt_menu.nib DESTINATION "${companion_res_dir}" COMPONENT Runtime)
506   # manually add the required plugins
507   foreach (plugin ${Qt5Multimedia_PLUGINS} ${Qt5PrintSupport_PLUGINS} ${Qt5Gui_PLUGINS} ${Qt5Svg_PLUGINS})
508     get_target_property(QPA_PLUGIN ${plugin} LOCATION)
509     get_filename_component(QPA_PLUGIN_FILENAME ${QPA_PLUGIN} NAME)
510     # Todo is there a nicer way to get the QT Plugin directory name?!
511     get_filename_component(QPA_PLUGIN_DIRECTORY ${QPA_PLUGIN} DIRECTORY)
512     get_filename_component(QPA_PLUGIN_DIRECTORY ${QPA_PLUGIN_DIRECTORY} NAME)
514     install(FILES ${QPA_PLUGIN} DESTINATION "${plugin_dest_dir}/${QPA_PLUGIN_DIRECTORY}/" COMPONENT Runtime)
516     list(APPEND bundle_qt_libs "\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/${QPA_PLUGIN_DIRECTORY}/${QPA_PLUGIN_FILENAME}")
517   endforeach()
519   # Add icon
520   set(MACOSX_BUNDLE_ICON_FILE iconmac.icns)
521   set(MAC_ICON_FILE ${COMPANION_SRC_DIRECTORY}/images/${MACOSX_BUNDLE_ICON_FILE})
522   SET_SOURCE_FILES_PROPERTIES(${MAC_ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
523   set(${COMPANION_SOURCES} ${COMPANION_SOURCES} ${PROJECT_SOURCE_DIR}/images/${MACOSX_BUNDLE_ICON_FILE})
524   install(FILES ${MAC_ICON_FILE} DESTINATION ${companion_res_dir} COMPONENT Runtime)
526   # Copy dfu-util and avrdude, resolve symlink first
527   get_filename_component(DFU_UTIL_ABSOLUTE_PATH ${DFU_UTIL_PATH} REALPATH)
528   get_filename_component(AVRDUDE_ABSOLUTE_PATH ${AVRDUDE_PATH} REALPATH)
529   get_filename_component(AVRDUDECONF_ABSOLUTE_PATH ${AVRDUDE_CONF} REALPATH)
530   install(PROGRAMS ${DFU_UTIL_ABSOLUTE_PATH} ${AVRDUDE_ABSOLUTE_PATH} DESTINATION ${companion_res_dir} COMPONENT Runtime)
531   install(FILES ${AVRDUDECONF_ABSOLUTE_PATH} DESTINATION ${companion_res_dir} COMPONENT Runtime)
533   set(bundle_tools_path "\${CMAKE_INSTALL_PREFIX}/${companion_res_dir}/dfu-util;\${CMAKE_INSTALL_PREFIX}/${companion_res_dir}/avrdude")
536   # Include depencies (adding frameworks, fixing the embbeded libraries)
537   # I get write errors without setting BU_CHMOD_BUNDLE_ITEMS even though it is
538   # technically a hack (that is already is in the Bundle library ...)
539   install(CODE "
540    include(BundleUtilities)
541    file(GLOB bundle_simulator_libs \"\${CMAKE_INSTALL_PREFIX}/${companion_res_dir}/libopentx-*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
542    set(BU_CHMOD_BUNDLE_ITEMS on)
543    fixup_bundle(\"${APPS}\"   \"\${bundle_simulator_libs};${bundle_qt_libs};${bundle_tools_path}\"   \"${QT_LIB_DIR}\")
544    file(RENAME \"\${CMAKE_INSTALL_PREFIX}/${COMPANION_NAME}.app\" \"\${CMAKE_INSTALL_PREFIX}/${COMPANION_OSX_APP_BUNDLE_NAME}.app\")
545    " COMPONENT Runtime)
546 endif()
548 find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
550 if(DPKG_PROGRAM)
551   set(CPACK_GENERATOR "DEB")
552   execute_process(
553     COMMAND ${DPKG_PROGRAM} --print-architecture
554     OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
555     OUTPUT_STRIP_TRAILING_WHITESPACE
556   )
557   set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
558   set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Bertrand Songis <bsongis-nosp@m-gmail.com>")
559   set(CPACK_DEBIAN_PACKAGE_VERSION ${VERSION})
560   set(CPACK_DEBIAN_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
561   set(CPACK_DEBIAN_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
562   set(CPACK_DEBIAN_ARCHITECTURE $(CMAKE_SYSTEM_PROCESSOR))
563   set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt5multimedia5-plugins")
564   set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
565 elseif(APPLE)
566   set(CPACK_GENERATOR "DragNDrop")
567 # set(CPACK_GENERATOR "TGZ")  # for quick testing
568   set(CPACK_BINARY_DRAGNDROP ON)
569   set(CPACK_DMG_BACKGROUND_IMAGE ${COMPANION_SRC_DIRECTORY}/images/splash22_3_dmg.png)
570   set(CPACK_DMG_VOLUME_NAME "OpenTX Companion")
571   set(CPACK_DMG_DS_STORE ${PROJECT_SOURCE_DIR}/companion/targets/mac/DS_Store)
572   set(CPACK_PACKAGE_FILE_NAME "opentx-${CPACK_PACKAGE_NAME_LOWERCASE}-${VERSION}")
573 else(DPKG_PROGRAM)
574   set(CPACK_GENERATOR "RPM")
575   set(CPACK_RPM_PACKAGE_VERSION ${VERSION})
576   set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
577   set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}-${VERSION}-${CMAKE_SYSTEM_PROCESSOR}")
578   set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/lib /lib/udev /lib/udev/rules.d")
579 endif(DPKG_PROGRAM)
581 include(CPack)