Merge pull request #6086 from YuxinPan/patch-2
[inav.git] / CMakeLists.txt
blob6d7b40dca16867cce48cc8a5d931f03dfc822600
1 cmake_minimum_required(VERSION 3.13...3.18)
3 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
5 set(MAIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
6 set(MAIN_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib")
7 set(MAIN_UTILS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/utils")
8 set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/main")
9 set(SVD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dev/svd")
10 set(DOWNLOADS_DIR "${MAIN_DIR}/downloads")
11 set(TOOLS_DIR "${MAIN_DIR}/tools")
13 set(TOOLCHAIN_OPTIONS none arm-none-eabi)
14 set(TOOLCHAIN "arm-none-eabi" CACHE STRING "Toolchain to use. Available: ${TOOLCHAIN_OPTIONS}")
15 set_property(CACHE TOOLCHAIN PROPERTY STRINGS ${TOOLCHAIN_OPTIONS})
16 if("" STREQUAL TOOLCHAIN)
17     set(TOOLCHAIN none)
18 endif()
19 if (NOT ${TOOLCHAIN} IN_LIST TOOLCHAIN_OPTIONS)
20     message(FATAL_ERROR "Invalid toolchain ${TOOLCHAIN}. Valid options are: ${TOOLCHAIN_OPTIONS}")
21 endif()
23 option(COMPILER_VERSION_CHECK "Ensure the compiler matches the expected version" ON)
25 if(TOOLCHAIN STREQUAL none)
26     add_subdirectory(src/test)
27 else()
28     set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${TOOLCHAIN}.cmake")
29     include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/${TOOLCHAIN}-checks.cmake")
30 endif()
32 project(INAV VERSION 2.6.0)
34 enable_language(ASM)
36 set(CMAKE_C_STANDARD 99)
37 set(CMAKE_C_EXTENSIONS ON)
38 set(CMAKE_C_STANDARD_REQUIRED ON)
39 set(CMAKE_CXX_STANDARD 11)
40 set(CMAKE_CXX_EXTENSIONS ON)
41 set(CMAKE_CXX_STANDARD_REQUIRED ON)
43 find_program(RUBY_EXECUTABLE ruby)
44 if (NOT RUBY_EXECUTABLE)
45     message(FATAL_ERROR "Could not find ruby")
46 endif()
48 if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
49     set(IS_RELEASE_BUILD ON)
50 endif()
52 include(GetGitRevisionDescription)
53 get_git_head_revision(GIT_REFSPEC GIT_SHA1)
54 string(SUBSTRING ${GIT_SHA1} 0 8 GIT_REV)
56 set(FIRMWARE_VERSION ${PROJECT_VERSION})
58 option(WARNINGS_AS_ERRORS "Make all warnings into errors")
59 message("-- toolchain: ${TOOLCHAIN}, WARNINGS_AS_ERRORS: ${WARNINGS_AS_ERRORS}")
61 include(settings)
62 include(openocd)
63 include(svd)
64 include(main)
65 include(stm32)
67 add_subdirectory(src)
69 collect_targets()
71 message("-- Build type: ${CMAKE_BUILD_TYPE}")
72 include(ci)