diff --git a/CMakeLists.txt b/CMakeLists.txt index 4100ac21..e6440f42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 "") diff --git a/share/rocmcmakebuildtools/cmake/ROCMTest.cmake b/share/rocmcmakebuildtools/cmake/ROCMTest.cmake index f534ea42..2d0d2391 100644 --- a/share/rocmcmakebuildtools/cmake/ROCMTest.cmake +++ b/share/rocmcmakebuildtools/cmake/ROCMTest.cmake @@ -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) @@ -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} + $<$>:-D$, -D>> + $<$>:$, >> + -M + $<$>:$, >> + $<$>:-I$, -I>> + $<$>:$/$, $/>> + 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}) diff --git a/test/fail/simple-hip-test.cmake b/test/fail/simple-hip-test.cmake new file mode 100644 index 00000000..396d8723 --- /dev/null +++ b/test/fail/simple-hip-test.cmake @@ -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) diff --git a/test/libsimplehiptest/CMakeLists.txt b/test/libsimplehiptest/CMakeLists.txt new file mode 100644 index 00000000..daa6298b --- /dev/null +++ b/test/libsimplehiptest/CMakeLists.txt @@ -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) diff --git a/test/libsimplehiptest/LICENSE b/test/libsimplehiptest/LICENSE new file mode 100644 index 00000000..6d0ea731 --- /dev/null +++ b/test/libsimplehiptest/LICENSE @@ -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". \ No newline at end of file diff --git a/test/libsimplehiptest/include/hip_runtime.h b/test/libsimplehiptest/include/hip_runtime.h new file mode 100644 index 00000000..c4eaf345 --- /dev/null +++ b/test/libsimplehiptest/include/hip_runtime.h @@ -0,0 +1,6 @@ +#ifndef GUARD_HIP_RUNTIME_H +#define GUARD_HIP_RUNTIME_H + +void hip_function(); + +#endif diff --git a/test/libsimplehiptest/include/simple.h b/test/libsimplehiptest/include/simple.h new file mode 100644 index 00000000..e17a9e2b --- /dev/null +++ b/test/libsimplehiptest/include/simple.h @@ -0,0 +1,12 @@ +/******************************************************************************* + * Copyright (C) 2017 Advanced Micro Devices, Inc. + ******************************************************************************/ + + +#ifndef GUARD_SIMPLE_H +#define GUARD_SIMPLE_H + +void simple(); + + +#endif diff --git a/test/libsimplehiptest/main.cpp b/test/libsimplehiptest/main.cpp new file mode 100644 index 00000000..2629b287 --- /dev/null +++ b/test/libsimplehiptest/main.cpp @@ -0,0 +1,7 @@ +#include "hip_runtime.h" + +void simple(); + +int main() { + simple(); +} diff --git a/test/libsimplehiptest/simple.cpp b/test/libsimplehiptest/simple.cpp new file mode 100644 index 00000000..c5ae3d49 --- /dev/null +++ b/test/libsimplehiptest/simple.cpp @@ -0,0 +1,7 @@ +/******************************************************************************* + * Copyright (C) 2017 Advanced Micro Devices, Inc. + ******************************************************************************/ + + +void simple() +{} diff --git a/test/libsimplehiptest/test.cpp b/test/libsimplehiptest/test.cpp new file mode 100644 index 00000000..3035b313 --- /dev/null +++ b/test/libsimplehiptest/test.cpp @@ -0,0 +1,6 @@ + +void simple(); + +int main() { + simple(); +} diff --git a/test/libsimplehiptest/test/CMakeLists.txt b/test/libsimplehiptest/test/CMakeLists.txt new file mode 100644 index 00000000..664e3a42 --- /dev/null +++ b/test/libsimplehiptest/test/CMakeLists.txt @@ -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)