Skip to content

Commit

Permalink
Add cmake target for rocm_smi
Browse files Browse the repository at this point in the history
rocm_smi will provide cmake files exporting the INCLUDE/LIBRARY targets.

Change-Id: I1943a3142bdc0abd8f03ff62e12e947aac835401
  • Loading branch information
bill-shuzhou-liu committed Oct 4, 2021
1 parent 2f84906 commit 088fe48
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,41 @@ set(CMN_INC_LIST ${CMN_INC_LIST} "${SHR_MUTEX_DIR}/shared_mutex.h")
add_subdirectory("rocm_smi")
add_subdirectory("oam")

# Create cmake target
# Add all targets to the build-tree export set
export(TARGETS ${ROCM_SMI_TARGET} ${OAM_TARGET}
FILE "${PROJECT_BINARY_DIR}/rcom_smi_target.cmake")

# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE rocm_smi)
# Create the rocm_smiConfig.cmake and rocm_smiConfigVersion files
# ... for the build tree
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
set(CONF_LIB_DIR "${PROJECT_BINARY_DIR}")
set(CONF_LIBS "${ROCM_SMI_LIB_NAME}.so")
configure_file(rocm_smi-config.cmake.in
"${PROJECT_BINARY_DIR}/rocm_smi-config.cmake" @ONLY)
# ... for the install tree
set(CONF_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/rocm_smi/include")
set(CONF_LIB_DIR "${CMAKE_INSTALL_PREFIX}/rocm_smi/lib")
set(CONF_LIBS "${ROCM_SMI_LIB_NAME}.so")
configure_file(rocm_smi-config.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/rocm_smi-config.cmake" @ONLY)
# ... for both
configure_file(rocm_smi-config-version.cmake.in
"${PROJECT_BINARY_DIR}/rocm_smi-config-version.cmake" @ONLY)
# Install the rocm_smi-config.cmake and rocm_smi-config-version.cmake
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/rocm_smi-config.cmake"
"${PROJECT_BINARY_DIR}/rocm_smi-config-version.cmake"
DESTINATION "${ROCM_SMI}/lib/cmake" COMPONENT dev)
# Install the export set for use with the install-tree
install(EXPORT rocm_smiTargets DESTINATION
"${ROCM_SMI}/lib/cmake" COMPONENT dev)



###########################
# Packaging directives
###########################
Expand Down
8 changes: 8 additions & 0 deletions oam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,16 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL Release)
endif()
endif ()

# use the target_include_directories() command to specify the include directories for the target
target_include_directories(${OAM_TARGET}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:{OAM_NAME}/include>")


## Add the install directives for the runtime library.
install(TARGETS ${OAM_TARGET}
EXPORT rocm_smiTargets
LIBRARY DESTINATION ${OAM_NAME}/lib
ARCHIVE DESTINATION ${OAM_NAME}/lib
COMPONENT ${OAM_COMPONENT})
Expand Down
12 changes: 12 additions & 0 deletions rocm_smi-config-version.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(PACKAGE_VERSION "@ROCM_SMI_VERSION@")

# Check whether the requested PACKAGE_FIND_VERSION is compatible
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()

18 changes: 18 additions & 0 deletions rocm_smi-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# - Config file for the rocm_smi package
# It defines the following variables
# ROCM_SMI_INCLUDE_DIRS - include directories for rocm_smi
# ROCM_SMI_LIBRARIES - libraries to link against

# Compute paths
get_filename_component(ROCM_SMI_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(ROCM_SMI_INCLUDE_DIR "@CONF_INCLUDE_DIRS@")
set(ROCM_SMI_LIB_DIR "@CONF_LIB_DIR@")

# Our library dependencies (contains definitions for IMPORTED targets)
if(NOT TARGET rocm_smi AND NOT rocm_smi_BINARY_DIR)
include("${ROCM_SMI_CMAKE_DIR}/rocm_smiTargets.cmake")
endif()

# These are IMPORTED targets created by RocmSmiTargets.cmake
set(ROCM_SMI_LIBRARIES "@CONF_LIBS@")

9 changes: 9 additions & 0 deletions rocm_smi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ target_link_libraries(${ROCM_SMI_TARGET} pthread rt)
target_include_directories(${ROCM_SMI_TARGET} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR} ${COMMON_PROJ_ROOT}/common/shared_mutex)

# use the target_include_directories() command to specify the include directories for the target
target_include_directories(${ROCM_SMI_TARGET}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${ROCM_SMI}/include>"
)


## Set the VERSION and SOVERSION values
set_property(TARGET ${ROCM_SMI_TARGET} PROPERTY
SOVERSION "${VERSION_MAJOR}")
Expand Down Expand Up @@ -113,6 +121,7 @@ if(${BUILD_SHARED_LIBS})
endif()
## Add the install directives for the runtime library.
install(TARGETS ${ROCM_SMI_TARGET}
EXPORT rocm_smiTargets
LIBRARY DESTINATION ${ROCM_SMI}/lib
ARCHIVE DESTINATION ${ROCM_SMI}/lib
COMPONENT ${ROCM_SMI_COMPONENT})
Expand Down

0 comments on commit 088fe48

Please sign in to comment.