function(AddToPath DIR)
  if("$ENV{PATH}" MATCHES "${DIR}")
    return()
  endif()
  if(WIN32)
    set(ENV{PATH} "${DIR};$ENV{PATH}")
    if(MC_RTC_SUPERBUILD_SET_ENVIRONMENT)
      execute_process(COMMAND powershell -c "[System.Environment]::SetEnvironmentVariable('PATH', '${DIR};' + [System.Environment]::GetEnvironmentVariable('PATH', 'User'), 'User')" COMMAND_ERROR_IS_FATAL ANY)
      if(DEFINED ENV{GITHUB_ENV})
        file(APPEND "$ENV{GITHUB_ENV}" "PATH=$ENV{PATH}\n")
      endif()
    endif()
  else()
    set(ENV{PATH} "${DIR}:$ENV{PATH}")
  endif()
endfunction()

AddToPath("${CMAKE_INSTALL_PREFIX}/bin")

if(APPLE)
  if(NOT "$ENV{DYLD_LIBRARY_PATH}" MATCHES "${CMAKE_INSTALL_PREFIX}/lib")
    set(ENV{DYLD_LIBRARY_PATH} "${CMAKE_INSTALL_PREFIX}/lib:$ENV{DYLD_LIBRARY_PATH}")
  endif()
elseif(UNIX)
  if(NOT "$ENV{LD_LIBRARY_PATH}" MATCHES "${CMAKE_INSTALL_PREFIX}/lib")
    set(ENV{LD_LIBRARY_PATH} "${CMAKE_INSTALL_PREFIX}/lib:$ENV{LD_LIBRARY_PATH}")
  endif()
endif()
