mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-25 22:28:17 +08:00
Bug 5591814: Support "make install" in single sample folder
This commit is contained in:
@@ -47,14 +47,17 @@ endif()
|
||||
# Create the installation path: bin/$(TARGET_ARCH)/$(TARGET_OS)/$(BUILD_TYPE)
|
||||
set(CUDA_SAMPLES_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${TARGET_OS}/${BUILD_TYPE_LOWER}" CACHE PATH "Installation directory for CUDA samples")
|
||||
|
||||
# Print installation configuration
|
||||
message(STATUS "CUDA Samples installation configured:")
|
||||
message(STATUS " Architecture: ${TARGET_ARCH}")
|
||||
message(STATUS " OS: ${TARGET_OS}")
|
||||
message(STATUS " Build Type: ${BUILD_TYPE_LOWER}")
|
||||
message(STATUS " Install Directory: ${CUDA_SAMPLES_INSTALL_DIR}")
|
||||
# Print installation configuration only once
|
||||
if(NOT CUDA_SAMPLES_INSTALL_CONFIG_PRINTED)
|
||||
message(STATUS "CUDA Samples installation configured:")
|
||||
message(STATUS " Architecture: ${TARGET_ARCH}")
|
||||
message(STATUS " OS: ${TARGET_OS}")
|
||||
message(STATUS " Build Type: ${BUILD_TYPE_LOWER}")
|
||||
message(STATUS " Install Directory: ${CUDA_SAMPLES_INSTALL_DIR}")
|
||||
set(CUDA_SAMPLES_INSTALL_CONFIG_PRINTED TRUE CACHE INTERNAL "Installation config printed flag")
|
||||
endif()
|
||||
|
||||
# Function to setup installation for the project
|
||||
# Function to setup installation for regular samples
|
||||
# This should be called after all targets are defined
|
||||
function(setup_samples_install)
|
||||
# Create an install script that will copy executables and specific file types
|
||||
@@ -63,10 +66,32 @@ function(setup_samples_install)
|
||||
# - run_tests.py automatically tries flattened paths as fallback
|
||||
# This script runs at install time, after the build is complete
|
||||
install(CODE "
|
||||
file(GLOB_RECURSE SAMPLE_FILES
|
||||
|
||||
# Search in the current project's binary directory for built executables
|
||||
file(GLOB_RECURSE BINARY_FILES
|
||||
LIST_DIRECTORIES false
|
||||
\"${CMAKE_BINARY_DIR}/Samples/*/*\"
|
||||
\"${CMAKE_BINARY_DIR}/Samples/*/*/*\")
|
||||
\"${CMAKE_CURRENT_BINARY_DIR}/*\")
|
||||
|
||||
# Copy data files from sample's own data directory
|
||||
file(GLOB_RECURSE SAMPLE_DATA_FILES
|
||||
LIST_DIRECTORIES false
|
||||
\"${CMAKE_CURRENT_SOURCE_DIR}/data/*\")
|
||||
|
||||
# Copy shared data files from Common/data directory
|
||||
# Try both paths: ../../../Common (for regular samples) and ../../../../Common (for Tegra)
|
||||
set(COMMON_DATA_FILES \"\")
|
||||
if(EXISTS \"${CMAKE_CURRENT_SOURCE_DIR}/../../../Common/data\")
|
||||
file(GLOB_RECURSE COMMON_DATA_FILES
|
||||
LIST_DIRECTORIES false
|
||||
\"${CMAKE_CURRENT_SOURCE_DIR}/../../../Common/data/*\")
|
||||
elseif(EXISTS \"${CMAKE_CURRENT_SOURCE_DIR}/../../../../Common/data\")
|
||||
file(GLOB_RECURSE COMMON_DATA_FILES
|
||||
LIST_DIRECTORIES false
|
||||
\"${CMAKE_CURRENT_SOURCE_DIR}/../../../../Common/data/*\")
|
||||
endif()
|
||||
|
||||
# Combine all lists
|
||||
set(SAMPLE_FILES \${BINARY_FILES} \${SAMPLE_DATA_FILES} \${COMMON_DATA_FILES})
|
||||
|
||||
# Filter to include executable files and specific file types
|
||||
foreach(SAMPLE_FILE IN LISTS SAMPLE_FILES)
|
||||
@@ -82,27 +107,20 @@ function(setup_samples_install)
|
||||
NOT SAMPLE_NAME MATCHES \"^(Makefile|cmake_install\\\\.cmake)$\" AND
|
||||
NOT \"\${SAMPLE_FILE}\" MATCHES \"/CMakeFiles/\")
|
||||
|
||||
# Determine file type and whether to install
|
||||
set(IS_EXECUTABLE FALSE)
|
||||
set(IS_INTERMEDIATE_FILE FALSE)
|
||||
|
||||
# Check if file has required extension (fatbin, ptx, bc, raw, ppm)
|
||||
# Check if file has required extension (fatbin, ptx, bc, raw, ppm) or is executable
|
||||
if(SAMPLE_EXT MATCHES \"\\\\.(fatbin|ptx|bc|raw|ppm)$\")
|
||||
set(SHOULD_INSTALL TRUE)
|
||||
set(IS_INTERMEDIATE_FILE TRUE)
|
||||
else()
|
||||
# Check if file is executable
|
||||
if(IS_SYMLINK \"\${SAMPLE_FILE}\" OR
|
||||
(EXISTS \"\${SAMPLE_FILE}\" AND NOT IS_DIRECTORY \"\${SAMPLE_FILE}\"))
|
||||
execute_process(
|
||||
COMMAND test -x \"\${SAMPLE_FILE}\"
|
||||
RESULT_VARIABLE HAS_EXEC_BIT
|
||||
RESULT_VARIABLE IS_EXEC
|
||||
OUTPUT_QUIET ERROR_QUIET
|
||||
)
|
||||
|
||||
if(HAS_EXEC_BIT EQUAL 0)
|
||||
if(IS_EXEC EQUAL 0)
|
||||
set(SHOULD_INSTALL TRUE)
|
||||
set(IS_EXECUTABLE TRUE)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
@@ -110,59 +128,36 @@ function(setup_samples_install)
|
||||
|
||||
if(SHOULD_INSTALL)
|
||||
get_filename_component(FILE_NAME \"\${SAMPLE_FILE}\" NAME)
|
||||
set(DEST_FILE \"${CUDA_SAMPLES_INSTALL_DIR}/\${FILE_NAME}\")
|
||||
|
||||
if(IS_EXECUTABLE)
|
||||
# Executables: install to flat directory for easy access
|
||||
# run_tests.py will handle finding data files via flattened paths
|
||||
message(STATUS \"Installing: ${CUDA_SAMPLES_INSTALL_DIR}/\${FILE_NAME}\")
|
||||
# Check if file is executable
|
||||
execute_process(
|
||||
COMMAND test -x \"\${SAMPLE_FILE}\"
|
||||
RESULT_VARIABLE HAS_EXEC_BIT
|
||||
OUTPUT_QUIET ERROR_QUIET
|
||||
)
|
||||
|
||||
get_filename_component(DEST_DIR \"\${DEST_FILE}\" DIRECTORY)
|
||||
|
||||
if(HAS_EXEC_BIT EQUAL 0)
|
||||
# File is executable - copy with execute permissions
|
||||
message(STATUS \"Installing executable: \${DEST_FILE}\")
|
||||
file(COPY \"\${SAMPLE_FILE}\"
|
||||
DESTINATION \"${CUDA_SAMPLES_INSTALL_DIR}\"
|
||||
DESTINATION \"\${DEST_DIR}\"
|
||||
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE)
|
||||
else()
|
||||
# Data/intermediate files: preserve subdirectory structure (no execute bit)
|
||||
# This maintains original relative paths for compatibility
|
||||
# file(RELATIVE_PATH REL_PATH \"${CMAKE_BINARY_DIR}/Samples\" \"\${SAMPLE_FILE}\")
|
||||
# get_filename_component(REL_DIR \"\${REL_PATH}\" DIRECTORY)
|
||||
# set(DEST_DIR \"${CUDA_SAMPLES_INSTALL_DIR}/\${REL_DIR}\")
|
||||
message(STATUS \"Installing: ${CUDA_SAMPLES_INSTALL_DIR}/\${FILE_NAME}\")
|
||||
# Regular file - copy without execute permissions
|
||||
message(STATUS \"Installing data file: \${DEST_FILE}\")
|
||||
file(COPY \"\${SAMPLE_FILE}\"
|
||||
DESTINATION \"${CUDA_SAMPLES_INSTALL_DIR}\"
|
||||
DESTINATION \"\${DEST_DIR}\"
|
||||
FILE_PERMISSIONS OWNER_READ OWNER_WRITE
|
||||
GROUP_READ
|
||||
WORLD_READ)
|
||||
WORLD_READ)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Copy everything from bin/bin (created by libNVVM samples install)
|
||||
# The libNVVM samples install their .ll and data files to bin/bin
|
||||
# Skip files that already exist (e.g., executable files already copied above)
|
||||
set(BIN_BIN_DIR \"${CMAKE_BINARY_DIR}/bin/bin\")
|
||||
if(EXISTS \"\${BIN_BIN_DIR}\" AND IS_DIRECTORY \"\${BIN_BIN_DIR}\")
|
||||
file(GLOB_RECURSE BIN_BIN_FILES
|
||||
RELATIVE \"\${BIN_BIN_DIR}\"
|
||||
\"\${BIN_BIN_DIR}/*\")
|
||||
foreach(REL_FILE IN LISTS BIN_BIN_FILES)
|
||||
set(SRC_FILE \"\${BIN_BIN_DIR}/\${REL_FILE}\")
|
||||
set(DEST_FILE \"${CUDA_SAMPLES_INSTALL_DIR}/\${REL_FILE}\")
|
||||
|
||||
# Only copy if destination doesn't exist (avoid duplicate executables)
|
||||
if(NOT EXISTS \"\${DEST_FILE}\")
|
||||
get_filename_component(DEST_DIR \"\${DEST_FILE}\" DIRECTORY)
|
||||
message(STATUS \"Installing from bin/bin: \${DEST_FILE}\")
|
||||
file(COPY \"\${SRC_FILE}\"
|
||||
DESTINATION \"\${DEST_DIR}\"
|
||||
USE_SOURCE_PERMISSIONS)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Remove bin/bin after copying
|
||||
message(STATUS \"Removing bin/bin directory\")
|
||||
file(REMOVE_RECURSE \"\${BIN_BIN_DIR}\")
|
||||
endif()
|
||||
")
|
||||
endfunction()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user