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(ext2)
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
18set(CMAKE_C_FLAGS ${LLEXT_CFLAGS} "-c")
19
20add_custom_command(
21    OUTPUT
22        ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.llext
23        ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.inc
24    COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS}
25        -o ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.llext
26        ${PROJECT_SOURCE_DIR}/src/main.c
27    COMMAND xxd -ip ${PROJECT_NAME}.llext
28        ${PROJECT_NAME}.inc
29)
30
31add_custom_target(ext2 ALL DEPENDS ${PROJECT_BINARY_DIR}/ext2.llext)
32