5 set(VERSION_REVISION "2")
6 set(VERSION_SUFFIX $ENV{OPENTX_VERSION_SUFFIX})
7 set(VERSION_FAMILY ${VERSION_MAJOR}.${VERSION_MINOR})
8 set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}${VERSION_SUFFIX})
9 set(SDCARD_REVISION "0016")
10 set(SDCARD_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}V${SDCARD_REVISION})
12 cmake_minimum_required(VERSION 2.8)
13 cmake_policy(SET CMP0020 NEW)
14 cmake_policy(SET CMP0023 OLD)
16 cmake_policy(SET CMP0042 NEW)
19 cmake_policy(SET CMP0043 NEW)
22 cmake_policy(SET CMP0054 NEW)
25 cmake_policy(SET CMP0058 NEW) # for ninja
28 set(CMAKE_COLOR_MAKEFILE ON)
30 set(CMAKE_CXX_STANDARD 11)
32 set(RADIO_DIRECTORY ${PROJECT_SOURCE_DIR}/radio)
33 set(RADIO_SRC_DIRECTORY ${RADIO_DIRECTORY}/src)
34 set(COMPANION_SRC_DIRECTORY ${PROJECT_SOURCE_DIR}/companion/src)
35 set(SIMU_SRC_DIRECTORY ${COMPANION_SRC_DIRECTORY}/simulation)
37 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
38 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
39 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
46 message(STATUS "OpenTX ${VERSION} @${GIT_STR}")
48 # options shared by all targets
50 option(APP_CUSTOM_DBG_HANDLER "Use custom message handler for debug output in all Qt apps." ON)
51 set(APP_CUSTOM_DBG_LEVEL "0" CACHE STRING
52 "Debug output level: 0=debug+; 1=info+; 2=warn+; 3=critical+; 4=fatal only.")
53 set(APP_CUSTOM_DBG_SHOW_FILE "DEFAULT" CACHE STRING
54 "Show source file names in debug output. 1/0/DEFAULT (default is ON with DEBUG builds).")
56 option(VERBOSE_CMAKELISTS "Show extra information while processing CMakeLists.txt files." OFF)
57 option(WARNINGS_AS_ERRORS "Treat any compiler warning as an error (adds -Werror flag)." OFF)
60 set(WIN_EXTRA_LIBS_PATH "C:/Programs" CACHE PATH
61 "Base path to extra libs/headers on Windows (SDL & pthreads folders should be in here).")
62 list(APPEND CMAKE_PREFIX_PATH "${WIN_EXTRA_LIBS_PATH}" "${WIN_EXTRA_LIBS_PATH}/SDL") # hints for FindSDL
66 find_package("PythonInterp")
67 if(PYTHONINTERP_FOUND)
68 message(STATUS "Python found, version: ${PYTHON_VERSION_STRING}")
69 get_filename_component(PYTHON_DIRECTORY ${PYTHON_EXECUTABLE} DIRECTORY)
71 message(WARNING "Python not found! Most firmware and simu flavors not buildable.")
75 option(DISABLE_COMPANION "Disable building companion and simulators" OFF)
77 if(NOT DISABLE_COMPANION)
79 find_package(Qt5Widgets)
81 find_package(Qt5LinguistTools)
82 find_package(Qt5PrintSupport)
83 find_package(Qt5Multimedia)
87 message(STATUS "Qt Version: ${Qt5Core_VERSION}")
89 ### Get locations of Qt binary executables & libs (libs are for distros, not for linking)
90 # first set up some hints
91 get_target_property(QtCore_LOCATION Qt5::Core LOCATION)
92 get_filename_component(qt_core_path ${QtCore_LOCATION} PATH)
94 get_filename_component(qt_core_path "${qt_core_path}/.." ABSOLUTE)
97 set(QT_LIB_DIR ${qt_core_path} CACHE PATH "Path to Qt libraries (.dll|.framework|.so).")
98 find_path(QT_BIN_DIR NAMES "qmake" "qmake.exe" HINTS "${CMAKE_PREFIX_PATH}/bin" "${qt_core_path}/../bin" "${qt_core_path}" DOC "Path to Qt binaries (qmake, lupdate, etc.).")
99 find_program(QT_QMAKE_EXECUTABLE qmake HINTS "${QT_BIN_DIR}" DOC "Location of qmake program.")
100 find_program(QT_LUPDATE_EXECUTABLE lupdate HINTS "${QT_BIN_DIR}" DOC "Location of Qt's 'lupdate' program for updating translation files.")
102 # Try to find Qt translations
103 if(QT_QMAKE_EXECUTABLE)
105 COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_TRANSLATIONS
106 OUTPUT_VARIABLE qt_translations_hint
107 OUTPUT_STRIP_TRAILING_WHITESPACE
110 find_path(QT_TRANSLATIONS_DIR NAMES "qt_en.qm" HINTS "${qt_translations_hint}" DOC "Path to prebuilt Qt translations (qt_*.qm).")
112 ### Common definitions for the Qt-based apps
113 list(APPEND APP_COMMON_DEFINES -DSIMU)
114 list(APPEND APP_COMMON_DEFINES -DQXT_STATIC)
115 list(APPEND APP_COMMON_DEFINES -DQT_USE_QSTRINGBUILDER) # more efficient QString construction using % operator
117 if(APP_CUSTOM_DBG_HANDLER)
118 # provide full qDebug log context to our custom handler. This may also affect libsimulator, which is why it is here
119 list(APPEND APP_COMMON_DEFINES -DQT_MESSAGELOGCONTEXT)
120 list(APPEND APP_COMMON_DEFINES -DAPP_DBG_HANDLER_ENABLE=1)
121 if(APP_CUSTOM_DBG_LEVEL GREATER -1 AND APP_CUSTOM_DBG_LEVEL LESS 5)
122 list(APPEND APP_COMMON_DEFINES -DAPP_DBG_HANDLER_DEFAULT_LEVEL=${APP_CUSTOM_DBG_LEVEL})
124 if(NOT APP_CUSTOM_DBG_SHOW_FILE STREQUAL "DEFAULT" AND (APP_CUSTOM_DBG_SHOW_FILE STREQUAL "1" OR APP_CUSTOM_DBG_SHOW_FILE STREQUAL "0"))
125 list(APPEND APP_COMMON_DEFINES -DAPP_DBG_HANDLER_SHOW_SRC_PATH=${APP_CUSTOM_DBG_SHOW_FILE})
128 list(APPEND APP_COMMON_DEFINES -DAPP_DBG_HANDLER_ENABLE=0)
132 message(WARNING "Qt not found! Companion and Simulator builds disabled.")
136 find_package(Fox QUIET) # QUIET not working on WIN32?
138 message(STATUS "Foxlib found at ${FOX_LIBRARY}")
139 else() # if(NOT WIN32)
140 message("Libfox not found, simu target will not be available")
144 if(Qt5Core_FOUND OR FOX_FOUND)
145 set(SDL_BUILDING_LIBRARY YES) # this prevents FindSDL from appending SDLmain lib to the results, which we don't want
148 message(STATUS "SDL Lib: ${SDL_LIBRARY}; Headers: ${SDL_INCLUDE_DIR}; Version: ${SDL_VERSION_STRING}")
149 if (NOT ${SDL_VERSION_STRING} VERSION_LESS "2.0")
150 message(FATAL_ERROR "OpenTX requires SDL 1.x, not 2.x")
153 message(STATUS "SDL not found! Simulator audio, and joystick inputs, will not work.")
158 # Check for a file that is typically left from a OpenTX 2.1 build and abort if found
159 if (EXISTS ${RADIO_SRC_DIRECTORY}/stamp.h OR EXISTS ${RADIO_SRC_DIRECTORY}/translations/en.h)
160 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")
163 # Windows-specific includes and libs shared by sub-projects
165 list(APPEND WIN_INCLUDE_DIRS "${RADIO_SRC_DIRECTORY}/thirdparty/windows/dirent")
167 list(APPEND WIN_INCLUDE_DIRS "${RADIO_SRC_DIRECTORY}/thirdparty/windows/msinttypes")
168 set(WIN_PTHREAD_BASE_PATH "${WIN_EXTRA_LIBS_PATH}/pthreads/Pre-built.2" CACHE PATH "Where to find pthreads include and lib folders.")
169 list(APPEND WIN_INCLUDE_DIRS "${WIN_PTHREAD_BASE_PATH}/include")
170 find_file(WIN_PTHREAD_LIB pthreadVC2.lib PATHS "${WIN_PTHREAD_BASE_PATH}" PATH_SUFFIXES lib/x86 lib NO_DEFAULT_PATH)
171 find_file(WIN_PTHREAD_DLL pthreadVC2.dll PATHS "${WIN_PTHREAD_BASE_PATH}" PATH_SUFFIXES lib/x86 lib dll/x86 dll NO_DEFAULT_PATH)
173 list(APPEND WIN_LINK_LIBRARIES "${WIN_PTHREAD_LIB}")
175 message(SEND_ERROR "pthreadVC2.lib not found!")
178 set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
179 set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES OFF)
180 set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
181 set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES OFF)
185 add_subdirectory(${RADIO_SRC_DIRECTORY})
187 if(Qt5Core_FOUND AND NOT DISABLE_COMPANION)
188 add_subdirectory(${COMPANION_SRC_DIRECTORY})