function(detect_llvm_version outputVersionVar outputDirVar libDir)
	file(GLOB FILEZ LIST_DIRECTORIES ON "${libDir}/*")
	set(latestLLVMVersion "")
	set(latestLLVMVersionDir "")
	foreach(file ${FILEZ})
		if(IS_DIRECTORY "${file}")
			get_filename_component(dirName "${file}" NAME)
			string(REGEX MATCH "^llvm-(([0-9]+)(.[0-9]+)*)$" MATCHED "${dirName}")
			if(MATCHED)
				set(libgccVersionCandidate "${CMAKE_MATCH_1}")
				message(STATUS "Found LLVM version candidate: ${libgccVersionCandidate}")
				if(libgccVersionCandidate VERSION_GREATER latestLLVMVersion)
					set(latestLLVMVersion "${libgccVersionCandidate}")
					set(latestLLVMVersionDir "${dirName}")
				endif()
			endif()
		endif()
	endforeach()
	if(latestLLVMVersion)
		set(latestLLVMVersionDir "${libDir}/${latestLLVMVersionDir}")
		set("${outputDirVar}" "${latestLLVMVersionDir}" PARENT_SCOPE)
		set("${outputVersionVar}" "${latestLLVMVersion}" PARENT_SCOPE)
		message(STATUS "Detected LLVM version: ${latestLLVMVersion}")
		message(STATUS "In directory: ${latestLLVMVersionDir}")
	endif()
endfunction()
