From 4fcfa82d7d6ccd5dc3999f47215ba3c78efa618d Mon Sep 17 00:00:00 2001
From: shawnz <shawnz@nvidia.com>
Date: Tue, 11 Feb 2025 17:01:43 +0800
Subject: [PATCH 1/2] Copy all the needed .ll and .dll for 7_libNVVM

---
 .../7_libNVVM/cuda-shared-memory/CMakeLists.txt  |  4 ++--
 .../7_libNVVM/device-side-launch/CMakeLists.txt  | 15 ++++++++++++++-
 Samples/7_libNVVM/ptxgen/CMakeLists.txt          | 16 +++++++++++++++-
 Samples/7_libNVVM/simple/CMakeLists.txt          | 15 ++++++++++++++-
 Samples/7_libNVVM/syscalls/CMakeLists.txt        |  4 ++--
 Samples/7_libNVVM/uvmlite/CMakeLists.txt         | 15 ++++++++++++++-
 6 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/Samples/7_libNVVM/cuda-shared-memory/CMakeLists.txt b/Samples/7_libNVVM/cuda-shared-memory/CMakeLists.txt
index 1a1bbeae..57ea0ced 100644
--- a/Samples/7_libNVVM/cuda-shared-memory/CMakeLists.txt
+++ b/Samples/7_libNVVM/cuda-shared-memory/CMakeLists.txt
@@ -28,11 +28,11 @@ add_custom_target(clobber)
 add_custom_target(testrun)
 
 add_test(NAME test-cuda-shared-memory-shared_memory
-	COMMAND "${CMAKE_CURRENT_BINARY_DIR}/ptxgen/ptxgen" "${CMAKE_CURRENT_SOURCE_DIR}/shared_memory.ll"
+	COMMAND "${CMAKE_CURRENT_BINARY_DIR}/../ptxgen/ptxgen" "${CMAKE_CURRENT_SOURCE_DIR}/shared_memory.ll"
 	WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
 
 add_test(NAME test-cuda-shared-memory-extern_shared_memory
-	COMMAND "${CMAKE_CURRENT_BINARY_DIR}/ptxgen/ptxgen" "${CMAKE_CURRENT_SOURCE_DIR}/extern_shared_memory.ll"
+	COMMAND "${CMAKE_CURRENT_BINARY_DIR}/../ptxgen/ptxgen" "${CMAKE_CURRENT_SOURCE_DIR}/extern_shared_memory.ll"
 	WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
 
 set_tests_properties(test-cuda-shared-memory-shared_memory
diff --git a/Samples/7_libNVVM/device-side-launch/CMakeLists.txt b/Samples/7_libNVVM/device-side-launch/CMakeLists.txt
index bc96a297..c0edbb3a 100644
--- a/Samples/7_libNVVM/device-side-launch/CMakeLists.txt
+++ b/Samples/7_libNVVM/device-side-launch/CMakeLists.txt
@@ -46,4 +46,17 @@ install(FILES dsl-gpu64.ll DESTINATION bin)
 
 # 'dsl' will load dsl-gpu64.ll from the current working directory. That
 # .ll file should be present where tests are executed (the build directory).
-file(COPY dsl-gpu64.ll DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
+add_custom_command(
+    TARGET dsl
+    POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+            "${CMAKE_CURRENT_SOURCE_DIR}/dsl-gpu64.ll" "$<TARGET_FILE_DIR:dsl>"
+)
+if (WIN32)
+add_custom_command(
+    TARGET dsl
+    POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+            "${CMAKE_BINARY_DIR}/nvvm64_40_0.dll" "$<TARGET_FILE_DIR:dsl>"
+)
+endif ()
diff --git a/Samples/7_libNVVM/ptxgen/CMakeLists.txt b/Samples/7_libNVVM/ptxgen/CMakeLists.txt
index 591b43e1..f544d084 100644
--- a/Samples/7_libNVVM/ptxgen/CMakeLists.txt
+++ b/Samples/7_libNVVM/ptxgen/CMakeLists.txt
@@ -43,4 +43,18 @@ else (WIN32)
 endif (WIN32)
 
 install(TARGETS ptxgen DESTINATION bin)
-file(COPY test.ll DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
+
+add_custom_command(
+    TARGET ptxgen
+    POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+            "${CMAKE_CURRENT_SOURCE_DIR}/test.ll" "$<TARGET_FILE_DIR:ptxgen>"
+)
+if (WIN32)
+add_custom_command(
+    TARGET ptxgen
+    POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+            "${CMAKE_BINARY_DIR}/nvvm64_40_0.dll" "$<TARGET_FILE_DIR:ptxgen>"
+)
+endif ()
\ No newline at end of file
diff --git a/Samples/7_libNVVM/simple/CMakeLists.txt b/Samples/7_libNVVM/simple/CMakeLists.txt
index 30d192a8..bebee572 100644
--- a/Samples/7_libNVVM/simple/CMakeLists.txt
+++ b/Samples/7_libNVVM/simple/CMakeLists.txt
@@ -45,4 +45,17 @@ install(FILES simple-gpu64.ll DESTINATION bin)
 
 # 'simple' will load simple-gpu64.ll from the current working directory. That
 # .ll file should be present where tests are executed (the build directory).
-file(COPY simple-gpu64.ll DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
+add_custom_command(
+    TARGET simple
+    POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+            "${CMAKE_CURRENT_SOURCE_DIR}/simple-gpu64.ll" "$<TARGET_FILE_DIR:simple>"
+)
+if (WIN32)
+add_custom_command(
+    TARGET simple
+    POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+            "${CMAKE_BINARY_DIR}/nvvm64_40_0.dll" "$<TARGET_FILE_DIR:simple>"
+)
+endif ()
\ No newline at end of file
diff --git a/Samples/7_libNVVM/syscalls/CMakeLists.txt b/Samples/7_libNVVM/syscalls/CMakeLists.txt
index 0f323058..48368041 100644
--- a/Samples/7_libNVVM/syscalls/CMakeLists.txt
+++ b/Samples/7_libNVVM/syscalls/CMakeLists.txt
@@ -26,11 +26,11 @@
 
 
 add_test(NAME test-syscalls-malloc-free
-	COMMAND "${CMAKE_CURRENT_BINARY_DIR}/ptxgen/ptxgen" "${CMAKE_CURRENT_SOURCE_DIR}/malloc-free.ll"
+	COMMAND "${CMAKE_CURRENT_BINARY_DIR}/../ptxgen/ptxgen" "${CMAKE_CURRENT_SOURCE_DIR}/malloc-free.ll"
   WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
 
 add_test(NAME test-syscalls-vprintf
-	COMMAND "${CMAKE_CURRENT_BINARY_DIR}/ptxgen/ptxgen" "${CMAKE_CURRENT_SOURCE_DIR}/vprintf.ll"
+	COMMAND "${CMAKE_CURRENT_BINARY_DIR}/../ptxgen/ptxgen" "${CMAKE_CURRENT_SOURCE_DIR}/vprintf.ll"
   WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
 
 set_tests_properties(test-syscalls-vprintf test-syscalls-malloc-free
diff --git a/Samples/7_libNVVM/uvmlite/CMakeLists.txt b/Samples/7_libNVVM/uvmlite/CMakeLists.txt
index 34d9bef0..59d1fcfe 100644
--- a/Samples/7_libNVVM/uvmlite/CMakeLists.txt
+++ b/Samples/7_libNVVM/uvmlite/CMakeLists.txt
@@ -49,4 +49,17 @@ install(FILES uvmlite64.ll DESTINATION bin)
 
 # 'uvmlite' will load uvmlite64.ll from the current working directory. That
 # .ll file should be present where tests are executed (the build directory).
-file(COPY uvmlite64.ll DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
+add_custom_command(
+    TARGET uvmlite
+    POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+            "${CMAKE_CURRENT_SOURCE_DIR}/uvmlite64.ll" "$<TARGET_FILE_DIR:uvmlite>"
+)
+if (WIN32)
+add_custom_command(
+    TARGET uvmlite
+    POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+            "${CMAKE_BINARY_DIR}/nvvm64_40_0.dll" "$<TARGET_FILE_DIR:uvmlite>"
+)
+endif ()
\ No newline at end of file

From f8f3e1b347f1dbe54e6f0c3ff61755c0be3ece23 Mon Sep 17 00:00:00 2001
From: shawnz <shawnz@nvidia.com>
Date: Tue, 11 Feb 2025 17:05:29 +0800
Subject: [PATCH 2/2] Add new line at end of files

---
 Samples/7_libNVVM/ptxgen/CMakeLists.txt  | 2 +-
 Samples/7_libNVVM/simple/CMakeLists.txt  | 2 +-
 Samples/7_libNVVM/uvmlite/CMakeLists.txt | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Samples/7_libNVVM/ptxgen/CMakeLists.txt b/Samples/7_libNVVM/ptxgen/CMakeLists.txt
index f544d084..fb8a5855 100644
--- a/Samples/7_libNVVM/ptxgen/CMakeLists.txt
+++ b/Samples/7_libNVVM/ptxgen/CMakeLists.txt
@@ -57,4 +57,4 @@ add_custom_command(
     COMMAND ${CMAKE_COMMAND} -E copy_if_different
             "${CMAKE_BINARY_DIR}/nvvm64_40_0.dll" "$<TARGET_FILE_DIR:ptxgen>"
 )
-endif ()
\ No newline at end of file
+endif ()
diff --git a/Samples/7_libNVVM/simple/CMakeLists.txt b/Samples/7_libNVVM/simple/CMakeLists.txt
index bebee572..08672a1e 100644
--- a/Samples/7_libNVVM/simple/CMakeLists.txt
+++ b/Samples/7_libNVVM/simple/CMakeLists.txt
@@ -58,4 +58,4 @@ add_custom_command(
     COMMAND ${CMAKE_COMMAND} -E copy_if_different
             "${CMAKE_BINARY_DIR}/nvvm64_40_0.dll" "$<TARGET_FILE_DIR:simple>"
 )
-endif ()
\ No newline at end of file
+endif ()
diff --git a/Samples/7_libNVVM/uvmlite/CMakeLists.txt b/Samples/7_libNVVM/uvmlite/CMakeLists.txt
index 59d1fcfe..dbf1d723 100644
--- a/Samples/7_libNVVM/uvmlite/CMakeLists.txt
+++ b/Samples/7_libNVVM/uvmlite/CMakeLists.txt
@@ -62,4 +62,4 @@ add_custom_command(
     COMMAND ${CMAKE_COMMAND} -E copy_if_different
             "${CMAKE_BINARY_DIR}/nvvm64_40_0.dll" "$<TARGET_FILE_DIR:uvmlite>"
 )
-endif ()
\ No newline at end of file
+endif ()