Merge pull request #10458 from Holybro/add-spa06-spl07
[inav.git] / CMakeLists.txt
blob9b5f40f33371c43904df0acfc7c7db03813a9c1f
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 option(SITL "SITL build for host system" OFF)
15 set(TOOLCHAIN_OPTIONS none arm-none-eabi host)
16 if (SITL)
17     if (CMAKE_HOST_APPLE)
18         set(MACOSX TRUE)
19     endif()
20     set(TOOLCHAIN "host" CACHE STRING "Toolchain to use. Available: ${TOOLCHAIN_OPTIONS}")
21 else()
22     set(TOOLCHAIN "arm-none-eabi" CACHE STRING "Toolchain to use. Available: ${TOOLCHAIN_OPTIONS}")
23 endif()
25 set_property(CACHE TOOLCHAIN PROPERTY STRINGS ${TOOLCHAIN_OPTIONS})
26 if("" STREQUAL TOOLCHAIN)
27     set(TOOLCHAIN none)
28 endif()
29 if (NOT ${TOOLCHAIN} IN_LIST TOOLCHAIN_OPTIONS)
30     message(FATAL_ERROR "Invalid toolchain ${TOOLCHAIN}. Valid options are: ${TOOLCHAIN_OPTIONS}")
31 endif()
33 option(COMPILER_VERSION_CHECK "Ensure the compiler matches the expected version" ON)
35 include(GetGitRevisionDescription)
36 get_git_head_revision(GIT_REFSPEC GIT_SHA1)
37 string(SUBSTRING ${GIT_SHA1} 0 8 GIT_REV)
39 # Load settings related functions, so the tests can use them
40 include(main)
41 include(settings)
43 if(TOOLCHAIN STREQUAL none)
44     add_subdirectory(src/test)
45 else()
46     if (SITL)
47         include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/${TOOLCHAIN}.cmake")
48     else()
49         set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${TOOLCHAIN}.cmake")
50         include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/${TOOLCHAIN}-checks.cmake")
51     endif()
52 endif()
54 project(INAV VERSION 8.0.0)
56 enable_language(ASM)
58 if(MACOSX AND SITL)
59     set(CMAKE_C_STANDARD 11)
60 else()
61     set(CMAKE_C_STANDARD 99)
62 endif()
63 set(CMAKE_C_EXTENSIONS ON)
64 set(CMAKE_C_STANDARD_REQUIRED ON)
65 set(CMAKE_CXX_STANDARD 11)
66 set(CMAKE_CXX_EXTENSIONS ON)
67 set(CMAKE_CXX_STANDARD_REQUIRED ON)
69 if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
70     set(IS_RELEASE_BUILD ON)
71 endif()
73 set(FIRMWARE_VERSION ${PROJECT_VERSION})
75 option(WARNINGS_AS_ERRORS "Make all warnings into errors")
76 message("-- toolchain: ${TOOLCHAIN}, WARNINGS_AS_ERRORS: ${WARNINGS_AS_ERRORS}")
78 set(COMMON_COMPILE_DEFINITIONS
79     FC_VERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR}
80     FC_VERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR}
81     FC_VERSION_PATCH_LEVEL=${CMAKE_PROJECT_VERSION_PATCH}
82     FC_VERSION_TYPE="${VERSION_TYPE}"
85 if (NOT SITL)
86     include(openocd)
87     include(svd)
88 endif()
90 include(stm32)
91 include(at32)
92 include(sitl)
94 add_subdirectory(src)
96 collect_targets()
98 message("-- Build type: ${CMAKE_BUILD_TYPE}")
99 include(ci)