Browse Source

[CMAKE] Allow running tests from the main source build

When no alternative toolchain is provided, we explicitely include
the src/tests directory, so the check target (which builds and runs
tests) is available from a main source build without having to
build specifically the src/tests directory
master
Alberto García Hierro 4 years ago
parent
commit
15777844ac
  1. 14
      CMakeLists.txt
  2. 5
      cmake/main.cmake
  3. 4
      cmake/stm32.cmake
  4. 1
      src/test/CMakeLists.txt

14
CMakeLists.txt

@ -1,17 +1,23 @@
cmake_minimum_required(VERSION 3.17)
set(TOOLCHAIN_OPTIONS "arm-none-eabi")
set(TOOLCHAIN_OPTIONS none arm-none-eabi)
set(TOOLCHAIN "arm-none-eabi" CACHE STRING "Toolchain to use. Available: ${TOOLCHAIN_OPTIONS}")
set_property(CACHE TOOLCHAIN PROPERTY STRINGS ${TOOLCHAIN_OPTIONS})
if("" STREQUAL TOOLCHAIN)
set(TOOLCHAIN none)
endif()
if (NOT ${TOOLCHAIN} IN_LIST TOOLCHAIN_OPTIONS)
message(FATAL_ERROR "Invalid toolchain ${TOOLCHAIN}")
message(FATAL_ERROR "Invalid toolchain ${TOOLCHAIN}. Valid options are: ${TOOLCHAIN_OPTIONS}")
endif()
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${TOOLCHAIN}.cmake")
if(TOOLCHAIN STREQUAL none)
add_subdirectory(src/test)
else()
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${TOOLCHAIN}.cmake")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(IS_RELEASE_BUILD ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
endif()
project(INAV VERSION 2.5.0)

5
cmake/main.cmake

@ -55,6 +55,11 @@ function(setup_executable exe name)
set_target_properties(${exe} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
if(IS_RELEASE_BUILD)
set_target_properties(${exe} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION ON
)
endif()
endfunction()
function(setup_firmware_target exe name)

4
cmake/stm32.cmake

@ -1,4 +1,3 @@
include(arm-none-eabi)
include(stm32-bootloader)
include(stm32f3)
include(stm32f4)
@ -267,6 +266,9 @@ function(add_stm32_executable)
endfunction()
function(target_stm32)
if(NOT arm-none-eabi STREQUAL TOOLCHAIN)
return()
endif()
# Parse keyword arguments
cmake_parse_arguments(
args

1
src/test/CMakeLists.txt

@ -13,5 +13,4 @@ include(cmake/gtest.cmake)
enable_testing()
include(GoogleTest)
#add_subdirectory(googletest)
add_subdirectory(unit)
Loading…
Cancel
Save