FreeRTOS / FreeRTOS-Kernel

FreeRTOS kernel files only, submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.
https://www.FreeRTOS.org
MIT License
2.51k stars 1.05k forks source link

[BUG] FreeRTOS install with Pico-SDK fails (CMAKE_C_COMPILER_OBJECT) #1076

Closed Lithimlin closed 1 month ago

Lithimlin commented 1 month ago

Describe the bug First of, sorry for putting this here instead of the Forums, but new sign-ups are currently blocked.

I'm trying to install FreeRTOS and the Pico-SDK via CMake but get the following error:

[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_COMPILE_OBJECT

For configuring/building, I use the CMake extension with an unspecified kit, and debug build.

Target

Host

To Reproduce I have the following structure:

├── CMakeLists.txt
├── free_rtos_import.cmake
├── config
│   └── FreeRTOSConfig.h
├── src
│   ├── CMakeLists.txt
│   └── main.cpp
└── lib
    └── CMakeLists.txt

Here are the relevant file contents: ./CMakeLists.txt:

cmake_minimum_required(VERSION 3.17)

set(PICO_SDK_VERSION_MAJOR 1)
set(PICO_SDK_VERSION_MINOR 5)
set(PICO_SDK_VERSION_REVISION 1)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Import FreeRTOS
message("Importing FreeRTOS")
include(free_rtos_import.cmake)

project(freeRTOS-pico C CXX ASM)

# Initialize the Raspberry Pi Pico SDK
pico_sdk_init()

# Include source
add_subdirectory(src)

# Add other libraries (if needed) 
# add_subdirectory(lib)

free_rtos_import.cmake:

# File docs: https://github.com/FreeRTOS/FreeRTOS-Kernel#consume-with-cmake
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
# Fetch FreeRTOS-Kernel
FetchContent_Declare( freertos_kernel
  GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git
  GIT_TAG        V11.1.0 #Note: Best practice to use specific git-hash or tagged version
  GIT_SUBMODULES_RECURSE FALSE
)

# Add config file
add_library(freertos_config INTERFACE)

target_include_directories(freertos_config SYSTEM
INTERFACE
    config
)

target_compile_definitions(freertos_config
  INTERFACE
    projCOVERAGE_TEST=0
)

# Set variables
set(FREERTOS_HEAP "4" CACHE STRING "" FORCE)
set(FREERTOS_PORT "GCC_RP2040" CACHE STRING "" FORCE)
# Select the native compile PORT
set(FREERTOS_PORT "TEMPLATE" CACHE STRING "" FORCE)

# Cross-Compile options
target_compile_definitions(freertos_config INTERFACE ${definitions})
target_compile_options(freertos_config INTERFACE ${options})
# Set try_compile to static library mode
# see https://cmake.org/cmake/help/latest/variable/CMAKE_TRY_COMPILE_TARGET_TYPE.html
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")

message("Downloading Free RTOS")
FetchContent_MakeAvailable(freertos_kernel)

message("Importing FreeRTOS RP2040 Kernel")
set(FREERTOS_KERNEL_PATH ${freertos_kernel_SOURCE_DIR})
set(PICO_SDK_FETCH_FROM_GIT on)
include(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)

The FreeRTOSConfig.h is the template one from the examples directory of this repo. The main.cpp is from the Pico example:

#include "FreeRTOS.h"
#include "task.h"
#include <stdio.h>
#include "pico/stdlib.h"

void led_task()
{   
    const uint LED_PIN = PICO_DEFAULT_LED_PIN;
    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);
    while (true) {
        gpio_put(LED_PIN, 1);
        vTaskDelay(100);
        gpio_put(LED_PIN, 0);
        vTaskDelay(100);
    }
}

int main()
{
    stdio_init_all();

    xTaskCreate(led_task, "LED_Task", 256, NULL, 1, NULL);
    vTaskStartScheduler();

    while(1){};
}

src/CMakeLists.txt:

add_executable(${PROJECT_NAME}
    main.cpp
)

target_include_directories(${PROJECT_NAME} PRIVATE
    ${CMAKE_CURRENT_LIST_DIR}
)

target_link_libraries(${PROJECT_NAME}
    pico_stdlib
    freertos_kernel
    freertos_config
)

pico_add_extra_outputs(${PROJECT_NAME})

Expected behavior FreeRTOS and the Pico-SDK are installed into the build directory without issues.

Additional context CLI output:

[main] Configuring project: freeRTOS-pico 
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -S<my-home>/Code/freeRTOS-pico -B<my-home>/Code/freeRTOS-pico/build -G Ninja
[cmake] Importing FreeRTOS
[cmake] Not searching for unused variables given on the command line.
[cmake] Downloading Free RTOS
[cmake] Importing FreeRTOS RP2040 Kernel
[cmake] PICO_SDK_PATH is <my-home>/Code/freeRTOS-pico/build/_deps/pico_sdk-src
[cmake] PICO platform is rp2040.
[cmake] System is unknown to cmake, create:
[cmake] Platform/PICO to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
[cmake] Your CMakeCache.txt file was copied to CopyOfCMakeCache.txt. Please post that file on discourse.cmake.org.
[cmake] Build type is Debug
[cmake] Using regular optimized debug build (set PICO_DEOPTIMIZED_DEBUG=1 to de-optimize)
[cmake] PICO target board is pico.
[cmake] Using board configuration from <my-home>/Code/freeRTOS-pico/build/_deps/pico_sdk-src/src/boards/include/boards/pico.h
[cmake] TinyUSB available at <my-home>/Code/freeRTOS-pico/build/_deps/pico_sdk-src/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.
[cmake] Compiling TinyUSB with CFG_TUSB_DEBUG=1
[cmake] BTstack available at <my-home>/Code/freeRTOS-pico/build/_deps/pico_sdk-src/lib/btstack
[cmake] cyw43-driver available at <my-home>/Code/freeRTOS-pico/build/_deps/pico_sdk-src/lib/cyw43-driver
[cmake] Pico W Bluetooth build support available.
[cmake] lwIP available at <my-home>/Code/freeRTOS-pico/build/_deps/pico_sdk-src/lib/lwip
[cmake] mbedtls available at<my-home>/Code/freeRTOS-pico/build/_deps/pico_sdk-src/lib/mbedtls
[cmake] -- Configuring done (0.4s)
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_COMPILE_OBJECT
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_COMPILE_OBJECT
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_COMPILE_OBJECT
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_COMPILE_OBJECT
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_COMPILE_OBJECT
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_COMPILE_OBJECT
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_COMPILE_OBJECT
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_COMPILE_OBJECT
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_COMPILE_OBJECT
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_ARCHIVE_CREATE
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_ARCHIVE_FINISH
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_COMPILE_OBJECT
[cmake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
[cmake] Missing variable is:
[cmake] CMAKE_C_COMPILE_OBJECT
[cmake] -- Generating done (0.0s)
[cmake] CMake Generate step failed.  Build files cannot be regenerated correctly.
[proc] The command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -S<my-home>/Code/freeRTOS-pico -B<my-home>/Code/freeRTOS-pico/build -G Ninja exited with code: 1
Lithimlin commented 1 month ago

The issue was solved my moving the project() command before the FreeRTOS import…

Sorry for the noise