From 2f559823a63cf6909d5a9e32dee47d6891caf553 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Mon, 25 Mar 2024 16:49:08 +0800 Subject: [PATCH] build: add cmake as build system --- CMakeLists.txt | 16 +++++++++ tests/cpu-tests/CMakeLists.txt | 3 ++ tests/cpu-tests/Makefile | 2 +- tests/cpu-tests/tests/CMakeLists.txt | 53 ++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt create mode 100644 tests/cpu-tests/CMakeLists.txt create mode 100644 tests/cpu-tests/tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..61f185a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.22) + +project(am-kernels) +set(CMAKE_C_STANDARD 11) +enable_language(C ASM) + +include(CheckPIESupported) +check_pie_supported() + +if(${PLATFORM} MATCHES "native") +set(ARCH "native") +else() +set(ARCH ${ISA}-${PLATFORM}) +endif() + +add_subdirectory(tests/cpu-tests) \ No newline at end of file diff --git a/tests/cpu-tests/CMakeLists.txt b/tests/cpu-tests/CMakeLists.txt new file mode 100644 index 0000000..4504c42 --- /dev/null +++ b/tests/cpu-tests/CMakeLists.txt @@ -0,0 +1,3 @@ + +include_directories(include) +add_subdirectory(tests) diff --git a/tests/cpu-tests/Makefile b/tests/cpu-tests/Makefile index fb63e0b..7abb6b5 100644 --- a/tests/cpu-tests/Makefile +++ b/tests/cpu-tests/Makefile @@ -15,7 +15,7 @@ all: $(addprefix Makefile., $(ALL)) $(ALL): %: Makefile.% Makefile.%: tests/%.c latest - @/bin/echo -e "NAME = $*\nSRCS = $<\ninclude $${AM_HOME}/Makefile" > $@ + @echo -e "NAME = $*\nSRCS = $<\ninclude $${AM_HOME}/Makefile" > $@ @if make -s -f $@ ARCH=$(ARCH) $(MAKECMDGOALS); then \ printf "[%14s] $(COLOR_GREEN)PASS$(COLOR_NONE)\n" $* >> $(RESULT); \ else \ diff --git a/tests/cpu-tests/tests/CMakeLists.txt b/tests/cpu-tests/tests/CMakeLists.txt new file mode 100644 index 0000000..3e1bb7a --- /dev/null +++ b/tests/cpu-tests/tests/CMakeLists.txt @@ -0,0 +1,53 @@ +find_package(am-${ARCH}) +find_package(klib) + +set(SOURCES + add.c + add-longlong.c + bit.c + bubble-sort.c + crc32.c + div.c + dummy.c + fact.c + fib.c + goldbach.c + hello-str.c + if-else.c + leap-year.c + load-store.c + matrix-mul.c + max.c + mersenne.c + min3.c + mov-c.c + movsx.c + mul-longlong.c + pascal.c + prime.c + quick-sort.c + recursion.c + select-sort.c + shift.c + shuixianhua.c + string.c + sub-longlong.c + sum.c + switch.c + to-lower-case.c + unalign.c + wanshu.c) + +foreach(SOURCE IN LISTS SOURCES) + get_filename_component(SOURCE_NAME ${SOURCE} NAME_WLE) + add_executable(${SOURCE_NAME} + ${SOURCE}) + target_link_libraries(${SOURCE_NAME} PRIVATE am-${ARCH}) + + # -- Extract binary file from ELF + add_custom_command(TARGET ${SOURCE_NAME} + COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary ${SOURCE_NAME} ${SOURCE_NAME}.bin) + + install(TARGETS ${SOURCE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_DATADIR}/elf) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_NAME}.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/binary) +endforeach()