### Install License File Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Installs the LICENSE.txt file to the appropriate location for the installed package. ```cmake install(FILES "LICENSE.txt" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${PROJECT_NAME}" COMPONENT library ) ``` -------------------------------- ### Configuring Installation Paths Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Sets up installation directories for CMake configuration files and pkgconfig files based on the operating system (Windows/MinGW vs. others). This ensures that CMake can find the installed package correctly. ```cmake if(SDLSHADERCROSS_INSTALL) if(WIN32 AND NOT MINGW) set(INSTALL_CMAKEDIR_ROOT_DEFAULT "cmake") else() set(INSTALL_CMAKEDIR_ROOT_DEFAULT "${CMAKE_INSTALL_LIBDIR}/cmake") endif() set(SDLSHADERCROSS_INSTALL_CMAKEDIR_ROOT "${INSTALL_CMAKEDIR_ROOT_DEFAULT}" CACHE STRING "Root folder where to install SDL3_shadercross cmake related files (SDL3_shadercross subfolder for MSVC projects)") set(SDLSHADERCROSS_PKGCONFIG_INSTALLDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig") if(WIN32 AND NOT MINGW) set(SDLSHADERCROSS_INSTALL_CMAKEDIR "${SDLSHADERCROSS_INSTALL_CMAKEDIR_ROOT}") else() set(SDLSHADERCROSS_INSTALL_CMAKEDIR "${SDLSHADERCROSS_INSTALL_CMAKEDIR_ROOT}/SDL3_shadercross") endif() endif() ``` -------------------------------- ### Installing Shared Library and Targets Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Installs the shared library, its runtime components, and the corresponding CMake export file. This makes the shared library available for use by other projects after installation. ```cmake if(TARGET SDL3_shadercross-shared) install(TARGETS SDL3_shadercross-shared EXPORT SDL3_shadercross-shared-export ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT devel LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT library RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT library ) install(EXPORT SDL3_shadercross-shared-export FILE SDL3_shadercross-shared-targets.cmake NAMESPACE SDL3_shadercross:: DESTINATION "${SDLSHADERCROSS_INSTALL_CMAKEDIR}" COMPONENT devel ) ``` -------------------------------- ### Installing CLI Executable Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Installs the 'shadercross' command-line executable to the runtime destination directory if the SDLSHADERCROSS_CLI option is enabled. This makes the tool available in the system's PATH after installation. ```cmake if(SDLSHADERCROSS_CLI) install(TARGETS shadercross RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() ``` -------------------------------- ### Installing Header File Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Installs the main SDL3_shadercross header file to the appropriate include directory. This makes the library's API accessible to users. ```cmake install( FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/SDL3_shadercross/SDL_shadercross.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/SDL3_shadercross" COMPONENT DEVEL ) ``` -------------------------------- ### Installing Static Library and Targets Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Installs the static library and its corresponding CMake export file. This makes the static library available for linking into other projects. ```cmake if(TARGET SDL3_shadercross-static) install(TARGETS SDL3_shadercross-static EXPORT SDL3_shadercross-static-export ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT devel LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT library ) install(EXPORT SDL3_shadercross-static-export FILE SDL3_shadercross-static-targets.cmake NAMESPACE SDL3_shadercross:: DESTINATION "${SDLSHADERCROSS_INSTALL_CMAKEDIR}" COMPONENT devel ) ``` -------------------------------- ### Install Runtime Artifacts for DirectXShaderCompiler Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Installs runtime artifacts for DirectXShaderCompiler if SDLSHADERCROSS_DXC is enabled, placing them in the binary and library directories. ```cmake if(NOT SDLSHADERCROSS_VENDORED) if(SDLSHADERCROSS_DXC) install(IMPORTED_RUNTIME_ARTIFACTS DirectXShaderCompiler::dxcompiler DirectXShaderCompiler::dxil RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") endif() endif() ``` -------------------------------- ### Add SPIRV-Headers External Project Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Downloads, builds, and installs the SPIRV-Headers project from GitHub. It configures build type, installation directories, compiler, toolchain, and macOS-specific settings. The build and install commands use CMake's build and install utilities. ```cmake ExternalProject_Add(spirv_headers GIT_REPOSITORY "https://github.com/KhronosGroup/SPIRV-Headers.git" GIT_TAG "main" CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_LIBDIR=lib" "-DCMAKE_INSTALL_BINDIR=bin" "-DCMAKE_INSTALL_PREFIX=" "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DCMAKE_OSX_ARCHITECTURES=${genex_CMAKE_OSX_ARCHITECTURES}" "-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}" BUILD_COMMAND "${CMAKE_COMMAND}" "--build" "" --config "Release" INSTALL_COMMAND "${CMAKE_COMMAND}" "--install" "" --config "Release" ) ExternalProject_Get_property(spirv_headers INSTALL_DIR) set(spirv_headers_install_dir "${INSTALL_DIR}") ``` -------------------------------- ### Install SDL3 Shared Library Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Installs the SDL3 shared library artifacts to the specified runtime and library directories. This is conditional on SDLSHADERCROSS_CLI and not using static linking. ```cmake install(IMPORTED_RUNTIME_ARTIFACTS SDL3::SDL3-shared RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") ``` -------------------------------- ### Add Vulkan-Headers External Project Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Downloads, builds, and installs the Vulkan-Headers project from GitHub. Similar to SPIRV-Headers, it configures build type, installation paths, compiler, toolchain, and macOS-specific settings. The build and install processes are managed via CMake commands. ```cmake ExternalProject_Add(vulkan_headers GIT_REPOSITORY "https://github.com/KhronosGroup/Vulkan-Headers" GIT_TAG "main" CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_LIBDIR=lib" "-DCMAKE_INSTALL_BINDIR=bin" "-DCMAKE_INSTALL_PREFIX=" "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DCMAKE_OSX_ARCHITECTURES=${genex_CMAKE_OSX_ARCHITECTURES}" "-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}" BUILD_COMMAND "${CMAKE_COMMAND}" "--build" "" --config "Release" INSTALL_COMMAND "${CMAKE_COMMAND}" "--install" "" --config "Release" ) ExternalProject_Get_property(vulkan_headers INSTALL_DIR) set(vulkan_headers_install_dir "${INSTALL_DIR}") ``` -------------------------------- ### Configure PkgConfig File Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Configures the pkg-config file (sdl3-shadercross.pc) with library paths and requirements, ensuring correct installation. ```cmake if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") set(INCLUDEDIR_FOR_PKG_CONFIG "${CMAKE_INSTALL_INCLUDEDIR}") else() set(INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") endif() if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") set(LIBDIR_FOR_PKG_CONFIG "${CMAKE_INSTALL_LIBDIR}") else() set(LIBDIR_FOR_PKG_CONFIG "\${prefix}/${CMAKE_INSTALL_LIBDIR}") endif() file(RELATIVE_PATH SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG "${CMAKE_INSTALL_PREFIX}/${SDLSHADERCROSS_PKGCONFIG_INSTALLDIR}" "${CMAKE_INSTALL_PREFIX}") string(REGEX REPLACE "[/]+$" "" SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG "${SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG}") set(SDL_PKGCONFIG_PREFIX "\${pcfiledir}/${SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG}") if(NOT SDLSHADERCROSS_VENDORED) if(SDLSHADERCROSS_SPIRVCROSS_SHARED) set(PC_REQUIRES "spirv-cross-c-shared") else() set(PC_REQUIRES "spirv-cross-c") endif() endif() set(PC_LIBS "-ldxcompiler") configure_file(cmake/sdl3-shadercross.pc.in sdl3-shadercross.pc @ONLY) # Always install sdl3-shadercross.pc file: libraries might be different between config modes install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sdl3-shadercross.pc" DESTINATION "${SDLSHADERCROSS_PKGCONFIG_INSTALLDIR}" COMPONENT devel ) ``` -------------------------------- ### Install Runtime Artifacts for SPIRV-Cross Shared Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Installs runtime artifacts for the shared SPIRV-Cross library, handling platform-specific dependency resolution on Windows. ```cmake if(NOT SDLSHADERCROSS_VENDORED) if(SDLSHADERCROSS_SPIRVCROSS_SHARED) install(IMPORTED_RUNTIME_ARTIFACTS spirv-cross-c-shared RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") if(WIN32) install(CODE " set(CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM \"windows+pe\") set(CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL \"$,dumpbin,objdump>\") set(CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND \"${CMAKE_OBJDUMP}\") file(GET_RUNTIME_DEPENDENCIES RESOLVED_DEPENDENCIES_VAR resolved UNRESOLVED_DEPENDENCIES_VAR unresolved DIRECTORIES \"$\" \"${CMAKE_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR}\" LIBRARIES \"$\" POST_EXCLUDE_REGEXES ".*[sS][yY][sS][tT][eE][mM]32.*" ".*[aA][pP][iI]-[mM][sS].*" ".*[aA][pP][iI]-[eE][xX][tT].*" ) file(INSTALL DESTINATION \" ${CMAKE_INSTALL_PREFIX}/bin\" TYPE SHARED_LIBRARY FILES \${resolved}) ") endif() endif() endif() ``` -------------------------------- ### Installing Vendored Targets Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Installs any vendored targets, including their runtime, library, and archive components, along with a CMake export file. This is for dependencies that are built as part of the project. ```cmake if(vendored_targets) install(TARGETS ${vendored_targets} EXPORT SDL3_shadercross-vendored ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT devel RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT library LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT library ) install(EXPORT SDL3_shadercross-vendored FILE SDL3_shadercross-vendored-targets.cmake NAMESPACE SDL3_shadercross::vendored:: DESTINATION "${SDLSHADERCROSS_INSTALL_CMAKEDIR}" COMPONENT devel ) ``` -------------------------------- ### Test Configuration and Environment Setup Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/test/CMakeLists.txt This CMake code configures the test arguments, sets a timeout for the test, and modifies environment variables for the test executable based on the operating system. ```cmake set(test_args) if(SDLSHADERCROSS_TESTS_TRACKMEM) list(APPEND test_args "--trackmem") endif() add_test(NAME testshadercross COMMAND testshadercross ${test_args}) set_property(TEST testshadercross PROPERTY TIMEOUT 10) if(UNIX AND NOT APPLE) set_property(TEST testshadercross APPEND PROPERTY ENVIRONMENT_MODIFICATION "LD_LIBRARY_PATH=path_list_prepend:${SDL3_shadercross_BINARY_DIR}/vkd3d-prefix/lib") if(SDLSHADERCROSS_INSTALL_RUNTIME) set_property(TEST testshadercross APPEND PROPERTY ENVIRONMENT_MODIFICATION "LD_LIBRARY_PATH=path_list_prepend:$") endif() elseif(WIN32) set_property(TEST testshadercross APPEND PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") set_property(TEST testshadercross APPEND PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") set_property(TEST testshadercross APPEND PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") if(TARGET spirv-cross-c-shared) set_property(TEST testshadercross APPEND PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") endif() endif() if(SDLSHADERCROSS_TESTS_TRACKMEM) set_property(TEST testshadercross PROPERTY FAIL_REGULAR_EXPRESSION "Total: [0-9]+\\.[0-9]+ Kb in [1-9][0-9]* allocations") endif() ``` -------------------------------- ### Configure Package Configuration File Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Configures the package configuration file for SDL3_shadercross, specifying installation destinations and versioning. ```cmake include(CMakePackageConfigHelpers) configure_package_config_file(cmake/SDL3_shadercrossConfig.cmake.in SDL3_shadercrossConfig.cmake NO_SET_AND_CHECK_MACRO INSTALL_DESTINATION "${SDLSHADERCROSS_INSTALL_CMAKEDIR}" ) write_basic_package_version_file("${PROJECT_BINARY_DIR}/SDL3_shadercrossConfigVersion.cmake" COMPATIBILITY AnyNewerVersion ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/SDL3_shadercrossConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/SDL3_shadercrossConfigVersion.cmake" DESTINATION "${SDLSHADERCROSS_INSTALL_CMAKEDIR}" COMPONENT devel ) ``` -------------------------------- ### Basic CMake Configuration for SDL_shadercross Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/cmake/test/CMakeLists.txt Sets up the minimum CMake version, project name, and language. It also configures find root path modes to allow searching for SDL3 outside the sysroot. Use this as a starting point for your SDL_shadercross CMake project. ```cmake cmake_minimum_required(VERSION 3.12) project(sdl_test LANGUAGES C) cmake_policy(SET CMP0074 NEW) # Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL3 outside of sysroot set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) ``` -------------------------------- ### Set Install RPATH for Shadercross Target Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Sets the INSTALL_RPATH for the 'shadercross' target to ensure it can find its runtime libraries when installed. ```cmake if(TARGET shadercross) file(RELATIVE_PATH bin_to_lib "${CMAKE_INSTALL_FULL_BINDIR}" "${CMAKE_INSTALL_FULL_LIBDIR}") set_property(TARGET shadercross PROPERTY INSTALL_RPATH "${rpath_origin}/${bin_to_lib}") endif() ``` -------------------------------- ### Install Vendored CMake Modules Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Installs vendored CMake modules if SDLSHADERCROSS_VENDORED is not set. These are typically helper scripts for finding dependencies. ```cmake if(NOT SDLSHADERCROSS_VENDORED) install( FILES "cmake/sdlcpu.cmake" "cmake/FindDirectXShaderCompiler.cmake" DESTINATION "${SDLSHADERCROSS_INSTALL_CMAKEDIR}" COMPONENT devel ) endif() ``` -------------------------------- ### Add Vulkan-Loader External Project Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Downloads, builds, and installs the Vulkan-Loader project, with dependencies on spirv_headers and vulkan_headers. It configures build settings, installation paths, compiler, toolchain, and macOS-specific options, including the prefix path for Vulkan headers. ```cmake ExternalProject_Add(vulkan_loader DEPENDS spirv_headers vulkan_headers GIT_REPOSITORY "https://github.com/KhronosGroup/Vulkan-Loader.git" GIT_TAG "main" CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_LIBDIR=lib" "-DCMAKE_INSTALL_BINDIR=bin" "-DCMAKE_INSTALL_PREFIX=" "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DCMAKE_OSX_ARCHITECTURES=${genex_CMAKE_OSX_ARCHITECTURES}" "-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}" "-DCMAKE_PREFIX_PATH=${vulkan_headers_install_dir}" BUILD_COMMAND "${CMAKE_COMMAND}" "--build" "" --config "Release" INSTALL_COMMAND "${CMAKE_COMMAND}" "--install" "" --config "Release" ) ExternalProject_Get_property(vulkan_loader INSTALL_DIR) set(vulkan_loader_install_dir "${INSTALL_DIR}") ``` -------------------------------- ### Copying CMake Dependencies Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Copies necessary CMake configuration files to the build directory to enable package usage without installation. This is useful for development or testing. ```cmake file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdlcpu.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindDirectXShaderCompiler.cmake" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") ``` -------------------------------- ### Add vkd3d External Project Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Configures vkd3d as an external project, specifying dependencies, URL, hash, and build commands. It also sets up platform-specific installation rules for shared libraries. ```cmake find_package(BISON REQUIRED) ExternalProject_Add(vkd3d DEPENDS spirv_headers vulkan_headers vulkan_loader URL "https://dl.winehq.org/vkd3d/source/vkd3d-2.0.tar.xz" URL_HASH "SHA256=9ad29bb236808186a47ec66e853b21e6fca59b9dc62a9474b05d5e3eda2710ef" DOWNLOAD_EXTRACT_TIMESTAMP "1" CONFIGURE_COMMAND "sh" "/configure" "--prefix=" "--enable-tests=no" "--enable-demos=no" "--disable-doxygen-doc" "CFLAGS=-I${spirv_headers_install_dir}/include -I${vulkan_headers_install_dir}/include -I${vulkan_loader_install_dir}/include ${configure_CFLAGS}" "LDFLAGS=-L${vulkan_loader_install_dir}/lib" "BISON=${BISON_EXECUTABLE}" BUILD_COMMAND "make" INSTALL_COMMAND "make" "install" ) ExternalProject_Get_property(vkd3d SOURCE_DIR) ExternalProject_Get_property(vkd3d INSTALL_DIR) install(DIRECTORY "${INSTALL_DIR}/lib/" DESTINATION "${CMAKE_INSTALL_LIBDIR}" FILES_MATCHING PATTERN "*.so*" PERMISSIONS ${chmod_0755}) install(DIRECTORY "${INSTALL_DIR}/lib/" DESTINATION "${CMAKE_INSTALL_LIBDIR}" FILES_MATCHING PATTERN "*.dylib*" PERMISSIONS ${chmod_0755}) install(FILES "${SOURCE_DIR}/COPYING" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/vkd3d") endif() if(LINUX) find_program(PATCHELF_BIN NAMES "patchelf" REQUIRED) install(CODE "file(GLOB so_paths \"$ENV{DESTDIR}${{CMAKE_INSTALL_PREFIX}}/${CMAKE_INSTALL_LIBDIR}/*so*\")\n foreach(so_path ${so_paths}) if(NOT IS_SYMLINK ${so_path}) message(STATUS \"Adding \\\"$ORIGIN\\\" to RPATH of ${so_path}\")\n execute_process(COMMAND ${PATCHELF_BIN} \"${so_path}\" --add-rpath \"$ORIGIN\")\n endif()\n endforeach()") elseif(APPLE) find_program(INT_BIN NAMES "install_name_tool" REQUIRED) install(CODE "file(GLOB so_paths \"$ENV{DESTDIR}${{CMAKE_INSTALL_PREFIX}}/${CMAKE_INSTALL_LIBDIR}/*dylib*\")\n foreach(so_path ${so_paths}) if(NOT IS_SYMLINK ${so_path}) message(STATUS \"Adding \\\"@loader_path\\\" to RPATH of ${so_path}\")\n execute_process(COMMAND ${INT_BIN} \"${so_path}\" -add_rpath \"@loader_path\")\n endif()\n endforeach()") endif() endif() ``` -------------------------------- ### Configuring the Command-Line Interface Executable Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Adds the 'shadercross' executable if the SDLSHADERCROSS_CLI option is enabled. It configures warning options, linker options, and links against necessary libraries (SDL3, SDL3_test, and SDL3_shadercross) based on build flags like SDLSHADERCROSS_CLI_STATIC. ```cmake if(SDLSHADERCROSS_CLI) add_executable(shadercross src/cli.c) sdl_add_warning_options(shadercross WARNING_AS_ERROR ${SDLSHADERCROSS_WERROR}) sdl_target_link_options_no_undefined(shadercross) if(SDLSHADERCROSS_CLI_LEAKCHECK) target_link_libraries(shadercross PRIVATE SDL3::SDL3_test) target_compile_definitions(shadercross PRIVATE LEAKCHECK) endif() if(SDLSHADERCROSS_CLI_STATIC) target_link_libraries(shadercross PRIVATE SDL3_shadercross::SDL3_shadercross-static) target_link_libraries(shadercross PRIVATE SDL3::SDL3-static) else() if(NOT TARGET SDL3::SDL3) find_package(SDL3 ${SDL_REQUIRED_VERSION} REQUIRED COMPONENTS SDL3) endif() target_link_libraries(shadercross PRIVATE SDL3_shadercross::SDL3_shadercross) target_link_libraries(shadercross PRIVATE SDL3::SDL3) endif() endif() ``` -------------------------------- ### Configure CPack Generator Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Configures the CPack generator based on the operating system (ZIP for Windows, TGZ for others) and sets up project configuration for packaging. ```cmake if(SDLSHADERCROSS_INSTALL_CPACK) if(MSVC) set(CPACK_GENERATOR "ZIP") else() set(CPACK_GENERATOR "TGZ") endif() configure_file(cmake/CPackProjectConfig.cmake.in CPackProjectConfig.cmake @ONLY) set(CPACK_PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/CPackProjectConfig.cmake") # CPACK_SOURCE_PACKAGE_FILE_NAME must end with "-src" (so we can block creating a source archive) set(CPACK_SOURCE_PACKAGE_FILE_NAME "SDL3_shadercross-${PROJECT_VERSION}-src") set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/dist") include(CPack) endif() ``` -------------------------------- ### Build Executable for Static SDL3_shadercross Library Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/cmake/test/CMakeLists.txt Configures and builds an executable that links against the static SDL3_shadercross library. This snippet is used when `TEST_STATIC` is enabled, requiring C++ language support and finding both SDL3 and SDL3_shadercross packages. ```cmake if(TEST_STATIC) find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3) # some static vendored libraries use c++ (enable CXX after `find_package` might show a warning) enable_language(CXX) find_package(SDL3_shadercross REQUIRED CONFIG) add_executable(main_static main.c) target_link_libraries(main_static PRIVATE SDL3_shadercross::SDL3_shadercross-static SDL3::SDL3) endif() ``` -------------------------------- ### Generate Feature Summary Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/cmake/test/CMakeLists.txt Generates a summary of all configured features and options. This is typically called at the end of the CMake script to report build configuration details. ```cmake feature_summary(WHAT ALL) ``` -------------------------------- ### Feature Summary and Options for SDL_shadercross Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/cmake/test/CMakeLists.txt Includes the FeatureSummary module and defines options for testing shared and static linking of the SDL3_shadercross library. Use these options to control which library type is tested during the build. ```cmake include(FeatureSummary) option(TEST_SHARED "Test linking to shared SDL3_shadercross library" ON) add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library") option(TEST_STATIC "Test linking to static SDL3_shadercross library" ON) add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library") ``` -------------------------------- ### Configuring Build Targets Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Iterates through defined targets to apply common build options, such as warning levels, C standard, and linking against SPIRV-Cross and DirectXShaderCompiler libraries. This ensures consistent compilation settings across different targets. ```cmake foreach(target IN LISTS SDL3_shadercross_targets) sdl_add_warning_options(${target} WARNING_AS_ERROR ${SDLSHADERCROSS_WERROR}) target_compile_features(${target} PRIVATE c_std_99) if(SDLSHADERCROSS_DXC) add_compile_definitions(SDL_SHADERCROSS_DXC) endif() if(SDLSHADERCROSS_SPIRVCROSS_SHARED) target_link_libraries(${target} PRIVATE spirv-cross-c-shared) else() target_link_libraries(${target} PRIVATE spirv-cross-c) endif() if(SDLSHADERCROSS_DXC) target_link_libraries(${target} PRIVATE DirectXShaderCompiler::dxcompiler) endif() if(NOT SDLSHADERCROSS_SPIRVCROSS_SHARED) # spirv-cross uses C++ set_property(TARGET ${target} PROPERTY LINKER_LANGUAGE CXX) endif() endforeach() ``` -------------------------------- ### Enable Testing Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Enables testing for the project and adds the test subdirectory if SDLSHADERCROSS_TESTS is enabled. ```cmake if(SDLSHADERCROSS_TESTS) enable_testing() add_subdirectory(test) endif() ``` -------------------------------- ### Generate Manpages Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Generates manpages for the project using SDL_generate_manpages, requiring Git revision hash and specific header information. ```cmake if(SDLSHADERCROSS_INSTALL_MAN) sdl_get_git_revision_hash(SDLSHADERCROSS_REVISION) SDL_generate_manpages( HEADERS_DIR "${PROJECT_SOURCE_DIR}/include/SDL3_shadercross" SYMBOL "SDL_ShaderCross_Init" WIKIHEADERS_PL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build-scripts/wikiheaders.pl" REVISION "${SDLSHADERCROSS_REVISION}" ) endif() ``` -------------------------------- ### Creating an Alias Library Target Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Creates an alias target for SDL3_shadercross, pointing to either the shared or static library based on availability. This simplifies referencing the main library. ```cmake if(NOT TARGET SDL3_shadercross::SDL3_shadercross) if(TARGET SDL3_shadercross-shared) add_library(SDL3_shadercross::SDL3_shadercross ALIAS SDL3_shadercross-shared) else() add_library(SDL3_shadercross::SDL3_shadercross ALIAS SDL3_shadercross-static) endif() endif() ``` -------------------------------- ### Build Executable for Shared SDL3_shadercross Library Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/cmake/test/CMakeLists.txt Configures and builds an executable that links against the shared SDL3_shadercross library. This snippet is used when `TEST_SHARED` is enabled and requires finding both SDL3 and SDL3_shadercross packages. ```cmake if(TEST_SHARED) find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3) find_package(SDL3_shadercross REQUIRED CONFIG) add_executable(main_shared main.c) target_link_libraries(main_shared PRIVATE SDL3_shadercross::SDL3_shadercross-shared SDL3::SDL3) endif() ``` -------------------------------- ### Executable and Library Linking Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/test/CMakeLists.txt This CMake code defines the main executable for the shader cross-compiler and links it with necessary SDL libraries and the shader cross-compiler library. ```cmake find_package(SDL3 REQUIRED COMPONENTS SDL3_test) add_executable(testshadercross main.c ${includeable_shader_sources} ) sdl_add_warning_options(testshadercross) target_link_libraries(testshadercross PRIVATE SDL3_shadercross::SDL3_shadercross) target_link_libraries(testshadercross PRIVATE SDL3::SDL3_test) target_link_libraries(testshadercross PRIVATE SDL3::SDL3) ``` -------------------------------- ### Conditional Executable for Android Builds Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/cmake/test/CMakeLists.txt Defines a macro to add executables as shared libraries specifically for Android builds. This ensures compatibility with Android's build system requirements. ```cmake if(ANDROID) macro(add_executable NAME) set(args ${ARGN}) list(REMOVE_ITEM args WIN32) add_library(${NAME} SHARED ${args}) unset(args) endmacro() endif() ``` -------------------------------- ### Shader Source Processing Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/test/CMakeLists.txt This CMake code processes shader sources, generates header files, and adds custom commands for compilation, especially for Python 3.11+. ```cmake enable_testing() set(shader_sources "shaders/simple.vert.hlsl" ) find_package(Python3 COMPONENTS Interpreter) set(includeable_shader_sources) foreach(src IN LISTS shader_sources) get_filename_component(src_name "${src}" NAME) set(src_path "${CMAKE_CURRENT_SOURCE_DIR}/${src}") set(hdr_path "${CMAKE_CURRENT_SOURCE_DIR}/shaders/hinc/${src_name}.h") list(APPEND includeable_shader_sources "${hdr_path}") if(Python3_VERSION VERSION_GREATER_EQUAL "3.11") add_custom_command(OUTPUT "${hdr_path}" COMMAND Python3::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/embed.py" -i "${src_path}" -o "${hdr_path}" -z DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/embed.py" "${src_path}" ) endif() endforeach() ``` -------------------------------- ### Configure CFLAGS for macOS Architectures Source: https://github.com/libsdl-org/sdl_shadercross/blob/main/CMakeLists.txt Appends architecture flags to CMAKE_C_FLAGS for macOS builds. It iterates through CMAKE_OSX_ARCHITECTURES to ensure all specified architectures are included in the compilation flags. ```cmake set(configure_CFLAGS "${CMAKE_C_FLAGS}") if(APPLE) foreach(osx_arch IN LISTS CMAKE_OSX_ARCHITECTURES) string(APPEND configure_CFLAGS " -arch ${osx_arch}") endforeach() endif() string(REPLACE ";" "$" genex_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.