1# SPDX-License-Identifier: Apache-2.0
2
3cmake_minimum_required(VERSION 3.20.0)
4
5set(CMAKE_TOOLCHAIN_FILE toolchain.cmake)
6set(CMAKE_C_COMPILER_FORCED TRUE)
7set(CMAKE_CXX_COMPILER_FORCED TRUE)
8
9project(ext3)
10
11# Include EDK CFLAGS
12if(NOT DEFINED LLEXT_EDK_INSTALL_DIR)
13    set(LLEXT_EDK_INSTALL_DIR $ENV{LLEXT_EDK_INSTALL_DIR})
14endif()
15include(${LLEXT_EDK_INSTALL_DIR}/cmake.cflags)
16
17# Add LLEXT_CFLAGS to our flags
18add_compile_options(${LLEXT_CFLAGS})
19add_compile_options("-c")
20
21# Get flags from COMPILE_OPTIONS
22get_property(COMPILE_OPTIONS_PROP DIRECTORY PROPERTY COMPILE_OPTIONS)
23
24add_custom_command(
25    OUTPUT
26        ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.llext
27        ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.inc
28    COMMAND ${CMAKE_C_COMPILER} ${COMPILE_OPTIONS_PROP}
29        -o ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.llext
30        ${PROJECT_SOURCE_DIR}/src/main.c
31    COMMAND xxd -ip ${PROJECT_NAME}.llext
32        ${PROJECT_NAME}.inc
33)
34
35add_custom_target(ext3 ALL DEPENDS ${PROJECT_BINARY_DIR}/ext3.llext)
36