|
| 1 | +cmake_minimum_required(VERSION 3.10) |
| 2 | +project(Intrinsic) |
| 3 | + |
| 4 | +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 5 | + |
| 6 | +if(NOT CMAKE_BUILD_TYPE) |
| 7 | + message(STATUS "Build type not specified, defaulting to Release") |
| 8 | + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose build type" FORCE) |
| 9 | +endif() |
| 10 | + |
| 11 | +message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") |
| 12 | + |
| 13 | +add_compile_options( |
| 14 | + $<$<CONFIG:Release>:-O3> |
| 15 | + $<$<CONFIG:Debug>:-Og> |
| 16 | +) |
| 17 | +add_subdirectory(3rdparty/googletest) |
| 18 | +add_subdirectory(3rdparty/benchmark) |
| 19 | +set(BUILD_VERSION "scalar" CACHE STRING "Build version (scalar, native, custom)") |
| 20 | +set_property(CACHE BUILD_VERSION PROPERTY STRINGS scalar native custom) |
| 21 | +if(NOT DEFINED TARGET_ARCH) |
| 22 | + if(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64") |
| 23 | + set(TARGET_ARCH "riscv") |
| 24 | + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm") |
| 25 | + set(TARGET_ARCH "arm") |
| 26 | + else(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") |
| 27 | + set(TARGET_ARCH "avx2") |
| 28 | + endif() |
| 29 | +endif() |
| 30 | + |
| 31 | +message(STATUS "Selected build version: ${TARGET_ARCH} - ${BUILD_VERSION}") |
| 32 | +set(BUILD_CASES "" CACHE STRING "Semicolon-separated list of cases to build (e.g., 'saxpy;merge'). Leave empty to build all available cases.") |
| 33 | +if(BUILD_CASES) |
| 34 | + message(STATUS "Building only specified cases: ${BUILD_CASES}") |
| 35 | +endif() |
| 36 | + |
| 37 | +add_subdirectory(src/) |
| 38 | +add_subdirectory(test/) |
| 39 | +add_subdirectory(perf/) |
| 40 | +if(NOT DEFINED SRC_FILES_FOUND) |
| 41 | + message(FATAL_ERROR "SRC_FILES_FOUND variable not set by src/CMakeLists.txt") |
| 42 | +endif() |
| 43 | +set(SRC_BASENAMES "") |
| 44 | +foreach(src_file IN LISTS SRC_FILES_FOUND) |
| 45 | + get_filename_component(src_basename ${src_file} NAME_WE) |
| 46 | + list(APPEND SRC_BASENAMES ${src_basename}) |
| 47 | +endforeach() |
| 48 | +set(FILTERED_TEST_SOURCES "") |
| 49 | +foreach(test_file IN LISTS TEST_SOURCES) |
| 50 | + get_filename_component(test_basename ${test_file} NAME_WE) |
| 51 | + if(NOT ${test_basename} IN_LIST SRC_BASENAMES) |
| 52 | + message(STATUS "Excluding test: ${test_basename}") |
| 53 | + continue() |
| 54 | + endif() |
| 55 | + if(BUILD_CASES) |
| 56 | + if(NOT ${test_basename} IN_LIST BUILD_CASES) |
| 57 | + message(STATUS "Excluding test: ${test_basename} (not in BUILD_CASES)") |
| 58 | + continue() |
| 59 | + endif() |
| 60 | + endif() |
| 61 | + |
| 62 | + list(APPEND FILTERED_TEST_SOURCES ${test_file}) |
| 63 | + message(STATUS "Including test: ${test_basename}") |
| 64 | +endforeach() |
| 65 | +set(FILTERED_PERF_SOURCES "") |
| 66 | +foreach(perf_file IN LISTS PERF_SOURCES) |
| 67 | + get_filename_component(perf_basename ${perf_file} NAME_WE) |
| 68 | + if(NOT ${perf_basename} IN_LIST SRC_BASENAMES) |
| 69 | + message(STATUS "Excluding perf: ${perf_basename}") |
| 70 | + continue() |
| 71 | + endif() |
| 72 | + if(BUILD_CASES) |
| 73 | + if(NOT ${perf_basename} IN_LIST BUILD_CASES) |
| 74 | + message(STATUS "Excluding perf: ${perf_basename} (not in BUILD_CASES)") |
| 75 | + continue() |
| 76 | + endif() |
| 77 | + endif() |
| 78 | + |
| 79 | + list(APPEND FILTERED_PERF_SOURCES ${perf_file}) |
| 80 | + message(STATUS "Including perf: ${perf_basename}") |
| 81 | +endforeach() |
| 82 | + |
| 83 | +add_executable(intrinsicTest intrinsicTest.cpp ${FILTERED_TEST_SOURCES}) |
| 84 | +target_link_libraries(intrinsicTest PRIVATE static_source) |
| 85 | +target_link_libraries(intrinsicTest PRIVATE gtest) |
| 86 | + |
| 87 | +add_executable(intrinsicPerf intrinsicPerf.cpp ${FILTERED_PERF_SOURCES}) |
| 88 | +target_link_libraries(intrinsicPerf PRIVATE static_source) |
| 89 | +target_link_libraries(intrinsicPerf PRIVATE benchmark::benchmark) |
0 commit comments