| 1 |
# SPDX-License-Identifier: BSD-2-Clause |
| 2 |
# |
| 3 |
# Copyright (c) 2025 Intel Corporation |
| 4 |
# |
| 5 |
# CMakeLists.txt for workloads |
| 6 |
# |
| 7 |
# Automatically compile all workloads in subdirectories |
| 8 |
|
| 9 |
# Function to create a workload shared library |
| 10 |
function(add_workload_library workload_name workload_dir) |
| 11 |
# Check if the workload directory exists and has .c files |
| 12 |
file(GLOB WORKLOAD_SOURCES "${workload_dir}/*.c") |
| 13 |
|
| 14 |
if(WORKLOAD_SOURCES) |
| 15 |
# Create the shared library target |
| 16 |
add_library(${workload_name} SHARED ${WORKLOAD_SOURCES}) |
| 17 |
|
| 18 |
# Set properties for shared library |
| 19 |
set_target_properties(${workload_name} PROPERTIES |
| 20 |
POSITION_INDEPENDENT_CODE ON |
| 21 |
PREFIX "" # Remove lib prefix |
| 22 |
SUFFIX ".so" |
| 23 |
) |
| 24 |
|
| 25 |
# Set compile options |
| 26 |
target_compile_options(${workload_name} PRIVATE |
| 27 |
-Wall |
| 28 |
-Wextra |
| 29 |
-fPIC |
| 30 |
-std=gnu99 |
| 31 |
) |
| 32 |
|
| 33 |
# Allow undefined symbols (they will be resolved by the main application) |
| 34 |
target_link_options(${workload_name} PRIVATE |
| 35 |
-Wl,--allow-shlib-undefined |
| 36 |
) |
| 37 |
|
| 38 |
# Include the src directory for log.h and other headers |
| 39 |
target_include_directories(${workload_name} PRIVATE |
| 40 |
"${CMAKE_SOURCE_DIR}/src" |
| 41 |
) |
| 42 |
|
| 43 |
# Set output directory to the workload's directory |
| 44 |
set_target_properties(${workload_name} PROPERTIES |
| 45 |
LIBRARY_OUTPUT_DIRECTORY "${workload_dir}" |
| 46 |
) |
| 47 |
|
| 48 |
message(STATUS "Added workload: ${workload_name} from ${workload_dir}") |
| 49 |
endif() |
| 50 |
endfunction() |
| 51 |
|
| 52 |
# Get all subdirectories in the workloads directory |
| 53 |
file(GLOB WORKLOAD_DIRS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*") |
| 54 |
|
| 55 |
# Process each subdirectory |
| 56 |
foreach(WORKLOAD_DIR ${WORKLOAD_DIRS}) |
| 57 |
set(FULL_WORKLOAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${WORKLOAD_DIR}") |
| 58 |
|
| 59 |
# Check if it's a directory (not a file) and currently only for x86_64 |
| 60 |
if(IS_DIRECTORY "${FULL_WORKLOAD_DIR}" AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") |
| 61 |
# Use the directory name as the workload name |
| 62 |
add_workload_library("${WORKLOAD_DIR}" "${FULL_WORKLOAD_DIR}") |
| 63 |
endif() |
| 64 |
endforeach() |