Skip to content

Commit

Permalink
change to wrap FetchContent calls
Browse files Browse the repository at this point in the history
still needs tests created
  • Loading branch information
lawruble13 committed Jul 18, 2024
1 parent 7ab09c9 commit 102da84
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
35 changes: 26 additions & 9 deletions share/rocmcmakebuildtools/cmake/ROCMChecks.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ######################################################################################################################
# Copyright (C) 2019-2021 Advanced Micro Devices, Inc.
# Copyright (C) 2019-2024 Advanced Micro Devices, Inc.
# ######################################################################################################################

set(ROCM_WARN_TOOLCHAIN_VAR
Expand All @@ -20,14 +20,15 @@ define_property(GLOBAL PROPERTY ROCMChecksSuppressed INHERITED
BRIEF_DOCS "Property to indicate suppression of ROCMChecks."
FULL_DOCS "Property to indicate suppression of ROCMChecks."
)
set_property(GLOBAL PROPERTY ROCMChecksSuppressed 0)
define_property(GLOBAL PROPERTY ROCMChecksWatched
BRIEF_DOCS "Property recording variables watched by ROCMChecks."
FULL_DOCS "Property recording variables watched by ROCMChecks."
)

function(rocm_check_toolchain_var var access value list_file)
get_property(suppressed GLOBAL PROPERTY ROCMChecksSuppressed)
if ((NOT "${suppressed}" STREQUAL "") AND suppressed)
if (suppressed GREATER 0)
return()
endif()
set(message_type STATUS)
Expand Down Expand Up @@ -69,20 +70,36 @@ function(rocm_variable_watch VAR)
variable_watch("${VAR}" rocm_check_toolchain_var)
endfunction()

function(add_subdirectory_unchecked source_directory)
function(_push_watched_vars)
get_property(watched_vars GLOBAL PROPERTY ROCMChecksWatched)
set_property(GLOBAL PROPERTY ROCMChecksSuppressed "ON")
get_property(current_suppression GLOBAL PROPERTY ROCMChecksSuppressed)
math(EXPR current_suppression "${current_suppression} + 1")
set_property(GLOBAL PROPERTY ROCMChecksSuppressed "${current_suppression}")
foreach(var IN_LISTS watched_vars)
set(_rocmchecks_restore_${var} "${var}" CACHE INTERNAL)
set(_rocmchecks_restore_var_${var}_${current_suppression} "${var}" CACHE INTERNAL)
endforeach()
add_subdirectory(${ARGV})
set(_rocmchecks_restore_varlist_${current_suppression} "${watched_vars}" CACHE INTERNAL)
endfunction()

function(_pop_watched_vars)
get_property(current_suppression GLOBAL PROPERTY ROCMChecksSuppressed)
if(current_suppresion LESS_EQUAL 0)
message(WARNING "pop_watched_vars called while without a stack.")
return()
endif()
set(watched_vars $CACHE{_rocmchecks_restore_varlist_${current_suppression}})
unset(_rocmchecks_restore_varlist_${current_suppression} CACHE)
foreach(var IN_LISTS watched_vars)
if (DEFINED CACHE{${var}})
set(${var} "$CACHE{_rocmchecks_restore_${var}}")
# how do we restore a cache variable when we don't know its type or docstring?
set(${var} "$CACHE{_rocmchecks_restore_var_${var}_${current_suppression}}")
else()
set(${var} "$CACHE{_rocmchecks_restore_var_${var}_${current_suppression}}")
endif()
unset(_rocmchecks_restore_${var} CACHE)
unset(_rocmchecks_restore_var_${var}_${current_suppression} CACHE)
endforeach()
set_property(GLOBAL PROPERTY ROCMChecksSuppressed "OFF")
math(EXPR current_suppression "${current_suppresion} - 1")
set_property(GLOBAL PROPERTY ROCMChecksSuppressed "${current_suppression}")
endfunction()

if(UNIX AND (ROCM_WARN_TOOLCHAIN_VAR OR ROCM_ERROR_TOOLCHAIN_VAR))
Expand Down
20 changes: 20 additions & 0 deletions share/rocmcmakebuildtools/cmake/ROCMFetchContent.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ######################################################################################################################
# Copyright (C) 2024 Advanced Micro Devices, Inc.
# ######################################################################################################################

include(ROCMChecks)
include(FetchContent)
macro(_save_watched_wrapper func_name)
function(ROCM_${func_name})
set(func_ARGV ARGV)
_push_watched_vars()
${func_name}(${func_ARGV})
_pop_watched_vars()
endfunction()
endmacro()

_save_watched_wrapper(FetchContent_Declare)
_save_watched_wrapper(FetchContent_MakeAvailable)
_save_watched_wrapper(FetchContent_Populate)
_save_watched_wrapper(FetchContent_GetProperties)
_save_watched_wrapper(FetchContent_SetPopulated)

0 comments on commit 102da84

Please sign in to comment.