5 set(VERSION_REVISION "0")
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 "0008")
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 set(CMAKE_COLOR_MAKEFILE ON)
27 set(CMAKE_CXX_STANDARD 11)
29 set(RADIO_DIRECTORY ${PROJECT_SOURCE_DIR}/radio)
30 set(RADIO_SRC_DIRECTORY ${RADIO_DIRECTORY}/src)
31 set(COMPANION_SRC_DIRECTORY ${PROJECT_SOURCE_DIR}/companion/src)
32 set(SIMU_SRC_DIRECTORY ${COMPANION_SRC_DIRECTORY}/simulation)
34 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
35 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
36 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
43 message(STATUS "OpenTX ${VERSION} @${GIT_STR}")
45 # options shared by all targets
47 option(APP_CUSTOM_DBG_HANDLER "Use custom message handler for debug output in all Qt apps." ON)
48 set(APP_CUSTOM_DBG_LEVEL "0" CACHE STRING
49 "Debug output level: 0=debug+; 1=info+; 2=warn+; 3=critical+; 4=fatal only.")
50 set(APP_CUSTOM_DBG_SHOW_FILE "DEFAULT" CACHE STRING
51 "Show source file names in debug output. 1/0/DEFAULT (default is ON with DEBUG builds).")
53 option(VERBOSE_CMAKELISTS "Show extra information while processing CMakeLists.txt files." OFF)
54 option(WARNINGS_AS_ERRORS "Treat any compiler warning as an error (adds -Werror flag)." OFF)
57 set(WIN_EXTRA_LIBS_PATH "C:/Programs" CACHE PATH
58 "Base path to extra libs/headers on Windows (SDL & pthreads folders should be in here).")
59 list(APPEND CMAKE_PREFIX_PATH "${WIN_EXTRA_LIBS_PATH}" "${WIN_EXTRA_LIBS_PATH}/SDL") # hints for FindSDL
62 find_package(Qt5Widgets)
64 find_package(Qt5LinguistTools)
65 find_package(Qt5PrintSupport)
66 find_package(Qt5Multimedia)
70 message(STATUS "Qt Version: ${Qt5Widgets_VERSION}")
71 list(APPEND APP_COMMON_DEFINES -DSIMU)
72 list(APPEND APP_COMMON_DEFINES -DQXT_STATIC)
73 list(APPEND APP_COMMON_DEFINES -DQT_USE_QSTRINGBUILDER) # more efficient QString construction using % operator
74 if(APP_CUSTOM_DBG_HANDLER)
75 # provide full qDebug log context to our custom handler. This may also affect libsimulator, which is why it is here
76 list(APPEND APP_COMMON_DEFINES -DQT_MESSAGELOGCONTEXT)
77 list(APPEND APP_COMMON_DEFINES -DAPP_DBG_HANDLER_ENABLE=1)
78 if(APP_CUSTOM_DBG_LEVEL GREATER -1 AND APP_CUSTOM_DBG_LEVEL LESS 5)
79 list(APPEND APP_COMMON_DEFINES -DAPP_DBG_HANDLER_DEFAULT_LEVEL=${APP_CUSTOM_DBG_LEVEL})
81 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"))
82 list(APPEND APP_COMMON_DEFINES -DAPP_DBG_HANDLER_SHOW_SRC_PATH=${APP_CUSTOM_DBG_SHOW_FILE})
85 list(APPEND APP_COMMON_DEFINES -DAPP_DBG_HANDLER_ENABLE=0)
88 message(WARNING "Qt not found! Companion and Simulator builds disabled.")
92 find_package(Fox QUIET) # QUIET not working on WIN32?
94 message(STATUS "Foxlib found at ${FOX_LIBRARY}")
95 else() # if(NOT WIN32)
96 message("Libfox not found, simu target will not be available")
100 if(Qt5Widgets_FOUND OR FOX_FOUND)
101 set(SDL_BUILDING_LIBRARY YES) # this prevents FindSDL from appending SDLmain lib to the results, which we don't want
104 message(STATUS "SDL Lib: ${SDL_LIBRARY}; Headers: ${SDL_INCLUDE_DIR}; Version: ${SDL_VERSION_STRING}")
106 message(STATUS "SDL not found! Simulator audio, and joystick inputs, will not work.")
110 # Check for a file that is typically left from a OpenTX 2.1 build and abort if found
111 if (EXISTS ${RADIO_SRC_DIRECTORY}/stamp.h OR EXISTS ${RADIO_SRC_DIRECTORY}/translations/en.h)
112 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")
115 # Windows-specific includes and libs shared by sub-projects
117 list(APPEND WIN_INCLUDE_DIRS "${RADIO_SRC_DIRECTORY}/thirdparty/windows/dirent")
119 list(APPEND WIN_INCLUDE_DIRS "${RADIO_SRC_DIRECTORY}/thirdparty/windows/msinttypes")
120 set(WIN_PTHREAD_BASE_PATH "${WIN_EXTRA_LIBS_PATH}/pthreads/Pre-built.2" CACHE PATH "Where to find pthreads include and lib folders.")
121 list(APPEND WIN_INCLUDE_DIRS "${WIN_PTHREAD_BASE_PATH}/include")
122 find_file(WIN_PTHREAD_LIB pthreadVC2.lib PATHS "${WIN_PTHREAD_BASE_PATH}" PATH_SUFFIXES lib/x86 lib NO_DEFAULT_PATH)
123 find_file(WIN_PTHREAD_DLL pthreadVC2.dll PATHS "${WIN_PTHREAD_BASE_PATH}" PATH_SUFFIXES lib/x86 lib dll/x86 dll NO_DEFAULT_PATH)
125 list(APPEND WIN_LINK_LIBRARIES "${WIN_PTHREAD_LIB}")
127 message(SEND_ERROR "pthreadVC2.lib not found!")
130 set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
131 set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES OFF)
132 set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
133 set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES OFF)
137 add_subdirectory(${RADIO_SRC_DIRECTORY})
140 add_subdirectory(${COMPANION_SRC_DIRECTORY})