1- set (CMAKE_VERSION 3.20 )
1+ set (CMAKE_VERSION 3.23 )
22cmake_minimum_required (VERSION ${CMAKE_VERSION} )
33
4+ project (function_examples LANGUAGES C CXX ASM)
5+
6+ include (FetchContent)
7+
48# option to include libc-dependent examples
5- option (USE_LIBC "Use libc" OFF )
9+ set (ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR} CACHE STRING "the architecture to build for" )
10+ set (PLATFORM "debug" CACHE STRING "backend to build for" )
11+
12+ if (NOT CMAKE_BUILD_TYPE )
13+ set (CMAKE_BUILD_TYPE "Debug" )
14+ endif ()
15+
16+ message (STATUS "Building ${CMAKE_BUILD_TYPE} for ${PLATFORM} on ${ARCHITECTURE} " )
617
718# prevent in-source builds
819if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
920 message (FATAL_ERROR "In-source build detected" )
1021endif ()
1122
12- project (function_examples LANGUAGES C CXX ASM)
13-
14- if ("${CMAKE_C_COMPILER_ID} " STREQUAL "Clang" )
15- else ()
16- message (FATAL_ERROR "Compiler not clang\n " "${CMAKE_C_COMPILER_ID} " )
23+ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
24+ set_property (CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_BINARY_DIR} /dandelion_sdk" )
1725endif ()
1826
19- # prepare mlibc
20- if (USE_LIBC)
21- # make cross file
22- configure_file (cross_template.txt crossfile.txt)
23- include (ExternalProject)
24- ExternalProject_Add(mlibc
25- SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /../mlibc
26- CONFIGURE_COMMAND meson setup --cross-file ${CMAKE_CURRENT_BINARY_DIR} /crossfile.txt -Dprefix=<INSTALL_DIR> <BINARY_DIR> <SOURCE_DIR>
27- BUILD_COMMAND ninja -C <BINARY_DIR>
28- # Enable when working on the libc to make sure it is freshly compiled
29- # BUILD_ALWAYS TRUE
30- INSTALL_COMMAND meson install -C <BINARY_DIR> --no -rebuild --only-changed --quiet
31- )
32- ExternalProject_Get_Property(mlibc INSTALL_DIR)
33- set (MLIBC_INSTALL_DIR ${INSTALL_DIR} )
34-
35- add_library (dlibc OBJECT IMPORTED )
36- add_dependencies (dlibc mlibc)
37- set (MLIBC_OBJ
38- "${MLIBC_INSTALL_DIR} /lib/crt1.o"
39- "${MLIBC_INSTALL_DIR} /lib/crti.o"
40- "${MLIBC_INSTALL_DIR} /lib/crtn.o" )
41- set_target_properties (dlibc PROPERTIES IMPORTED_OBJECTS "${MLIBC_OBJ} " )
42- file (MAKE_DIRECTORY "${MLIBC_INSTALL_DIR} /include" )
43- target_include_directories (dlibc INTERFACE "${MLIBC_INSTALL_DIR} /include" )
44- set (MLIBC_LIBS
45- "${MLIBC_INSTALL_DIR} /lib/libc.a"
46- "${MLIBC_INSTALL_DIR} /lib/libcrypt.a"
47- "${MLIBC_INSTALL_DIR} /lib/libdl.a"
48- "${MLIBC_INSTALL_DIR} /lib/libm.a"
49- "${MLIBC_INSTALL_DIR} /lib/libpthread.a"
50- "${MLIBC_INSTALL_DIR} /lib/libresolv.a"
51- "${MLIBC_INSTALL_DIR} /lib/librt.a"
52- "${MLIBC_INSTALL_DIR} /lib/libutil.a"
53- ${COMP_RTLIB}
54- )
55- target_link_libraries (dlibc INTERFACE ${RUNTIME_LIB} ${MLIBC_LIBS} )
56- target_link_options (dlibc INTERFACE -nostdlib)
57- endif ()
27+ # setup build toolchain
28+ FetchContent_Declare(
29+ dandelion_sdk
30+ DOWNLOAD_COMMAND gh release download latest -R eth-easl/dandelionFunctionInterface -p "*${CMAKE_BUILD_TYPE} _${PLATFORM} _${ARCHITECTURE} .tar.gz"
31+ COMMAND tar -xzf "dandelion_sdk_${CMAKE_BUILD_TYPE} _${PLATFORM} _${ARCHITECTURE} .tar.gz" -C ${CMAKE_BINARY_DIR}
32+ )
33+ FetchContent_MakeAvailable(dandelion_sdk)
34+
35+ execute_process (
36+ COMMAND ${CMAKE_C_COMPILER} -print-file-name =include
37+ OUTPUT_STRIP_TRAILING_WHITESPACE
38+ OUTPUT_VARIABLE COMPILER_RUNTIME_INCLUDE
39+ COMMAND_ERROR_IS_FATAL ANY
40+ )
5841
42+ add_subdirectory ("${CMAKE_BINARY_DIR} /dandelion_sdk" "${CMAKE_BINARY_DIR} /dandelion_sdk_build" )
43+
44+ if (CMAKE_BUILD_TYPE MATCHES "Debug" )
45+ add_compile_options (-gdwarf-4)
46+ endif ()
5947
6048# cheri compile flags
61- if ("${DANDELION_PLATFORM } " STREQUAL "cheri" )
49+ if ("${PLATFORM } " STREQUAL "cheri" )
6250 add_compile_options (-march=morello -mabi=aapcs)
6351 add_link_options (-march=morello -mabi=aapcs -fuse-ld=lld -Xlinker --image-base=0x10000)
6452 get_property (CROSS_COMPILE_OPTIONS DIRECTORY PROPERTY COMPILE_OPTIONS)
6553 string (REPLACE ";" " " CROSS_COMPILE_OPTIONS "${CROSS_COMPILE_OPTIONS} " )
6654 get_property (CROSS_LINK_OPTIONS DIRECTORY PROPERTY LINK_OPTIONS)
6755 string (REPLACE ";" " " CROSS_LINK_OPTIONS "${CROSS_LINK_OPTIONS} " )
6856# WebAssembly flags
69- elseif ("${DANDELION_PLATFORM } " STREQUAL "wasm" )
57+ elseif ("${PLATFORM } " STREQUAL "wasm" )
7058 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --verbose -target wasm32-unknown-unknown -Wl,--export-all -Wl,--import-undefined -Wl,--import-memory" )
7159else ()
7260# currently still want to set the base image lower for all other images, if some don't want make special case
7361 add_link_options (-fuse-ld=lld -Xlinker --image-base=0x10000)
7462endif ()
7563
76- add_subdirectory ("${CMAKE_CURRENT_SOURCE_DIR} /../dandelionFunctionInterface" functionInterface)
77-
7864# add folders with function examples
7965# add_subdirectory(access)
8066add_subdirectory (basic)
8167add_subdirectory (busy)
8268add_subdirectory (matmac)
8369add_subdirectory (matmul)
8470add_subdirectory (example_app_nolibc)
71+
8572# dependent on dlibc
86- if (USE_LIBC)
87- # add_subdirectory(image_processing)
88- add_subdirectory (dirigent_busy)
89- add_subdirectory (example_app)
90- add_subdirectory (files )
91- add_subdirectory (stdio)
92- endif ()
73+ add_subdirectory (dirigent_busy)
74+ add_subdirectory (example_app)
75+ add_subdirectory (files )
76+ add_subdirectory (stdio)
77+ add_subdirectory (stdio_cxx)
78+ # add_subdirectory(example_app_hybrid)
79+ add_subdirectory (compression)
80+ add_subdirectory (busy_libc)
81+ add_subdirectory (busy_hybrid)
82+
83+ # set(CONFIG_FLAG "--config ${CMAKE_BINARY_DIR}/dandelion.cfg")
84+ # set(CONFIG_FLAGXX "--config ${CMAKE_BINARY_DIR}/dandelion++.cfg")
85+
86+ # include(ExternalProject)
87+ # ExternalProject_Add(
88+ # llvmproject
89+ # PREFIX llvmproject
90+ # GIT_REPOSITORY https://github.com/llvm/llvm-project
91+ # GIT_TAG release/18.x
92+ # SOURCE_SUBDIR llvm
93+ # UPDATE_DISCONNECTED 1
94+ # INSTALL_DIR ${CMAKE_BINARY_DIR}/llvm
95+ # LIST_SEPARATOR ","
96+ # CMAKE_ARGS
97+ # -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
98+ # -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
99+ # -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
100+ # -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
101+ # -DCMAKE_SYSTEM_NAME=Generic
102+ # -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
103+ # -DCMAKE_C_FLAGS:STRING=${CONFIG_FLAG}
104+ # -DCMAKE_CXX_FLAGS:STRING=${CONFIG_FLAGXX}
105+ # -DLLVM_ENABLE_PROJECTS=clang,lld
106+ # -DLLVM_TARGETS_TO_BUILD=AArch64,X86
107+ # -DBUILD_SHARED_LIBS=OFF
108+ # -DLLVM_ENABLE_PIC=OFF
109+ # -DLLVM_ENABLE_THREADS=OFF
110+ # EXCLUDE_FROM_ALL TRUE
111+ # )
0 commit comments