Skip to content

Commit

Permalink
💄 (cmake): Clean up main CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Jan 12, 2022
1 parent b5f34e3 commit 6e94d17
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 37 deletions.
106 changes: 74 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,95 @@

cmake_minimum_required(VERSION 3.21)

# Activate ccache if available
#
# MARK: - External tools
#

find_program(CCACHE "ccache")
if(CCACHE)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE}")
endif(CCACHE)

# Activate LogKit
option(ENABLE_LOG_DEBUG "Enable LogKit output" OFF)
message(STATUS "ENABLE_LOG_DEBUG --> ${ENABLE_LOG_DEBUG}")
if(ENABLE_LOG_DEBUG)
add_definitions(-DENABLE_LOG_DEBUG)
endif(ENABLE_LOG_DEBUG)
# Compile commands database
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
if(CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()

#
# MARK: - Compilation flags/options
#

# Set C/C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS TRUE)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_C_STANDARD 17)
set(CMAKE_C_EXTENSIONS TRUE)
set(CMAKE_C_STANDARD_REQUIRED ON)

set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")

# Add custom flags
add_compile_options(
$<$<COMPILE_LANGUAGE:CXX>:-Wno-register>
$<$<COMPILE_LANGUAGE:CXX>:-Wno-volatile>
-fdiagnostics-color=always
)

# Before all, set ROOT_DIR, MBED_OS_DIR
set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
set(MBED_OS_DIR ${ROOT_DIR}/extern/mbed-os)
set(MCUBOOT_DIR ${ROOT_DIR}/extern/mcuboot/boot)
set(MBED_HTTP_DIR ${ROOT_DIR}/extern/mbed-http)

# Bootloader option
# Bootloader
option(BUILD_TARGETS_TO_USE_WITH_BOOTLOADER "Build targets with padding to use with bootloader" OFF)
message(STATUS "Build targets with padding to use with bootloader --> ${BUILD_TARGETS_TO_USE_WITH_BOOTLOADER}")
if (BUILD_TARGETS_TO_USE_WITH_BOOTLOADER)
set(MBED_APP_FLAGS
-DMBED_APP_START=0x08041000
-DMBED_APP_SIZE=0x17E000
)
endif(BUILD_TARGETS_TO_USE_WITH_BOOTLOADER)

# And include mbed-cmake.cmake
include(./mbed-cmake.cmake)
# Logger
option(ENABLE_LOG_DEBUG "Enable LogKit output" OFF)
if(ENABLE_LOG_DEBUG)
add_definitions(-DENABLE_LOG_DEBUG)
endif(ENABLE_LOG_DEBUG)

# Then configure name of the project
project(LekaOS LANGUAGES C CXX ASM)

# Generate compile commands database
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
#
# MARK: - Directories
#

if(CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()
# Before all
set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})

# extern
set(MBED_OS_DIR ${ROOT_DIR}/extern/mbed-os)
set(MCUBOOT_DIR ${ROOT_DIR}/extern/mcuboot/boot)
set(MBED_HTTP_DIR ${ROOT_DIR}/extern/mbed-http)

# includes
set(LIBS_DIR ${ROOT_DIR}/libs)
set(DRIVERS_DIR ${ROOT_DIR}/drivers)
set(INCLUDE_DIR ${ROOT_DIR}/include)
set(TARGETS_DIR ${ROOT_DIR}/targets)

# For convenience you can define useful variables
# app
set(OS_DIR ${ROOT_DIR}/app/os)
set(LIBS_DIR ${ROOT_DIR}/libs)
set(TESTS_DIR ${ROOT_DIR}/tests)
set(SPIKES_DIR ${ROOT_DIR}/spikes)
set(DRIVERS_DIR ${ROOT_DIR}/drivers)
set(TARGETS_DIR ${ROOT_DIR}/targets)
set(INCLUDE_DIR ${ROOT_DIR}/include)
set(BOOTLOADER_DIR ${ROOT_DIR}/app/bootloader)

# spikes, functional tests
set(SPIKES_DIR ${ROOT_DIR}/spikes)
set(FUNCTIONAL_TESTS_DIR ${ROOT_DIR}/tests/functional)

#
# MARK: - LekaOS Project
#

# And include mbed-cmake.cmake
include(${ROOT_DIR}/mbed-cmake.cmake)

project(LekaOS LANGUAGES C CXX ASM)

# Add custom target subdirectory
set(AVAILABLE_CUSTOM_TARGETS LEKA_DISCO LEKA_V1_2_DEV)
if (${TARGET_BOARD} IN_LIST AVAILABLE_CUSTOM_TARGETS)
Expand Down Expand Up @@ -103,7 +128,7 @@ add_subdirectory(${LIBS_DIR})

# Add spikes, functional tests
add_subdirectory(${SPIKES_DIR})
add_subdirectory(${TESTS_DIR}/functional)
add_subdirectory(${FUNCTIONAL_TESTS_DIR})

# Add bootloader
add_subdirectory(${BOOTLOADER_DIR})
Expand All @@ -113,3 +138,20 @@ add_subdirectory(${OS_DIR})

# Finally print the mbed-cmake build report
mbed_cmake_print_build_report()

#
# MARK: - Misc. options
#

option(VERBOSE_BUILD "Have a verbose build process")
if(VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()

# Print options
message(STATUS "")
message(STATUS "CMAKE_EXPORT_COMPILE_COMMANDS --> ${CMAKE_EXPORT_COMPILE_COMMANDS}")
message(STATUS "ENABLE_LOG_DEBUG --> ${ENABLE_LOG_DEBUG}")
message(STATUS "BUILD_TARGETS_FOR_BOOTLOADER --> ${BUILD_TARGETS_TO_USE_WITH_BOOTLOADER}")
message(STATUS "CMAKE_VERBOSE_MAKEFILE --> ${VERBOSE_BUILD}")
message(STATUS "")
10 changes: 5 additions & 5 deletions tests/functional/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# Copyright 2020 APF France handicap
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(${TESTS_DIR}/functional/cert/emc_ble_bt_lcd_led_motors)
add_subdirectory(${TESTS_DIR}/functional/cert/emc_ble_led_motors)
add_subdirectory(${TESTS_DIR}/functional/cert/emc_lcd_led_motors)
add_subdirectory(${TESTS_DIR}/functional/cert/emc_bt_lcd_qspi_rfid_touch_wifi)
add_subdirectory(${TESTS_DIR}/functional/hardware/motors_test_reduction_and_wheels)
add_subdirectory(${FUNCTIONAL_TESTS_DIR}/cert/emc_ble_bt_lcd_led_motors)
add_subdirectory(${FUNCTIONAL_TESTS_DIR}/cert/emc_ble_led_motors)
add_subdirectory(${FUNCTIONAL_TESTS_DIR}/cert/emc_lcd_led_motors)
add_subdirectory(${FUNCTIONAL_TESTS_DIR}/cert/emc_bt_lcd_qspi_rfid_touch_wifi)
add_subdirectory(${FUNCTIONAL_TESTS_DIR}/hardware/motors_test_reduction_and_wheels)

add_custom_target(tests_functional)
add_dependencies(tests_functional
Expand Down

0 comments on commit 6e94d17

Please sign in to comment.