Bsongis/horus flash external device (#4446)
[opentx.git] / CMakeLists.txt
blob119c598f72aedc41b6a930f1d4606e51908c8325
1 project(OpenTX)
3 set(VERSION_MAJOR "2")
4 set(VERSION_MINOR "2")
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 "0006")
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)
15 if(POLICY CMP0042)
16   cmake_policy(SET CMP0042 NEW)
17 endif()
18 if(POLICY CMP0043)
19   cmake_policy(SET CMP0043 NEW)
20 endif()
21 if(POLICY CMP0054)
22   cmake_policy(SET CMP0054 NEW)
23 endif()
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)
38 include(Macros)
39 today(DATE)
40 now(TIME)
41 git_id(GIT_STR)
43 message(STATUS "OpenTX ${VERSION} @${GIT_STR}")
45 # options shared by all targets
46 option(VERBOSE_CMAKELISTS "Show extra information while processing CMakeLists.txt files." OFF)
47 option(WARNINGS_AS_ERRORS "Treat any compiler warning as an error (adds -Werror flag)." OFF)
48 if(WIN32)
49   set(WIN_EXTRA_LIBS_PATH "C:/Programs" CACHE PATH
50     "Base path to extra libs/headers on Windows (SDL & pthreads folders should be in here).")
51   list(APPEND CMAKE_PREFIX_PATH "${WIN_EXTRA_LIBS_PATH}" "${WIN_EXTRA_LIBS_PATH}/SDL")  # hints for FindSDL
52 endif()
54 find_package(Qt5Widgets)
55 find_package(Qt5Xml)
56 find_package(Qt5LinguistTools)
57 find_package(Qt5PrintSupport)
58 find_package(Qt5Multimedia)
59 find_package(Qt5Svg)
61 if(Qt5Widgets_FOUND)
62   message(STATUS "Qt Version: ${Qt5Widgets_VERSION}")
63 else()
64   message(WARNING "Qt not found! Companion and Simulator builds disabled.")
65 endif()
67 if(NOT WIN32)
68   find_package(Fox QUIET)  # QUIET not working on WIN32?
69   if (FOX_FOUND)
70     message(STATUS "Foxlib found at ${FOX_LIBRARY}")
71   else() # if(NOT WIN32)
72     message("Libfox not found, simu target will not be available")
73   endif()
74 endif()
76 if(Qt5Widgets_FOUND OR FOX_FOUND)
77   set(SDL_BUILDING_LIBRARY YES)  # this prevents FindSDL from appending SDLmain lib to the results, which we don't want
78   find_package("SDL")
79   if(SDL_FOUND)
80     message(STATUS "SDL Lib: ${SDL_LIBRARY}; Headers: ${SDL_INCLUDE_DIR}; Version: ${SDL_VERSION_STRING}")
81   else()
82     message(STATUS "SDL not found! Simulator audio, and joystick inputs, will not work.")
83   endif()
84 endif()
86 # Check for a file that is typically left from a OpenTX 2.1 build and abort if found
87 if (EXISTS ${RADIO_SRC_DIRECTORY}/stamp.h OR EXISTS ${RADIO_SRC_DIRECTORY}/translations/en.h)
88    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")
89 endif()
91 # Windows-specific includes and libs shared by sub-projects
92 if(WIN32)
93   list(APPEND WIN_INCLUDE_DIRS "${RADIO_SRC_DIRECTORY}/thirdparty/windows/dirent")
94   if(MSVC)
95     list(APPEND WIN_INCLUDE_DIRS "${RADIO_SRC_DIRECTORY}/thirdparty/windows/msinttypes")
96     set(WIN_PTHREAD_BASE_PATH "${WIN_EXTRA_LIBS_PATH}/pthreads/Pre-built.2" CACHE PATH "Where to find pthreads include and lib folders.")
97     list(APPEND WIN_INCLUDE_DIRS "${WIN_PTHREAD_BASE_PATH}/include")
98     find_file(WIN_PTHREAD_LIB pthreadVC2.lib PATHS "${WIN_PTHREAD_BASE_PATH}" PATH_SUFFIXES lib/x86 lib NO_DEFAULT_PATH)
99     find_file(WIN_PTHREAD_DLL pthreadVC2.dll PATHS "${WIN_PTHREAD_BASE_PATH}" PATH_SUFFIXES lib/x86 lib dll/x86 dll NO_DEFAULT_PATH)
100     if(WIN_PTHREAD_LIB)
101       list(APPEND WIN_LINK_LIBRARIES "${WIN_PTHREAD_LIB}")
102     else()
103       message(SEND_ERROR "pthreadVC2.lib not found!")
104     endif()
105   else()
106     set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
107     set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES OFF)
108     set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
109     set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES OFF)
110   endif()
111 endif()
113 add_subdirectory(${RADIO_SRC_DIRECTORY})
115 if(Qt5Widgets_FOUND)
116   add_subdirectory(${COMPANION_SRC_DIRECTORY})
117 endif()