Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (C) 2017 Advanced Micro Devices, Inc.
################################################################################

cmake_minimum_required (VERSION 3.6)
cmake_minimum_required (VERSION 3.16)

set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "")

Expand Down
46 changes: 45 additions & 1 deletion share/rocmcmakebuildtools/cmake/ROCMTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ macro(rocm_enable_test_package NAME)
endmacro()

if(POLICY CMP0079)
cmake_policy(SET CMP0079 OLD)
cmake_policy(SET CMP0079 NEW)
endif()

add_library(rocm_test_dependencies INTERFACE)
Expand Down Expand Up @@ -289,6 +289,50 @@ function(rocm_test_headers)
endforeach()
endfunction()

function(rocm_test_target_hip_runtime_include)
set(options)
set(oneValueArgs TARGET)
set(multiValueArgs)

cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(PARSE_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown keywords given to rocm_test_target_hip_runtime_include(): \"${PARSE_UNPARSED_ARGUMENTS}\"")
endif()

set(NAME ${PARSE_TARGET}_includes_hip_runtime)
set(TEST_DIR test_${NAME})

file(
GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${TEST_DIR}/run.cmake"
CONTENT
"
execute_process(
COMMAND
${CMAKE_CXX_COMPILER}
$<$<BOOL:$<TARGET_PROPERTY:${PARSE_TARGET},COMPILE_DEFINITIONS>>:-D$<JOIN:$<TARGET_PROPERTY:${PARSE_TARGET},COMPILE_DEFINITIONS>, -D>>
$<$<BOOL:$<TARGET_PROPERTY:${PARSE_TARGET},COMPILE_OPTIONS>>:$<JOIN:$<TARGET_PROPERTY:${PARSE_TARGET},COMPILE_OPTIONS>, >>
-M
$<$<BOOL:$<TARGET_PROPERTY:${PARSE_TARGET},COMPILE_FEATURES>>:$<JOIN:$<TARGET_PROPERTY:${PARSE_TARGET},COMPILE_FEATURES>, >>
$<$<BOOL:$<TARGET_PROPERTY:${PARSE_TARGET},INCLUDE_DIRECTORIES>>:-I$<JOIN:$<TARGET_PROPERTY:${PARSE_TARGET},INCLUDE_DIRECTORIES>, -I>>
$<$<BOOL:$<TARGET_PROPERTY:${PARSE_TARGET},SOURCES>>:$<TARGET_PROPERTY:${PARSE_TARGET},SOURCE_DIR>/$<JOIN:$<TARGET_PROPERTY:${PARSE_TARGET},SOURCES>, $<TARGET_PROPERTY:${PARSE_TARGET},SOURCE_DIR>/>>
OUTPUT_VARIABLE TARGET_COMMAND
RESULT_VARIABLE RESULT
)
if(NOT RESULT EQUAL 0)
message(FATAL_ERROR \"Test failed due to compilation error.\")
# TODO: what should we do if this fails?
else()
if(TARGET_COMMAND MATCHES \"hip_runtime.h\")
message(FATAL_ERROR \"Test failed, executable includes hip_runtime.h\")
endif()
endif()
")
set(COMMAND ${CMAKE_COMMAND} -P "${TEST_DIR}/run.cmake")
rocm_add_test(NAME ${NAME} COMMAND ${COMMAND})
rocm_install_test(FILES "${CMAKE_CURRENT_BINARY_DIR}/${TEST_DIR}/run.cmake" DESTINATION "${TEST_DIR}")
endfunction()

function(rocm_test_install_ctest)
file(WRITE ${_rocm_test_config_file}.in "")
include(${_rocm_test_run_save_tests})
Expand Down
7 changes: 7 additions & 0 deletions test/fail/simple-hip-test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ######################################################################################################################
# Copyright (C) 2023 Advanced Micro Devices, Inc.
# ######################################################################################################################

install_dir(${TEST_DIR}/libsimplehiptest TARGETS check install-tests)
test_expect_file(${PREFIX}/libexec/installed-tests/simple/CTestTestfile.cmake)
test_exec(COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure WORKING_DIRECTORY ${PREFIX}/libexec/installed-tests/simple)
41 changes: 41 additions & 0 deletions test/libsimplehiptest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
################################################################################
# Copyright (C) 2017 Advanced Micro Devices, Inc.
################################################################################


cmake_minimum_required (VERSION 3.16)
project(simple CXX)

find_package(ROCmCMakeBuildTools)

include(ROCMInstallTargets)
include(ROCMPackageConfigHelpers)
include(ROCMSetupVersion)
include(ROCMInstallSymlinks)
include(ROCMCreatePackage)
include(ROCMTest)

rocm_setup_version(VERSION 1.0.0)

rocm_enable_test_package(simple)

rocm_create_package(
NAME simple
MAINTAINER "Amd amd@amd.com"
PTH
LDCONFIG)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)

add_library(simple simple.cpp)
rocm_set_soversion(simple 1.1.2)

add_executable(simple-main main.cpp)
target_link_libraries(simple-main simple)

rocm_install_targets(TARGETS simple simple-main INCLUDE include)
rocm_export_targets(TARGETS simple)

add_subdirectory(test)
3 changes: 3 additions & 0 deletions test/libsimplehiptest/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is a placeholder license file for the purposes of testing, and is not the license for this repository or the files
contained in this directory. The license for rocm-cmake (including all files in this directory) can be located at
"https://github.com/RadeonOpenCompute/rocm-cmake/blob/master/LICENSE".
6 changes: 6 additions & 0 deletions test/libsimplehiptest/include/hip_runtime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef GUARD_HIP_RUNTIME_H
#define GUARD_HIP_RUNTIME_H

void hip_function();

#endif
12 changes: 12 additions & 0 deletions test/libsimplehiptest/include/simple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*******************************************************************************
* Copyright (C) 2017 Advanced Micro Devices, Inc.
******************************************************************************/


#ifndef GUARD_SIMPLE_H
#define GUARD_SIMPLE_H

void simple();


#endif
7 changes: 7 additions & 0 deletions test/libsimplehiptest/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "hip_runtime.h"

void simple();

int main() {
simple();
}
7 changes: 7 additions & 0 deletions test/libsimplehiptest/simple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*******************************************************************************
* Copyright (C) 2017 Advanced Micro Devices, Inc.
******************************************************************************/


void simple()
{}
6 changes: 6 additions & 0 deletions test/libsimplehiptest/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

void simple();

int main() {
simple();
}
6 changes: 6 additions & 0 deletions test/libsimplehiptest/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


rocm_test_link_libraries(simple)
rocm_add_test_executable(simple-test ../test.cpp)
rocm_test_headers(HEADERS ../include/simple.h)
rocm_test_target_hip_runtime_include(TARGET simple-main)