[companion] Adjust GVAR not possible in global functions (fix #5425)
[opentx.git] / companion / src / CMakeLists.txt
blob20a6c0ea9ccc1fe5c408aa3198d0a2a73de675fb
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   boards.cpp
165   customdebug.cpp
166   eeprominterface.cpp
167   helpers.cpp
168   radiodata.cpp
169   translations.cpp
170   firmwares/er9x/er9xeeprom.cpp
171   firmwares/er9x/er9xinterface.cpp
172   firmwares/ersky9x/ersky9xeeprom.cpp
173   firmwares/ersky9x/ersky9xinterface.cpp
174   firmwares/opentx/opentxeeprom.cpp
175   firmwares/opentx/opentxinterface.cpp
176   modeledit/node.cpp  # used in simulator
177   modeledit/edge.cpp  # used by node
178   )
180 set(common_MOC_HDRS
181   appdebugmessagehandler.h
182   helpers.h
183   modeledit/node.h
184   )
186 set(common_RESOURCES
187   companion.qrc
188   ${TRANSLATIONS_QRC}
189   )
191 qt5_wrap_cpp(common_SRCS ${common_MOC_HDRS})
192 qt5_add_resources(common_RCC ${common_RESOURCES})
193 #add_custom_target(gen_qrc DEPENDS ${common_RCC} ${companion_QM})
195 add_library(common ${common_SRCS} ${common_RCC})
196 qt5_use_modules(common Core Xml Widgets)
197 target_link_libraries(common PRIVATE simulation)
198 #add_dependencies(common gen_qrc)
200 set(CPN_COMMON_LIB common)
202 ############# Supporting libraries ###############
204 add_subdirectory(shared)
205 add_subdirectory(modeledit)
206 add_subdirectory(generaledit)
207 add_subdirectory(simulation)
208 add_subdirectory(storage)
209 add_subdirectory(thirdparty/qcustomplot)
211 ############# Companion ###############
213 set(companion_SRCS
214   helpers_html.cpp
215   mdichild.cpp
216   modelslist.cpp
217   apppreferencesdialog.cpp
218   fwpreferencesdialog.cpp
219   burnconfigdialog.cpp
220   multimodelprinter.cpp
221   comparedialog.cpp
222   creditsdialog.cpp
223   releasenotesdialog.cpp
224   releasenotesfirmwaredialog.cpp
225   customizesplashdialog.cpp
226   radiointerface.cpp
227   progresswidget.cpp
228   progressdialog.cpp
229   process_copy.cpp
230   process_flash.cpp
231   process_sync.cpp
232   flashfirmwaredialog.cpp
233   flasheepromdialog.cpp
234   printdialog.cpp
235   modelprinter.cpp
236   fusesdialog.cpp
237   logsdialog.cpp
238   downloaddialog.cpp
239   splashlibrarydialog.cpp
240   mainwindow.cpp
241   companion.cpp
242   radionotfound.cpp
243   wizarddata.cpp
244   wizarddialog.cpp
245   multiprotocols.cpp
246   )
248 set(companion_MOC_HDRS
249   apppreferencesdialog.h
250   fwpreferencesdialog.h
251   burnconfigdialog.h
252   comparedialog.h
253   printdialog.h
254   fusesdialog.h
255   logsdialog.h
256   creditsdialog.h
257   releasenotesdialog.h
258   releasenotesfirmwaredialog.h
259   customizesplashdialog.h
260   splashlibrarydialog.h
261   splashlabel.h
262   progresswidget.h
263   progressdialog.h
264   process_copy.h
265   process_flash.h
266   process_sync.h
267   flashfirmwaredialog.h
268   flasheepromdialog.h
269   downloaddialog.h
270   mdichild.h
271   mainwindow.h
272   radionotfound.h
273   wizarddialog.h
274   modelprinter.h
275   multimodelprinter.h
276   modelslist.h
277   )
279 set(companion_UIS
280   mdichild.ui
281   comparedialog.ui
282   fusesdialog.ui
283   logsdialog.ui
284   apppreferencesdialog.ui
285   fwpreferencesdialog.ui
286   burnconfigdialog.ui
287   downloaddialog.ui
288   printdialog.ui
289   htmldialog.ui
290   customizesplashdialog.ui
291   splashlibrarydialog.ui
292   progresswidget.ui
293   progressdialog.ui
294   flashfirmwaredialog.ui
295   flasheepromdialog.ui
296   radionotfound.ui
297   )
299 if(WIN32)
300   set(icon_RC icon.rc)
301 endif()
303 qt5_wrap_ui(companion_SRCS ${companion_UIS})
304 qt5_wrap_cpp(companion_SRCS ${companion_MOC_HDRS})
306 add_executable(${COMPANION_NAME} MACOSX_BUNDLE ${WIN_EXECUTABLE_TYPE} ${companion_SRCS} ${icon_RC})
307 qt5_use_modules(${COMPANION_NAME} Core Widgets Network)
308 target_link_libraries(${COMPANION_NAME} PRIVATE generaledit modeledit simulation ${CPN_COMMON_LIB} qcustomplot shared storage ${PTHREAD_LIBRARY} ${SDL_LIBRARY} ${WIN_LINK_LIBRARIES})
310 PrintTargetReport("${COMPANION_NAME}")
312 ############# Standalone simulator ###############
314 set(simu_SRCS simulator.cpp )
316 add_executable(${SIMULATOR_NAME} MACOSX_BUNDLE ${WIN_EXECUTABLE_TYPE} ${simu_SRCS} ${icon_RC})
317 target_link_libraries(${SIMULATOR_NAME} PRIVATE simulation ${CPN_COMMON_LIB} storage ${PTHREAD_LIBRARY} ${SDL_LIBRARY} ${WIN_LINK_LIBRARIES})
319 ############# Install ####################
321 # Generate list of simulator plugins, used by all platforms
322 file(GLOB simulator_plugins "${CMAKE_BINARY_DIR}/*opentx-*simulator${CMAKE_SHARED_LIBRARY_SUFFIX}")
323 # the current flavour is not automatically added if build in the current cmake iteration, so always
324 # add its library name to be sure
325 string(TOLOWER ${PCB} FLAVOUR)
326 if(POLICY CMP0026)
327   cmake_policy(SET CMP0026 OLD)  # https://cmake.org/cmake/help/v3.0/policy/CMP0026.html
328 endif()
329 get_property(current_plugin TARGET opentx-${FLAVOUR}-simulator PROPERTY LOCATION)
330 list(APPEND simulator_plugins "${current_plugin}")
332 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
334   message(STATUS "install " ${CMAKE_BINARY_DIR} " to " ${CMAKE_INSTALL_PREFIX}/bin)
335   install(TARGETS ${COMPANION_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
336   install(TARGETS ${SIMULATOR_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
337   install(FILES ${simulator_plugins} DESTINATION "${SIMULATOR_LIB_INSTALL_PATH}")
338   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/companion.desktop DESTINATION share/applications RENAME companion${C9X_NAME_SUFFIX}.desktop)
339   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/simulator.desktop DESTINATION share/applications RENAME simulator${C9X_NAME_SUFFIX}.desktop)
340   if(${CMAKE_INSTALL_PREFIX} MATCHES "/usr/local")
341     set(INSTALL_TEMP_SHR_PFX "/usr/")
342     set(INSTALL_TEMP_LIB_PFX "/")
343   endif()
344   install(FILES images/linuxicons/16x16/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/16x16/apps RENAME companion${C9X_NAME_SUFFIX}.png)
345   install(FILES images/linuxicons/22x22/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/22x22/apps RENAME companion${C9X_NAME_SUFFIX}.png)
346   install(FILES images/linuxicons/24x24/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/24x24/apps RENAME companion${C9X_NAME_SUFFIX}.png)
347   install(FILES images/linuxicons/32x32/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/32x32/apps RENAME companion${C9X_NAME_SUFFIX}.png)
348   install(FILES images/linuxicons/48x48/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/48x48/apps RENAME companion${C9X_NAME_SUFFIX}.png)
349   install(FILES images/linuxicons/128x128/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/128x128/apps RENAME companion${C9X_NAME_SUFFIX}.png)
350   install(FILES images/linuxicons/256x256/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/256x256/apps RENAME companion${C9X_NAME_SUFFIX}.png)
351   install(FILES images/linuxicons/512x512/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/512x512/apps RENAME companion${C9X_NAME_SUFFIX}.png)
352   install(FILES images/linuxicons/scalable/companion.svg DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/scalable/apps RENAME companion${C9X_NAME_SUFFIX}.svg)
353   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)
354   install(FILES ../targets/linux/45-usbasp.rules DESTINATION ${INSTALL_TEMP_LIB_PFX}lib/udev/rules.d RENAME 45-companion${C9X_NAME_SUFFIX}-usbasp.rules)
355   # Linux specific code
356   set(OperatingSystem "Linux")
358 elseif(WIN32)
360   set(QT_DLL_DIR ${QT_LIB_DIR})
361   set(INSTALL_TEMP_QTDLL_FILES Qt5Core Qt5Gui Qt5Widgets Qt5Xml Qt5Network Qt5PrintSupport Qt5Multimedia Qt5Svg)
362   set(INSTALL_TEMP_ICUDLL_FILES icudt54.dll icuin54.dll icuuc54.dll)
363   if(CMAKE_BUILD_TYPE STREQUAL "Debug")
364     set(INSTALL_TEMP_QTDLL_SFX "d")
365   endif()
367   if(NOT WIN_DO_FULL_INSTALL)
368     # Just copy supporting DLLs to build folder
369     set(INSTALL_DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
370     message(STATUS "Partial install to " ${INSTALL_DESTINATION})
371   else()
372     # Full Windows installation with all supporting files
373     set(INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}")
374     message(STATUS "Full install to " ${INSTALL_DESTINATION})
375     # companion & simulator binaries
376     install(TARGETS ${COMPANION_NAME} DESTINATION ${INSTALL_DESTINATION})
377     install(TARGETS ${SIMULATOR_NAME} DESTINATION ${INSTALL_DESTINATION})
378     install(FILES ${simulator_plugins} DESTINATION "${INSTALL_DESTINATION}")
379     # supporting utilities
380     set(INSTALL_TEMP_FILES avrdude.exe avrdude.conf dfu-util.exe libusb0.dll libusb-1.0.dll)
381     foreach(tmpfile ${INSTALL_TEMP_FILES})
382       install(FILES "${COMPANION_SRC_DIRECTORY}/../targets/windows/${tmpfile}" DESTINATION ${INSTALL_DESTINATION})
383     endforeach()
384   endif()  # WIN_DO_FULL_INSTALL
386   # Qt dlls
387   foreach(tmpfile ${INSTALL_TEMP_QTDLL_FILES})
388     install(FILES ${QT_DLL_DIR}/${tmpfile}${INSTALL_TEMP_QTDLL_SFX}.dll DESTINATION ${INSTALL_DESTINATION})
389   endforeach()
390   install(FILES ${QT_DLL_DIR}/../plugins/platforms/qwindows${INSTALL_TEMP_QTDLL_SFX}.dll DESTINATION ${INSTALL_DESTINATION}/platforms)
391   # ICU dlls
392   foreach(tmpfile ${INSTALL_TEMP_ICUDLL_FILES})
393     # Qt5.7+ doesn't use icu dlls anymore, hence optional
394     install(FILES ${QT_DLL_DIR}/${tmpfile}.dll DESTINATION ${INSTALL_DESTINATION} OPTIONAL)
395   endforeach()
396   # SDL dll
397   if(SDL_FOUND AND SDL_LIBRARY_PATH AND EXISTS "${SDL_LIBRARY_PATH}/SDL.dll")
398     set(SDL_DIR ${SDL_LIBRARY_PATH})  # this is also used by NSIS installer script
399     install(FILES ${SDL_DIR}/SDL.dll DESTINATION ${INSTALL_DESTINATION})
400   elseif(SDL_FOUND)
401     message(WARNING "Installer: SDL.dll not found!")
402   endif()
403   # C++/system dlls, depends on compiler
404   if(MSVC)
405     string(REPLACE "\\" "/" WIN_SYSDIR "$ENV{windir}")
406     set(WIN_SYSDIR "${WIN_SYSDIR}/SysWOW64")  # This would be "system32" for a 64-bit build or on x86... but how to tell?
407     if(IS_DIRECTORY "${WIN_SYSDIR}")
408       install(FILES "${WIN_SYSDIR}/msvcp140.dll" "${WIN_SYSDIR}/vcruntime140.dll" DESTINATION ${INSTALL_DESTINATION} OPTIONAL)
409     endif()
410     if(WIN_PTHREAD_DLL)
411       install(FILES "${WIN_PTHREAD_DLL}" DESTINATION ${INSTALL_DESTINATION})
412     endif()
413   elseif(MINGW)
414     get_filename_component(MINGW_DIR ${CMAKE_CXX_COMPILER} PATH)
415     if(IS_DIRECTORY ${MINGW_DIR})
416       install(FILES "${MINGW_DIR}/libgcc_s_dw2-1.dll" "${MINGW_DIR}/libstdc++-6.dll" "${MINGW_DIR}/libwinpthread-1.dll" DESTINATION ${INSTALL_DESTINATION})
417       set(MINGW_DIR "${MINGW_DIR}/../opt/bin")
418       # SSL support
419       install(FILES "${MINGW_DIR}/libeay32.dll" "${MINGW_DIR}/ssleay32.dll" DESTINATION ${INSTALL_DESTINATION} OPTIONAL)
420     endif()
421   endif()
423 endif() # WIN32 install
425 ############# Packaging ####################
427 # Create Windows installer with NSIS (only works for MSVC for now)
428 if(WIN32)
429   if(MSVC)
430     set(COMPANION_NSI_IN_FILE companion-vs.nsi.in)
431     set(SIMULATOR_NSI_IN_FILE simulator-vs.nsi.in)
432   else()
433     set(COMPANION_NSI_IN_FILE companion-msys.nsi.in)
434     set(SIMULATOR_NSI_IN_FILE simulator-msys.nsi.in)
435   endif()
437   set(SYSDIR "$ENV{windir}/system32")
438   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../targets/windows/${COMPANION_NSI_IN_FILE} ${PROJECT_BINARY_DIR}/companion/companion.nsi @ONLY)
439   #configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../targets/windows/${SIMULATOR_NSI_IN_FILE} ${PROJECT_BINARY_DIR}/companion/simulator.nsi @ONLY)
441   find_program(NSIS_EXE makensis.exe PATHS
442     "C:/Program Files/NSIS"
443     "C:/Program Files (x86)/NSIS"
444     "C:/Programs/NSIS"
445     )
447   add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/companion/companion-windows.exe
448     COMMAND "${NSIS_EXE}" ARGS ${PROJECT_BINARY_DIR}/companion/companion.nsi
449     DEPENDS companion simulator opentx-simulators ${PROJECT_BINARY_DIR}/companion/companion.nsi
450     COMMENT "Companion Windows NSIS Installer")
452 #  add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/companion/simulator-install.exe
453 #    COMMAND "${NSIS_EXE}" ARGS ${PROJECT_BINARY_DIR}/companion/simulator.nsi
454 #    DEPENDS simulator ${PROJECT_BINARY_DIR}/companion/simulator.nsi
455 #    COMMENT "Simulator Windows NSIS Installer")
457   add_custom_target(installer
458     DEPENDS ${PROJECT_BINARY_DIR}/companion/companion-windows.exe
459 #    DEPENDS ${PROJECT_BINARY_DIR}/companion/simulator-windows.exe
460     SOURCES ${PROJECT_BINARY_DIR}/companion/companion.nsi
461 #    SOURCES ${PROJECT_BINARY_DIR}/companion/simulator.nsi
462     )
463 endif()
465 set(CPACK_PACKAGE_NAME "companion${C9X_NAME_SUFFIX}")
466 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Models and settings editor for the OpenTX open source firmware")
467 string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE)
469 # The file stripping is deliberately disabled, with the stripped file we get
470 # very poor trace-backs from the users when they report Companion crash
471 set(CPACK_STRIP_FILES FALSE)
473 # Qt5 + Cmake + Mac is poorly documented. A lot of this is guesswork
474 # and trial and error. Do not hesitate to fix it for the better
475 IF(APPLE)
476   set(plugin_dest_dir ${COMPANION_NAME}.app/Contents/Plugins)
477   set(qtconf_dest_dir ${COMPANION_NAME}.app/Contents/Resources)
478   set(APPS "\${CMAKE_INSTALL_PREFIX}/${COMPANION_NAME}.app")
479   set(companion_res_dir ${COMPANION_NAME}.app/Contents/Resources)
481   set_target_properties(${COMPANION_NAME} PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Companion ${VERSION_MAJOR}.${VERSION_MINOR}")
482   set_target_properties(${SIMULATOR_NAME} PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Simulator ${VERSION_MAJOR}.${VERSION_MINOR}")
484   # Use a non standard Info.plist that adds Retina support flags
485   set_target_properties(${COMPANION_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/companion/targets/mac/MacOSXBundleInfo.plist.in)
486   set_target_properties(${SIMULATOR_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/companion/targets/mac/MacOSXBundleInfo.plist.in)
488   INSTALL(TARGETS ${COMPANION_NAME}
489       BUNDLE DESTINATION . COMPONENT Runtime
490       RUNTIME DESTINATION bin COMPONENT Runtime
491       )
493   install(FILES ${simulator_plugins} DESTINATION "${companion_res_dir}" COMPONENT Runtime)
495   # Write qt.conf to tell qt where to find it plugins
496   file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
497     "[Paths]\nPlugins = Plugins\n")
498   install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
499     DESTINATION "${companion_res_dir}"
500     COMPONENT Runtime)
502   # menu file
503   install(DIRECTORY ${PROJECT_SOURCE_DIR}/companion/targets/mac/qt_menu.nib DESTINATION "${companion_res_dir}" COMPONENT Runtime)
505   # manually add the required plugins
506   foreach (plugin ${Qt5Multimedia_PLUGINS} ${Qt5PrintSupport_PLUGINS} ${Qt5Gui_PLUGINS} ${Qt5Svg_PLUGINS})
507     get_target_property(QPA_PLUGIN ${plugin} LOCATION)
508     get_filename_component(QPA_PLUGIN_FILENAME ${QPA_PLUGIN} NAME)
509     # Todo is there a nicer way to get the QT Plugin directory name?!
510     get_filename_component(QPA_PLUGIN_DIRECTORY ${QPA_PLUGIN} DIRECTORY)
511     get_filename_component(QPA_PLUGIN_DIRECTORY ${QPA_PLUGIN_DIRECTORY} NAME)
513     install(FILES ${QPA_PLUGIN} DESTINATION "${plugin_dest_dir}/${QPA_PLUGIN_DIRECTORY}/" COMPONENT Runtime)
515     list(APPEND bundle_qt_libs "\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/${QPA_PLUGIN_DIRECTORY}/${QPA_PLUGIN_FILENAME}")
516   endforeach()
518   # Add icon
519   set(MACOSX_BUNDLE_ICON_FILE iconmac.icns)
520   set(MAC_ICON_FILE ${COMPANION_SRC_DIRECTORY}/images/${MACOSX_BUNDLE_ICON_FILE})
521   SET_SOURCE_FILES_PROPERTIES(${MAC_ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
522   set(${COMPANION_SOURCES} ${COMPANION_SOURCES} ${PROJECT_SOURCE_DIR}/images/${MACOSX_BUNDLE_ICON_FILE})
523   install(FILES ${MAC_ICON_FILE} DESTINATION ${companion_res_dir} COMPONENT Runtime)
525   # Copy dfu-util and avrdude, resolve symlink first
526   get_filename_component(DFU_UTIL_ABSOLUTE_PATH ${DFU_UTIL_PATH} REALPATH)
527   get_filename_component(AVRDUDE_ABSOLUTE_PATH ${AVRDUDE_PATH} REALPATH)
528   get_filename_component(AVRDUDECONF_ABSOLUTE_PATH ${AVRDUDE_CONF} REALPATH)
529   install(PROGRAMS ${DFU_UTIL_ABSOLUTE_PATH} ${AVRDUDE_ABSOLUTE_PATH} DESTINATION ${companion_res_dir} COMPONENT Runtime)
530   install(FILES ${AVRDUDECONF_ABSOLUTE_PATH} DESTINATION ${companion_res_dir} COMPONENT Runtime)
531   
532   set(bundle_tools_path "\${CMAKE_INSTALL_PREFIX}/${companion_res_dir}/dfu-util;\${CMAKE_INSTALL_PREFIX}/${companion_res_dir}/avrdude")
533   
535   # Include depencies (adding frameworks, fixing the embbeded libraries)
536   # I get write errors without setting BU_CHMOD_BUNDLE_ITEMS even though it is
537   # technically a hack (that is already is in the Bundle library ...)
538   install(CODE "
539    include(BundleUtilities)
540    file(GLOB bundle_simulator_libs \"\${CMAKE_INSTALL_PREFIX}/${companion_res_dir}/libopentx-*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
541    set(BU_CHMOD_BUNDLE_ITEMS on)
542    fixup_bundle(\"${APPS}\"   \"\${bundle_simulator_libs};${bundle_qt_libs};${bundle_tools_path}\"   \"${QT_LIB_DIR}\")
543    file(RENAME \"\${CMAKE_INSTALL_PREFIX}/${COMPANION_NAME}.app\" \"\${CMAKE_INSTALL_PREFIX}/${COMPANION_OSX_APP_BUNDLE_NAME}.app\")
544    " COMPONENT Runtime)
545 endif()
547 find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
549 if(DPKG_PROGRAM)
550   set(CPACK_GENERATOR "DEB")
551   execute_process(
552     COMMAND ${DPKG_PROGRAM} --print-architecture
553     OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
554     OUTPUT_STRIP_TRAILING_WHITESPACE
555   )
556   set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
557   set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Bertrand Songis <bsongis-nosp@m-gmail.com>")
558   set(CPACK_DEBIAN_PACKAGE_VERSION ${VERSION})
559   set(CPACK_DEBIAN_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
560   set(CPACK_DEBIAN_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
561   set(CPACK_DEBIAN_ARCHITECTURE $(CMAKE_SYSTEM_PROCESSOR))
562   set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt5multimedia5-plugins")
563   set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
564 elseif(APPLE)
565   set(CPACK_GENERATOR "DragNDrop")
566 # set(CPACK_GENERATOR "TGZ")  # for quick testing
567   set(CPACK_BINARY_DRAGNDROP ON)
568   set(CPACK_DMG_BACKGROUND_IMAGE ${COMPANION_SRC_DIRECTORY}/images/splash22_3_dmg.png)
569   set(CPACK_DMG_VOLUME_NAME "OpenTX Companion")
570   set(CPACK_DMG_DS_STORE ${PROJECT_SOURCE_DIR}/companion/targets/mac/DS_Store)
571   set(CPACK_PACKAGE_FILE_NAME "opentx-${CPACK_PACKAGE_NAME_LOWERCASE}-${VERSION}")
572 else(DPKG_PROGRAM)
573   set(CPACK_GENERATOR "RPM")
574   set(CPACK_RPM_PACKAGE_VERSION ${VERSION})
575   set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
576   set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}-${VERSION}-${CMAKE_SYSTEM_PROCESSOR}")
577   set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/lib /lib/udev /lib/udev/rules.d")
578 endif(DPKG_PROGRAM)
580 include(CPack)