From fe438f3a875ebe8de96c5656e4169656e3004e07 Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sat, 27 Jul 2024 21:26:52 -0700 Subject: [PATCH] REFACTOR: improve CMake rules --- examples/diffuse-loco/CMakeLists.txt | 39 +++++-------------- examples/fast-depth/CMakeLists.txt | 1 + examples/llama2/CMakeLists.txt | 1 + examples/mlp/CMakeLists.txt | 31 +++------------ examples/mnist/CMakeLists.txt | 31 ++++++++------- examples/ppo/CMakeLists.txt | 32 ++++++++------- examples/simple/CMakeLists.txt | 30 +++++++------- examples/stereo-block-matching/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 1 + 9 files changed, 68 insertions(+), 100 deletions(-) diff --git a/examples/diffuse-loco/CMakeLists.txt b/examples/diffuse-loco/CMakeLists.txt index 96b2656..d65aff6 100644 --- a/examples/diffuse-loco/CMakeLists.txt +++ b/examples/diffuse-loco/CMakeLists.txt @@ -2,44 +2,23 @@ cmake_minimum_required(VERSION 3.10) project(diffuse-loco LANGUAGES C) - add_executable(diffuse-loco main.c) -target_include_directories(diffuse-loco PUBLIC inc) + +target_include_directories(diffuse-loco PUBLIC ./) + target_compile_features(diffuse-loco INTERFACE c_std_11) if (X86) - message("diffuse-loco: building for x86") - target_link_libraries(diffuse-loco PUBLIC target-x86) - + message("diffuse-loco: building for x86") + target_link_libraries(diffuse-loco PUBLIC target-x86) elseif (RISCV) - message("diffuse-loco: building for RISC-V") - # CMake toolchain definition for RISC-V GCC toolchain - set(CMAKE_SYSTEM_NAME "Generic" CACHE STRING "") - set(CMAKE_SYSTEM_PROCESSOR "riscv" CACHE STRING "") - - set(TOOLCHAIN_PREFIX "riscv64-unknown-elf-") - - set(CMAKE_C_COMPILER "${TOOLCHAIN_PREFIX}gcc") - set(CMAKE_ASM_COMPILER "${TOOLCHAIN_PREFIX}gcc") - set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PREFIX}g++") - set(CMAKE_AR "${TOOLCHAIN_PREFIX}ar") - set(CMAKE_LINKER "{TOOLCHAIN_PREFIX}ld") - set(CMAKE_OBJCOPY "${TOOLCHAIN_PREFIX}objcopy") - set(CMAKE_SIZE "${TOOLCHAIN_PREFIX}size") - set(CMAKE_STRIP "${TOOLCHAIN_PREFIX}ld") - - target_link_libraries(diffuse-loco PUBLIC target-riscv) + message("diffuse-loco: building for RISC-V") + target_link_libraries(diffuse-loco PUBLIC target-riscv) + set_target_properties(diffuse-loco PROPERTIES SUFFIX ".elf") endif () -add_compile_options(-O3 -Wall -Wextra) +target_compile_options(diffuse-loco -O3 -Wall -Wextra) -target_compile_options(diffuse-loco PRIVATE -u _printf_float) - -add_subdirectory(../../ ./build/) - -add_subdirectory(../../nn/ ./build/nn) target_link_libraries(diffuse-loco PUBLIC nn) - target_link_libraries(diffuse-loco PUBLIC m) - diff --git a/examples/fast-depth/CMakeLists.txt b/examples/fast-depth/CMakeLists.txt index 84047fa..fc73a0e 100644 --- a/examples/fast-depth/CMakeLists.txt +++ b/examples/fast-depth/CMakeLists.txt @@ -16,6 +16,7 @@ if (X86) elseif (RISCV) message(STATUS "fast-depth: Building for RISC-V") target_link_libraries(fast-depth PUBLIC target-riscv) + set_target_properties(fast-depth PROPERTIES SUFFIX ".elf") endif () target_compile_options(fast-depth PRIVATE -O3 -Wall -Wextra) diff --git a/examples/llama2/CMakeLists.txt b/examples/llama2/CMakeLists.txt index ae460fa..ea3653e 100644 --- a/examples/llama2/CMakeLists.txt +++ b/examples/llama2/CMakeLists.txt @@ -14,6 +14,7 @@ if (X86) elseif (RISCV) message(STATUS "llama2: Building for RISC-V") target_link_libraries(llama2 PUBLIC target-riscv) + set_target_properties(llama2 PROPERTIES SUFFIX ".elf") endif () target_compile_options(llama2 PRIVATE -O3 -Wall -Wextra) diff --git a/examples/mlp/CMakeLists.txt b/examples/mlp/CMakeLists.txt index 3b18f6a..a48ec60 100644 --- a/examples/mlp/CMakeLists.txt +++ b/examples/mlp/CMakeLists.txt @@ -2,44 +2,23 @@ cmake_minimum_required(VERSION 3.10) project(mlp LANGUAGES C) - add_executable(mlp main.c) -target_include_directories(mlp PUBLIC inc) + +target_include_directories(mlp PUBLIC ./) + target_compile_features(mlp INTERFACE c_std_11) if (X86) message("mlp: building for x86") target_link_libraries(mlp PUBLIC target-x86) - elseif (RISCV) message("mlp: building for RISC-V") - # CMake toolchain definition for RISC-V GCC toolchain - set(CMAKE_SYSTEM_NAME "Generic" CACHE STRING "") - set(CMAKE_SYSTEM_PROCESSOR "riscv" CACHE STRING "") - - set(TOOLCHAIN_PREFIX "riscv64-unknown-elf-") - - set(CMAKE_C_COMPILER "${TOOLCHAIN_PREFIX}gcc") - set(CMAKE_ASM_COMPILER "${TOOLCHAIN_PREFIX}gcc") - set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PREFIX}g++") - set(CMAKE_AR "${TOOLCHAIN_PREFIX}ar") - set(CMAKE_LINKER "{TOOLCHAIN_PREFIX}ld") - set(CMAKE_OBJCOPY "${TOOLCHAIN_PREFIX}objcopy") - set(CMAKE_SIZE "${TOOLCHAIN_PREFIX}size") - set(CMAKE_STRIP "${TOOLCHAIN_PREFIX}ld") - target_link_libraries(mlp PUBLIC target-riscv) + set_target_properties(mlp PROPERTIES SUFFIX ".elf") endif () -add_compile_options(-O3 -Wall -Wextra) +target_compile_options(mlp PRIVATE -O3 -Wall -Wextra) -target_compile_options(mlp PRIVATE -u _printf_float) - -add_subdirectory(../../ ./build/) - -add_subdirectory(../../nn/ ./build/nn) target_link_libraries(mlp PUBLIC nn) - target_link_libraries(mlp PUBLIC m) - diff --git a/examples/mnist/CMakeLists.txt b/examples/mnist/CMakeLists.txt index 213891b..8e35fe9 100644 --- a/examples/mnist/CMakeLists.txt +++ b/examples/mnist/CMakeLists.txt @@ -1,22 +1,25 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.10) -set(PROJECT_NAME "mnist") +project(mnist LANGUAGES C) -set(PROJECT_INCLUDES - inc -) +add_executable(mnist main.c) -set(PROJECT_SOURCES - main.c -) +target_include_directories(mnist PUBLIC ./) +target_include_directories(mnist PUBLIC ../utility) -project(${PROJECT_NAME}) +target_compile_features(mnist INTERFACE c_std_11) -add_executable(${PROJECT_NAME} ${PROJECT_SOURCES}) -target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_INCLUDES}) - -add_subdirectory(../../nn ./build/nn) -target_link_libraries(${PROJECT_NAME} PUBLIC nn) +if (X86) + message(STATUS "mnist: Building for x86") + target_link_libraries(mnist PUBLIC target-x86) +elseif (RISCV) + message(STATUS "mnist: Building for RISC-V") + target_link_libraries(mnist PUBLIC target-riscv) + set_target_properties(mnist PROPERTIES SUFFIX ".elf") +endif () +target_compile_options(mnist PRIVATE -O3 -Wall -Wextra) +target_link_libraries(mnist PUBLIC nn) +target_link_libraries(mnist PUBLIC m) diff --git a/examples/ppo/CMakeLists.txt b/examples/ppo/CMakeLists.txt index 9a323c1..5f085b5 100644 --- a/examples/ppo/CMakeLists.txt +++ b/examples/ppo/CMakeLists.txt @@ -1,23 +1,25 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.10) -set(PROJECT_NAME "ppo") +project(mlp-ppo LANGUAGES C) -set(PROJECT_INCLUDES - inc -) +add_executable(mlp-ppo main.c) -set(PROJECT_SOURCES - main.c -) +target_include_directories(mlp-ppo PUBLIC ./) +target_include_directories(mlp-ppo PUBLIC ../utility) -project(${PROJECT_NAME}) +target_compile_features(mlp-ppo INTERFACE c_std_11) -add_executable(${PROJECT_NAME} ${PROJECT_SOURCES}) -target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_INCLUDES}) +if (X86) + message(STATUS "mlp-ppo: Building for x86") + target_link_libraries(mlp-ppo PUBLIC target-x86) +elseif (RISCV) + message(STATUS "mlp-ppo: Building for RISC-V") + target_link_libraries(mlp-ppo PUBLIC target-riscv) + set_target_properties(mlp-ppo PROPERTIES SUFFIX ".elf") +endif () -add_subdirectory(../../nn ./build/nn) -target_link_libraries(${PROJECT_NAME} PUBLIC nn) - -target_link_libraries(${PROJECT_NAME} PUBLIC m) +target_compile_options(mlp-ppo PRIVATE -O3 -Wall -Wextra) +target_link_libraries(mlp-ppo PUBLIC nn) +target_link_libraries(mlp-ppo PUBLIC m) diff --git a/examples/simple/CMakeLists.txt b/examples/simple/CMakeLists.txt index c59ef9d..9befd67 100644 --- a/examples/simple/CMakeLists.txt +++ b/examples/simple/CMakeLists.txt @@ -1,22 +1,24 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.10) -set(PROJECT_NAME "simple") +project(simple LANGUAGES C) -set(PROJECT_INCLUDES - inc -) +add_executable(simple main.c) -set(PROJECT_SOURCES - main.c -) +target_include_directories(simple PUBLIC ./) -project(${PROJECT_NAME}) +target_compile_features(simple INTERFACE c_std_11) -add_executable(${PROJECT_NAME} ${PROJECT_SOURCES}) -target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_INCLUDES}) - -add_subdirectory(../../nn ./build/nn) -target_link_libraries(${PROJECT_NAME} PUBLIC nn) +if (X86) + message(STATUS "simple: Building for x86") + target_link_libraries(simple PUBLIC target-x86) +elseif (RISCV) + message(STATUS "simple: Building for RISC-V") + target_link_libraries(simple PUBLIC target-riscv) + set_target_properties(simple PROPERTIES SUFFIX ".elf") +endif () +target_compile_options(simple PRIVATE -O3 -Wall -Wextra) +target_link_libraries(simple PUBLIC nn) +target_link_libraries(simple PUBLIC m) diff --git a/examples/stereo-block-matching/CMakeLists.txt b/examples/stereo-block-matching/CMakeLists.txt index 2613f46..d61ecc9 100644 --- a/examples/stereo-block-matching/CMakeLists.txt +++ b/examples/stereo-block-matching/CMakeLists.txt @@ -16,9 +16,9 @@ if (X86) elseif (RISCV) message("stereoBM: building for RISC-V") target_link_libraries(stereoBM PUBLIC target-riscv) + set_target_properties(stereoBM PROPERTIES SUFFIX ".elf") endif () - target_compile_options(stereoBM PRIVATE -O3 -Wall -Wextra) target_link_libraries(stereoBM PUBLIC nn) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 462a412..4d773b4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,6 +11,7 @@ if (X86) target_link_libraries(tests PUBLIC target-x86) elseif (RISCV) target_link_libraries(tests PUBLIC target-riscv) + set_target_properties(tests PROPERTIES SUFFIX ".elf") endif()