forked from wid4soe/matlib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
71 lines (58 loc) · 3.09 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
cmake_minimum_required(VERSION 3.15.0)
message("Processing ${CMAKE_CURRENT_LIST_DIR}")
if (NOT DEFINED MATLIB_CMAKE_PATH)
include(${CMAKE_CURRENT_LIST_DIR}/matlib.cmake)
endif()
set(MATLIB_INCLUDE_PATH ${MATLIB_CMAKE_PATH}/include/${USE_TYPE} CACHE STRING "Matlib include path")
project(matlib VERSION 0.2.0 LANGUAGES CXX)
function(add_matlib_executable target_name)
add_matlib_target(${target_name} TRUE ${ARGN})
endfunction()
function(add_matlib_library target_name)
add_matlib_target(${target_name} FALSE ${ARGN})
endfunction()
function(add_matlib_target target_name is_executable)
set(unrolled_files "")
set(flags WIN32_EXECUTABLE MACOSX_BUNDLE EXCLUDE_FROM_ALL)
cmake_parse_arguments(arg "${flags}" "" "" ${ARGN})
if (${is_executable} AND NOT TARGET target_name)
add_executable(${target_name})
else()
add_library(${target_name} STATIC)
endif()
get_target_property(directory ${target_name} SOURCE_DIR)
if (USE_RVVU OR USE_RVVF)
foreach(original_file ${arg_UNPARSED_ARGUMENTS})
get_filename_component(basename ${original_file} NAME_WE)
get_filename_component(extension ${original_file} EXT)
set(unrolled_file "${directory}/${basename}_rvvu${extension}")
set(preprocessed_file "{directory}/${basename}.ii")
set(unrolled_file "${CMAKE_CURRENT_BINARY_DIR}/${basename}_rvvu${extension}")
set(preprocessed_file "${CMAKE_CURRENT_BINARY_DIR}/${basename}.ii")
set(unroller_command $<IF:$<BOOL:${USE_RVVF}>,matlib_rvvf.py,matlib_rvvu.py>)
add_custom_command(
OUTPUT "${unrolled_file}"
COMMAND "${CMAKE_CXX_COMPILER}" $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -P -o "${preprocessed_file}" -E "${directory}/${original_file}"
COMMAND "python3" ${MATLIB_INCLUDE_PATH}/${unroller_command} ${preprocessed_file} ${USE_LMUL} > ${unrolled_file}
DEPENDS "${original_file}" "${MATLIB_INCLUDE_PATH}/matlib_rvvf.py"
DEPENDS "${original_file}" "${MATLIB_INCLUDE_PATH}/matlib_rvvu.py"
DEPENDS "${original_file}" "${MATLIB_INCLUDE_PATH}/matlib_rvvu.h"
VERBATIM COMMAND_EXPAND_LISTS
)
list(APPEND unrolled_files ${unrolled_file})
endforeach()
target_sources(${target_name} PRIVATE ${unrolled_files})
else(USE_RVVU OR USE_RVVF)
target_sources(${target_name} PRIVATE ${arg_UNPARSED_ARGUMENTS})
endif(USE_RVVU OR USE_RVVF)
endfunction()
if(USE_RVV OR USE_RVVU OR USE_RVVF OR USE_CPU)
add_matlib_library(matlib src/matlib.cpp)
target_include_directories(matlib PUBLIC ${MATLIB_INCLUDE_PATH} include)
add_matlib_executable(test_matlib_rvv test/test_matlib_rvv.cpp)
target_link_libraries(test_matlib_rvv LINK_PUBLIC matlib)
target_include_directories(test_matlib_rvv PUBLIC matlib)
add_matlib_executable(test_matperf_rvv test/test_matperf_rvv.cpp)
target_link_libraries(test_matperf_rvv LINK_PUBLIC matlib)
target_include_directories(test_matperf_rvv PUBLIC matlib)
endif(USE_RVV OR USE_RVVU OR USE_RVVF OR USE_CPU)