Files
TheRock/rocm-systems/projects/hipfile/cmake/AISAddLibraries.cmake
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

101 lines
3.6 KiB
CMake

# Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
#
# SPDX-License-Identifier: MIT
include(AISCompilerOptions)
include(CheckLinkerFlag)
# Add a library using AIS build conventions. Shared vs. static
# is decided by the BUILD_SHARED_LIBS option and only one can
# be built at a time (like the rest of ROCm).
#
# Parameters:
# NAME <name> The name of the libraries to create
# DETAIL "amd"|"nvidia" Whether this is an AMD or NVIDIA target
# LIBINCL <path> Path to installed include files (e.g., hipfile.h)
# SYSINCLS [path1 [path2 ...]] Paths to other include dirs
# SRCS [src1 [src2 ...]] The source files
# LIBS [lib1, [lib2 ...]] List of external library dependencies
function(ais_add_libraries)
# Parse arguments
set(options) # None at this time
set(oneValueArgs NAME DETAIL LIBINCL)
set(multiValueArgs SRCS SYSINCLS LIBS)
cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# Add the library target
add_library(${arg_NAME} ${arg_SRCS})
# Set C++ standard
target_compile_features(${arg_NAME} PUBLIC cxx_std_${AIS_CXX_STANDARD})
set_target_properties(${arg_NAME} PROPERTIES CXX_EXTENSIONS OFF)
# Set position-independent code
set_target_properties(${arg_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
# Add version numbers
set_target_properties(${arg_NAME} PROPERTIES VERSION ${AIS_LIBRARY_VERSION})
if(BUILD_SHARED_LIBS)
set_target_properties(${arg_NAME} PROPERTIES SOVERSION ${AIS_LIBRARY_SOVERSION})
endif()
# Add dependencies on external libraries
foreach(lib IN LISTS arg_LIBS)
find_library(${arg_NAME}_${lib}_LIBRARY NAMES ${lib})
if(NOT ${arg_NAME}_${lib}_LIBRARY)
message(FATAL_ERROR "lib${lib} not found")
endif()
target_link_libraries(${arg_NAME} PRIVATE ${${arg_NAME}_${lib}_LIBRARY})
endforeach()
if(BUILD_TESTING)
target_compile_definitions(${arg_NAME} PRIVATE AIS_TESTING)
endif()
if(arg_DETAIL STREQUAL "nvidia")
target_compile_definitions(${arg_NAME} PRIVATE __HIP_PLATFORM_NVIDIA__)
else()
target_compile_definitions(${arg_NAME} PRIVATE __HIP_PLATFORM_AMD__)
endif()
# Set the library name, minus the .a, .so, or whatever
set_target_properties(${arg_NAME} PROPERTIES OUTPUT_NAME ${arg_NAME})
# Set the public include paths (these are installed libraries)
target_include_directories(${arg_NAME}
PUBLIC
$<BUILD_INTERFACE:${arg_LIBINCL}>
$<INSTALL_INTERFACE:include>
)
# Add other include paths
foreach(incl IN LISTS arg_SYSINCLS)
target_include_directories(${arg_NAME} SYSTEM PRIVATE ${incl})
endforeach()
# Add libraries and headers for NVIDIA targets
if(arg_DETAIL STREQUAL "nvidia")
target_include_directories(${arg_NAME}
SYSTEM
PRIVATE
${HIP_INCLUDE_DIRS}
${CUDAToolkit_INCLUDE_DIRS}
)
target_link_libraries(${arg_NAME} PRIVATE ${CUFILE_LIBRARY})
endif()
target_link_libraries(${arg_NAME} PRIVATE hip::host)
# Add link options (mainly for hardening)
check_linker_flag(CXX "-Wl,-z,noexecstack" LINKER_SUPPORTS_NOEXECSTACK)
if(LINKER_SUPPORTS_NOEXECSTACK)
target_link_options(${arg_NAME} PRIVATE "-Wl,-z,noexecstack")
endif()
# Add the common include path
target_include_directories(${arg_NAME} PRIVATE "${HIPFILE_ROOT_PATH}/shared")
# Set compiler flags
ais_set_compiler_flags(${arg_NAME})
endfunction()