diff --git a/CMakeLists.txt b/CMakeLists.txt index b79b92b05..865d38e5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,24 +33,41 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) +if(WIN32) + set(WIN_EXTRA_LIBS_PATH "C:/Programs" CACHE PATH + "Base path to extra libs/headers on Windows (SDL, dirent, pthreads, msinttypes folders should be in here).") + list(APPEND CMAKE_PREFIX_PATH "${WIN_EXTRA_LIBS_PATH}" "${WIN_EXTRA_LIBS_PATH}/SDL") # hints for FindSDL +endif() + find_package(Qt5Widgets) find_package(Qt5Xml) find_package(Qt5LinguistTools) find_package(Qt5PrintSupport) find_package(Qt5Multimedia) -message(STATUS "Looking for SDL ") -find_package(Sdl) -if(SDL_FOUND) - message("SDL Include Path: " ${SDL_INCLUDE_DIR}) +if(Qt5Widgets_FOUND) + message(STATUS "Qt Version: ${Qt5Widgets_VERSION}") else() - message("SDL not found! Joysticks support will be disabled. Simulator audio will not work.") + message(WARNING "Qt not found! Companion and Simulator builds disabled.") endif() -message(STATUS "Looking for FOX ") -find_package(Fox) -if ((NOT FOX_FOUND) AND (NOT WIN32)) - message("Libfox not found, simu target will not be available") +if(NOT WIN32) + find_package(Fox QUIET) # QUIET not working on WIN32? + if (FOX_FOUND) + message(STATUS "Foxlib found at ${FOX_LIBRARY}") + else() # if(NOT WIN32) + message("Libfox not found, simu target will not be available") + endif() +endif() + +if(Qt5Widgets_FOUND OR FOX_FOUND) + set(SDL_BUILDING_LIBRARY YES) # this prevents FindSDL from appending SDLmain lib to the results, which we don't want + find_package("SDL") + if(SDL_FOUND) + message(STATUS "SDL Lib: ${SDL_LIBRARY}; Headers: ${SDL_INCLUDE_DIR}; Version: ${SDL_VERSION_STRING}") + else() + message(STATUS "SDL not found! Joysticks support will be disabled. Simulator audio will not work.") + endif() endif() # Check for a file that is typically left from a OpenTX 2.1 build and abort if found @@ -58,6 +75,16 @@ if (EXISTS ${RADIO_SRC_DIRECTORY}/stamp.h OR EXISTS ${RADIO_SRC_DIRECTORY}/trans message(FATAL_ERROR "Source directory contains files leftover from a OpenTX 2.1 build. Please run `git clean -f` in source directory (Careful: Will remove any extra files) or do a new clean git checkout") endif() +# Windows-specific includes and libs shared by sub-projects +if(WIN32) + list(APPEND WIN_INCLUDE_DIRS "${WIN_EXTRA_LIBS_PATH}/dirent/include") + if(MSVC) + set(WIN_PTHREAD_BASE_PATH "${WIN_EXTRA_LIBS_PATH}/pthreads/Pre-built.2") + list(APPEND WIN_INCLUDE_DIRS "${WIN_PTHREAD_BASE_PATH}/include" "${WIN_EXTRA_LIBS_PATH}/msinttypes") + list(APPEND WIN_LINK_LIBRARIES "${WIN_PTHREAD_BASE_PATH}/lib/pthreadVC2.lib") + endif(MSVC) +endif() + include(Macros) today(DATE) now(TIME) diff --git a/cmake/FindSDL.cmake b/cmake/FindSDL.cmake new file mode 100644 index 000000000..b2abd3042 --- /dev/null +++ b/cmake/FindSDL.cmake @@ -0,0 +1,256 @@ +#.rst: +# FindSDL +# ------- +# +# Locate SDL library +# +# This module defines +# +# :: +# +# SDL_FOUND, if false, do not try to link to SDL +# SDL_LIBRARY, the name(s) of the library(ies) to link against +# SDL_LIBSDL, the full path and name of libSDL (or SDL.[lib|dll]. +# SDL_LIBSDLMAIN, full path and name of libSDLmain (or SDLmain.lib). +# SDL_LIBRARY_PATH, the full path to the found libSDL +# SDL_INCLUDE_DIR, where to find SDL.h +# SDL_VERSION_STRING, human-readable string containing the version of SDL +# +# +# +# This module responds to the flag: +# +# :: +# +# SDL_BUILDING_LIBRARY +# If this is defined, then no SDL_main will be linked in because +# only applications need main(). +# Otherwise, it is assumed you are building an application and this +# module will attempt to locate and set the proper link flags +# as part of the returned SDL_LIBRARY variable. +# +# +# +# Don't forget to include SDLmain.h and SDLmain.m your project for the +# OS X framework based version. (Other versions link to -lSDLmain which +# this module will try to find on your behalf.) Also for OS X, this +# module will automatically add the -framework Cocoa on your behalf. +# +# +# +# Additional Note: If you see an empty SDL_LIBSDL in your +# configuration and no SDL_LIBRARY, it means CMake did not find your SDL +# library (SDL.dll, libsdl.so, SDL.framework, etc). Set +# SDL_LIBSDL to point to your SDL library, and configure again. +# Similarly, if you see an empty SDL_LIBSDLMAIN, you should set this +# value as appropriate. These values are used to generate the final +# SDL_LIBRARY variable, but when these values are unset, SDL_LIBRARY +# does not get created. +# +# +# +# $SDLDIR is an environment variable that would correspond to the +# ./configure --prefix=$SDLDIR used in building SDL. l.e.galup 9-20-02 +# +# Modified by Eric Wing. Added code to assist with automated building +# by using environmental variables and providing a more +# controlled/consistent search behavior. Added new modifications to +# recognize OS X frameworks and additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL +# guidelines. Added a search for SDLmain which is needed by some +# platforms. Added a search for threads which is needed by some +# platforms. Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of SDL_LIBRARY to +# override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL/SDL.h to just SDL.h +# This needed to change because "proper" SDL convention is #include +# "SDL.h", not . This is done for portability reasons +# because not all systems place things in SDL/ (see FreeBSD). + +# +# Modified for OpenTx by Maxim Paperno 19-Dec-2016 +# Added SDL_LIBSDL, SDL_LIBSDLMAIN & SDL_LIBRARY_PATH, removed SDLMAIN_LIBRARY, +# SDL_LIBRARY_TEMP, and fixed bug with recursive appending of supporting +# libraries to cached SDL_LIBRARY_TEMP variable. +# + +#============================================================================= +#CMake - Cross Platform Makefile Generator +#Copyright 2000-2015 Kitware, Inc. +#Copyright 2000-2011 Insight Software Consortium +#All rights reserved. +# +#Redistribution and use in source and binary forms, with or without +#modification, are permitted provided that the following conditions +#are met: +# +#* Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +#* Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +#* Neither the names of Kitware, Inc., the Insight Software Consortium, +# nor the names of their contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +#A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +#HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +#SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +#LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +#DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +#THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#------------------------------------------------------------------------------ +# +#The above copyright and license notice applies to distributions of +#CMake in source and binary form. Some source files contain additional +#notices of original copyright by their contributors; see each source +#for details. Third-party software packages supplied with CMake under +#compatible licenses provide their own copyright notices documented in +#corresponding subdirectories. +# +#------------------------------------------------------------------------------ +# +#CMake was initially developed by Kitware with the following sponsorship: +# +# * National Library of Medicine at the National Institutes of Health +# as part of the Insight Segmentation and Registration Toolkit (ITK). +# +# * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel +# Visualization Initiative. +# +# * National Alliance for Medical Image Computing (NAMIC) is funded by the +# National Institutes of Health through the NIH Roadmap for Medical Research, +# Grant U54 EB005149. +# +# * Kitware, Inc. +#============================================================================= + + +find_path(SDL_INCLUDE_DIR SDL.h + HINTS + ENV SDLDIR + PATH_SUFFIXES SDL SDL12 SDL11 + # path suffixes to search inside ENV{SDLDIR} + include/SDL include/SDL12 include/SDL11 include +) + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(VC_LIB_PATH_SUFFIX lib/x64) +else() + set(VC_LIB_PATH_SUFFIX lib/x86) +endif() + +# SDL-1.1 is the name used by FreeBSD ports... +# don't confuse it for the version number. +find_library(SDL_LIBSDL + NAMES SDL SDL-1.1 + HINTS + ENV SDLDIR + PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} +) + +# Non-OS X framework versions expect you to also dynamically link to +# SDLmain. This is mainly for Windows and OS X. Other (Unix) platforms +# seem to provide SDLmain for compatibility even though they don't +# necessarily need it. +find_library(SDL_LIBSDLMAIN + NAMES SDLmain SDLmain-1.1 + HINTS + ENV SDLDIR + PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} + PATHS + /sw + /opt/local + /opt/csw + /opt +) + +# SDL may require threads on your system. +# The Apple build may not need an explicit flag because one of the +# frameworks may already provide it. +# But for non-OSX systems, I will use the CMake Threads package. +if(NOT APPLE) + find_package(Threads) +endif() + +# MinGW needs an additional library, mwindows +# It's total link flags should look like -lmingw32 -lSDLmain -lSDL +if(MINGW) + set(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") +endif() + +if(SDL_LIBSDL) + # For SDLmain + if(SDL_LIBSDLMAIN AND NOT SDL_BUILDING_LIBRARY AND NOT SDL_INCLUDE_DIR MATCHES ".framework") + list(FIND SDL_LIBSDL "${SDL_LIBSDLMAIN}" _SDL_MAIN_INDEX) + if(_SDL_MAIN_INDEX EQUAL -1) + list(APPEND _SDL_LIBRARY_TEMP "${SDL_LIBSDLMAIN}") + endif() + unset(_SDL_MAIN_INDEX) + endif() + + list(APPEND _SDL_LIBRARY_TEMP "${SDL_LIBSDL}") + + # For OS X, SDL uses Cocoa as a backend so it must link to Cocoa. + # CMake doesn't display the -framework Cocoa string in the UI even + # though it actually is there if I modify a pre-used variable. + # I think it has something to do with the CACHE STRING. + # So I use a temporary variable until the end so I can set the + # "real" variable in one-shot. + if(APPLE) + list(APPEND _SDL_LIBRARY_TEMP "-framework Cocoa") + endif() + + if(Threads_FOUND) + list(APPEND _SDL_LIBRARY_TEMP ${CMAKE_THREAD_LIBS_INIT}) + endif() + + # MinGW needs an additional library, mwindows + # It's total link flags should look like -lmingw32 -lSDLmain -lSDL + if(MINGW) + list(INSERT 0 _SDL_LIBRARY_TEMP mingw32) + endif() + + # Set the final string here so the GUI reflects the final state. + set(SDL_LIBRARY ${_SDL_LIBRARY_TEMP} CACHE STRING "Full list of required SDL & supporting libraries.") + unset(_SDL_LIBRARY_TEMP) + + get_filename_component(_SDL_LIBRARY_TEMP ${SDL_LIBSDL} PATH) + set(SDL_LIBRARY_PATH ${_SDL_LIBRARY_TEMP} CACHE PATH "Path to SDL library.") + unset(_SDL_LIBRARY_TEMP) +endif() + +if(SDL_INCLUDE_DIR AND EXISTS "${SDL_INCLUDE_DIR}/SDL_version.h") + file(STRINGS "${SDL_INCLUDE_DIR}/SDL_version.h" SDL_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_INCLUDE_DIR}/SDL_version.h" SDL_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_INCLUDE_DIR}/SDL_version.h" SDL_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MAJOR "${SDL_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MINOR "${SDL_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_VERSION_PATCH "${SDL_VERSION_PATCH_LINE}") + set(SDL_VERSION_STRING ${SDL_VERSION_MAJOR}.${SDL_VERSION_MINOR}.${SDL_VERSION_PATCH}) + unset(SDL_VERSION_MAJOR_LINE) + unset(SDL_VERSION_MINOR_LINE) + unset(SDL_VERSION_PATCH_LINE) + unset(SDL_VERSION_MAJOR) + unset(SDL_VERSION_MINOR) + unset(SDL_VERSION_PATCH) +endif() + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL + REQUIRED_VARS SDL_LIBRARY SDL_LIBRARY_PATH SDL_INCLUDE_DIR + VERSION_VAR SDL_VERSION_STRING) diff --git a/cmake/FindSdl.cmake b/cmake/FindSdl.cmake deleted file mode 100644 index e81419c21..000000000 --- a/cmake/FindSdl.cmake +++ /dev/null @@ -1,159 +0,0 @@ -# - Locate the SDL library -# This module defines -# SDL_LIBRARY, the library to link against -# SDL_FOUND, if false, do not try to link to SDL -# SDL_INCLUDE_DIR, where to find SDL.h -# -# Don't forget to include SDLmain.h and SDLmain.m your project for the -# OS X framework based version. (Other versions link to -lSDLmain which -# this module will try to find on your behalf.) Also for OS X, this -# module will automatically add the -framework Cocoa on your behalf. -# $SDLDIR is an environment variable that would -# correspond to the ./configure --prefix=$SDLDIR -# used in building SDL. -# l.e.galup 9-20-02 -# -# Modified by Eric Wing. -# Added new modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). -# Also corrected the header search path to follow "proper" SDL guidelines. -# Added a search for SDLmain which is needed by some platforms. -# Added a search for threads which is needed by some platforms. -# Added needed compile switches for MinGW. -# -# On OSX, this will prefer the Framework version (if found) over others. -# People will have to manually change the cache values of -# SDL_LIBRARY to override this selection. -# -# Note that the header path has changed from SDL/SDL.h to just SDL.h -# This needed to change because "proper" SDL convention -# is #include "SDL.h", not . This is done for portability -# reasons because not all systems place things in SDL/ (see FreeBSD). -FIND_PATH(SDL_INCLUDE_DIR SDL.h - $ENV{SDLDIR}/include - ~/Library/Frameworks/SDL.framework/Headers - /Library/Frameworks/SDL.framework/Headers - /usr/local/include/SDL - /usr/include/SDL - /usr/local/include/SDL12 - /usr/local/include/SDL11 # FreeBSD ports - /usr/include/SDL12 - /usr/include/SDL11 - /usr/local/include - /usr/include - /sw/include/SDL # Fink - /sw/include - /opt/local/include/SDL # DarwinPorts - /opt/local/include - /opt/csw/include/SDL # Blastwave - /opt/csw/include - /opt/include/SDL - /opt/include - C:/Programs/SDL/include - ) -# I'm not sure if I should do a special casing for Apple. It is -# unlikely that other Unix systems will find the framework path. -# But if they do ([Next|Open|GNU]Step?), -# do they want the -framework option also? -IF(${SDL_INCLUDE_DIR} MATCHES ".framework") - # The Cocoa framework must be linked into SDL because SDL is Cocoa based. - # Remember that the OS X framework version expects you to drop in - # SDLmain.h and SDLmain.m directly into your project. - # (Cocoa link moved to bottom of this script.) - # SET (SDL_LIBRARY "-framework SDL -framework Cocoa" CACHE STRING "SDL framework for OSX") - # SET(SDL_LIBRARY "-framework SDL" CACHE STRING "SDL framework for OSX") - # Extract the path the framework resides in so we can use it for the -F flag - STRING(REGEX REPLACE "(.*)/.*\\.framework/.*" "\\1" SDL_FRAMEWORK_PATH_TEMP ${SDL_INCLUDE_DIR}) - IF("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks" - OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks" - ) - # String is in default search path, don't need to use -F - SET(SDL_LIBRARY_TEMP "-framework SDL") - ELSE("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks" - OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks" - ) - # String is not /Library/Frameworks, need to use -F - SET(SDL_LIBRARY_TEMP "-F${SDL_FRAMEWORK_PATH_TEMP} -framework SDL") - ENDIF("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks" - OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks" - ) - # Clear the temp variable so nobody can see it - SET(SDL_FRAMEWORK_PATH_TEMP "" CACHE INTERNAL "") - -ELSE(${SDL_INCLUDE_DIR} MATCHES ".framework") - # SDL-1.1 is the name used by FreeBSD ports... - # don't confuse it for the version number. - FIND_LIBRARY(SDL_LIBRARY_TEMP - NAMES SDL SDL-1.1 - PATHS - $ENV{SDLDIR}/lib - /usr/local/lib - /usr/lib - /sw/lib - /opt/local/lib - /opt/csw/lib - /opt/lib - C:/Programs/SDL/lib/x86 - ) - # Non-OS X framework versions expect you to also dynamically link to - # SDLmain. This is mainly for Windows and OS X. Other platforms - # seem to provide SDLmain for compatibility even though they don't - # necessarily need it. - FIND_LIBRARY(SDLMAIN_LIBRARY - NAMES SDLmain SDLmain-1.1 - PATHS - $ENV{SDLDIR}/lib - /usr/local/lib - /usr/lib - /sw/lib - /opt/local/lib - /opt/csw/lib - /opt/lib - ) -ENDIF(${SDL_INCLUDE_DIR} MATCHES ".framework") - -# SDL may require threads on your system. -# The Apple build may not need an explicit flag because one of the -# frameworks may already provide it. -# But for non-OSX systems, I will use the CMake Threads package. -IF(NOT APPLE) - FIND_PACKAGE(Threads) -ENDIF(NOT APPLE) - -# MinGW needs an additional library, mwindows -# It's total link flags should look like -lmingw32 -lSDLmain -lSDL -lmwindows -# (Actually on second look, I think it only needs one of the m* libraries.) -IF(MINGW) - SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") -ENDIF(MINGW) - -SET(SDL_FOUND "NO") -IF(SDL_LIBRARY_TEMP) - # For SDLmain - IF(SDLMAIN_LIBRARY) - SET(SDL_LIBRARY_TEMP ${SDLMAIN_LIBRARY} ${SDL_LIBRARY_TEMP}) - ENDIF(SDLMAIN_LIBRARY) - - # For OS X, SDL uses Cocoa as a backend so it must link to Cocoa. - # CMake doesn't display the -framework Cocoa string in the UI even - # though it actually is there. I think it has something to do - # with the CACHE STRING. Maybe somebody else knows how to fix this. - # The problem is mainly cosmetic, and not a functional issue. - IF(APPLE) - SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "-framework Cocoa") - ENDIF(APPLE) - - # For threads, as mentioned Apple doesn't need this. - # In fact, there seems to be a problem if Find the threads package - # and try using this line, so I'm just skipping it entirely for OS X. - IF(NOT APPLE) - SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) - ENDIF(NOT APPLE) - - # Set the final string here so the GUI reflects the final state. - SET(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found") - - SET(SDL_FOUND "YES") -ENDIF(SDL_LIBRARY_TEMP) - -MARK_AS_ADVANCED(SDL_LIBRARY_TEMP) diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 1dd2a20b6..a2a389eca 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -1,4 +1,4 @@ - if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(C9X_NAME_SUFFIX ${VERSION_MAJOR}${VERSION_MINOR}) set(COMPANION_NAME "companion${C9X_NAME_SUFFIX}") set(SIMULATOR_NAME "simulator${C9X_NAME_SUFFIX}") @@ -38,28 +38,47 @@ if(TABLE_LAYOUT) message(STATUS "Using QTableWidget") endif() +if(WIN32) + 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) + option(WIN_USE_CONSOLE "Open a Windows command console for Simulator debug output." OFF) + if(WIN_USE_CONSOLE) + add_definitions(-DWIN_USE_CONSOLE_STDIO) + endif() +endif() + if(SDL_FOUND) include_directories(${SDL_INCLUDE_DIR}) - add_definitions(-DSIMU_AUDIO) add_definitions(-DJOYSTICKS) +else() + remove_definitions(-DSIMU_AUDIO) endif() -message(STATUS "Looking for QT lupdate ") find_package(Lupdate) if(LUPDATE_FOUND) - message("QT lupdate: " ${LUPDATE_EXECUTABLE}) + message("Qt lupdate: " ${LUPDATE_EXECUTABLE}) else() - message("QT lupdate not found!") + message("Qt lupdate not found, 'translations' target will not be availabe.") endif() +add_definitions(-DSIMU) add_definitions(-DQXT_STATIC) -if(MSVC) - set(CMAKE_CXX_FLAGS "/EHsc /LD /MP") - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS,5.01") - include_directories(${PROJECT_SOURCE_DIR}/winbuild C:/Programs/pthreads/Pre-built.2/include C:/Programs/msinttypes C:/Programs/dirent/include) - link_directories(C:/Programs/pthreads/Pre-built.2/lib/) - set(PTHREAD_LIBRARY pthreadVC2.lib) +if (NOT MSVC AND ${CMAKE_VERSION} VERSION_LESS 3.1.0}) + message("companion: adding -std=gnu++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") +endif() + +if(WIN32) + include_directories(SYSTEM ${WIN_INCLUDE_DIRS}) + if(MSVC) + set(CMAKE_CXX_FLAGS "/EHsc /LD /MP") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS,5.01") + message("companion: using MSVC with ${CMAKE_CXX_FLAGS}") + elseif(MINGW) + # 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 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-ms-bitfields -mwindows") + message("companion: using MinGW with ${CMAKE_CXX_FLAGS}") + endif() else() set(PTHREAD_LIBRARY pthread) add_definitions(-Wall) @@ -229,7 +248,8 @@ add_executable(${COMPANION_NAME} MACOSX_BUNDLE WIN32 ${companion_SRCS} ${compani add_dependencies(${COMPANION_NAME} gen_qrc) qt5_use_modules(${COMPANION_NAME} Core Widgets Network) -target_link_libraries(${COMPANION_NAME} PRIVATE generaledit modeledit simulation common qcustomplot shared storage ${PTHREAD_LIBRARY} ${SDL_LIBRARY}) + +target_link_libraries(${COMPANION_NAME} PRIVATE generaledit modeledit simulation common qcustomplot shared storage ${PTHREAD_LIBRARY} ${SDL_LIBRARY} ${WIN_LINK_LIBRARIES}) ############# Standalone simu ############### @@ -249,60 +269,113 @@ if(WIN32) set(simu_SRCS ${simu_SRCS} icon.rc) endif() - add_executable(${SIMULATOR_NAME} MACOSX_BUNDLE WIN32 ${simu_SRCS} ${companion_RCC}) add_dependencies(${SIMULATOR_NAME} gen_qrc) -# TODO not the same link command than companion? -target_link_libraries(${SIMULATOR_NAME} PRIVATE simulation common storage qxtcommandoptions ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY} ${PTHREAD_LIBRARY} ${SDL_LIBRARY} ${OPENTX_SIMULATOR_LIBS}) -############# Packaging #################### -message(STATUS ${CMAKE_BINARY_DIR} ${CMAKE_INSTALL_PREFIX}/bin) +# TODO not the same link command than companion? +target_link_libraries(${SIMULATOR_NAME} PRIVATE simulation common storage qxtcommandoptions ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY} ${PTHREAD_LIBRARY} ${SDL_LIBRARY} ${OPENTX_SIMULATOR_LIBS} ${WIN_LINK_LIBRARIES}) + +############# Install #################### + if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + + message(STATUS "install " ${CMAKE_BINARY_DIR} " to " ${CMAKE_INSTALL_PREFIX}/bin) install(TARGETS ${COMPANION_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) install(TARGETS ${SIMULATOR_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) - install(DIRECTORY ${CMAKE_BINARY_DIR}/ DESTINATION ${SIMULATOR_LIB_PATH} USE_SOURCE_PERMISSIONS - FILES_MATCHING PATTERN "libopentx-*${CMAKE_SHARED_LIBRARY_SUFFIX}" - PATTERN "CMakeFiles" EXCLUDE - PATTERN "_CPack_Packages" EXCLUDE - PATTERN "companion" EXCLUDE - PATTERN "radio" EXCLUDE - ) + file(GLOB simulator_plugins "${CMAKE_BINARY_DIR}/libopentx-*${CMAKE_SHARED_LIBRARY_SUFFIX}") + install(FILES ${simulator_plugins} DESTINATION "${SIMULATOR_LIB_PATH}") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/companion.desktop DESTINATION share/applications RENAME companion${C9X_NAME_SUFFIX}.desktop) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/simulator.desktop DESTINATION share/applications RENAME simulator${C9X_NAME_SUFFIX}.desktop) if(${CMAKE_INSTALL_PREFIX} MATCHES "/usr/local") - install(FILES images/linuxicons/16x16/companion.png DESTINATION /usr/share/icons/hicolor/16x16/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/22x22/companion.png DESTINATION /usr/share/icons/hicolor/22x22/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/24x24/companion.png DESTINATION /usr/share/icons/hicolor/24x24/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/32x32/companion.png DESTINATION /usr/share/icons/hicolor/32x32/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/48x48/companion.png DESTINATION /usr/share/icons/hicolor/48x48/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/128x128/companion.png DESTINATION /usr/share/icons/hicolor/128x128/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/256x256/companion.png DESTINATION /usr/share/icons/hicolor/256x256/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/512x512/companion.png DESTINATION /usr/share/icons/hicolor/512x512/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/scalable/companion.svg DESTINATION /usr/share/icons/hicolor/scalable/apps RENAME companion${C9X_NAME_SUFFIX}.svg) - install(FILES ../targets/linux/45-companion-taranis.rules DESTINATION /lib/udev/rules.d RENAME 45-companion${C9X_NAME_SUFFIX}-taranis.rules) - else() - install(FILES images/linuxicons/16x16/companion.png DESTINATION share/icons/hicolor/16x16/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/22x22/companion.png DESTINATION share/icons/hicolor/22x22/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/24x24/companion.png DESTINATION share/icons/hicolor/24x24/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/32x32/companion.png DESTINATION share/icons/hicolor/32x32/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/48x48/companion.png DESTINATION share/icons/hicolor/48x48/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/128x128/companion.png DESTINATION share/icons/hicolor/128x128/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/256x256/companion.png DESTINATION share/icons/hicolor/256x256/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/512x512/companion.png DESTINATION share/icons/hicolor/512x512/apps RENAME companion${C9X_NAME_SUFFIX}.png) - install(FILES images/linuxicons/scalable/companion.svg DESTINATION share/icons/hicolor/scalable/apps RENAME companion${C9X_NAME_SUFFIX}.svg) - install(FILES ../targets/linux/45-companion-taranis.rules DESTINATION lib/udev/rules.d RENAME 45-companion${C9X_NAME_SUFFIX}-taranis.rules) + set(INSTALL_TEMP_SHR_PFX "/usr/") + set(INSTALL_TEMP_LIB_PFX "/") endif() + install(FILES images/linuxicons/16x16/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/16x16/apps RENAME companion${C9X_NAME_SUFFIX}.png) + install(FILES images/linuxicons/22x22/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/22x22/apps RENAME companion${C9X_NAME_SUFFIX}.png) + install(FILES images/linuxicons/24x24/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/24x24/apps RENAME companion${C9X_NAME_SUFFIX}.png) + install(FILES images/linuxicons/32x32/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/32x32/apps RENAME companion${C9X_NAME_SUFFIX}.png) + install(FILES images/linuxicons/48x48/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/48x48/apps RENAME companion${C9X_NAME_SUFFIX}.png) + install(FILES images/linuxicons/128x128/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/128x128/apps RENAME companion${C9X_NAME_SUFFIX}.png) + install(FILES images/linuxicons/256x256/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/256x256/apps RENAME companion${C9X_NAME_SUFFIX}.png) + install(FILES images/linuxicons/512x512/companion.png DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/512x512/apps RENAME companion${C9X_NAME_SUFFIX}.png) + install(FILES images/linuxicons/scalable/companion.svg DESTINATION ${INSTALL_TEMP_SHR_PFX}share/icons/hicolor/scalable/apps RENAME companion${C9X_NAME_SUFFIX}.svg) + 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) # Linux specific code set(OperatingSystem "Linux") + elseif(WIN32) + get_target_property(QtCore_LOCATION Qt5::Core LOCATION) get_filename_component(QT_DLL_DIR ${QtCore_LOCATION} PATH) - get_filename_component(SDL_DIR ${SDL_LIBRARY} PATH) - 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}/$) - 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}/$) -endif() + set(INSTALL_TEMP_QTDLL_FILES Qt5Core Qt5Gui Qt5Widgets Qt5Xml Qt5Network Qt5PrintSupport Qt5Multimedia) + set(INSTALL_TEMP_ICUDLL_FILES icudt54.dll icuin54.dll icuuc54.dll) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(INSTALL_TEMP_QTDLL_SFX "d") + endif() + if(NOT WIN_DO_FULL_INSTALL) + # Just copy supporting DLLs to build folder + set(INSTALL_DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + message(STATUS "Partial install to " ${INSTALL_DESTINATION}) + else() + # Full Windows installation with all supporting files + set(INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}) + message(STATUS "Full install to " ${INSTALL_DESTINATION}) + # companion & simulator binaries + install(TARGETS ${COMPANION_NAME} DESTINATION ${INSTALL_DESTINATION}) + install(TARGETS ${SIMULATOR_NAME} DESTINATION ${INSTALL_DESTINATION}) + file(GLOB simulator_plugins "${CMAKE_BINARY_DIR}/*opentx-*-simulator${CMAKE_SHARED_LIBRARY_SUFFIX}") + install(FILES ${simulator_plugins} DESTINATION "${INSTALL_DESTINATION}") + # language files + file(GLOB language_files "${CMAKE_BINARY_DIR}/companion/src/companion_*.qm") + install(FILES ${language_files} DESTINATION "${INSTALL_DESTINATION}/lang") + # supporting utilities + set(INSTALL_TEMP_FILES avrdude.exe avrdude.conf dfu-util.exe libusb0.dll libusb-1.0.dll) + foreach(tmpfile ${INSTALL_TEMP_FILES}) + install(FILES "${COMPANION_SRC_DIRECTORY}/../targets/windows/${tmpfile}" DESTINATION ${INSTALL_DESTINATION}) + endforeach() + endif() # WIN_DO_FULL_INSTALL + + # Qt dlls + foreach(tmpfile ${INSTALL_TEMP_QTDLL_FILES}) + install(FILES ${QT_DLL_DIR}/${tmpfile}${INSTALL_TEMP_QTDLL_SFX}.dll DESTINATION ${INSTALL_DESTINATION}) + endforeach() + install(FILES ${QT_DLL_DIR}/../plugins/platforms/qwindows${INSTALL_TEMP_QTDLL_SFX}.dll DESTINATION ${INSTALL_DESTINATION}/platforms) + # ICU dlls + foreach(tmpfile ${INSTALL_TEMP_ICUDLL_FILES}) + # Qt5.7+ doesn't use icu dlls anymore (at least with MinGW), hence optional + install(FILES ${QT_DLL_DIR}/${tmpfile}.dll DESTINATION ${INSTALL_DESTINATION} OPTIONAL) + endforeach() + # SDL dll + if(SDL_FOUND AND SDL_LIBRARY_PATH AND EXISTS "${SDL_LIBRARY_PATH}/SDL.dll") + set(SDL_DIR ${SDL_LIBRARY_PATH}) # this is also used by NSIS installer script + install(FILES ${SDL_DIR}/SDL.dll DESTINATION ${INSTALL_DESTINATION}) + else() + message(WARNING "Installer: SDL.dll not found!") + endif() + # C++/system dlls, depends on compiler + if(MSVC) + set(WIN_SYSDIR "$ENV{windir}/SysWOW64") # This would be "system32" for a 64-bit build or on x86... but how to tell? + if(IS_DIRECTORY ${WIN_SYSDIR}) + install(FILES ${WIN_SYSDIR}/msvcp140.dll ${WIN_SYSDIR}/vcruntime140.dll DESTINATION ${INSTALL_DESTINATION} OPTIONAL) + endif() + install(FILES "${WIN_PTHREAD_BASE_PATH}/lib/pthreadVC2.dll" DESTINATION ${INSTALL_DESTINATION}) + elseif(MINGW) + get_filename_component(MINGW_DIR ${CMAKE_CXX_COMPILER} PATH) + if(IS_DIRECTORY ${MINGW_DIR}) + install(FILES ${MINGW_DIR}/libgcc_s_dw2-1.dll ${MINGW_DIR}/libstdc++-6.dll ${MINGW_DIR}/libwinpthread-1.dll DESTINATION ${INSTALL_DESTINATION}) + set(MINGW_DIR "${MINGW_DIR}/../opt/bin") + # SSL support + install(FILES ${MINGW_DIR}/libeay32.dll ${MINGW_DIR}/ssleay32.dll DESTINATION ${INSTALL_DESTINATION} OPTIONAL) + endif() + endif() + +endif() # WIN32 install + +############# Packaging #################### + +# Create Windows installer with NSIS (only works for MSVC for now) if(WIN32) if(MSVC) set(COMPANION_NSI_IN_FILE companion-vs.nsi.in) @@ -359,9 +432,8 @@ string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE) # very poor trace-backs from the users when they report Companion crash set(CPACK_STRIP_FILES FALSE) -set(plugin_dest_dir bin) -set(qtconf_dest_dir bin) -set(APPS "\${CMAKE_INSTALL_PREFIX}/bin/${COMPANION_NAME}") +# Qt5 + Cmake + Mac is poorly documented. A lot of this is guesswork +# and trial and error. Do not hesitate to fix it for the better IF(APPLE) set(plugin_dest_dir ${COMPANION_NAME}.app/Contents/Plugins) set(qtconf_dest_dir ${COMPANION_NAME}.app/Contents/Resources) @@ -373,21 +445,11 @@ IF(APPLE) # Use a non standard Info.plist that adds Retina support flags set_target_properties(${COMPANION_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/companion/targets/mac/MacOSXBundleInfo.plist.in) set_target_properties(${SIMULATOR_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/companion/targets/mac/MacOSXBundleInfo.plist.in) -ENDIF(APPLE) -IF(WIN32) - set(APPS "\${CMAKE_INSTALL_PREFIX}/bin/QtTest.exe") -ENDIF(WIN32) - -INSTALL(TARGETS ${COMPANION_NAME} - BUNDLE DESTINATION . COMPONENT Runtime - RUNTIME DESTINATION bin COMPONENT Runtime - ) - -# Qt5 + Cmake + Mac is poorly documented. A lot of this is guesswork -# and trial and error. Do not hesitate to fix it for the better -if(APPLE) - set(APPS "\${CMAKE_INSTALL_PREFIX}/${COMPANION_NAME}.app") + INSTALL(TARGETS ${COMPANION_NAME} + BUNDLE DESTINATION . COMPONENT Runtime + RUNTIME DESTINATION bin COMPONENT Runtime + ) file(GLOB simulator_plugins "${CMAKE_BINARY_DIR}/libopentx-*${CMAKE_SHARED_LIBRARY_SUFFIX}") set(companion_res_dir ${COMPANION_NAME}.app/Contents/Resources) @@ -396,7 +458,7 @@ if(APPLE) # Write qt.conf to tell qt where to find it plugins file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" "[Paths]\nPlugins = Plugins\n") - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" DESTINATION "${companion_res_dir}" COMPONENT Runtime) diff --git a/companion/src/burnconfigdialog.cpp b/companion/src/burnconfigdialog.cpp index 3590a3756..2f93c3ae7 100644 --- a/companion/src/burnconfigdialog.cpp +++ b/companion/src/burnconfigdialog.cpp @@ -26,7 +26,7 @@ #include "progressdialog.h" #include "process_flash.h" -#if !defined WIN32 && defined __GNUC__ +#if !defined _MSC_VER && defined __GNUC__ #include #endif diff --git a/companion/src/companion.cpp b/companion/src/companion.cpp index db9aa9438..433fc059a 100644 --- a/companion/src/companion.cpp +++ b/companion/src/companion.cpp @@ -36,7 +36,7 @@ #include "eeprominterface.h" #include "appdata.h" -#if defined WIN32 || !defined __GNUC__ +#if defined _MSC_VER || !defined __GNUC__ #include #define sleep(x) Sleep(x*1000) #else diff --git a/companion/src/comparedialog.cpp b/companion/src/comparedialog.cpp index 85ee904ba..12e154572 100644 --- a/companion/src/comparedialog.cpp +++ b/companion/src/comparedialog.cpp @@ -24,10 +24,6 @@ #include #include -// #if !defined WIN32 && defined __GNUC__ -// #include -// #endif - class DragDropHeader { public: DragDropHeader(): diff --git a/companion/src/flashfirmwaredialog.cpp b/companion/src/flashfirmwaredialog.cpp index cf70061f8..4779aa68f 100644 --- a/companion/src/flashfirmwaredialog.cpp +++ b/companion/src/flashfirmwaredialog.cpp @@ -32,7 +32,7 @@ #include "progresswidget.h" #include "splashlibrarydialog.h" -#if defined WIN32 || !defined __GNUC__ +#if defined _MSC_VER || !defined __GNUC__ #include #define sleep(x) Sleep(x*1000) #else diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 7908afd35..1ad8aee35 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -19,13 +19,16 @@ */ #include -#if defined WIN32 +#if defined _MSC_VER #include #include -#endif -#if !defined WIN32 && defined __GNUC__ +#elif defined __GNUC__ #include #endif +#if defined(WIN32) && defined(WIN_USE_CONSOLE_STDIO) + #include "windows.h" +#endif + #include "appdata.h" #include "helpers.h" #include "simulatordialog.h" @@ -809,6 +812,12 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx) Firmware * firmware = GetCurrentFirmware(); SimulatorInterface * simulator = GetCurrentFirmwareSimulator(); if (simulator) { +#if defined(WIN32) && defined(WIN_USE_CONSOLE_STDIO) + AllocConsole(); + freopen("conin$", "r", stdin); + freopen("conout$", "w", stdout); + freopen("conout$", "w", stderr); +#endif RadioData * simuData = new RadioData(radioData); unsigned int flags = 0; if (modelIdx >= 0) { @@ -854,6 +863,9 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx) } dialog->exec(); +#if defined(WIN32) && defined(WIN_USE_CONSOLE_STDIO) + FreeConsole(); +#endif delete dialog; delete simuData; } diff --git a/companion/src/logsdialog.cpp b/companion/src/logsdialog.cpp index e87478779..0830a32e4 100644 --- a/companion/src/logsdialog.cpp +++ b/companion/src/logsdialog.cpp @@ -23,7 +23,7 @@ #include "appdata.h" #include "ui_logsdialog.h" #include "helpers.h" -#if defined WIN32 || !defined __GNUC__ +#if defined _MSC_VER || !defined __GNUC__ #include #else #include diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index be5621654..5cc3c9d60 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -61,12 +61,15 @@ #define COMPANION_INSTALLER "companion-windows-%1.exe" #endif -#if defined WIN32 || !defined __GNUC__ +#if defined _MSC_VER || !defined __GNUC__ #include #define sleep(x) Sleep(x*1000) - #define OPENTX_NIGHT_COMPANION_DOWNLOADS "http://downloads-22.open-tx.org/nightly/companion/windows" #else #include +#endif +#ifdef WIN32 + #define OPENTX_NIGHT_COMPANION_DOWNLOADS "http://downloads-22.open-tx.org/nightly/companion/windows" +#else #define OPENTX_NIGHT_COMPANION_DOWNLOADS "http://downloads-22.open-tx.org/nightly/companion/linux" #endif diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index ac45c4e4e..1e16fb00d 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -34,7 +34,7 @@ #include "flashfirmwaredialog.h" #include "storage_eeprom.h" -#if defined WIN32 || !defined __GNUC__ +#if defined _MSC_VER || !defined __GNUC__ #include #define sleep(x) Sleep(x*1000) #else diff --git a/companion/src/printdialog.cpp b/companion/src/printdialog.cpp index 8d846f1b8..5f6746f4f 100644 --- a/companion/src/printdialog.cpp +++ b/companion/src/printdialog.cpp @@ -24,10 +24,6 @@ #include #include -// #if !defined WIN32 && defined __GNUC__ -// #include -// #endif - PrintDialog::PrintDialog(QWidget *parent, Firmware * firmware, GeneralSettings & generalSettings, ModelData & model, const QString & filename) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), firmware(firmware), diff --git a/companion/src/process_flash.cpp b/companion/src/process_flash.cpp index 424b24eb0..a0b201a3f 100644 --- a/companion/src/process_flash.cpp +++ b/companion/src/process_flash.cpp @@ -26,7 +26,7 @@ #include "eeprominterface.h" //#include "firmwareinterface.h" -#if defined WIN32 || !defined __GNUC__ +#if defined _MSC_VER || !defined __GNUC__ #include #include #include diff --git a/companion/src/simulation/simulatorinterface.cpp b/companion/src/simulation/simulatorinterface.cpp index b235d288d..4358ce5ad 100644 --- a/companion/src/simulation/simulatorinterface.cpp +++ b/companion/src/simulation/simulatorinterface.cpp @@ -26,7 +26,7 @@ #include #include #include "version.h" -#if defined WIN32 || !defined __GNUC__ +#if defined _MSC_VER || !defined __GNUC__ #include #endif @@ -59,7 +59,7 @@ void registerSimulators() QStringList filters; #if defined(__APPLE__) filters << "*-simulator.dylib"; -#elif (!defined __GNUC__) || (defined __CYGWIN__) +#elif defined(WIN32) || defined(__CYGWIN__) filters << "*-simulator.dll"; #else filters << "*-simulator.so"; diff --git a/companion/src/simulator.cpp b/companion/src/simulator.cpp index 9ed9438ba..c69938ffb 100644 --- a/companion/src/simulator.cpp +++ b/companion/src/simulator.cpp @@ -37,10 +37,13 @@ #include "appdata.h" #include "qxtcommandoptions.h" -#if defined WIN32 || !defined __GNUC__ -#include -#define sleep(x) Sleep(x*1000) -#else +#ifdef WIN32 + #include + #ifdef _MSC_VER + #define sleep(x) Sleep(x*1000) + #endif +#endif +#if !defined(_MSC_VER) || defined(__GNUC__) #include #endif @@ -59,7 +62,6 @@ class MyProxyStyle : public QProxyStyle }; #endif - void showMessage(const QString & message, enum QMessageBox::Icon icon = QMessageBox::NoIcon) { QMessageBox msgBox; msgBox.setText(message); @@ -73,6 +75,12 @@ int main(int argc, char *argv[]) #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif +#if defined(WIN32) && defined(WIN_USE_CONSOLE_STDIO) + AllocConsole(); + freopen("conin$", "r", stdin); + freopen("conout$", "w", stdout); + freopen("conout$", "w", stderr); +#endif QApplication app(argc, argv); app.setApplicationName("OpenTX Simulator"); @@ -229,6 +237,9 @@ int main(int argc, char *argv[]) #if defined(JOYSTICKS) || defined(SIMU_AUDIO) SDL_Quit(); #endif +#if defined(WIN32) && defined(WIN_USE_CONSOLE_STDIO) + FreeConsole(); +#endif return result; } diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index e325a9154..0b7e53351 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -21,12 +21,22 @@ option(JITTER_MEASURE "Enable ADC jitter measurement" OFF) option(WATCHDOG_DISABLED "Disable hardware Watchdog" OFF) option(SIMU_AUDIO "Enable simulator audio" OFF) option(SIMU_DISKIO "Enable disk IO simulation in simulator. Simulator will use FatFs module and simulated IO layer that uses \"./sdcard.image\" file as image of SD card. This file must contain whole SD card from first to last sector" OFF) +option(SIMU_LUA_COMPILER "Pre-compile and save Lua scripts in simulator." ON) option(FAS_PROTOTYPE "Support of old FAS prototypes (different resistors)" OFF) option(TEMPLATES "Model templates menu" OFF) option(WARNINGS_AS_ERRORS "Treat all compiler warnings as error" OFF) option(TRACE_SIMPGMSPACE "Turn on traces in simpgmspace.cpp" ON) set(DEFAULT_MODE "" CACHE STRING "Default sticks mode") +# Python check +find_package("PythonInterp") +if(PYTHONINTERP_FOUND) + message(STATUS "Python found, version: ${PYTHON_VERSION_STRING}") +else() + message(WARNING "Python not found! Most firmware and simu flavors not buildable.") + set(LUA OFF) +endif() + enable_language(ASM) set(OPT s) @@ -336,7 +346,7 @@ endforeach() add_definitions(-DCORRECT_NEGATIVE_SHIFTS) -if(NOT WIN32) +if(NOT MSVC) add_definitions(-Wall -Wno-strict-aliasing -Wformat -Wreturn-type -Wunused -Wuninitialized -Wunknown-pragmas -Wno-switch -Wtype-limits) if(WARNINGS_AS_ERRORS) set(WARNING_FLAGS -Werror) diff --git a/radio/src/definitions.h b/radio/src/definitions.h index d18ebbd84..9aec93a27 100644 --- a/radio/src/definitions.h +++ b/radio/src/definitions.h @@ -73,10 +73,4 @@ typedef __int24 int24_t; #define CONVERT_UINT_PTR(x) ((uint32_t *)(x)) #endif -#if defined(WIN32) -#define round(x) floor(x+0.5) -#define strcasecmp _stricmp -#define strncasecmp _tcsnicmp -#endif - #endif // _DEFINITIONS_H_ diff --git a/radio/src/lua/CMakeLists.txt b/radio/src/lua/CMakeLists.txt index fffc3629f..7ec17a77a 100644 --- a/radio/src/lua/CMakeLists.txt +++ b/radio/src/lua/CMakeLists.txt @@ -1,15 +1,14 @@ -if(MSVC) - set(INTTYPES_INCLUDE_OPTION -IC:/Programs/msinttypes) -endif() macro(add_lua_export_target target) - add_custom_command( - OUTPUT lua_exports_${target}.inc - COMMAND ${CMAKE_C_COMPILER} -E ${ARGN} -DEXPORT ${INTTYPES_INCLUDE_OPTION} ${RADIO_SRC_DIRECTORY}/dataconstants.h > lua_exports_${target}.tmp - COMMAND grep LEXP lua_exports_${target}.tmp > lua_exports_${target}.txt - COMMAND rm lua_exports_${target}.tmp - COMMAND python ${RADIO_DIRECTORY}/util/luaexport.py ${VERSION} lua_exports_${target}.txt lua_exports_${target}.inc lua_fields_${target}.txt - ) + if(PYTHONINTERP_FOUND) + add_custom_command( + OUTPUT lua_exports_${target}.inc + COMMAND ${CMAKE_C_COMPILER} -E ${ARGN} -DEXPORT ${RADIO_SRC_DIRECTORY}/dataconstants.h > lua_exports_${target}.tmp + COMMAND grep LEXP lua_exports_${target}.tmp > lua_exports_${target}.txt + COMMAND rm lua_exports_${target}.tmp + COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/luaexport.py ${VERSION} lua_exports_${target}.txt lua_exports_${target}.inc lua_fields_${target}.txt + ) + endif() add_custom_target(lua_export_${target} DEPENDS lua_exports_${target}.inc) endmacro(add_lua_export_target) @@ -26,6 +25,12 @@ set(LUA_INCLUDES -I${RADIO_SRC_DIRECTORY}/${STM32USB_DIR}/STM32_USB_Device_Library/Class/hid/inc ) +if(WIN32 AND WIN_INCLUDE_DIRS) + foreach(include ${WIN_INCLUDE_DIRS}) + set(LUA_INCLUDES "${LUA_INCLUDES} -I${include}") + endforeach() +endif() + set(LUA_INCLUDES_STM32F2 ${LUA_INCLUDES} -DSTM32F2 diff --git a/radio/src/targets/common/arm/CMakeLists.txt b/radio/src/targets/common/arm/CMakeLists.txt index 7d2e25061..25d20d956 100644 --- a/radio/src/targets/common/arm/CMakeLists.txt +++ b/radio/src/targets/common/arm/CMakeLists.txt @@ -1,4 +1,4 @@ -option(TIMERS "Timers count" 3) +set(TIMERS 3 CACHE STRING "Timers count (2 or 3)") option(CLI "Command Line Interface" OFF) option(DEBUG "Debug mode" OFF) option(LOG_TELEMETRY "Telemetry Logs on SD card" OFF) diff --git a/radio/src/targets/simu/CMakeLists.txt b/radio/src/targets/simu/CMakeLists.txt index 3984229d0..3d49e4b85 100644 --- a/radio/src/targets/simu/CMakeLists.txt +++ b/radio/src/targets/simu/CMakeLists.txt @@ -9,27 +9,23 @@ set(SIMU_SRC ) add_definitions(-DSIMU) -add_definitions(-DLUA_COMPILER) remove_definitions(-DCLI) if(SDL_FOUND) include_directories(${SDL_INCLUDE_DIR}) - add_definitions(-DSIMU_AUDIO) add_definitions(-DJOYSTICKS) +else() + remove_definitions(-DSIMU_AUDIO) +endif() + +if(SIMU_LUA_COMPILER) + add_definitions(-DLUA_COMPILER) endif() if(Qt5Widgets_FOUND) set(SIMULATOR_FLAVOUR opentx-${FLAVOUR}) set(SIMULATOR_TARGET ${SIMULATOR_FLAVOUR}-simulator) add_definitions(-DSIMULATOR_FLAVOUR="${SIMULATOR_FLAVOUR}") - - if (${CMAKE_VERSION} VERSION_LESS 3.1.0}) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -std=gnu++11") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=gnu++11") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=gnu++11") - endif() - include_directories(${COMPANION_SRC_DIRECTORY} ${COMPANION_SRC_DIRECTORY}/simulation) add_library(${SIMULATOR_TARGET} SHARED ${SIMU_SRC} opentxsimulator.cpp) add_dependencies(${SIMULATOR_TARGET} ${FIRMWARE_DEPENDENCIES}) @@ -38,19 +34,26 @@ if(Qt5Widgets_FOUND) add_custom_target(libsimulator DEPENDS ${SIMULATOR_TARGET}) endif() +if(WIN32) + include_directories(SYSTEM ${WIN_INCLUDE_DIRS}) + target_link_libraries(${SIMULATOR_TARGET} PRIVATE ${WIN_LINK_LIBRARIES}) +endif(WIN32) + if(MSVC) set(CMAKE_CXX_FLAGS "/EHsc /LD /MP") - include_directories(${PROJECT_SOURCE_DIR}/winbuild C:/Programs/pthreads/Pre-built.2/include C:/Programs/msinttypes C:/Programs/dirent/include) - target_link_libraries(${SIMULATOR_TARGET} PRIVATE C:/Programs/pthreads/Pre-built.2/lib/pthreadVC2.lib) + message("simu: using MSVC with ${CMAKE_CXX_FLAGS}") else() if (${CMAKE_VERSION} VERSION_LESS 3.1.0}) - set(COMMON_CPP_FLAGS "${COMMON_FLAGS} -std=gnu++11") - message("USING -std=gnu++11") - else() - set(COMMON_CPP_FLAGS ${COMMON_FLAGS}) + message("simu: adding -std=gnu++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") endif() - set(CMAKE_C_FLAGS_DEBUG "${COMMON_FLAGS} -g -O0") - set(CMAKE_CXX_FLAGS_DEBUG "${COMMON_CPP_FLAGS} -g -O0") + if(MINGW) + # 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 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-ms-bitfields -mwindows") + message("simu: using MinGW with ${CMAKE_CXX_FLAGS}") + endif() + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") endif() if((NOT WIN32) AND FOX_FOUND) diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index 0c98ac870..89b4d1841 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -34,7 +34,6 @@ #if defined(SIMU_AUDIO) && defined(CPUARM) #include - #undef main #endif #if defined(TRACE_SIMPGMSPACE) @@ -939,11 +938,7 @@ FRESULT f_getcwd (TCHAR *path, UINT sz_path) } // remove simuSdDirectory from the cwd -#ifdef _MSC_VER - strcpy(path, cwd + sdlen + 2); // account for drive name -#else strcpy(path, cwd + sdlen); -#endif if (path[0] == '\0') { strcpy(path, "/"); // fix for the root directory diff --git a/radio/src/targets/taranis/bootloader/CMakeLists.txt b/radio/src/targets/taranis/bootloader/CMakeLists.txt index 32f0945ee..43851a3f8 100644 --- a/radio/src/targets/taranis/bootloader/CMakeLists.txt +++ b/radio/src/targets/taranis/bootloader/CMakeLists.txt @@ -69,9 +69,10 @@ set(CMAKE_EXE_LINKER_FLAGS "-mcpu=${MCU} -mthumb -nostartfiles -lm -T${RADIO_SRC add_executable(bootloader ${BOOTLOADER_SRC}) add_dependencies(bootloader ${BITMAPS_TARGET} firmware_translations) -add_custom_command( - TARGET bootloader POST_BUILD - COMMAND arm-none-eabi-objcopy -O binary bootloader.elf bootloader.bin - COMMAND python ${RADIO_DIRECTORY}/util/bin2lbm.py bootloader.bin bootloader.lbm -) - +if(PYTHONINTERP_FOUND) + add_custom_command( + TARGET bootloader POST_BUILD + COMMAND arm-none-eabi-objcopy -O binary bootloader.elf bootloader.bin + COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/bin2lbm.py bootloader.bin bootloader.lbm + ) +endif() diff --git a/radio/src/translations/CMakeLists.txt b/radio/src/translations/CMakeLists.txt index 79f5aa15e..5736578d6 100644 --- a/radio/src/translations/CMakeLists.txt +++ b/radio/src/translations/CMakeLists.txt @@ -6,11 +6,13 @@ foreach(translation ${translations}) if(NOT(PCB STREQUAL HORUS) AND language STREQUAL "cz") set(language cz_reduced) endif() - add_custom_command( - OUTPUT ${target} - COMMAND python ${RADIO_DIRECTORY}/util/translate.py ${translation} ${target} ${language} - DEPENDS ${translation} - ) + if(PYTHONINTERP_FOUND) + add_custom_command( + OUTPUT ${target} + COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/translate.py ${translation} ${target} ${language} + DEPENDS ${translation} + ) + endif() list(APPEND translations_files ${target}) endforeach()