Does this work? (#4269)
[opentx.git] / CMakeLists.txt
blob9edde34e19c748deaa291dc07b691a6e00c6b19c
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 message(STATUS "OpenTX ${VERSION}")
11 set(SDCARD_REVISION "0004")
12 set(SDCARD_VERSION  ${VERSION_MAJOR}.${VERSION_MINOR}V${SDCARD_REVISION})
14 cmake_minimum_required(VERSION 2.8)
15 cmake_policy(SET CMP0020 NEW)
16 cmake_policy(SET CMP0023 OLD)
17 if(POLICY CMP0042)
18   cmake_policy(SET CMP0042 NEW)
19 endif()
20 if(POLICY CMP0043)
21   cmake_policy(SET CMP0043 NEW)
22 endif()
23 if(POLICY CMP0054)
24   cmake_policy(SET CMP0054 NEW)
25 endif()
27 set(CMAKE_COLOR_MAKEFILE ON)
29 set(CMAKE_CXX_STANDARD 11)
31 set(RADIO_DIRECTORY ${PROJECT_SOURCE_DIR}/radio)
32 set(RADIO_SRC_DIRECTORY ${RADIO_DIRECTORY}/src)
33 set(COMPANION_SRC_DIRECTORY ${PROJECT_SOURCE_DIR}/companion/src)
34 set(SIMU_SRC_DIRECTORY ${COMPANION_SRC_DIRECTORY}/simulation)
36 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
37 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
38 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
40 # options shared by all targets
41 option(VERBOSE_CMAKELISTS "Show extra information while processing CMakeLists.txt files." OFF)
42 option(WARNINGS_AS_ERRORS "Treat any compiler warning as an error (adds -Werror flag)." OFF)
43 if(WIN32)
44   set(WIN_EXTRA_LIBS_PATH "C:/Programs" CACHE PATH
45     "Base path to extra libs/headers on Windows (SDL, dirent, pthreads, msinttypes folders should be in here).")
46   list(APPEND CMAKE_PREFIX_PATH "${WIN_EXTRA_LIBS_PATH}" "${WIN_EXTRA_LIBS_PATH}/SDL")  # hints for FindSDL
47 endif()
49 find_package(Qt5Widgets)
50 find_package(Qt5Xml)
51 find_package(Qt5LinguistTools)
52 find_package(Qt5PrintSupport)
53 find_package(Qt5Multimedia)
55 if(Qt5Widgets_FOUND)
56   message(STATUS "Qt Version: ${Qt5Widgets_VERSION}")
57 else()
58   message(WARNING "Qt not found! Companion and Simulator builds disabled.")
59 endif()
61 if(NOT WIN32)
62   find_package(Fox QUIET)  # QUIET not working on WIN32?
63   if (FOX_FOUND)
64     message(STATUS "Foxlib found at ${FOX_LIBRARY}")
65   else() # if(NOT WIN32)
66     message("Libfox not found, simu target will not be available")
67   endif()
68 endif()
70 if(Qt5Widgets_FOUND OR FOX_FOUND)
71   set(SDL_BUILDING_LIBRARY YES)  # this prevents FindSDL from appending SDLmain lib to the results, which we don't want
72   find_package("SDL")
73   if(SDL_FOUND)
74     message(STATUS "SDL Lib: ${SDL_LIBRARY}; Headers: ${SDL_INCLUDE_DIR}; Version: ${SDL_VERSION_STRING}")
75   else()
76     message(STATUS "SDL not found! Joysticks support will be disabled. Simulator audio will not work.")
77   endif()
78 endif()
80 # Check for a file that is typically left from a OpenTX 2.1 build and abort if found
81 if (EXISTS ${RADIO_SRC_DIRECTORY}/stamp.h OR EXISTS ${RADIO_SRC_DIRECTORY}/translations/en.h)
82    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")
83 endif()
85 # Windows-specific includes and libs shared by sub-projects
86 if(WIN32)
87   list(APPEND WIN_INCLUDE_DIRS "${WIN_EXTRA_LIBS_PATH}/dirent/include")
88   if(MSVC)
89     set(WIN_PTHREAD_BASE_PATH "${WIN_EXTRA_LIBS_PATH}/pthreads/Pre-built.2")
90     list(APPEND WIN_INCLUDE_DIRS "${WIN_PTHREAD_BASE_PATH}/include" "${WIN_EXTRA_LIBS_PATH}/msinttypes")
91     find_file(WIN_PTHREAD_LIB pthreadVC2.lib PATHS "${WIN_PTHREAD_BASE_PATH}" PATH_SUFFIXES lib/x86 lib NO_DEFAULT_PATH)
92     find_file(WIN_PTHREAD_DLL pthreadVC2.dll PATHS "${WIN_PTHREAD_BASE_PATH}" PATH_SUFFIXES lib/x86 lib dll/x86 dll NO_DEFAULT_PATH)
93     if(WIN_PTHREAD_LIB)
94       list(APPEND WIN_LINK_LIBRARIES "${WIN_PTHREAD_LIB}")
95     else()
96       message(SEND_ERROR "pthreadVC2.lib not found!")
97     endif()
98   else()
99     set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
100     set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES OFF)
101     set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
102     set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES OFF)
103   endif()
104 endif()
106 include(Macros)
107 today(DATE)
108 now(TIME)
109 git_id(GIT_STR)
111 add_subdirectory(${RADIO_SRC_DIRECTORY})
113 if(Qt5Widgets_FOUND)
114   add_subdirectory(${COMPANION_SRC_DIRECTORY})
115 endif()