Skip to content

Commit

Permalink
REFACTOR: improve CMake rules
Browse files Browse the repository at this point in the history
  • Loading branch information
T-K-233 committed Jul 28, 2024
1 parent 0fa2a2f commit fe438f3
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 100 deletions.
39 changes: 9 additions & 30 deletions examples/diffuse-loco/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

1 change: 1 addition & 0 deletions examples/fast-depth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions examples/llama2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 5 additions & 26 deletions examples/mlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

31 changes: 17 additions & 14 deletions examples/mnist/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
32 changes: 17 additions & 15 deletions examples/ppo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 16 additions & 14 deletions examples/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion examples/stereo-block-matching/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down

0 comments on commit fe438f3

Please sign in to comment.