diff options
| author | OpportunityLiu <[email protected]> | 2025-12-01 12:18:10 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2025-12-01 12:18:10 +0800 |
| commit | 35502fa3b332a70811baf75fc91c3daa49380eb5 (patch) | |
| tree | 373c5b43518cd7b3239df5dce9fdbe81edd9be81 | |
| parent | c7e1e6519762517d87e366a9ec7569aa49273f48 (diff) | |
fix check clang cuda flags, Fixes #7077
| -rw-r--r-- | xmake/modules/core/tools/gcc/has_flags.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/xmake/modules/core/tools/gcc/has_flags.lua b/xmake/modules/core/tools/gcc/has_flags.lua index 4d001ef6e..b9e37f5ae 100644 --- a/xmake/modules/core/tools/gcc/has_flags.lua +++ b/xmake/modules/core/tools/gcc/has_flags.lua @@ -22,6 +22,8 @@ import("core.cache.detectcache") import("core.language.language") import("core.base.hashset") +import("core.base.semver") +import("detect.sdks.find_cuda") -- is linker? function _islinker(flags, opt) @@ -109,6 +111,29 @@ function _check_try_running(flags, opt, islinker) return _try_running(opt.program, table.join(flags, "-o", tmpfile, sourcefile), opt) end + -- check flags for clang cuda compiler + if opt.toolkind == "cu" then + local cuda_gpu_flags = false + for _, flag in ipairs(flags) do + if flag:startswith("--cuda-gpu-arch=") then + cuda_gpu_flags = true + break + end + end + + local args = table.join(flags, "-c", "-o", tmpfile, sourcefile) + if not cuda_gpu_flags then + local cuda = get_config("cuda") + local cuda_sdk = find_cuda(cuda and cuda or nil) + local cuda_sdkver = cuda_sdk and cuda_sdk.sdkver or "7.0" + if cuda_sdkver and semver.compare(cuda_sdkver, "12.0") >= 0 then + table.insert(args, 1, "--cuda-gpu-arch=sm_80") + end + end + + return _try_running(opt.program, args, opt) + end + -- check flags for compiler -- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage return _try_running(opt.program, table.join(flags, "-S", "-o", tmpfile, sourcefile), opt) |
