[SWDEV-431345][SWDEV-432633] toplevel cmake for hip samples

Change-Id: If22e7e96604f184458cc6ab6bb9945152f9359e0


[ROCm/hip-tests commit: 7481de706f]
Tento commit je obsažen v:
Rahul Manocha
2023-11-13 19:12:54 +00:00
rodič 6259d20646
revize b821fdbfba
33 změnil soubory, kde provedl 461 přidání a 89 odebrání
@@ -27,33 +27,42 @@ set(CMAKE_BUILD_TYPE Release)
# Turn static library generation ON
option(BUILD_SHARED_LIBS "Build as a shared library" OFF)
set(CPP_SOURCES hipDevice.cpp)
set(CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/hipDevice.cpp)
# For windows, We need to tell cmake how to create static library.
if (WIN32)
set (CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> /out:<TARGET> <LINK_FLAGS> <OBJECTS>")
endif()
if(TARGET build_cookbook)
set(EXCLUDE_OPTION EXCLUDE_FROM_ALL)
else()
set(EXCLUDE_OPTION )
endif()
# Generate static lib libHipDevice.a
add_library(HipDevice STATIC ${CPP_SOURCES})
add_library(HipDevice ${EXCLUDE_OPTION} STATIC ${CPP_SOURCES})
target_compile_options(HipDevice PRIVATE -fgpu-rdc)
target_link_libraries(HipDevice PRIVATE -fgpu-rdc)
target_include_directories(HipDevice PRIVATE ${CMAKE_PREFIX_PATH}/hsa/include)
# Create test executable that uses libHipDevice.a
set(TEST_SOURCES ${CMAKE_SOURCE_DIR}/hipMain2.cpp)
set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/hipMain2.cpp)
add_executable(test_device_static ${TEST_SOURCES})
add_executable(test_device_static ${EXCLUDE_OPTION} ${TEST_SOURCES})
add_dependencies(test_device_static HipDevice)
target_compile_options(test_device_static PRIVATE -fgpu-rdc)
# For windows, Change in a way to pass lib details
if (WIN32)
target_link_libraries(test_device_static PRIVATE -lHipDevice -L${CMAKE_BINARY_DIR})
target_link_libraries(test_device_static PRIVATE -lHipDevice -L${CMAKE_CURRENT_BINARY_DIR})
else()
target_link_libraries(test_device_static PRIVATE HipDevice)
endif()
target_link_libraries(test_device_static PRIVATE -fgpu-rdc amdhip64 amd_comgr)
if(TARGET build_cookbook)
add_dependencies(build_cookbook HipDevice test_device_static)
endif()
@@ -27,26 +27,32 @@ set(CMAKE_BUILD_TYPE Release)
# Turn static library generation ON
option(BUILD_SHARED_LIBS "Build as a shared library" OFF)
set(CPP_SOURCES hipOptLibrary.cpp)
set(CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/hipOptLibrary.cpp)
# For windows, We need to tell cmake how to create static library.
if (WIN32)
set (CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> /out:<TARGET> <LINK_FLAGS> <OBJECTS>")
endif()
if(TARGET build_cookbook)
set(EXCLUDE_OPTION EXCLUDE_FROM_ALL)
else()
set(EXCLUDE_OPTION )
endif()
set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/hipMain1.cpp)
# Generate static lib libHipOptLibrary.a.
add_library(HipOptLibrary STATIC ${CPP_SOURCES})
add_library(HipOptLibrary ${EXCLUDE_OPTION} STATIC ${CPP_SOURCES})
# Set-up the correct flags to generate the static library.
target_link_options(HipOptLibrary PRIVATE --emit-static-lib)
target_include_directories(HipOptLibrary PRIVATE /opt/rocm/hsa/include)
# Create test executable that uses libHipOptLibrary.a
set(TEST_SOURCES ${CMAKE_SOURCE_DIR}/hipMain1.cpp)
add_executable(test_opt_static ${TEST_SOURCES})
add_executable(test_opt_static ${EXCLUDE_OPTION} ${TEST_SOURCES})
add_dependencies(test_opt_static HipOptLibrary)
target_link_libraries(test_opt_static PRIVATE -lHipOptLibrary -L${CMAKE_BINARY_DIR})
target_link_libraries(test_opt_static PRIVATE -lHipOptLibrary -L${CMAKE_CURRENT_BINARY_DIR})
if (WIN32)
target_link_libraries(test_opt_static PRIVATE amdhip64 amd_comgr)
@@ -54,3 +60,6 @@ else()
target_link_libraries(test_opt_static PRIVATE amdhip64 amd_comgr hsa-runtime64::hsa-runtime64)
endif()
if(TARGET build_cookbook)
add_dependencies(build_cookbook HipOptLibrary test_opt_static)
endif()