summaryrefslogtreecommitdiffstats
path: root/premake5.lua
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-03-15 12:59:58 -0700
committerGitHub <noreply@github.com>2021-03-15 12:59:58 -0700
commit10b39e0cb545f98f1a417da8e8e52258134a3e87 (patch)
treef57192ca5b79365a40e02d64879591ed70c9975a /premake5.lua
parente428f6e6cb868e7ca487dba09f3ca5530fd85ca6 (diff)
Enable `gfx::CUDADevice` on linux. (#1756)
Diffstat (limited to 'premake5.lua')
-rw-r--r--premake5.lua90
1 files changed, 54 insertions, 36 deletions
diff --git a/premake5.lua b/premake5.lua
index 13debb57b..7052d1de9 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -351,6 +351,48 @@ function getBuildLocationName()
end
end
+-- Adds CUDA dependency to a project
+function addCUDAIfEnabled()
+ if type(cudaPath) == "string" and isTargetWindows then
+ filter {}
+ includedirs { cudaPath .. "/include" }
+ includedirs { cudaPath .. "/include", cudaPath .. "/common/inc" }
+ links { "cuda", "cudart" }
+ if optixPath then
+ defines { "RENDER_TEST_OPTIX" }
+ includedirs { optixPath .. "include/" }
+ end
+
+ filter { "platforms:x86" }
+ libdirs { cudaPath .. "/lib/Win32/" }
+
+ filter { "platforms:x64" }
+ libdirs { cudaPath .. "/lib/x64/" }
+ filter {}
+ return true
+ elseif enableCuda then
+ filter {}
+ if type(cudaPath) == "string" then
+ includedirs { cudaPath .. "/include" }
+ includedirs { cudaPath .. "/include" }
+ if optixPath then
+ defines { "GFX_OPTIX" }
+ includedirs { optixPath .. "include/" }
+ end
+ filter { "platforms:x86" }
+ libdirs { cudaPath .. "/lib32/" }
+ filter { "platforms:x64" }
+ libdirs { cudaPath .. "/lib64/" }
+ filter {}
+ links { "cuda", "cudart" }
+ else
+ print "Error: CUDA is enabled but --cuda-sdk-path is not specified."
+ end
+ return true
+ end
+ return false
+end
+
--
-- Next we will define a helper routine that all of our
-- projects will bottleneck through. Here `name` is
@@ -500,7 +542,7 @@ function toolSharedLibrary(name)
-- specifying that the project lives under the `tools/` path.
--
baseSlangProject(name .. "-tool", "tools/" .. name)
-
+
defines { "SLANG_SHARED_LIBRARY_TOOL" }
kind "SharedLib"
@@ -547,6 +589,8 @@ function example(name)
links {"X11"}
end
end
+
+ addCUDAIfEnabled();
end
--
@@ -716,7 +760,6 @@ toolSharedLibrary "render-test"
includedirs { ".", "external", "source", "tools/gfx", "tools/platform" }
links { "core", "slang", "gfx", "gfx-util", "platform" }
-
if isTargetWindows then
addSourceDir "tools/render-test/windows"
@@ -727,27 +770,14 @@ toolSharedLibrary "render-test"
-- directory into the output directory.
-- d3dcompiler_47.dll is copied from the external/slang-binaries submodule.
postbuildcommands { '"$(SolutionDir)tools\\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/%{cfg.platform:lower()}/" "%{cfg.targetdir}/" "windows-%{cfg.platform:lower()}"'}
+ if (type(cudaPath) == "string") then
+ addSourceDir "tools/render-test/cuda"
+ end
end
-
- if type(cudaPath) == "string" and isTargetWindows then
- addSourceDir "tools/render-test/cuda"
+ if addCUDAIfEnabled() then
defines { "RENDER_TEST_CUDA" }
- includedirs { cudaPath .. "/include" }
- includedirs { cudaPath .. "/include", cudaPath .. "/common/inc" }
- links { "cuda", "cudart" }
- if optixPath then
- defines { "RENDER_TEST_OPTIX" }
- includedirs { optixPath .. "include/" }
- end
-
- filter { "platforms:x86" }
- libdirs { cudaPath .. "/lib/Win32/" }
-
- filter { "platforms:x64" }
- libdirs { cudaPath .. "/lib/x64/" }
-
end
-
+
--
-- `gfx` is a abstraction layer for different GPU platforms.
--
@@ -769,6 +799,7 @@ tool "gfx"
-- Will compile across targets
addSourceDir "tools/gfx/cpu"
addSourceDir "tools/gfx/nvapi"
+ addSourceDir "tools/gfx/cuda"
-- To special case that we may be building using cygwin on windows. If 'true windows' we build for dx12/vk and run the script
-- If not we assume it's a cygwin/mingw type situation and remove files that aren't appropriate
@@ -786,22 +817,6 @@ tool "gfx"
addSourceDir "tools/gfx/d3d"
addSourceDir "tools/gfx/d3d11"
addSourceDir "tools/gfx/d3d12"
- addSourceDir "tools/gfx/cuda"
-
- if type(cudaPath) == "string" then
- defines { "GFX_ENABLE_CUDA" }
- includedirs { cudaPath .. "/include" }
- includedirs { cudaPath .. "/include", cudaPath .. "/common/inc" }
- if optixPath then
- defines { "GFX_OPTIX" }
- includedirs { optixPath .. "include/" }
- end
- links { "cuda", "cudart" }
- filter { "platforms:x86" }
- libdirs { cudaPath .. "/lib/Win32/" }
- filter { "platforms:x64" }
- libdirs { cudaPath .. "/lib/x64/" }
- end
elseif targetDetail == "mingw" or targetDetail == "cygwin" then
-- Don't support any render techs...
elseif os.target() == "macosx" then
@@ -836,6 +851,9 @@ tool "gfx"
links { "nvapi64" }
end
+ if addCUDAIfEnabled() then
+ defines { "GFX_ENABLE_CUDA" }
+ end
--
-- `gfx-util` is a static library containing utilities and helpers for using