This commit is contained in:
xsl
2025-09-04 10:54:47 +08:00
commit 6bc8f61b18
1808 changed files with 208268 additions and 0 deletions
+128
View File
@@ -0,0 +1,128 @@
#[[
Copyright (c) 2019-2023, Arm Limited and Contributors
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 the "License";
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
set(SCRIPT_DIR ${CMAKE_CURRENT_LIST_DIR})
function(add_android_package_project)
set(options)
set(oneValueArgs NAME JAVA_DIR RES_DIR MANIFEST_FILE)
set(multiValueArgs DEPENDS ASSET_DIRS)
cmake_parse_arguments(PARSE_ARGV 0 TARGET "${options}" "${oneValueArgs}" "${multiValueArgs}")
find_package(Gradle REQUIRED 4.10)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME})
project(${TARGET_NAME})
set(GRADLE_ANDROID_SCRIPT ${SCRIPT_DIR}/create_gradle_project.cmake)
if(NOT EXISTS ${GRADLE_ANDROID_SCRIPT})
message(FATAL_ERROR "No gradle android script exists at `${GRADLE_ANDROID_SCRIPT}`")
endif()
set(GRADLE_CONFIG_FILE ${SCRIPT_DIR}/template/gradle/build.gradle.in)
if(NOT EXISTS ${GRADLE_CONFIG_FILE})
message(FATAL_ERROR "No build.gradle.in template file exists at `${GRADLE_CONFIG_FILE}`")
endif()
set(JNI_LIBS_DIRS)
foreach(TARGET_DEPEND ${TARGET_DEPENDS})
if(TARGET ${TARGET_DEPEND})
get_target_property(BINARY_DIR ${TARGET_DEPEND} BINARY_DIR)
list(APPEND JNI_LIBS_DIRS ${BINARY_DIR}/lib/${CMAKE_BUILD_TYPE})
endif()
endforeach()
add_custom_command(
OUTPUT
gen.gradle.stamp
DEPENDS
${GRADLE_CONFIG_FILE}
${GRADLE_ANDROID_SCRIPT}
COMMAND
${CMAKE_COMMAND}
-DPROJECT_NAME=${CMAKE_PROJECT_NAME}
-DANDROID_API=${CMAKE_ANDROID_API}
-DARCH_ABI=${CMAKE_ANDROID_ARCH_ABI}
-DANDROID_MANIFEST=${TARGET_MANIFEST_FILE}
-DJAVA_DIRS=${TARGET_JAVA_DIR}
-DRES_DIRS=${TARGET_RES_DIR}
-DJNI_LIBS_DIRS=${JNI_LIBS_DIRS}
-DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
-DASSET_DIRS=${TARGET_ASSET_DIRS}
-P ${GRADLE_ANDROID_SCRIPT}
COMMAND
${CMAKE_COMMAND} -E touch gen.gradle.stamp
COMMENT
"Generate android gradle project"
WORKING_DIRECTORY
${TARGET_NAME}
VERBATIM)
add_custom_command(
OUTPUT
bld.gradle.stamp
DEPENDS
gen.gradle.stamp
COMMAND
${GRADLE_EXECUTABLE} assemble --no-daemon
COMMAND
${CMAKE_COMMAND} -E touch bld.gradle.stamp
COMMENT
"Build android gradle project"
WORKING_DIRECTORY
${TARGET_NAME}
VERBATIM)
add_custom_target(${TARGET_NAME} ALL
DEPENDS
bld.gradle.stamp
${TARGET_DEPENDS})
endfunction()
function(android_sync_folder)
set(options)
set(oneValueArgs PATH)
set(multiValueArgs)
cmake_parse_arguments(PARSE_ARGV 0 TARGET "${options}" "${oneValueArgs}" "${multiValueArgs}")
get_filename_component(FOLDER_NAME "${TARGET_PATH}" NAME)
set(SYNC_COMMAND ${CMAKE_COMMAND}
-DCMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}
-DFOLDER_DIR=${TARGET_PATH}/.
-DDEVICE_DIR=/sdcard/Android/data/com.khronos.${PROJECT_NAME}/files/${FOLDER_NAME}/
-P "${SCRIPT_DIR}/android_sync_folder.cmake")
add_custom_target(
sync.${FOLDER_NAME}.stamp
COMMAND
${SYNC_COMMAND}
COMMENT
"Update ${FOLDER_NAME} in external storage"
VERBATIM)
add_dependencies(${PROJECT_NAME} sync.${FOLDER_NAME}.stamp)
endfunction()
+97
View File
@@ -0,0 +1,97 @@
#[[
Copyright (c) 2019-2024, Arm Limited and Contributors
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 the "License";
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_MODULE_PATH}/module)
set(FOLDER_DIR ${FOLDER_DIR})
set(DEVICE_DIR ${DEVICE_DIR})
find_package(Adb 1.0.39 REQUIRED)
# Sync files to temporary directory
get_filename_component(DIR_PATH "${FOLDER_DIR}" DIRECTORY)
get_filename_component(DIR_NAME "${DIR_PATH}" NAME)
set(TEMP_DIR "/data/local/tmp/${DIR_NAME}")
# Ensure that directory exists in the target
set(ADB_COMMAND ${ADB_EXECUTABLE} shell mkdir -p ${TEMP_DIR})
execute_process(
COMMAND
${ADB_COMMAND})
set(ADB_COMMAND ${ADB_EXECUTABLE} push --sync ${FOLDER_DIR} ${TEMP_DIR})
execute_process(
COMMAND
${ADB_COMMAND}
RESULT_VARIABLE
ret_var
OUTPUT_VARIABLE
ret_msg
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT "${ret_var}" STREQUAL "0")
message(WARNING "Could not sync ${FOLDER_DIR} to temp dir:\n${ret_msg}")
else()
message(STATUS "Updated ${FOLDER_DIR} to ${TEMP_DIR}:\n${ret_msg}")
endif()
# Copy to final device destination
get_filename_component(DIR_PATH "${DEVICE_DIR}" DIRECTORY)
# Ensure that directory exists in the target
set(ADB_COMMAND ${ADB_EXECUTABLE} shell mkdir -p ${DIR_PATH})
execute_process(
COMMAND
${ADB_COMMAND})
set(ADB_COMMAND ${ADB_EXECUTABLE} shell cp -r ${TEMP_DIR} ${DIR_PATH})
execute_process(
COMMAND
${ADB_COMMAND}
RESULT_VARIABLE
ret_var
OUTPUT_VARIABLE
ret_msg
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT "${ret_var}" STREQUAL "0")
message(WARNING "Could not copy ${FOLDER_DIR} to final dir:\n${ret_msg}")
else()
message(STATUS "Copied ${TEMP_DIR} to ${DIR_PATH}:\n${ret_msg}")
endif()
execute_process(
COMMAND
${ADB_COMMAND})
# Ensure file permissions
set(ADB_COMMAND ${ADB_EXECUTABLE} shell chmod 777 -R ${DIR_PATH})
execute_process(
COMMAND
${ADB_COMMAND})
+79
View File
@@ -0,0 +1,79 @@
# Copyright (c) 2020-2021, Arm Limited and Contributors
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 the "License";
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# check whether need to link atomic library explicitly
INCLUDE(CheckCXXSourceCompiles)
INCLUDE(CheckLibraryExists)
if(NOT DEFINED VULKAN_COMPILER_IS_GCC_COMPATIBLE)
if(CMAKE_COMPILER_IS_GNUCXX)
set(VULKAN_COMPILER_IS_GCC_COMPATIBLE ON)
elseif( MSVC )
set(VULKAN_COMPILER_IS_GCC_COMPATIBLE OFF)
elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
set(VULKAN_COMPILER_IS_GCC_COMPATIBLE ON)
elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel" )
set(VULKAN_COMPILER_IS_GCC_COMPATIBLE ON)
endif()
endif()
# Sometimes linking against libatomic is required for atomic ops, if
# the platform doesn't support lock-free atomics.
function(check_working_cxx_atomics varname)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
std::atomic<int> x;
std::atomic<short> y;
std::atomic<char> z;
int main() {
++z;
++y;
return ++x;
}
" ${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
endfunction(check_working_cxx_atomics)
function(check_working_cxx_atomics64 varname)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}")
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
#include <cstdint>
std::atomic<uint64_t> x (0);
int main() {
uint64_t i = x.load(std::memory_order_relaxed);
(void)i;
return 0;
}
" ${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
endfunction(check_working_cxx_atomics64)
set(NEED_LINK_ATOMIC OFF CACHE BOOL "whether need to link against atomic library")
if(VULKAN_COMPILER_IS_GCC_COMPATIBLE)
# check if non-64-bit atomics work without the library.
check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)
# check 64-bit atomics work without the library.
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
if (NOT HAVE_CXX_ATOMICS_WITHOUT_LIB OR NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
set(NEED_LINK_ATOMIC ON CACHE BOOL "whether need to link to atomic library" FORCE)
endif()
endif()
+83
View File
@@ -0,0 +1,83 @@
# Copyright (c) 2023-2025, Thomas Atkinson
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 the "License";
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
## Bucket target for all components
add_custom_target(vkb__components)
set_target_properties(vkb__components PROPERTIES FOLDER "CMake/CustomTargets")
# Create a new component
# Adds the component to the vkb__components target
# Automatically decides whether to create a static or interface library
# If NO_DEFAULT_INCLUDES is set, then the component must provide its own include directories and set its own source groups
function(vkb__register_component)
set(options NO_DEFAULT_INCLUDES)
set(oneValueArgs NAME)
set(multiValueArgs SRC HEADERS LINK_LIBS INCLUDE_DIRS)
cmake_parse_arguments(TARGET "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(TARGET_NAME STREQUAL "")
message(FATAL_ERROR "NAME must be defined in vkb__register_comoponents")
endif()
set(TARGET "vkb__${TARGET_NAME}")
set(TARGET_FOLDER "components")
set(LINKAGE "UNKNOWN") # Used to determine whether to create a static or interface library
if(TARGET_SRC)
message(STATUS "STATIC: ${TARGET}")
set(LINKAGE "PUBLIC")
add_library(${TARGET} STATIC ${TARGET_SRC} ${TARGET_HEADERS})
if(${VKB_WARNINGS_AS_ERRORS})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(${TARGET} PRIVATE -Werror)
# target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wpedantic -Werror)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(${TARGET} PRIVATE /W3 /WX)
# target_compile_options(${TARGET} PRIVATE /W4 /WX)
endif()
endif()
else()
message(STATUS "INTERFACE: ${TARGET}")
set(LINKAGE "INTERFACE")
add_library(${TARGET} INTERFACE)
target_sources(${TARGET} INTERFACE ${TARGET_HEADERS})
endif()
if (LINKAGE STREQUAL "UNKNOWN")
message(FATAL_ERROR "Failed to determine linkage type for ${TARGET}")
endif()
if(TARGET_LINK_LIBS)
target_link_libraries(${TARGET} ${LINKAGE} ${TARGET_LINK_LIBS})
endif()
if(TARGET_INCLUDE_DIRS)
target_include_directories(${TARGET} ${LINKAGE} ${TARGET_INCLUDE_DIRS})
endif()
target_compile_features(${TARGET} ${LINKAGE} cxx_std_17)
set_property(TARGET ${TARGET} PROPERTY FOLDER ${TARGET_FOLDER})
if(NOT TARGET_NO_DEFAULT_INCLUDES)
target_include_directories(${TARGET} ${LINKAGE} ${CMAKE_CURRENT_SOURCE_DIR}/include)
endif()
add_dependencies(vkb__components ${TARGET})
endfunction()
+207
View File
@@ -0,0 +1,207 @@
#[[
Copyright (c) 2019-2023, Arm Limited and Contributors
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 the "License";
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
cmake_minimum_required(VERSION 3.12)
set(SCRIPT_DIR ${CMAKE_CURRENT_LIST_DIR})
set(ROOT_DIR ${SCRIPT_DIR}/../..)
set(GRADLE_BUILD_FILE ${SCRIPT_DIR}/template/gradle/build.gradle.in)
set(GRADLE_APP_BUILD_FILE ${SCRIPT_DIR}/template/gradle/app.build.gradle.in)
set(DOWNLOAD_VVL_GRADLE_SCRIPT_FILE ${SCRIPT_DIR}/template/gradle/download_vvl.gradle)
set(GRADLE_SETTINGS_FILE ${SCRIPT_DIR}/template/gradle/settings.gradle.in)
set(GRADLE_PROPERTIES_FILE ${SCRIPT_DIR}/template/gradle/gradle.properties.in)
set(GRADLE_WRAPPER_PROPERTIES_FILE ${SCRIPT_DIR}/template/gradle/gradle-wrapper.properties.in)
set(GRADLE_WRAPPER_PROPERTIES_JAR ${SCRIPT_DIR}/template/gradle/gradle-wrapper.jar)
set(GRADLE_WRAPPER_SCRIPT_LINUX ${SCRIPT_DIR}/template/gradle/gradlew)
set(GRADLE_WRAPPER_SCRIPT_WIN ${SCRIPT_DIR}/template/gradle/gradlew.bat)
set(VALID_ABI "armeabi" "armeabi-v7a" "arm64-v8a" "x86" "x86_64")
include(${SCRIPT_DIR}/utils.cmake)
# script parameters
set(ANDROID_API 30 CACHE STRING "")
set(ANDROID_MANIFEST "AndroidManifest.xml" CACHE STRING "")
set(ARCH_ABI "arm64-v8a" CACHE STRING "")
set(ASSET_DIRS "assets" CACHE STRING "")
set(RES_DIRS "res" CACHE STRING "")
set(JAVA_DIRS "java" CACHE STRING "")
set(JNI_LIBS_DIRS "jni" CACHE STRING "")
set(NATIVE_SCRIPT "CMakeLists.txt" CACHE STRING "")
set(NATIVE_ARGUMENTS "ANDROID_TOOLCHAIN=clang;ANDROID_STL=c++_static;VKB_VALIDATION_LAYERS=OFF" CACHE STRING "")
set(OUTPUT_DIR "${ROOT_DIR}/build/android_gradle" CACHE PATH "")
# minSdkVersion
set(MIN_SDK_VERSION "minSdk ${ANDROID_API}")
# manifest.srcFile
if(NOT IS_ABSOLUTE ${ANDROID_MANIFEST})
set(ANDROID_MANIFEST ${CMAKE_SOURCE_DIR}/${ANDROID_MANIFEST})
endif()
if(EXISTS ${ANDROID_MANIFEST})
file(RELATIVE_PATH ANDROID_MANIFEST ${OUTPUT_DIR}/app ${ANDROID_MANIFEST})
set(MANIFEST_FILE "manifest.srcFile '${ANDROID_MANIFEST}'")
else()
message(FATAL_ERROR "Manifest file does not exists at `${ANDROID_MANIFEST}`")
endif()
# ndk.abiFilters
set(ABI_LIST)
foreach(ABI_FILTER ${ARCH_ABI})
if(${ABI_FILTER} IN_LIST VALID_ABI)
list(APPEND ABI_LIST ${ABI_FILTER})
else()
message(STATUS "Filter abi is invalid `${ABI_FILTER}`")
endif()
endforeach()
list(JOIN ABI_LIST "', '" ABI_LIST)
if(NOT ${ABI_LIST})
set(NDK_ABI_FILTERS "abiFilters.addAll( '${ABI_LIST}' )")
else()
message(FATAL_ERROR "Minimum one android arch abi required.")
endif()
# assets.srcDirs
set(ASSETS_LIST)
foreach(ASSET_DIR ${ASSET_DIRS})
if(NOT IS_ABSOLUTE ${ASSET_DIR})
set(ASSET_DIR ${CMAKE_SOURCE_DIR}/${ASSET_DIR})
endif()
if(IS_DIRECTORY ${ASSET_DIR})
file(RELATIVE_PATH ASSET_DIR ${OUTPUT_DIR}/app ${ASSET_DIR})
list(APPEND ASSETS_LIST ${ASSET_DIR})
else()
message(STATUS "Asset dir not exists at `${ASSET_DIR}`")
endif()
endforeach()
list(JOIN ASSETS_LIST "', '" ASSETS_LIST)
if(NOT ${ASSETS_LIST})
set(ASSETS_SRC_DIRS "assets.srcDirs += [ '${ASSETS_LIST}' ]")
endif()
# res.srcDirs
set(RES_LIST)
foreach(RES_DIR ${RES_DIRS})
if(NOT IS_ABSOLUTE ${RES_DIR})
set(RES_DIR ${CMAKE_SOURCE_DIR}/${RES_DIR})
endif()
if(IS_DIRECTORY ${RES_DIR})
file(RELATIVE_PATH RES_DIR ${OUTPUT_DIR}/app ${RES_DIR})
list(APPEND RES_LIST ${RES_DIR})
else()
message(STATUS "Resource dir not exists at `${RES_DIR}`")
endif()
endforeach()
list(JOIN RES_LIST "', '" RES_LIST)
if(NOT ${RES_LIST})
set(RES_SRC_DIRS "res.srcDirs += [ '${RES_LIST}' ]")
endif()
# java.srcDirs
set(JAVA_LIST)
foreach(JAVA_DIR ${JAVA_DIRS})
if(NOT IS_ABSOLUTE ${JAVA_DIR})
set(JAVA_DIR ${CMAKE_SOURCE_DIR}/${JAVA_DIR})
endif()
if(IS_DIRECTORY ${JAVA_DIR})
file(RELATIVE_PATH JAVA_DIR ${OUTPUT_DIR}/app ${JAVA_DIR})
list(APPEND JAVA_LIST ${JAVA_DIR})
else()
message(STATUS "Java dir not exists at `${JAVA_DIR}`")
endif()
endforeach()
list(JOIN JAVA_LIST "', '" JAVA_LIST)
if(NOT ${JAVA_LIST})
set(JAVA_SRC_DIRS "java.srcDirs += [ '${JAVA_LIST}' ]")
endif()
# jniLibs.srcDirs
set(JNI_LIBS_DIR_LIST)
foreach(JNI_LIBS_DIR ${JNI_LIBS_DIRS})
if(NOT IS_ABSOLUTE ${JNI_LIBS_DIR})
set(JNI_LIBS_DIR ${CMAKE_SOURCE_DIR}/${JNI_LIBS_DIR})
endif()
if(IS_DIRECTORY ${JNI_LIBS_DIR})
file(RELATIVE_PATH JNI_LIBS_DIR ${OUTPUT_DIR}/app ${JNI_LIBS_DIR})
list(APPEND JNI_LIBS_DIR_LIST ${JNI_LIBS_DIR})
else()
message(STATUS "JNI lib dir not exists at `${JNI_LIBS_DIR}`")
endif()
endforeach()
list(JOIN JNI_LIBS_DIR_LIST "', '" JNI_LIBS_DIR_LIST)
if(NOT ${JNI_LIBS_DIR_LIST})
set(JNI_LIBS_SRC_DIRS "jniLibs.srcDirs += [ '${JNI_LIBS_DIR_LIST}' ]")
endif()
# cmake.path
if(NOT IS_ABSOLUTE ${NATIVE_SCRIPT})
set(NATIVE_SCRIPT ${CMAKE_SOURCE_DIR}/${NATIVE_SCRIPT})
endif()
if(EXISTS ${NATIVE_SCRIPT})
file(RELATIVE_PATH NATIVE_SCRIPT_TMP ${OUTPUT_DIR}/app ${NATIVE_SCRIPT})
set(CMAKE_PATH "path '${NATIVE_SCRIPT_TMP}'\n\t\t\tbuildStagingDirectory \'build-native\'")
endif()
# cmake.arguments
set(ARGS_LIST)
foreach(NATIVE_ARG ${NATIVE_ARGUMENTS})
list(APPEND ARGS_LIST "-D${NATIVE_ARG}")
endforeach()
list(JOIN ARGS_LIST "', '" ARGS_LIST)
if(NOT ${ARGS_LIST} AND EXISTS ${NATIVE_SCRIPT})
set(CMAKE_ARGUMENTS "cmake {\n\t\t\t\t${NDK_ABI_FILTERS}\n\t\t\t\targuments '${ARGS_LIST}'\n\t\t\t}")
endif()
file(MAKE_DIRECTORY ${OUTPUT_DIR}/gradle/wrapper)
file(MAKE_DIRECTORY ${OUTPUT_DIR}/app)
configure_file(${GRADLE_BUILD_FILE} ${OUTPUT_DIR}/build.gradle)
configure_file(${GRADLE_APP_BUILD_FILE} ${OUTPUT_DIR}/app/build.gradle)
file(COPY ${DOWNLOAD_VVL_GRADLE_SCRIPT_FILE} DESTINATION ${OUTPUT_DIR}/app)
configure_file(${GRADLE_SETTINGS_FILE} ${OUTPUT_DIR}/settings.gradle)
configure_file(${GRADLE_PROPERTIES_FILE} ${OUTPUT_DIR}/gradle.properties)
configure_file(${GRADLE_WRAPPER_PROPERTIES_FILE} ${OUTPUT_DIR}/gradle/wrapper/gradle-wrapper.properties)
file(COPY ${GRADLE_WRAPPER_PROPERTIES_JAR} DESTINATION ${OUTPUT_DIR}/gradle/wrapper)
file(COPY ${GRADLE_WRAPPER_SCRIPT_LINUX} DESTINATION ${OUTPUT_DIR})
file(COPY ${GRADLE_WRAPPER_SCRIPT_WIN} DESTINATION ${OUTPUT_DIR})
message(STATUS "Android Gradle Project (With Native Support) generated at:\n\t${OUTPUT_DIR}")
+50
View File
@@ -0,0 +1,50 @@
#[[
Copyright (c) 2019-2023, Arm Limited and Contributors
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 the "License";
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
cmake_minimum_required(VERSION 3.12)
set(SCRIPT_DIR ${CMAKE_CURRENT_LIST_DIR})
set(ROOT_DIR ${SCRIPT_DIR}/../..)
set(SAMPLE_NAME "" CACHE STRING "")
set(TEMPLATE_NAME "sample" CACHE STRING "")
set(OUTPUT_DIR "${ROOT_DIR}/samples" CACHE PATH "")
set(CMAKE_FILE ${SCRIPT_DIR}/template/${TEMPLATE_NAME}/CMakeLists.txt.in)
set(SAMPLE_SOURCE_FILE ${SCRIPT_DIR}/template/${TEMPLATE_NAME}/sample.cpp.in)
set(SAMPLE_HEADER_FILE ${SCRIPT_DIR}/template/${TEMPLATE_NAME}/sample.h.in)
set(SAMPLE_README_FILE ${SCRIPT_DIR}/template/README.adoc.in)
# Only create a new sample if a name is given
if(NOT SAMPLE_NAME)
message(FATAL_ERROR "Sample name cannot be empty.")
endif()
# Convert filename to accepted format
# insert an underscore before any upper case letter
string(REGEX REPLACE "(.)([A-Z][a-z]+)" "\\1_\\2" result ${SAMPLE_NAME})
# insert an underscore before any upper case letter
string(REGEX REPLACE "([a-z0-9])([A-Z])" "\\1_\\2" result ${result})
# transform characters to lower case
string(TOLOWER ${result} SAMPLE_NAME_FILE)
configure_file(${CMAKE_FILE} ${OUTPUT_DIR}/${SAMPLE_NAME_FILE}/CMakeLists.txt @ONLY)
configure_file(${SAMPLE_SOURCE_FILE} ${OUTPUT_DIR}/${SAMPLE_NAME_FILE}/${SAMPLE_NAME_FILE}.cpp)
configure_file(${SAMPLE_HEADER_FILE} ${OUTPUT_DIR}/${SAMPLE_NAME_FILE}/${SAMPLE_NAME_FILE}.h)
configure_file(${SAMPLE_README_FILE} ${OUTPUT_DIR}/${SAMPLE_NAME_FILE}/README.adoc)
+143
View File
@@ -0,0 +1,143 @@
#[[
Copyright (c) 2019-2025, Arm Limited and Contributors
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 the "License";
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
if(NOT CMAKE_ANDROID_NDK)
set(CMAKE_ANDROID_NDK ${ANDROID_NDK})
endif()
# Enable group projects in folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
if(ANDROID)
set(TARGET_ARCH ${CMAKE_ANDROID_ARCH_ABI})
else()
set(TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR})
endif()
if(APPLE)
cmake_minimum_required(VERSION 3.24)
set(VKB_ENABLE_PORTABILITY ON CACHE BOOL "Enable portability enumeration and subset features in the framework. This is required to be set when running on Apple platforms." FORCE)
find_package(Vulkan QUIET OPTIONAL_COMPONENTS MoltenVK)
if(USE_MoltenVK OR (IOS AND (NOT Vulkan_MoltenVK_FOUND OR (${CMAKE_OSX_SYSROOT} STREQUAL "iphonesimulator" AND ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64"))))
# if using MoltenVK, or MoltenVK for iOS was not found, or using iOS Simulator on x86_64, look for MoltenVK in the Vulkan SDK and MoltenVK project locations
if(NOT Vulkan_MoltenVK_LIBRARY)
# since both are available in the Vulkan SDK and MoltenVK github project, make sure we look for MoltenVK framework on iOS and dylib on macOS
set(_saved_cmake_find_framework ${CMAKE_FIND_FRAMEWORK})
if(IOS)
set(CMAKE_FIND_FRAMEWORK ALWAYS)
else()
set(CMAKE_FIND_FRAMEWORK NEVER)
endif()
find_library(Vulkan_MoltenVK_LIBRARY NAMES MoltenVK HINTS "$ENV{VULKAN_SDK}/lib" "$ENV{VULKAN_SDK}/dynamic" "$ENV{VULKAN_SDK}/dylib/macOS")
set(CMAKE_FIND_FRAMEWORK ${_saved_cmake_find_framework})
unset(_saved_cmake_find_framework)
endif()
if(Vulkan_MoltenVK_LIBRARY)
get_filename_component(MoltenVK_LIBRARY_PATH ${Vulkan_MoltenVK_LIBRARY} DIRECTORY)
# For both iOS and macOS: set up global Vulkan Library defines so that MoltenVK is dynamically loaded versus the Vulkan loader
# on iOS we can control Vulkan library loading priority by selecting which libraries are embedded in the iOS application bundle
if(IOS)
add_compile_definitions(_HPP_VULKAN_LIBRARY="MoltenVK.framework/MoltenVK")
# unset FindVulkan.cmake cache variables so Vulkan loader, Validation Layer, and icd/layer json files are not embedded on iOS
unset(Vulkan_LIBRARY CACHE)
unset(Vulkan_Layer_VALIDATION CACHE)
# on macOS make sure that MoltenVK_LIBRARY_PATH points to the MoltenVK project installation and not to the Vulkan_LIBRARY location
# otherwise if DYLD_LIBRARY_PATH points to a common search path, Volk may dynamically load libvulkan.dylib versus libMoltenVK.dylib
elseif(NOT Vulkan_LIBRARY MATCHES "${MoltenVK_LIBRARY_PATH}")
add_compile_definitions(_HPP_VULKAN_LIBRARY="libMoltenVK.dylib")
add_compile_definitions(_GLFW_VULKAN_LIBRARY="libMoltenVK.dylib")
set(ENV{DYLD_LIBRARY_PATH} "${MoltenVK_LIBRARY_PATH}:$ENV{DYLD_LIBRARY_PATH}")
else()
message(FATAL_ERROR "Vulkan library found in MoltenVK search path. Please set VULKAN_SDK to the MoltenVK project install location.")
endif()
message(STATUS "Using MoltenVK: ${Vulkan_MoltenVK_LIBRARY}")
else()
message(FATAL_ERROR "Can't find MoltenVK library. Please install the Vulkan SDK or MoltenVK project and set VULKAN_SDK.")
endif()
elseif(IOS)
# if not using MoltenVK on iOS, set up global Vulkan Library define for iOS Vulkan loader
add_compile_definitions(_HPP_VULKAN_LIBRARY="vulkan.framework/vulkan")
endif()
if(CMAKE_GENERATOR MATCHES "Xcode")
set(CMAKE_XCODE_GENERATE_SCHEME ON)
set(CMAKE_XCODE_SCHEME_ENABLE_GPU_API_VALIDATION OFF)
if(NOT IOS)
# If the Vulkan library's or loader's environment variables are defined, make them available within Xcode schemes
if(DEFINED ENV{DYLD_LIBRARY_PATH})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};DYLD_LIBRARY_PATH=$ENV{DYLD_LIBRARY_PATH}")
endif()
if(DEFINED ENV{VK_ADD_LAYER_PATH})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_ADD_LAYER_PATH=$ENV{VK_ADD_LAYER_PATH}")
endif()
if(DEFINED ENV{VK_ICD_FILENAMES})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_ICD_FILENAMES=$ENV{VK_ICD_FILENAMES}")
endif()
if(DEFINED ENV{VK_DRIVER_FILES})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_DRIVER_FILES=$ENV{VK_DRIVER_FILES}")
endif()
# Suppress regeneration for Xcode since environment variables will be lost if not set in Xcode locations/custom paths
set(CMAKE_SUPPRESS_REGENERATION ON)
endif()
endif()
endif()
set(VKB_WARNINGS_AS_ERRORS ON CACHE BOOL "Enable Warnings as Errors")
set(VKB_VALIDATION_LAYERS OFF CACHE BOOL "Enable validation layers for every application.")
set(VKB_VALIDATION_LAYERS_GPU_ASSISTED OFF CACHE BOOL "Enable GPU assisted validation layers for every application (implicitly enables VKB_VALIDATION_LAYERS).")
set(VKB_VALIDATION_LAYERS_BEST_PRACTICES OFF CACHE BOOL "Enable best practices validation layers for every application (implicitly enables VKB_VALIDATION_LAYERS).")
set(VKB_VALIDATION_LAYERS_SYNCHRONIZATION OFF CACHE BOOL "Enable synchronization validation layers for every application (implicitly enables VKB_VALIDATION_LAYERS).")
set(VKB_VULKAN_DEBUG ON CACHE BOOL "Enable VK_EXT_debug_utils or VK_EXT_debug_marker if supported.")
set(VKB_BUILD_SAMPLES ON CACHE BOOL "Enable generation and building of Vulkan best practice samples.")
set(VKB_BUILD_TESTS OFF CACHE BOOL "Enable generation and building of Vulkan best practice tests.")
set(VKB_WSI_SELECTION "XCB" CACHE STRING "Select WSI target (XCB, XLIB, WAYLAND, D2D)")
set(VKB_CLANG_TIDY OFF CACHE STRING "Use CMake Clang Tidy integration")
set(VKB_CLANG_TIDY_EXTRAS "-header-filter=framework,samples,app;-checks=-*,google-*,-google-runtime-references;--fix;--fix-errors" CACHE STRING "Clang Tidy Parameters")
set(VKB_PROFILING OFF CACHE BOOL "Enable Tracy profiling")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin/${CMAKE_BUILD_TYPE}/${TARGET_ARCH}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib/${CMAKE_BUILD_TYPE}/${TARGET_ARCH}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib/${CMAKE_BUILD_TYPE}/${TARGET_ARCH}")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_C_FLAGS_DEBUG "-DDEBUG=0 ${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG=0 ${CMAKE_CXX_FLAGS_DEBUG}")
if (VKB_CLANG_TIDY)
find_program(CLANG_TIDY "clang-tidy" "clang-tidy-15" REQUIRED)
set(VKB_DO_CLANG_TIDY ${CLANG_TIDY} ${VKB_CLANG_TIDY_EXTRAS})
endif()
if (ANDROID AND VKB_PROFILING)
message(WARNING "Tracy Profiling is not supported on android yet")
set(VKB_PROFILING OFF)
endif()
set(TRACY_ENABLE ${VKB_PROFILING})
+361
View File
@@ -0,0 +1,361 @@
# Adapted from https://github.com/jeffdaily/parasail/blob/600fb26151ff19899ee39a214972dcf2b9b11ed7/cmake/FindAVX2.cmake
#[[
Copyright (c) 2015-2024, Battelle Memorial Institute
1. Battelle Memorial Institute (hereinafter Battelle) hereby grants
permission to any person or entity lawfully obtaining a copy of this
software and associated documentation files (hereinafter “the
Software”) to redistribute and use the Software in source and binary
forms, with or without modification. Such person or entity may use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and may permit others to do so, subject to
the following conditions:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimers.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
- Other than as used herein, neither the name Battelle Memorial
Institute or Battelle may be used in any form whatsoever without
the express written consent of Battelle.
- Redistributions of the software in any form, and publications
based on work performed using the software should include the
following citation as a reference:
Daily, Jeff. (2016). Parasail: SIMD C library for global,
semi-global, and local pairwise sequence alignments. *BMC
Bioinformatics*, 17(1), 1-11. doi:10.1186/s12859-016-0930-z
2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BATTELLE
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
]]
# .rst:
# FindAVX2
# --------
#
# Finds AVX2 support
#
# This module can be used to detect AVX2 support in a C compiler. If
# the compiler supports AVX2, the flags required to compile with
# AVX2 support are returned in variables for the different languages.
# The variables may be empty if the compiler does not need a special
# flag to support AVX2.
#
# The following variables are set:
#
# ::
#
# AVX2_C_FLAGS - flags to add to the C compiler for AVX2 support
# AVX2_FOUND - true if AVX2 is detected
# =============================================================================
set(_AVX2_REQUIRED_VARS)
set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
set(CMAKE_REQUIRED_QUIET ${AVX2_FIND_QUIETLY})
# sample AVX2 source code to test
set(AVX2_C_TEST_SOURCE
"
#include <immintrin.h>
void parasail_memset___m256i(__m256i *b, __m256i c, size_t len)
{
size_t i;
for (i=0; i<len; ++i) {
_mm256_store_si256(&b[i], c);
}
}
int foo() {
__m256i vOne = _mm256_set1_epi8(1);
__m256i result = _mm256_add_epi8(vOne,vOne);
return _mm_extract_epi16(_mm256_extracti128_si256(result,0),0);
}
int main(void) { return (int)foo(); }
")
# if these are set then do not try to find them again,
# by avoiding any try_compiles for the flags
if((DEFINED AVX2_C_FLAGS) OR (DEFINED HAVE_AVX2))
else()
if(WIN32)
# MSVC can compile AVX intrinsics without the arch flag, however it
# will detect that AVX code is found and "consider using /arch:AVX".
set(AVX2_C_FLAG_CANDIDATES
"/arch:AVX"
"/arch:AVX2")
else()
set(AVX2_C_FLAG_CANDIDATES
#Empty, if compiler automatically accepts AVX2
" "
#GNU, Intel
"-march=core-avx2"
#clang
"-mavx2"
)
endif()
include(CheckCSourceCompiles)
foreach(FLAG IN LISTS AVX2_C_FLAG_CANDIDATES)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${FLAG}")
unset(HAVE_AVX2 CACHE)
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Try AVX2 C flag = [${FLAG}]")
endif()
check_c_source_compiles("${AVX2_C_TEST_SOURCE}" HAVE_AVX2)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
if(HAVE_AVX2)
set(AVX2_C_FLAGS_INTERNAL "${FLAG}")
break()
endif()
endforeach()
unset(AVX2_C_FLAG_CANDIDATES)
set(AVX2_C_FLAGS "${AVX2_C_FLAGS_INTERNAL}"
CACHE STRING "C compiler flags for AVX2 intrinsics")
endif()
list(APPEND _AVX2_REQUIRED_VARS AVX2_C_FLAGS)
set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
if(_AVX2_REQUIRED_VARS)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(AVX2
REQUIRED_VARS ${_AVX2_REQUIRED_VARS})
mark_as_advanced(${_AVX2_REQUIRED_VARS})
unset(_AVX2_REQUIRED_VARS)
else()
message(SEND_ERROR "FindAVX2 requires C or CXX language to be enabled")
endif()
# begin tests for AVX2 specfic features
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(SAFE_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(SAFE_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif()
set(AVX2_C_TEST_SOURCE_SET1_EPI64X
"
#include <stdint.h>
#include <immintrin.h>
__m256i foo() {
__m256i vOne = _mm256_set1_epi64x(1);
return vOne;
}
int main(void) { foo(); return 0; }
")
if(AVX2_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}")
check_c_source_compiles("${AVX2_C_TEST_SOURCE_SET1_EPI64X}" HAVE_AVX2_MM256_SET1_EPI64X)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
set(AVX2_C_TEST_SOURCE_SET_EPI64X
"
#include <stdint.h>
#include <immintrin.h>
__m256i foo() {
__m256i vOne = _mm256_set_epi64x(1,1,1,1);
return vOne;
}
int main(void) { foo(); return 0; }
")
if(AVX2_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}")
check_c_source_compiles("${AVX2_C_TEST_SOURCE_SET_EPI64X}" HAVE_AVX2_MM256_SET_EPI64X)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
set(AVX2_C_TEST_SOURCE_INSERT64
"
#include <stdint.h>
#include <immintrin.h>
__m256i foo() {
__m256i vOne = _mm256_set1_epi8(1);
return _mm256_insert_epi64(vOne,INT64_MIN,0);
}
int main(void) { foo(); return 0; }
")
if(AVX2_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}")
check_c_source_compiles("${AVX2_C_TEST_SOURCE_INSERT64}" HAVE_AVX2_MM256_INSERT_EPI64)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
set(AVX2_C_TEST_SOURCE_INSERT32
"
#include <stdint.h>
#include <immintrin.h>
__m256i foo() {
__m256i vOne = _mm256_set1_epi8(1);
return _mm256_insert_epi32(vOne,INT32_MIN,0);
}
int main(void) { foo(); return 0; }
")
if(AVX2_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}")
check_c_source_compiles("${AVX2_C_TEST_SOURCE_INSERT32}" HAVE_AVX2_MM256_INSERT_EPI32)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
set(AVX2_C_TEST_SOURCE_INSERT16
"
#include <stdint.h>
#include <immintrin.h>
__m256i foo() {
__m256i vOne = _mm256_set1_epi8(1);
return _mm256_insert_epi16(vOne,INT16_MIN,0);
}
int main(void) { foo(); return 0; }
")
if(AVX2_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}")
check_c_source_compiles("${AVX2_C_TEST_SOURCE_INSERT16}" HAVE_AVX2_MM256_INSERT_EPI16)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
set(AVX2_C_TEST_SOURCE_INSERT8
"
#include <stdint.h>
#include <immintrin.h>
__m256i foo() {
__m256i vOne = _mm256_set1_epi8(1);
return _mm256_insert_epi8(vOne,INT8_MIN,0);
}
int main(void) { foo(); return 0; }
")
if(AVX2_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}")
check_c_source_compiles("${AVX2_C_TEST_SOURCE_INSERT8}" HAVE_AVX2_MM256_INSERT_EPI8)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
set(AVX2_C_TEST_SOURCE_EXTRACT64
"
#include <stdint.h>
#include <immintrin.h>
int64_t foo() {
__m256i vOne = _mm256_set1_epi8(1);
return (int64_t)_mm256_extract_epi64(vOne,0);
}
int main(void) { return (int)foo(); }
")
if(AVX2_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}")
check_c_source_compiles("${AVX2_C_TEST_SOURCE_EXTRACT64}" HAVE_AVX2_MM256_EXTRACT_EPI64)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
set(AVX2_C_TEST_SOURCE_EXTRACT32
"
#include <stdint.h>
#include <immintrin.h>
int32_t foo() {
__m256i vOne = _mm256_set1_epi8(1);
return (int32_t)_mm256_extract_epi32(vOne,0);
}
int main(void) { return (int)foo(); }
")
if(AVX2_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}")
check_c_source_compiles("${AVX2_C_TEST_SOURCE_EXTRACT32}" HAVE_AVX2_MM256_EXTRACT_EPI32)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
set(AVX2_C_TEST_SOURCE_EXTRACT16
"
#include <stdint.h>
#include <immintrin.h>
int16_t foo() {
__m256i vOne = _mm256_set1_epi8(1);
return (int16_t)_mm256_extract_epi16(vOne,0);
}
int main(void) { return (int)foo(); }
")
if(AVX2_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}")
check_c_source_compiles("${AVX2_C_TEST_SOURCE_EXTRACT16}" HAVE_AVX2_MM256_EXTRACT_EPI16)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
set(AVX2_C_TEST_SOURCE_EXTRACT8
"
#include <stdint.h>
#include <immintrin.h>
int8_t foo() {
__m256i vOne = _mm256_set1_epi8(1);
return (int8_t)_mm256_extract_epi8(vOne,0);
}
int main(void) { return (int)foo(); }
")
if(AVX2_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}")
check_c_source_compiles("${AVX2_C_TEST_SOURCE_EXTRACT8}" HAVE_AVX2_MM256_EXTRACT_EPI8)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_C_FLAGS "${SAFE_CMAKE_C_FLAGS}")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${SAFE_CMAKE_C_FLAGS}")
endif()
+52
View File
@@ -0,0 +1,52 @@
#[[
Copyright (c) 2022, Arm Limited and Contributors
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 the "License";
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
include(FindPackageHandleStandardArgs)
if(CMAKE_HOST_WIN32)
set(ADB_FILE "adb.exe")
else()
set(ADB_FILE "adb")
endif()
find_program(ADB_EXECUTABLE
NAMES
${ADB_FILE}
PATH_SUFFIXES
platform-tools
PATHS
$ENV{ANDROID_HOME})
mark_as_advanced(ADB_EXECUTABLE)
if(ADB_EXECUTABLE)
execute_process(
COMMAND ${ADB_EXECUTABLE} --version
OUTPUT_VARIABLE ADB_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(ADB_VERSION_PREFIX "Android Debug Bridge version ")
string(REGEX MATCH "${ADB_VERSION_PREFIX}[0-9]+.[0-9]+.[0-9]+" ADB_VERSION ${ADB_VERSION})
string(REPLACE ${ADB_VERSION_PREFIX} "" ADB_VERSION ${ADB_VERSION})
endif()
find_package_handle_standard_args(Adb
VERSION_VAR ADB_VERSION
REQUIRED_VARS ADB_EXECUTABLE)
+51
View File
@@ -0,0 +1,51 @@
#[[
Copyright (c) 2019, Arm Limited and Contributors
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 the "License";
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
include(FindPackageHandleStandardArgs)
if(CMAKE_HOST_WIN32)
set(GRADLE_FILE "gradle.bat")
else()
set(GRADLE_FILE "gradle")
endif()
find_program(GRADLE_EXECUTABLE
NAMES
${GRADLE_FILE}
PATH_SUFFIXES
bin
PATHS
$ENV{GRADLE_HOME})
mark_as_advanced(GRADLE_EXECUTABLE)
if(GRADLE_EXECUTABLE)
execute_process(
COMMAND ${GRADLE_EXECUTABLE} --version
OUTPUT_VARIABLE GRADLE_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "Gradle [0-9]+.[0-9]+" GRADLE_VERSION ${GRADLE_VERSION})
string(REPLACE "Gradle " "" GRADLE_VERSION ${GRADLE_VERSION})
endif()
find_package_handle_standard_args(Gradle
VERSION_VAR GRADLE_VERSION
REQUIRED_VARS GRADLE_EXECUTABLE)
+145
View File
@@ -0,0 +1,145 @@
# Adapted from https://github.com/jeffdaily/parasail/blob/600fb26151ff19899ee39a214972dcf2b9b11ed7/cmake/FindNEON.cmake
#[[
Copyright (c) 2015-2024, Battelle Memorial Institute
1. Battelle Memorial Institute (hereinafter Battelle) hereby grants
permission to any person or entity lawfully obtaining a copy of this
software and associated documentation files (hereinafter “the
Software”) to redistribute and use the Software in source and binary
forms, with or without modification. Such person or entity may use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and may permit others to do so, subject to
the following conditions:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimers.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
- Other than as used herein, neither the name Battelle Memorial
Institute or Battelle may be used in any form whatsoever without
the express written consent of Battelle.
- Redistributions of the software in any form, and publications
based on work performed using the software should include the
following citation as a reference:
Daily, Jeff. (2016). Parasail: SIMD C library for global,
semi-global, and local pairwise sequence alignments. *BMC
Bioinformatics*, 17(1), 1-11. doi:10.1186/s12859-016-0930-z
2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BATTELLE
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
]]
#.rst:
# FindNEON
# --------
#
# Finds NEON support
#
# This module can be used to detect NEON support in a C compiler. If
# the compiler supports NEON, the flags required to compile with
# NEON support are returned in variables for the different languages.
# The variables may be empty if the compiler does not need a special
# flag to support NEON.
#
# The following variables are set:
#
# ::
#
# NEON_C_FLAGS - flags to add to the C compiler for NEON support
# NEON_FOUND - true if NEON is detected
#
#=============================================================================
set(_NEON_REQUIRED_VARS)
set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
set(CMAKE_REQUIRED_QUIET ${NEON_FIND_QUIETLY})
# sample NEON source code to test
set(NEON_C_TEST_SOURCE
"
#include <arm_neon.h>
uint32x4_t double_elements(uint32x4_t input)
{
return(vaddq_u32(input, input));
}
int main(void)
{
uint32x4_t one;
uint32x4_t two = double_elements(one);
return 0;
}
")
# if these are set then do not try to find them again,
# by avoiding any try_compiles for the flags
if((DEFINED NEON_C_FLAGS) OR (DEFINED HAVE_NEON))
else()
if(WIN32)
set(NEON_C_FLAG_CANDIDATES
#Empty, if compiler automatically accepts NEON
" ")
else()
set(NEON_C_FLAG_CANDIDATES
#Empty, if compiler automatically accepts NEON
" "
"-mfpu=neon"
"-mfpu=neon -mfloat-abi=softfp"
)
endif()
include(CheckCSourceCompiles)
foreach(FLAG IN LISTS NEON_C_FLAG_CANDIDATES)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${FLAG}")
unset(HAVE_NEON CACHE)
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Try NEON C flag = [${FLAG}]")
endif()
check_c_source_compiles("${NEON_C_TEST_SOURCE}" HAVE_NEON)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
if(HAVE_NEON)
set(NEON_C_FLAGS_INTERNAL "${FLAG}")
break()
endif()
endforeach()
unset(NEON_C_FLAG_CANDIDATES)
set(NEON_C_FLAGS "${NEON_C_FLAGS_INTERNAL}"
CACHE STRING "C compiler flags for NEON intrinsics")
endif()
list(APPEND _NEON_REQUIRED_VARS NEON_C_FLAGS)
set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
if(_NEON_REQUIRED_VARS)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NEON
REQUIRED_VARS ${_NEON_REQUIRED_VARS})
mark_as_advanced(${_NEON_REQUIRED_VARS})
unset(_NEON_REQUIRED_VARS)
else()
message(SEND_ERROR "FindNEON requires C or CXX language to be enabled")
endif()
+194
View File
@@ -0,0 +1,194 @@
# Adapted from https://github.com/jeffdaily/parasail/blob/600fb26151ff19899ee39a214972dcf2b9b11ed7/cmake/FindSSE2.cmake
#[[
Copyright (c) 2015-2024, Battelle Memorial Institute
1. Battelle Memorial Institute (hereinafter Battelle) hereby grants
permission to any person or entity lawfully obtaining a copy of this
software and associated documentation files (hereinafter “the
Software”) to redistribute and use the Software in source and binary
forms, with or without modification. Such person or entity may use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and may permit others to do so, subject to
the following conditions:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimers.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
- Other than as used herein, neither the name Battelle Memorial
Institute or Battelle may be used in any form whatsoever without
the express written consent of Battelle.
- Redistributions of the software in any form, and publications
based on work performed using the software should include the
following citation as a reference:
Daily, Jeff. (2016). Parasail: SIMD C library for global,
semi-global, and local pairwise sequence alignments. *BMC
Bioinformatics*, 17(1), 1-11. doi:10.1186/s12859-016-0930-z
2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BATTELLE
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
]]
#.rst:
# FindSSE2
# --------
#
# Finds SSE2 support
#
# This module can be used to detect SSE2 support in a C compiler. If
# the compiler supports SSE2, the flags required to compile with
# SSE2 support are returned in variables for the different languages.
# The variables may be empty if the compiler does not need a special
# flag to support SSE2.
#
# The following variables are set:
#
# ::
#
# SSE2_C_FLAGS - flags to add to the C compiler for SSE2 support
# SSE2_FOUND - true if SSE2 is detected
#
#=============================================================================
set(_SSE2_REQUIRED_VARS)
set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
set(CMAKE_REQUIRED_QUIET ${SSE2_FIND_QUIETLY})
# sample SSE2 source code to test
set(SSE2_C_TEST_SOURCE
"
#if defined(_MSC_VER)
#include <intrin.h>
#else
#include <emmintrin.h>
#endif
int foo() {
__m128i vOne = _mm_set1_epi16(1);
__m128i result = _mm_add_epi16(vOne,vOne);
return _mm_extract_epi16(result, 0);
}
int main(void) { return foo(); }
")
# if these are set then do not try to find them again,
# by avoiding any try_compiles for the flags
if((DEFINED SSE2_C_FLAGS) OR (DEFINED HAVE_SSE2))
else()
if(WIN32)
set(SSE2_C_FLAG_CANDIDATES
#Empty, if compiler automatically accepts SSE2
" "
"/arch:SSE2")
else()
set(SSE2_C_FLAG_CANDIDATES
#Empty, if compiler automatically accepts SSE2
" "
#GNU, Intel
"-march=core2"
#clang
"-msse2"
)
endif()
include(CheckCSourceCompiles)
foreach(FLAG IN LISTS SSE2_C_FLAG_CANDIDATES)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${FLAG}")
unset(HAVE_SSE2 CACHE)
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Try SSE2 C flag = [${FLAG}]")
endif()
check_c_source_compiles("${SSE2_C_TEST_SOURCE}" HAVE_SSE2)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
if(HAVE_SSE2)
set(SSE2_C_FLAGS_INTERNAL "${FLAG}")
break()
endif()
endforeach()
unset(SSE2_C_FLAG_CANDIDATES)
set(SSE2_C_FLAGS "${SSE2_C_FLAGS_INTERNAL}"
CACHE STRING "C compiler flags for SSE2 intrinsics")
endif()
list(APPEND _SSE2_REQUIRED_VARS SSE2_C_FLAGS)
set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
if(_SSE2_REQUIRED_VARS)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SSE2
REQUIRED_VARS ${_SSE2_REQUIRED_VARS})
mark_as_advanced(${_SSE2_REQUIRED_VARS})
unset(_SSE2_REQUIRED_VARS)
else()
message(SEND_ERROR "FindSSE2 requires C or CXX language to be enabled")
endif()
set(SSE2_C_TEST_SOURCE_SET1_EPI64X
"
#include <stdint.h>
#if defined(_MSC_VER)
#include <intrin.h>
#else
#include <emmintrin.h>
#endif
__m128i foo() {
__m128i vOne = _mm_set1_epi64x(1);
return vOne;
}
int main(void) { foo(); return 0; }
")
if(SSE2_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${SSE2_C_FLAGS}")
check_c_source_compiles("${SSE2_C_TEST_SOURCE_SET1_EPI64X}" HAVE_SSE2_MM_SET1_EPI64X)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
set(SSE2_C_TEST_SOURCE_SET_EPI64X
"
#include <stdint.h>
#if defined(_MSC_VER)
#include <intrin.h>
#else
#include <emmintrin.h>
#endif
__m128i foo() {
__m128i vOne = _mm_set_epi64x(1,1);
return vOne;
}
int main(void) { foo(); return 0; }
")
if(SSE2_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${SSE2_C_FLAGS}")
check_c_source_compiles("${SSE2_C_TEST_SOURCE_SET_EPI64X}" HAVE_SSE2_MM_SET_EPI64X)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
+198
View File
@@ -0,0 +1,198 @@
# Adapted from https://github.com/jeffdaily/parasail/blob/600fb26151ff19899ee39a214972dcf2b9b11ed7/cmake/FindSSE41.cmake
#[[
Copyright (c) 2015-2024, Battelle Memorial Institute
1. Battelle Memorial Institute (hereinafter Battelle) hereby grants
permission to any person or entity lawfully obtaining a copy of this
software and associated documentation files (hereinafter “the
Software”) to redistribute and use the Software in source and binary
forms, with or without modification. Such person or entity may use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and may permit others to do so, subject to
the following conditions:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimers.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
- Other than as used herein, neither the name Battelle Memorial
Institute or Battelle may be used in any form whatsoever without
the express written consent of Battelle.
- Redistributions of the software in any form, and publications
based on work performed using the software should include the
following citation as a reference:
Daily, Jeff. (2016). Parasail: SIMD C library for global,
semi-global, and local pairwise sequence alignments. *BMC
Bioinformatics*, 17(1), 1-11. doi:10.1186/s12859-016-0930-z
2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BATTELLE
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
]]
#.rst:
# FindSSE41
# ---------
#
# Finds SSE41 support
#
# This module can be used to detect SSE41 support in a C compiler. If
# the compiler supports SSE41, the flags required to compile with
# SSE41 support are returned in variables for the different languages.
# The variables may be empty if the compiler does not need a special
# flag to support SSE41.
#
# The following variables are set:
#
# ::
#
# SSE41_C_FLAGS - flags to add to the C compiler for SSE41 support
# SSE41_FOUND - true if SSE41 is detected
#
#=============================================================================
set(_SSE41_REQUIRED_VARS)
set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
set(CMAKE_REQUIRED_QUIET ${SSE41_FIND_QUIETLY})
# sample SSE41 source code to test
set(SSE41_C_TEST_SOURCE
"
#if defined(_MSC_VER)
#include <intrin.h>
#else
#include <smmintrin.h>
#endif
int foo() {
__m128i vOne = _mm_set1_epi8(1);
__m128i result = _mm_max_epi8(vOne,vOne);
return _mm_extract_epi8(result, 0);
}
int main(void) { return foo(); }
")
# if these are set then do not try to find them again,
# by avoiding any try_compiles for the flags
if((DEFINED SSE41_C_FLAGS) OR (DEFINED HAVE_SSE41))
else()
if(WIN32)
set(SSE41_C_FLAG_CANDIDATES
#Empty, if compiler automatically accepts SSE41
" "
"/arch:SSE2")
else()
set(SSE41_C_FLAG_CANDIDATES
#Empty, if compiler automatically accepts SSE41
" "
#GNU, Intel
"-march=corei7"
#clang
"-msse4"
#GNU 4.4.7 ?
"-msse4.1"
)
endif()
include(CheckCSourceCompiles)
foreach(FLAG IN LISTS SSE41_C_FLAG_CANDIDATES)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${FLAG}")
unset(HAVE_SSE41 CACHE)
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Try SSE41 C flag = [${FLAG}]")
endif()
check_c_source_compiles("${SSE41_C_TEST_SOURCE}" HAVE_SSE41)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
if(HAVE_SSE41)
set(SSE41_C_FLAGS_INTERNAL "${FLAG}")
break()
endif()
endforeach()
unset(SSE41_C_FLAG_CANDIDATES)
set(SSE41_C_FLAGS "${SSE41_C_FLAGS_INTERNAL}"
CACHE STRING "C compiler flags for SSE41 intrinsics")
endif()
list(APPEND _SSE41_REQUIRED_VARS SSE41_C_FLAGS)
set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
if(_SSE41_REQUIRED_VARS)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SSE41
REQUIRED_VARS ${_SSE41_REQUIRED_VARS})
mark_as_advanced(${_SSE41_REQUIRED_VARS})
unset(_SSE41_REQUIRED_VARS)
else()
message(SEND_ERROR "FindSSE41 requires C or CXX language to be enabled")
endif()
# begin tests for SSE4.1 specfic features
set(SSE41_C_TEST_SOURCE_INSERT64
"
#include <stdint.h>
#if defined(_MSC_VER)
#include <intrin.h>
#else
#include <smmintrin.h>
#endif
__m128i foo() {
__m128i vOne = _mm_set1_epi8(1);
return _mm_insert_epi64(vOne,INT64_MIN,0);
}
int main(void) { foo(); return 0; }
")
if(SSE41_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${SSE41_C_FLAGS}")
check_c_source_compiles("${SSE41_C_TEST_SOURCE_INSERT64}" HAVE_SSE41_MM_INSERT_EPI64)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
set(SSE41_C_TEST_SOURCE_EXTRACT64
"
#include <stdint.h>
#if defined(_MSC_VER)
#include <intrin.h>
#else
#include <smmintrin.h>
#endif
int64_t foo() {
__m128i vOne = _mm_set1_epi8(1);
return (int64_t)_mm_extract_epi64(vOne,0);
}
int main(void) { return (int)foo(); }
")
if(SSE41_C_FLAGS)
include(CheckCSourceCompiles)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${SSE41_C_FLAGS}")
check_c_source_compiles("${SSE41_C_TEST_SOURCE_EXTRACT64}" HAVE_SSE41_MM_EXTRACT_EPI64)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
endif()
+962
View File
@@ -0,0 +1,962 @@
# Updates for iOS Copyright (c) 2024, Holochip Inc.
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindVulkan
----------
.. versionadded:: 3.7
Find Vulkan, which is a low-overhead, cross-platform 3D graphics
and computing API.
Optional COMPONENTS
^^^^^^^^^^^^^^^^^^^
.. versionadded:: 3.24
This module respects several optional COMPONENTS.
There are corresponding imported targets for each of these.
``glslc``
The SPIR-V compiler.
``glslangValidator``
The ``glslangValidator`` tool.
``glslang``
The SPIR-V generator library.
``shaderc_combined``
The static library for Vulkan shader compilation.
``SPIRV-Tools``
Tools to process SPIR-V modules.
``MoltenVK``
On macOS, an additional component ``MoltenVK`` is available.
``dxc``
.. versionadded:: 3.25
The DirectX Shader Compiler.
The ``glslc`` and ``glslangValidator`` components are provided even
if not explicitly requested (for backward compatibility).
IMPORTED Targets
^^^^^^^^^^^^^^^^
This module defines :prop_tgt:`IMPORTED` targets if Vulkan has been found:
``Vulkan::Vulkan``
The main Vulkan library.
``Vulkan::glslc``
.. versionadded:: 3.19
The GLSLC SPIR-V compiler, if it has been found.
``Vulkan::Headers``
.. versionadded:: 3.21
Provides just Vulkan headers include paths, if found. No library is
included in this target. This can be useful for applications that
load Vulkan library dynamically.
``Vulkan::glslangValidator``
.. versionadded:: 3.21
The glslangValidator tool, if found. It is used to compile GLSL and
HLSL shaders into SPIR-V.
``Vulkan::glslang``
.. versionadded:: 3.24
Defined if SDK has the Khronos-reference front-end shader parser and SPIR-V
generator library (glslang).
``Vulkan::shaderc_combined``
.. versionadded:: 3.24
Defined if SDK has the Google static library for Vulkan shader compilation
(shaderc_combined).
``Vulkan::SPIRV-Tools``
.. versionadded:: 3.24
Defined if SDK has the Khronos library to process SPIR-V modules
(SPIRV-Tools).
``Vulkan::MoltenVK``
.. versionadded:: 3.24
Defined if SDK has the Khronos library which implement a subset of Vulkan API
over Apple Metal graphics framework. (MoltenVK).
``Vulkan::volk``
.. versionadded:: 3.25
Defined if SDK has the Vulkan meta-loader (volk).
``Vulkan::dxc_lib``
.. versionadded:: 3.25
Defined if SDK has the DirectX shader compiler library.
``Vulkan::dxc_exe``
.. versionadded:: 3.25
Defined if SDK has the DirectX shader compiler CLI tool.
Result Variables
^^^^^^^^^^^^^^^^
This module defines the following variables:
``Vulkan_FOUND``
set to true if Vulkan was found
``Vulkan_INCLUDE_DIRS``
include directories for Vulkan
``Vulkan_LIBRARIES``
link against this library to use Vulkan
``Vulkan_VERSION``
.. versionadded:: 3.23
value from ``vulkan/vulkan_core.h``
``Vulkan_glslc_FOUND``
.. versionadded:: 3.24
True, if the SDK has the glslc executable.
``Vulkan_glslangValidator_FOUND``
.. versionadded:: 3.24
True, if the SDK has the glslangValidator executable.
``Vulkan_glslang_FOUND``
.. versionadded:: 3.24
True, if the SDK has the glslang library.
``Vulkan_shaderc_combined_FOUND``
.. versionadded:: 3.24
True, if the SDK has the shaderc_combined library.
``Vulkan_SPIRV-Tools_FOUND``
.. versionadded:: 3.24
True, if the SDK has the SPIRV-Tools library.
``Vulkan_MoltenVK_FOUND``
.. versionadded:: 3.24
True, if the SDK has the MoltenVK library.
``Vulkan_volk_FOUND``
.. versionadded:: 3.25
True, if the SDK has the volk library.
``Vulkan_dxc_lib_FOUND``
.. versionadded:: 3.25
True, if the SDK has the DirectX shader compiler library.
``Vulkan_dxc_exe_FOUND``
.. versionadded:: 3.25
True, if the SDK has the DirectX shader compiler CLI tool.
The module will also defines these cache variables:
``Vulkan_INCLUDE_DIR``
the Vulkan include directory
``Vulkan_LIBRARY``
the path to the Vulkan library
``Vulkan_GLSLC_EXECUTABLE``
the path to the GLSL SPIR-V compiler
``Vulkan_GLSLANG_VALIDATOR_EXECUTABLE``
the path to the glslangValidator tool
``Vulkan_glslang_LIBRARY``
.. versionadded:: 3.24
Path to the glslang library.
``Vulkan_shaderc_combined_LIBRARY``
.. versionadded:: 3.24
Path to the shaderc_combined library.
``Vulkan_SPIRV-Tools_LIBRARY``
.. versionadded:: 3.24
Path to the SPIRV-Tools library.
``Vulkan_MoltenVK_LIBRARY``
.. versionadded:: 3.24
Path to the MoltenVK library.
``Vulkan_volk_LIBRARY``
.. versionadded:: 3.25
Path to the volk library.
``Vulkan_dxc_LIBRARY``
.. versionadded:: 3.25
Path to the DirectX shader compiler library.
``Vulkan_dxc_EXECUTABLE``
.. versionadded:: 3.25
Path to the DirectX shader compiler CLI tool.
Hints
^^^^^
.. versionadded:: 3.18
The ``VULKAN_SDK`` environment variable optionally specifies the
location of the Vulkan SDK root directory for the given
architecture. It is typically set by sourcing the toplevel
``setup-env.sh`` script of the Vulkan SDK directory into the shell
environment.
#]=======================================================================]
cmake_policy(PUSH)
cmake_policy(SET CMP0057 NEW)
# Provide compatibility with a common invalid component request that
# was silently ignored prior to CMake 3.24.
if("FATAL_ERROR" IN_LIST Vulkan_FIND_COMPONENTS)
message(AUTHOR_WARNING
"Ignoring unknown component 'FATAL_ERROR'.\n"
"The find_package() command documents no such argument."
)
list(REMOVE_ITEM Vulkan_FIND_COMPONENTS "FATAL_ERROR")
endif()
# FindVulkan only works correctly with the default CMAKE_FIND_FRAMEWORK
# value: FIRST. If LAST it will find the macOS dylibs instead of the iOS
# frameworks when IOS is true. If ALWAYS it will fail to find the macOS
# dylibs. If NEVER it will fail to find the iOS frameworks. If frameworks
# are ever included in the SDK for macOS, the search mechanism will need
# revisiting.
if(DEFINED CMAKE_FIND_FRAMEWORK)
set(_Vulkan_saved_cmake_find_framework ${CMAKE_FIND_FRAMEWORK})
set(CMAKE_FIND_FRAMEWORK FIRST)
endif()
if(IOS)
get_filename_component(Vulkan_Target_SDK "$ENV{VULKAN_SDK}/.." REALPATH)
list(APPEND CMAKE_FRAMEWORK_PATH "${Vulkan_Target_SDK}/iOS/lib")
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
endif()
# For backward compatibility as `FindVulkan` in previous CMake versions allow to retrieve `glslc`
# and `glslangValidator` without requesting the corresponding component.
if(NOT glslc IN_LIST Vulkan_FIND_COMPONENTS)
list(APPEND Vulkan_FIND_COMPONENTS glslc)
endif()
if(NOT glslangValidator IN_LIST Vulkan_FIND_COMPONENTS)
list(APPEND Vulkan_FIND_COMPONENTS glslangValidator)
endif()
if(WIN32)
set(_Vulkan_library_name vulkan-1)
set(_Vulkan_hint_include_search_paths
"$ENV{VULKAN_SDK}/include"
)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_Vulkan_hint_executable_search_paths
"$ENV{VULKAN_SDK}/bin"
)
set(_Vulkan_hint_library_search_paths
"$ENV{VULKAN_SDK}/lib"
"$ENV{VULKAN_SDK}/bin"
)
else()
set(_Vulkan_hint_executable_search_paths
"$ENV{VULKAN_SDK}/bin32"
"$ENV{VULKAN_SDK}/bin"
)
set(_Vulkan_hint_library_search_paths
"$ENV{VULKAN_SDK}/lib32"
"$ENV{VULKAN_SDK}/bin32"
"$ENV{VULKAN_SDK}/lib"
"$ENV{VULKAN_SDK}/bin"
)
endif()
else()
set(_Vulkan_library_name vulkan)
set(_Vulkan_hint_include_search_paths
"$ENV{VULKAN_SDK}/include"
)
set(_Vulkan_hint_executable_search_paths
"$ENV{VULKAN_SDK}/bin"
)
set(_Vulkan_hint_library_search_paths
"$ENV{VULKAN_SDK}/lib"
)
endif()
if(APPLE AND DEFINED Vulkan_Target_SDK)
list(APPEND _Vulkan_hint_include_search_paths
"${Vulkan_Target_SDK}/macOS/include"
)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(APPEND _Vulkan_hint_library_search_paths
"${Vulkan_Target_SDK}/iOS/lib"
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
list(APPEND _Vulkan_hint_library_search_paths
"${Vulkan_Target_SDK}/tvOS/lib"
)
else()
list(APPEND _Vulkan_hint_library_search_paths
"${Vulkan_Target_SDK}/lib"
)
endif()
endif()
find_path(Vulkan_INCLUDE_DIR
NAMES vulkan/vulkan.h
HINTS
${_Vulkan_hint_include_search_paths}
)
mark_as_advanced(Vulkan_INCLUDE_DIR)
find_library(Vulkan_LIBRARY
NAMES ${_Vulkan_library_name}
HINTS
${_Vulkan_hint_library_search_paths}
)
#message(STATUS "vulkan_library ${Vulkan_LIBRARY} search paths ${_Vulkan_hint_library_search_paths}")
mark_as_advanced(Vulkan_LIBRARY)
find_library(Vulkan_Layer_API_DUMP
NAMES VkLayer_api_dump
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_Layer_API_DUMP)
find_library(Vulkan_Layer_SHADER_OBJECT
NAMES VkLayer_khronos_shader_object
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(VkLayer_khronos_shader_object)
find_library(Vulkan_Layer_SYNC2
NAMES VkLayer_khronos_synchronization2
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_Layer_SYNC2)
find_library(Vulkan_Layer_VALIDATION
NAMES VkLayer_khronos_validation
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_Layer_VALIDATION)
if(glslc IN_LIST Vulkan_FIND_COMPONENTS)
find_program(Vulkan_GLSLC_EXECUTABLE
NAMES glslc
HINTS
${_Vulkan_hint_executable_search_paths}
)
mark_as_advanced(Vulkan_GLSLC_EXECUTABLE)
endif()
if(glslangValidator IN_LIST Vulkan_FIND_COMPONENTS)
find_program(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE
NAMES glslangValidator
HINTS
${_Vulkan_hint_executable_search_paths}
)
mark_as_advanced(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE)
endif()
if(glslang IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_glslang-spirv_LIBRARY
NAMES SPIRV
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-spirv_LIBRARY)
find_library(Vulkan_glslang-spirv_DEBUG_LIBRARY
NAMES SPIRVd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-spirv_DEBUG_LIBRARY)
find_library(Vulkan_glslang-oglcompiler_LIBRARY
NAMES OGLCompiler
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-oglcompiler_LIBRARY)
find_library(Vulkan_glslang-oglcompiler_DEBUG_LIBRARY
NAMES OGLCompilerd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-oglcompiler_DEBUG_LIBRARY)
find_library(Vulkan_glslang-osdependent_LIBRARY
NAMES OSDependent
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-osdependent_LIBRARY)
find_library(Vulkan_glslang-osdependent_DEBUG_LIBRARY
NAMES OSDependentd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-osdependent_DEBUG_LIBRARY)
find_library(Vulkan_glslang-machineindependent_LIBRARY
NAMES MachineIndependent
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-machineindependent_LIBRARY)
find_library(Vulkan_glslang-machineindependent_DEBUG_LIBRARY
NAMES MachineIndependentd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-machineindependent_DEBUG_LIBRARY)
find_library(Vulkan_glslang-genericcodegen_LIBRARY
NAMES GenericCodeGen
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-genericcodegen_LIBRARY)
find_library(Vulkan_glslang-genericcodegen_DEBUG_LIBRARY
NAMES GenericCodeGend
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-genericcodegen_DEBUG_LIBRARY)
find_library(Vulkan_glslang_LIBRARY
NAMES glslang
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang_LIBRARY)
find_library(Vulkan_glslang_DEBUG_LIBRARY
NAMES glslangd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang_DEBUG_LIBRARY)
endif()
if(shaderc_combined IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_shaderc_combined_LIBRARY
NAMES shaderc_combined
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_shaderc_combined_LIBRARY)
find_library(Vulkan_shaderc_combined_DEBUG_LIBRARY
NAMES shaderc_combinedd
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_shaderc_combined_DEBUG_LIBRARY)
endif()
if(SPIRV-Tools IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_SPIRV-Tools_LIBRARY
NAMES SPIRV-Tools
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_SPIRV-Tools_LIBRARY)
find_library(Vulkan_SPIRV-Tools_DEBUG_LIBRARY
NAMES SPIRV-Toolsd
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_SPIRV-Tools_DEBUG_LIBRARY)
endif()
if(MoltenVK IN_LIST Vulkan_FIND_COMPONENTS)
# CMake has a bug in 3.28 that doesn't handle xcframeworks. Do it by hand for now.
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
if(CMAKE_VERSION VERSION_LESS 3.29)
set( _Vulkan_hint_library_search_paths ${Vulkan_Target_SDK}/ios/lib/MoltenVK.xcframework/ios-arm64)
else ()
set( _Vulkan_hint_library_search_paths ${Vulkan_Target_SDK}/ios/lib/)
endif ()
endif ()
find_library(Vulkan_MoltenVK_LIBRARY
NAMES MoltenVK
NO_DEFAULT_PATH
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_MoltenVK_LIBRARY)
find_path(Vulkan_MoltenVK_INCLUDE_DIR
NAMES MoltenVK/mvk_vulkan.h
HINTS
${_Vulkan_hint_include_search_paths}
)
mark_as_advanced(Vulkan_MoltenVK_INCLUDE_DIR)
endif()
if(volk IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_volk_LIBRARY
NAMES volk
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_Volk_LIBRARY)
endif()
if (dxc IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_dxc_LIBRARY
NAMES dxcompiler
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_dxc_LIBRARY)
find_program(Vulkan_dxc_EXECUTABLE
NAMES dxc
HINTS
${_Vulkan_hint_executable_search_paths})
mark_as_advanced(Vulkan_dxc_EXECUTABLE)
endif()
if(DEFINED _Vulkan_saved_cmake_find_framework)
set(CMAKE_FIND_FRAMEWORK ${_Vulkan_saved_cmake_find_framework})
unset(_Vulkan_saved_cmake_find_framework)
endif()
if(Vulkan_GLSLC_EXECUTABLE)
set(Vulkan_glslc_FOUND TRUE)
else()
set(Vulkan_glslc_FOUND FALSE)
endif()
if(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE)
set(Vulkan_glslangValidator_FOUND TRUE)
else()
set(Vulkan_glslangValidator_FOUND FALSE)
endif()
if (Vulkan_dxc_EXECUTABLE)
set(Vulkan_dxc_exe_FOUND TRUE)
else()
set(Vulkan_dxc_exe_FOUND FALSE)
endif()
function(_Vulkan_set_library_component_found component)
cmake_parse_arguments(PARSE_ARGV 1 _ARG
"NO_WARNING"
""
"DEPENDENT_COMPONENTS")
set(all_dependent_component_found TRUE)
foreach(dependent_component IN LISTS _ARG_DEPENDENT_COMPONENTS)
if(NOT Vulkan_${dependent_component}_FOUND)
set(all_dependent_component_found FALSE)
break()
endif()
endforeach()
if(all_dependent_component_found AND (Vulkan_${component}_LIBRARY OR Vulkan_${component}_DEBUG_LIBRARY))
set(Vulkan_${component}_FOUND TRUE PARENT_SCOPE)
# For Windows Vulkan SDK, third party tools binaries are provided with different MSVC ABI:
# - Release binaries uses a runtime library
# - Debug binaries uses a debug runtime library
# This lead to incompatibilities in linking for some configuration types due to CMake-default or project-configured selected MSVC ABI.
if(WIN32 AND NOT _ARG_NO_WARNING)
if(NOT Vulkan_${component}_LIBRARY)
message(WARNING
"Library ${component} for Release configuration is missing, imported target Vulkan::${component} may not be able to link when targeting this build configuration due to incompatible MSVC ABI.")
endif()
if(NOT Vulkan_${component}_DEBUG_LIBRARY)
message(WARNING
"Library ${component} for Debug configuration is missing, imported target Vulkan::${component} may not be able to link when targeting this build configuration due to incompatible MSVC ABI. Consider re-installing the Vulkan SDK and request debug libraries to fix this warning.")
endif()
endif()
else()
set(Vulkan_${component}_FOUND FALSE PARENT_SCOPE)
endif()
endfunction()
_Vulkan_set_library_component_found(glslang-spirv NO_WARNING)
_Vulkan_set_library_component_found(glslang-oglcompiler NO_WARNING)
_Vulkan_set_library_component_found(glslang-osdependent NO_WARNING)
_Vulkan_set_library_component_found(glslang-machineindependent NO_WARNING)
_Vulkan_set_library_component_found(glslang-genericcodegen NO_WARNING)
_Vulkan_set_library_component_found(glslang
DEPENDENT_COMPONENTS
glslang-spirv
glslang-oglcompiler
glslang-osdependent
glslang-machineindependent
glslang-genericcodegen)
_Vulkan_set_library_component_found(shaderc_combined)
_Vulkan_set_library_component_found(SPIRV-Tools)
_Vulkan_set_library_component_found(volk)
_Vulkan_set_library_component_found(dxc)
if(Vulkan_MoltenVK_INCLUDE_DIR AND Vulkan_MoltenVK_LIBRARY)
set(Vulkan_MoltenVK_FOUND TRUE)
else()
set(Vulkan_MoltenVK_FOUND FALSE)
endif()
set(Vulkan_LIBRARIES ${Vulkan_LIBRARY})
set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR})
# detect version e.g 1.2.189
set(Vulkan_VERSION "")
if(Vulkan_INCLUDE_DIR)
set(VULKAN_CORE_H ${Vulkan_INCLUDE_DIR}/vulkan/vulkan_core.h)
if(EXISTS ${VULKAN_CORE_H})
file(STRINGS ${VULKAN_CORE_H} VulkanHeaderVersionLine REGEX "^#define VK_HEADER_VERSION ")
string(REGEX MATCHALL "[0-9]+" VulkanHeaderVersion "${VulkanHeaderVersionLine}")
file(STRINGS ${VULKAN_CORE_H} VulkanHeaderVersionLine2 REGEX "^#define VK_HEADER_VERSION_COMPLETE ")
string(REGEX MATCHALL "[0-9]+" VulkanHeaderVersion2 "${VulkanHeaderVersionLine2}")
list(LENGTH VulkanHeaderVersion2 _len)
# versions >= 1.2.175 have an additional numbers in front of e.g. '0, 1, 2' instead of '1, 2'
if(_len EQUAL 3)
list(REMOVE_AT VulkanHeaderVersion2 0)
endif()
list(APPEND VulkanHeaderVersion2 ${VulkanHeaderVersion})
list(JOIN VulkanHeaderVersion2 "." Vulkan_VERSION)
endif()
endif()
if(Vulkan_MoltenVK_FOUND)
set(Vulkan_MoltenVK_VERSION "")
if(Vulkan_MoltenVK_INCLUDE_DIR)
set(VK_MVK_MOLTENVK_H ${Vulkan_MoltenVK_INCLUDE_DIR}/MoltenVK/vk_mvk_moltenvk.h)
if(EXISTS ${VK_MVK_MOLTENVK_H})
file(STRINGS ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_MAJOR REGEX "^#define MVK_VERSION_MAJOR ")
string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_MAJOR "${_Vulkan_MoltenVK_VERSION_MAJOR}")
file(STRINGS ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_MINOR REGEX "^#define MVK_VERSION_MINOR ")
string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_MINOR "${_Vulkan_MoltenVK_VERSION_MINOR}")
file(STRINGS ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_PATCH REGEX "^#define MVK_VERSION_PATCH ")
string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_PATCH "${_Vulkan_MoltenVK_VERSION_PATCH}")
set(Vulkan_MoltenVK_VERSION "${_Vulkan_MoltenVK_VERSION_MAJOR}.${_Vulkan_MoltenVK_VERSION_MINOR}.${_Vulkan_MoltenVK_VERSION_PATCH}")
unset(_Vulkan_MoltenVK_VERSION_MAJOR)
unset(_Vulkan_MoltenVK_VERSION_MINOR)
unset(_Vulkan_MoltenVK_VERSION_PATCH)
endif()
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Vulkan
REQUIRED_VARS
Vulkan_LIBRARY
Vulkan_INCLUDE_DIR
VERSION_VAR
Vulkan_VERSION
HANDLE_COMPONENTS
)
if(Vulkan_FOUND AND NOT TARGET Vulkan::Vulkan)
add_library(Vulkan::Vulkan UNKNOWN IMPORTED)
get_filename_component(_Vulkan_lib_extension ${Vulkan_LIBRARIES} LAST_EXT)
if(_Vulkan_lib_extension STREQUAL ".framework" AND CMAKE_VERSION VERSION_LESS 3.28)
set_target_properties(Vulkan::Vulkan PROPERTIES
# Prior to 3.28 must reference library just inside the framework.
IMPORTED_LOCATION "${Vulkan_LIBRARIES}/vulkan")
else()
set_target_properties(Vulkan::Vulkan PROPERTIES
IMPORTED_LOCATION "${Vulkan_LIBRARIES}")
endif()
set_target_properties(Vulkan::Vulkan PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
unset(_Vulkan_lib_extension)
endif()
if(Vulkan_FOUND AND NOT TARGET Vulkan::Headers)
add_library(Vulkan::Headers INTERFACE IMPORTED)
set_target_properties(Vulkan::Headers PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
endif()
if(Vulkan_FOUND AND Vulkan_GLSLC_EXECUTABLE AND NOT TARGET Vulkan::glslc)
add_executable(Vulkan::glslc IMPORTED)
set_property(TARGET Vulkan::glslc PROPERTY IMPORTED_LOCATION "${Vulkan_GLSLC_EXECUTABLE}")
endif()
if(Vulkan_FOUND AND Vulkan_GLSLANG_VALIDATOR_EXECUTABLE AND NOT TARGET Vulkan::glslangValidator)
add_executable(Vulkan::glslangValidator IMPORTED)
set_property(TARGET Vulkan::glslangValidator PROPERTY IMPORTED_LOCATION "${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE}")
endif()
if(Vulkan_FOUND)
if((Vulkan_glslang-spirv_LIBRARY OR Vulkan_glslang-spirv_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-spirv)
add_library(Vulkan::glslang-spirv STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-spirv
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-spirv_LIBRARY)
set_property(TARGET Vulkan::glslang-spirv APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-spirv
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-spirv_LIBRARY}")
endif()
if(Vulkan_glslang-spirv_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-spirv APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-spirv
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-spirv_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang-oglcompiler_LIBRARY OR Vulkan_glslang-oglcompiler_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-oglcompiler)
add_library(Vulkan::glslang-oglcompiler STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-oglcompiler
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-oglcompiler_LIBRARY)
set_property(TARGET Vulkan::glslang-oglcompiler APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-oglcompiler
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-oglcompiler_LIBRARY}")
endif()
if(Vulkan_glslang-oglcompiler_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-oglcompiler APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-oglcompiler
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-oglcompiler_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang-osdependent_LIBRARY OR Vulkan_glslang-osdependent_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-osdependent)
add_library(Vulkan::glslang-osdependent STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-osdependent
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-osdependent_LIBRARY)
set_property(TARGET Vulkan::glslang-osdependent APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-osdependent
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-osdependent_LIBRARY}")
endif()
if(Vulkan_glslang-osdependent_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-osdependent APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-osdependent
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-osdependent_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang-machineindependent_LIBRARY OR Vulkan_glslang-machineindependent_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-machineindependent)
add_library(Vulkan::glslang-machineindependent STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-machineindependent
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-machineindependent_LIBRARY)
set_property(TARGET Vulkan::glslang-machineindependent APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-machineindependent
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-machineindependent_LIBRARY}")
endif()
if(Vulkan_glslang-machineindependent_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-machineindependent APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-machineindependent
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-machineindependent_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang-genericcodegen_LIBRARY OR Vulkan_glslang-genericcodegen_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-genericcodegen)
add_library(Vulkan::glslang-genericcodegen STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-genericcodegen
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-genericcodegen_LIBRARY)
set_property(TARGET Vulkan::glslang-genericcodegen APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-genericcodegen
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-genericcodegen_LIBRARY}")
endif()
if(Vulkan_glslang-genericcodegen_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-genericcodegen APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-genericcodegen
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-genericcodegen_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang_LIBRARY OR Vulkan_glslang_DEBUG_LIBRARY)
AND TARGET Vulkan::glslang-spirv
AND TARGET Vulkan::glslang-oglcompiler
AND TARGET Vulkan::glslang-osdependent
AND TARGET Vulkan::glslang-machineindependent
AND TARGET Vulkan::glslang-genericcodegen
AND NOT TARGET Vulkan::glslang)
add_library(Vulkan::glslang STATIC IMPORTED)
set_property(TARGET Vulkan::glslang
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang_LIBRARY)
set_property(TARGET Vulkan::glslang APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang_LIBRARY}")
endif()
if(Vulkan_glslang_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang_DEBUG_LIBRARY}")
endif()
target_link_libraries(Vulkan::glslang
INTERFACE
Vulkan::glslang-spirv
Vulkan::glslang-oglcompiler
Vulkan::glslang-osdependent
Vulkan::glslang-machineindependent
Vulkan::glslang-genericcodegen
)
endif()
if((Vulkan_shaderc_combined_LIBRARY OR Vulkan_shaderc_combined_DEBUG_LIBRARY) AND NOT TARGET Vulkan::shaderc_combined)
add_library(Vulkan::shaderc_combined STATIC IMPORTED)
set_property(TARGET Vulkan::shaderc_combined
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_shaderc_combined_LIBRARY)
set_property(TARGET Vulkan::shaderc_combined APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::shaderc_combined
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_shaderc_combined_LIBRARY}")
endif()
if(Vulkan_shaderc_combined_DEBUG_LIBRARY)
set_property(TARGET Vulkan::shaderc_combined APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::shaderc_combined
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_shaderc_combined_DEBUG_LIBRARY}")
endif()
if(UNIX)
find_package(Threads REQUIRED)
target_link_libraries(Vulkan::shaderc_combined
INTERFACE
Threads::Threads)
endif()
endif()
if((Vulkan_SPIRV-Tools_LIBRARY OR Vulkan_SPIRV-Tools_DEBUG_LIBRARY) AND NOT TARGET Vulkan::SPIRV-Tools)
add_library(Vulkan::SPIRV-Tools STATIC IMPORTED)
set_property(TARGET Vulkan::SPIRV-Tools
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_SPIRV-Tools_LIBRARY)
set_property(TARGET Vulkan::SPIRV-Tools APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::SPIRV-Tools
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_SPIRV-Tools_LIBRARY}")
endif()
if(Vulkan_SPIRV-Tools_DEBUG_LIBRARY)
set_property(TARGET Vulkan::SPIRV-Tools APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::SPIRV-Tools
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_SPIRV-Tools_DEBUG_LIBRARY}")
endif()
endif()
if(Vulkan_volk_LIBRARY AND NOT TARGET Vulkan::volk)
add_library(Vulkan::volk STATIC IMPORTED)
set_property(TARGET Vulkan::volk
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
set_property(TARGET Vulkan::volk APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::volk APPEND
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_volk_LIBRARY}")
if (NOT WIN32)
set_property(TARGET Vulkan::volk APPEND
PROPERTY
IMPORTED_LINK_INTERFACE_LIBRARIES dl)
endif()
endif()
if (Vulkan_dxc_LIBRARY AND NOT TARGET Vulkan::dxc_lib)
add_library(Vulkan::dxc_lib STATIC IMPORTED)
set_property(TARGET Vulkan::dxc_lib
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
set_property(TARGET Vulkan::dxc_lib APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::dxc_lib APPEND
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_dxc_LIBRARY}")
endif()
if(Vulkan_dxc_EXECUTABLE AND NOT TARGET Vulkan::dxc_exe)
add_executable(Vulkan::dxc_exe IMPORTED)
set_property(TARGET Vulkan::dxc_exe PROPERTY IMPORTED_LOCATION "${Vulkan_dxc_EXECUTABLE}")
endif()
endif()
if(Vulkan_MoltenVK_FOUND)
if(Vulkan_MoltenVK_LIBRARY AND NOT TARGET Vulkan::MoltenVK)
add_library(Vulkan::MoltenVK SHARED IMPORTED)
set_target_properties(Vulkan::MoltenVK
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_MoltenVK_INCLUDE_DIR}"
IMPORTED_LOCATION "${Vulkan_MoltenVK_LIBRARY}"
)
endif()
endif()
unset(_Vulkan_library_name)
unset(_Vulkan_hint_include_search_paths)
unset(_Vulkan_hint_executable_search_paths)
unset(_Vulkan_hint_library_search_paths)
cmake_policy(POP)
+313
View File
@@ -0,0 +1,313 @@
#[[
Copyright (c) 2019-2025, Arm Limited and Contributors
Copyright (c) 2024-2025, Mobica Limited
Copyright (c) 2024-2025, Sascha Willems
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 the "License";
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
set(SCRIPT_DIR ${CMAKE_CURRENT_LIST_DIR})
function(add_sample)
set(options)
set(oneValueArgs ID CATEGORY AUTHOR NAME DESCRIPTION DXC_ADDITIONAL_ARGUMENTS GLSLC_ADDITIONAL_ARGUMENTS)
set(multiValueArgs FILES LIBS SHADER_FILES_GLSL SHADER_FILES_HLSL SHADER_FILES_SLANG)
cmake_parse_arguments(TARGET "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
add_sample_with_tags(
TYPE "Sample"
ID ${TARGET_ID}
CATEGORY ${TARGET_CATEGORY}
AUTHOR ${TARGET_AUTHOR}
NAME ${TARGET_NAME}
DESCRIPTION ${TARGET_DESCRIPTION}
TAGS
"any"
FILES
${TARGET_FILES}
LIBS
${TARGET_LIBS}
SHADER_FILES_GLSL
${TARGET_SHADER_FILES_GLSL}
SHADER_FILES_HLSL
${TARGET_SHADER_FILES_HLSL}
SHADER_FILES_SLANG
${TARGET_SHADER_FILES_SLANG}
DXC_ADDITIONAL_ARGUMENTS ${TARGET_DXC_ADDITIONAL_ARGUMENTS}
GLSLC_ADDITIONAL_ARGUMENTS ${TARGET_GLSLC_ADDITIONAL_ARGUMENTS})
endfunction()
function(add_sample_with_tags)
set(options)
set(oneValueArgs ID CATEGORY AUTHOR NAME DESCRIPTION DXC_ADDITIONAL_ARGUMENTS GLSLC_ADDITIONAL_ARGUMENTS)
set(multiValueArgs TAGS FILES LIBS SHADER_FILES_GLSL SHADER_FILES_HLSL SHADER_FILES_SLANG)
cmake_parse_arguments(TARGET "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
list(APPEND TARGET_TAGS "any")
set(SRC_FILES
${TARGET_ID}.h
${TARGET_ID}.cpp
)
# Append extra files if present
if (TARGET_FILES)
list(APPEND SRC_FILES ${TARGET_FILES})
endif()
# Add GLSL shader files for this sample
foreach(SHADER_FILE_GLSL ${TARGET_SHADER_FILES_GLSL})
list(APPEND SHADERS_GLSL "${PROJECT_SOURCE_DIR}/shaders/${SHADER_FILE_GLSL}")
endforeach()
# Add HLSL shader files for this sample
foreach(SHADER_FILE_HLSL ${TARGET_SHADER_FILES_HLSL})
list(APPEND SHADERS_HLSL "${PROJECT_SOURCE_DIR}/shaders/${SHADER_FILE_HLSL}")
endforeach()
# Add slang shader files for this sample
foreach(SHADER_FILE_SLANG ${TARGET_SHADER_FILES_SLANG})
list(APPEND SHADERS_SLANG "${PROJECT_SOURCE_DIR}/shaders/${SHADER_FILE_SLANG}")
endforeach()
add_project(
TYPE "Sample"
ID ${TARGET_ID}
CATEGORY ${TARGET_CATEGORY}
AUTHOR ${TARGET_AUTHOR}
NAME ${TARGET_NAME}
DESCRIPTION ${TARGET_DESCRIPTION}
TAGS
${TARGET_TAGS}
FILES
${SRC_FILES}
LIBS
${TARGET_LIBS}
SHADERS_GLSL
${SHADERS_GLSL}
SHADERS_HLSL
${SHADERS_HLSL}
SHADERS_SLANG
${SHADERS_SLANG}
DXC_ADDITIONAL_ARGUMENTS ${TARGET_DXC_ADDITIONAL_ARGUMENTS}
GLSLC_ADDITIONAL_ARGUMENTS ${TARGET_GLSLC_ADDITIONAL_ARGUMENTS})
endfunction()
function(add_project)
set(options)
set(oneValueArgs TYPE ID CATEGORY AUTHOR NAME DESCRIPTION DXC_ADDITIONAL_ARGUMENTS GLSLC_ADDITIONAL_ARGUMENTS)
set(multiValueArgs TAGS FILES LIBS SHADERS_GLSL SHADERS_HLSL SHADERS_SLANG)
cmake_parse_arguments(TARGET "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(${TARGET_TYPE} STREQUAL "Sample")
set("VKB_${TARGET_ID}" ON CACHE BOOL "Build sample ${TARGET_ID}")
endif()
if(NOT ${VKB_${TARGET_ID}})
# message(STATUS "${TARGET_TYPE} `${TARGET_ID}` - DISABLED")
return()
endif()
message(STATUS "${TARGET_TYPE} `${TARGET_ID}` - BUILD")
# create project (object target - reused by app target)
project(${TARGET_ID} LANGUAGES C CXX)
source_group("\\" FILES ${TARGET_FILES})
# Add shaders to project group
if (TARGET_SHADERS_GLSL)
source_group("\\Shaders\\glsl" FILES ${TARGET_SHADERS_GLSL})
endif()
if (TARGET_SHADERS_HLSL)
source_group("\\Shaders\\hlsl" FILES ${TARGET_SHADERS_HLSL})
# Disable automatic compilation of HLSL shaders for MSVC
set_source_files_properties(SOURCE ${SHADERS_HLSL} PROPERTIES VS_SETTINGS "ExcludedFromBuild=true")
endif()
if (TARGET_SHADERS_SLANG)
source_group("\\Shaders\\slang" FILES ${TARGET_SHADERS_SLANG})
endif()
if(${TARGET_TYPE} STREQUAL "Sample")
add_library(${PROJECT_NAME} OBJECT ${TARGET_FILES} ${SHADERS_GLSL} ${SHADERS_HLSL} ${SHADERS_SLANG})
elseif(${TARGET_TYPE} STREQUAL "Test")
add_library(${PROJECT_NAME} STATIC ${TARGET_FILES} ${SHADERS_GLSL} ${SHADERS_HLSL} ${SHADERS_SLANG})
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
# # inherit include directories from framework target
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE framework)
# Link against extra project specific libraries
if(TARGET_LIBS)
target_link_libraries(${PROJECT_NAME} PUBLIC ${TARGET_LIBS})
endif()
# capitalise the first letter of the category (performance -> Performance)
string(SUBSTRING ${TARGET_CATEGORY} 0 1 FIRST_LETTER)
string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" CATEGORY "${TARGET_CATEGORY}")
if(${TARGET_TYPE} STREQUAL "Sample")
# set sample properties
set_target_properties(${PROJECT_NAME}
PROPERTIES
SAMPLE_CATEGORY ${TARGET_CATEGORY}
SAMPLE_AUTHOR ${TARGET_AUTHOR}
SAMPLE_NAME ${TARGET_NAME}
SAMPLE_DESCRIPTION ${TARGET_DESCRIPTION}
SAMPLE_TAGS "${TARGET_TAGS}")
# add sample project to a folder
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Samples//${CATEGORY}")
elseif(${TARGET_TYPE} STREQUAL "Test")
# add test project to a folder
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Tests")
endif()
if(VKB_DO_CLANG_TIDY)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY "${VKB_DO_CLANG_TIDY}")
endif()
# HLSL compilation via DXC
if(Vulkan_dxc_EXECUTABLE AND DEFINED SHADERS_HLSL)
set(OUTPUT_FILES "")
set(HLSL_TARGET_NAME ${PROJECT_NAME}-HLSL)
foreach(SHADER_FILE_HLSL ${TARGET_SHADERS_HLSL})
get_filename_component(HLSL_SPV_FILE ${SHADER_FILE_HLSL} NAME_WLE)
get_filename_component(bare_name ${HLSL_SPV_FILE} NAME_WLE)
get_filename_component(extension ${HLSL_SPV_FILE} LAST_EXT)
get_filename_component(directory ${SHADER_FILE_HLSL} DIRECTORY)
string(REGEX REPLACE "[.]+" "" extension ${extension})
set(OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/shader-spv")
set(OUTPUT_FILE ${OUTPUT_DIR}/${bare_name}.${extension}.spv)
file(MAKE_DIRECTORY ${OUTPUT_DIR})
set(DXC_PROFILE_TYPE "")
set(DXC_PROFILE_VER "6_1")
if(${extension} STREQUAL "vert")
set(DXC_PROFILE_TYPE "vs")
elseif(${extension} STREQUAL "frag")
set(DXC_PROFILE_TYPE "ps")
set(DXC_PROFILE_VER "6_4")
elseif(${extension} STREQUAL "rgen" OR ${extension} STREQUAL "rmiss" OR ${extension} STREQUAL "rchit")
list(APPEND TARGET_DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_KHR_ray_tracing -fspv-target-env=vulkan1.1spirv1.4")
set(DXC_PROFILE_TYPE "lib")
set(DXC_PROFILE_VER "6_3")
elseif(${extension} STREQUAL "comp")
set(DXC_PROFILE_TYPE "cs")
elseif(${extension} STREQUAL "geom")
set(DXC_PROFILE_TYPE "gs")
elseif(${extension} STREQUAL "tesc")
set(DXC_PROFILE_TYPE "hs")
elseif(${extension} STREQUAL "tese")
set(DXC_PROFILE_TYPE "ds")
elseif(${extension} STREQUAL "mesh")
list(APPEND TARGET_DXC_ADDITIONAL_ARGUMENTS "-fspv-target-env=vulkan1.1spirv1.4")
set(DXC_PROFILE_TYPE "ms")
set(DXC_PROFILE_VER "6_6")
endif()
set(DXC_PROFILE ${DXC_PROFILE_TYPE}_${DXC_PROFILE_VER})
if(NOT "${TARGET_DXC_ADDITIONAL_ARGUMENTS}" STREQUAL "")
string(REPLACE " " ";" TARGET_DXC_ADDITIONAL_ARGUMENTS "${TARGET_DXC_ADDITIONAL_ARGUMENTS}")
endif ()
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND ${Vulkan_dxc_EXECUTABLE} -spirv -T ${DXC_PROFILE} -E main ${TARGET_DXC_ADDITIONAL_ARGUMENTS} ${SHADER_FILE_HLSL} -Fo ${OUTPUT_FILE}
COMMAND ${CMAKE_COMMAND} -E copy ${OUTPUT_FILE} ${directory}
MAIN_DEPENDENCY ${SHADER_FILE_HLSL}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
list(APPEND OUTPUT_FILES ${OUTPUT_FILE})
set_source_files_properties(${OUTPUT_FILE} PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
)
endforeach()
add_custom_target(${HLSL_TARGET_NAME} DEPENDS ${OUTPUT_FILES})
set_property(TARGET ${HLSL_TARGET_NAME} PROPERTY FOLDER "Shaders-HLSL")
add_dependencies(${PROJECT_NAME} ${HLSL_TARGET_NAME})
endif()
# Slang shader compilation
if(Vulkan_slang_EXECUTABLE AND DEFINED SHADERS_SLANG)
set(OUTPUT_FILES "")
set(SLANG_TARGET_NAME ${PROJECT_NAME}-SLANG)
foreach(SHADER_FILE_SLANG ${TARGET_SHADERS_SLANG})
get_filename_component(SLANG_SPV_FILE ${SHADER_FILE_SLANG} NAME_WLE)
get_filename_component(bare_name ${SLANG_SPV_FILE} NAME_WLE)
get_filename_component(extension ${SLANG_SPV_FILE} LAST_EXT)
get_filename_component(directory ${SHADER_FILE_SLANG} DIRECTORY)
string(REGEX REPLACE "[.]+" "" extension ${extension})
set(OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/shader-slang-spv")
set(OUTPUT_FILE ${OUTPUT_DIR}/${bare_name}.${extension}.spv)
file(MAKE_DIRECTORY ${OUTPUT_DIR})
set(SLANG_PROFILE "spirv_1_4")
set(SLANG_ENTRY_POINT "main")
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND ${Vulkan_slang_EXECUTABLE} ${SHADER_FILE_SLANG} -profile ${SLANG_PROFILE} -matrix-layout-column-major -target spirv -o ${OUTPUT_FILE} -entry ${SLANG_ENTRY_POINT}
COMMAND ${CMAKE_COMMAND} -E copy ${OUTPUT_FILE} ${directory}
MAIN_DEPENDENCY ${SHADER_FILE_SLANG}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
list(APPEND OUTPUT_FILES ${OUTPUT_FILE})
set_source_files_properties(${OUTPUT_FILE} PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
)
endforeach()
add_custom_target(${SLANG_TARGET_NAME} DEPENDS ${OUTPUT_FILES})
set_property(TARGET ${SLANG_TARGET_NAME} PROPERTY FOLDER "Shaders-SLANG")
add_dependencies(${PROJECT_NAME} ${SLANG_TARGET_NAME})
endif()
# GLSL shader compilation
if(Vulkan_glslc_EXECUTABLE AND DEFINED SHADERS_GLSL)
set(GLSL_TARGET_NAME ${PROJECT_NAME}-GLSL)
set(OUTPUT_FILES "")
foreach(SHADER_FILE_GLSL ${TARGET_SHADERS_GLSL})
get_filename_component(GLSL_SPV_FILE ${SHADER_FILE_GLSL} NAME_WLE)
get_filename_component(bare_name ${GLSL_SPV_FILE} NAME_WLE)
get_filename_component(extension ${SHADER_FILE_GLSL} LAST_EXT)
get_filename_component(directory ${SHADER_FILE_GLSL} DIRECTORY)
# Skip extensions that can't be compiled (cl, inlcudes)
if(${extension} STREQUAL ".cl" OR ${extension} STREQUAL ".h")
continue()
endif()
set(OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/shader-glsl-spv")
set(OUTPUT_FILE ${OUTPUT_DIR}/${bare_name}${extension}.spv)
file(MAKE_DIRECTORY ${OUTPUT_DIR})
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND ${Vulkan_glslc_EXECUTABLE} ${SHADER_FILE_GLSL} -o ${OUTPUT_FILE} -I "${CMAKE_SOURCE_DIR}/shaders/includes/glsl" ${TARGET_GLSLC_ADDITIONAL_ARGUMENTS}
COMMAND ${CMAKE_COMMAND} -E copy ${OUTPUT_FILE} ${directory}
MAIN_DEPENDENCY ${SHADER_FILE_GLSL}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
list(APPEND OUTPUT_FILES ${OUTPUT_FILE})
set_source_files_properties(${OUTPUT_FILE} PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
)
endforeach()
add_custom_target(${GLSL_TARGET_NAME} DEPENDS ${OUTPUT_FILES})
set_property(TARGET ${GLSL_TARGET_NAME} PROPERTY FOLDER "Shaders-GLSL")
add_dependencies(${PROJECT_NAME} ${GLSL_TARGET_NAME})
endif()
endfunction()
+89
View File
@@ -0,0 +1,89 @@
////
- Copyright (c) 2019-2023, The Khronos Group
-
- SPDX-License-Identifier: Apache-2.0
-
- Licensed under the Apache License, Version 2.0 the "License";
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
////
// NOTE: Remove the following comment block for the actual readme of your sample -->
////
This is a template for the sample's readme. Every new sample should come with a readme that contains at least a short tutorial that accompanies the code of the example.
Readmes are written in Asciidoc (see https://asciidoc.org/).
You can freely choose how to structure it, but it should always contain an overview and conclusion paragraph.
The readme can (and most often should) show code from along with an explanation. Code in asciidoc can be rendered with syntax highlighting using the following syntax:
[,cpp]
----
void main() {
std::cout << "Hello World";
}
----
or
[,glsl]
----
void main() {
gl_color = vec4(1.0f);
}
----
Ideally it also contains an image of how the sample is supposed to look.
For an example you can take a look at the readme's of existing samples, e.g. https://raw.githubusercontent.com/KhronosGroup/Vulkan-Samples/main/samples/extensions/descriptor_indexing/README.adoc
////
= Sample name
////
The following block adds linkage to this repo in the Vulkan docs site project. It's only visible if the file is viewed via the Antora framework.
////
ifdef::site-gen-antora[]
TIP: The source for this sample can be found in the https://github.com/KhronosGroup/Vulkan-Samples/tree/main/samples/PUT_SAMPLE_PATH_HERE[Khronos Vulkan samples github repository].
endif::[]
== Overview
////
This chapter should contain an overview of what this sample is trying to achieve. If extensions are used, this chapter should also list those.
The following chapters get into the details on how the sample is working, what features are used, etc.
The chapter itself can be structured by using sub paragraphs, e.g.:
# Feature description
# Enabling extensions
# etc.
////
== Conclusion
////
The tutorial should end with a conclusion chapter that recaps the tutorial and (if applicable) talks about pros and cons of the features demonstrated in this sample
////
////
NOTE: Please also add a link to the new samples' README.adoc to the file located in ./antora/modules/ROOT/nav.adoc
THis is necessary to have the sample show up on the build for the docs site under https://docs.vulkan.org
////
@@ -0,0 +1,84 @@
plugins {
id 'com.android.application'
}
ext.vvl_version='1.4.321.0'
apply from: "./download_vvl.gradle"
android {
ndkVersion '28.2.13676358'
compileSdk 35
defaultConfig {
applicationId 'com.khronos.vulkan_samples'
namespace "com.khronos.vulkan_samples"
@MIN_SDK_VERSION@
targetSdk 35
versionCode 1
versionName "1.0"
externalNativeBuild {
@CMAKE_ARGUMENTS@
}
}
buildTypes {
debug {
debuggable true
jniDebuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
signingConfig debug.signingConfig
}
applicationVariants.all{variant ->
variant.outputs.each{output->
def tempName = output.outputFile.name
tempName = tempName.replace("app-", "vulkan_samples-")
output.outputFileName = tempName
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_21
targetCompatibility JavaVersion.VERSION_21
}
sourceSets {
main {
@ASSETS_SRC_DIRS@
@RES_SRC_DIRS@
@JAVA_SRC_DIRS@
@JNI_LIBS_SRC_DIRS@
@MANIFEST_FILE@
}
}
externalNativeBuild {
cmake {
version "3.22.1"
@CMAKE_PATH@
}
}
lint {
abortOnError false
checkReleaseBuilds false
}
buildFeatures {
viewBinding true
prefab true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
implementation 'androidx.core:core:1.15.0'
implementation 'androidx.games:games-activity:3.0.5'
}
@@ -0,0 +1,8 @@
plugins {
id 'com.android.application' version '8.7.2' apply false
id 'com.android.library' version '8.7.2' apply false
}
tasks.register('clean', Delete) {
delete rootProject.layout.buildDirectory
}
@@ -0,0 +1,81 @@
apply plugin: 'com.android.application'
/*
* Copyright (c) 2022-2024, The Android Open Source Project.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* Download validation layer binary release zip file from Khronos github repo
* https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases
*
* To use this script, add the following to your module's build.gradle:
* ext.vvl_version='your-new-version'
* apply from: "${PATH-TO-THIS}/download_vvl.gradle"
* To update to a new version:
* - change the ext.vvl_version to a new version string.
* - delete directory pointed by ${VVL_JNILIB_DIR}.
* - sync gradle script in IDE and rebuild project.
*
* Note: binary release can also be manually downloaded and put it into
* the default jniLibs directory at app/src/main/jniLibs.
*/
// get the validation layer version.
def VVL_VER = "1.4.321.0"
if (ext.has("vvl_version")) {
VVL_VER = ext.vvl_version
}
// declare local variables shared between downloading and unzipping.
def VVL_SITE ="https://github.com/KhronosGroup/Vulkan-ValidationLayers"
def VVL_LIB_ROOT= rootDir.absolutePath.toString() + "/layerLib"
def VVL_JNILIB_DIR="${VVL_LIB_ROOT}/jniLibs"
def VVL_SO_NAME = "libVkLayer_khronos_validation.so"
// download the release zip file to ${VVL_LIB_ROOT}/
task download {
def VVL_ZIP_NAME = "releases/download/vulkan-sdk-${VVL_VER}/android-binaries-${VVL_VER}.zip"
mkdir "${VVL_LIB_ROOT}"
def f = new File("${VVL_LIB_ROOT}/android-binaries-${VVL_VER}.zip")
new URL("${VVL_SITE}/${VVL_ZIP_NAME}")
.withInputStream { i -> f.withOutputStream { it << i } }
}
// unzip the downloaded VVL zip archive to the ${VVL_JNILIB_DIR} for APK packaging.
task unzip(dependsOn: download, type: Copy) {
from zipTree(file("${VVL_LIB_ROOT}/android-binaries-${VVL_VER}.zip"))
into file("${VVL_JNILIB_DIR}")
}
android.sourceSets.main.jniLibs {
srcDirs += ["${VVL_JNILIB_DIR}/android-binaries-${VVL_VER}"]
}
// add vvl download as an application dependency.
dependencies {
def ARM64_VVL_FILE = "${VVL_JNILIB_DIR}/arm64-v8a/${VVL_SO_NAME}"
if(!file("${ARM64_VVL_FILE}").exists()) {
implementation files("${ARM64_VVL_FILE}") {
builtBy 'unzip'
}
}
}
project.afterEvaluate{
project.getTasks().getByName("mergeDebugJniLibFolders").dependsOn(unzip)
project.getTasks().getByName("mergeReleaseJniLibFolders").dependsOn(unzip)
}
Binary file not shown.
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
@@ -0,0 +1,7 @@
android.useAndroidX=true
android.enableJetifier=false
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.caching=true
android.prefabVersion=2.0.0
+252
View File
@@ -0,0 +1,252 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
+94
View File
@@ -0,0 +1,94 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
@@ -0,0 +1,16 @@
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "@PROJECT_NAME@"
include ':app'
@@ -0,0 +1,33 @@
# Copyright (c) 2019-2025, Arm Limited and Contributors
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 the "License";
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} PATH)
get_filename_component(CATEGORY_NAME ${PARENT_DIR} NAME)
add_sample(
ID ${FOLDER_NAME}
CATEGORY ${CATEGORY_NAME}
AUTHOR "Khronos"
NAME "@SAMPLE_NAME@"
DESCRIPTION "Sample description"
# Important note: Shaders are compiled offline via CMake, so all shaders
# used by this sample need to be put here
# The framework also supports HLSL (SHADER_FILES_HLSL) and Slang (SHADER_FILES_SLANG)
SHADER_FILES_GLSL
"triangle.vert"
"triangle.frag")
@@ -0,0 +1,64 @@
/* Copyright (c) 2019-2025, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "@SAMPLE_NAME_FILE@.h"
#include "common/vk_common.h"
#include "gltf_loader.h"
#include "gui.h"
#include "filesystem/legacy.h"
#include "platform/platform.h"
#include "rendering/subpasses/forward_subpass.h"
#include "stats/stats.h"
@SAMPLE_NAME@::@SAMPLE_NAME@()
{
}
bool @SAMPLE_NAME@::prepare(const vkb::ApplicationOptions &options)
{
if (!VulkanSample::prepare(options))
{
return false;
}
// Load a scene from the assets folder
load_scene("scenes/sponza/Sponza01.gltf");
// Attach a move script to the camera component in the scene
auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent());
auto camera = &camera_node.get_component<vkb::sg::Camera>();
// Example Scene Render Pipeline
vkb::ShaderSource vert_shader("base.vert.spv");
vkb::ShaderSource frag_shader("base.frag.spv");
auto scene_subpass = std::make_unique<vkb::ForwardSubpass>(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera);
auto render_pipeline = std::make_unique<vkb::RenderPipeline>();
render_pipeline->add_subpass(std::move(scene_subpass));
set_render_pipeline(std::move(render_pipeline));
// Add a GUI with the stats you want to monitor
get_stats().request_stats({/*stats you require*/});
create_gui(*window, &get_stats());
return true;
}
std::unique_ptr<vkb::VulkanSampleC> create_@SAMPLE_NAME_FILE@()
{
return std::make_unique<@SAMPLE_NAME@>();
}
+34
View File
@@ -0,0 +1,34 @@
/* Copyright (c) 2019-2024, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "rendering/render_pipeline.h"
#include "scene_graph/components/camera.h"
#include "vulkan_sample.h"
class @SAMPLE_NAME@ : public vkb::VulkanSampleC
{
public:
@SAMPLE_NAME@();
virtual bool prepare(const vkb::ApplicationOptions &options) override;
virtual ~@SAMPLE_NAME@() = default;
};
std::unique_ptr<vkb::VulkanSampleC> create_@SAMPLE_NAME_FILE@();
@@ -0,0 +1,33 @@
# Copyright (c) 2023-2025, Arm Limited and Contributors
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 the "License";
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} PATH)
get_filename_component(CATEGORY_NAME ${PARENT_DIR} NAME)
add_sample(
ID ${FOLDER_NAME}
CATEGORY ${CATEGORY_NAME}
AUTHOR "<<Contributor>>"
NAME "@SAMPLE_NAME@"
DESCRIPTION "Sample description"
# Important note: Shaders are compiled offline via CMake, so all shaders
# used by this sample need to be put here
# The framework also supports HLSL (SHADER_FILES_HLSL) and Slang (SHADER_FILES_SLANG)
SHADER_FILES_GLSL
"triangle.vert"
"triangle.frag")
@@ -0,0 +1,174 @@
/* Copyright (c) 2024-2025, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "@SAMPLE_NAME_FILE@.h"
@SAMPLE_NAME@::@SAMPLE_NAME@()
{
}
@SAMPLE_NAME@::~@SAMPLE_NAME@()
{
if (has_device())
{
vkDestroyPipeline(get_device().get_handle(), sample_pipeline, nullptr);
vkDestroyPipelineLayout(get_device().get_handle(), sample_pipeline_layout, nullptr);
}
}
bool @SAMPLE_NAME@::prepare(const vkb::ApplicationOptions &options)
{
if (!ApiVulkanSample::prepare(options))
{
return false;
}
prepare_pipelines();
build_command_buffers();
prepared = true;
return true;
}
void @SAMPLE_NAME@::prepare_pipelines()
{
// Create a blank pipeline layout.
// We are not binding any resources to the pipeline in this sample.
VkPipelineLayoutCreateInfo layout_info = vkb::initializers::pipeline_layout_create_info(nullptr, 0);
VK_CHECK(vkCreatePipelineLayout(get_device().get_handle(), &layout_info, nullptr, &sample_pipeline_layout));
VkPipelineVertexInputStateCreateInfo vertex_input = vkb::initializers::pipeline_vertex_input_state_create_info();
// Specify we will use triangle lists to draw geometry.
VkPipelineInputAssemblyStateCreateInfo input_assembly = vkb::initializers::pipeline_input_assembly_state_create_info(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE);
// Specify rasterization state.
VkPipelineRasterizationStateCreateInfo raster = vkb::initializers::pipeline_rasterization_state_create_info(VK_POLYGON_MODE_FILL, VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_CLOCKWISE);
// Our attachment will write to all color channels, but no blending is enabled.
VkPipelineColorBlendAttachmentState blend_attachment = vkb::initializers::pipeline_color_blend_attachment_state(VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, VK_FALSE);
VkPipelineColorBlendStateCreateInfo blend = vkb::initializers::pipeline_color_blend_state_create_info(1, &blend_attachment);
// We will have one viewport and scissor box.
VkPipelineViewportStateCreateInfo viewport = vkb::initializers::pipeline_viewport_state_create_info(1, 1);
// Enable depth testing (using reversed depth-buffer for increased precision).
VkPipelineDepthStencilStateCreateInfo depth_stencil = vkb::initializers::pipeline_depth_stencil_state_create_info(VK_TRUE, VK_TRUE, VK_COMPARE_OP_GREATER);
// No multisampling.
VkPipelineMultisampleStateCreateInfo multisample = vkb::initializers::pipeline_multisample_state_create_info(VK_SAMPLE_COUNT_1_BIT);
// Specify that these states will be dynamic, i.e. not part of pipeline state object.
std::array<VkDynamicState, 2> dynamics{VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR};
VkPipelineDynamicStateCreateInfo dynamic = vkb::initializers::pipeline_dynamic_state_create_info(dynamics.data(), vkb::to_u32(dynamics.size()));
// Load our SPIR-V shaders.
std::array<VkPipelineShaderStageCreateInfo, 2> shader_stages{};
// Vertex stage of the pipeline
shader_stages[0] = load_shader("triangle.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
shader_stages[1] = load_shader("triangle.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
// We need to specify the pipeline layout and the render pass description up front as well.
VkGraphicsPipelineCreateInfo pipeline_create_info = vkb::initializers::pipeline_create_info(sample_pipeline_layout, render_pass);
pipeline_create_info.stageCount = vkb::to_u32(shader_stages.size());
pipeline_create_info.pStages = shader_stages.data();
pipeline_create_info.pVertexInputState = &vertex_input;
pipeline_create_info.pInputAssemblyState = &input_assembly;
pipeline_create_info.pRasterizationState = &raster;
pipeline_create_info.pColorBlendState = &blend;
pipeline_create_info.pMultisampleState = &multisample;
pipeline_create_info.pViewportState = &viewport;
pipeline_create_info.pDepthStencilState = &depth_stencil;
pipeline_create_info.pDynamicState = &dynamic;
VK_CHECK(vkCreateGraphicsPipelines(get_device().get_handle(), pipeline_cache, 1, &pipeline_create_info, nullptr, &sample_pipeline));
}
void @SAMPLE_NAME@::build_command_buffers()
{
VkCommandBufferBeginInfo command_buffer_begin_info = vkb::initializers::command_buffer_begin_info();
// Clear color and depth values.
VkClearValue clear_values[2];
clear_values[0].color = {{0.0f, 0.0f, 0.0f, 0.0f}};
clear_values[1].depthStencil = {0.0f, 0};
// Begin the render pass.
VkRenderPassBeginInfo render_pass_begin_info = vkb::initializers::render_pass_begin_info();
render_pass_begin_info.renderPass = render_pass;
render_pass_begin_info.renderArea.offset.x = 0;
render_pass_begin_info.renderArea.offset.y = 0;
render_pass_begin_info.renderArea.extent.width = width;
render_pass_begin_info.renderArea.extent.height = height;
render_pass_begin_info.clearValueCount = 2;
render_pass_begin_info.pClearValues = clear_values;
for (int32_t i = 0; i < draw_cmd_buffers.size(); ++i)
{
auto cmd = draw_cmd_buffers[i];
// Begin command buffer.
vkBeginCommandBuffer(cmd, &command_buffer_begin_info);
// Set framebuffer for this command buffer.
render_pass_begin_info.framebuffer = framebuffers[i];
// We will add draw commands in the same command buffer.
vkCmdBeginRenderPass(cmd, &render_pass_begin_info, VK_SUBPASS_CONTENTS_INLINE);
// Bind the graphics pipeline.
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, sample_pipeline);
// Set viewport dynamically
VkViewport viewport = vkb::initializers::viewport(static_cast<float>(width), static_cast<float>(height), 0.0f, 1.0f);
vkCmdSetViewport(cmd, 0, 1, &viewport);
// Set scissor dynamically
VkRect2D scissor = vkb::initializers::rect2D(width, height, 0, 0);
vkCmdSetScissor(cmd, 0, 1, &scissor);
// Draw three vertices with one instance.
vkCmdDraw(cmd, 3, 1, 0, 0);
// Draw user interface.
draw_ui(draw_cmd_buffers[i]);
// Complete render pass.
vkCmdEndRenderPass(cmd);
// Complete the command buffer.
VK_CHECK(vkEndCommandBuffer(cmd));
}
}
void @SAMPLE_NAME@::render(float delta_time)
{
if (!prepared)
{
return;
}
ApiVulkanSample::prepare_frame();
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &draw_cmd_buffers[current_buffer];
VK_CHECK(vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE));
ApiVulkanSample::submit_frame();
}
std::unique_ptr<vkb::VulkanSampleC> create_@SAMPLE_NAME_FILE@()
{
return std::make_unique<@SAMPLE_NAME@>();
}
@@ -0,0 +1,42 @@
/* Copyright (c) 2024, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "api_vulkan_sample.h"
class @SAMPLE_NAME@ : public ApiVulkanSample
{
public:
@SAMPLE_NAME@();
virtual ~@SAMPLE_NAME@();
// Create pipeline
void prepare_pipelines();
// Override basic framework functionality
void build_command_buffers() override;
void render(float delta_time) override;
bool prepare(const vkb::ApplicationOptions &options) override;
private:
// Sample specific data
VkPipeline sample_pipeline{};
VkPipelineLayout sample_pipeline_layout{};
};
std::unique_ptr<vkb::VulkanSampleC> create_@SAMPLE_NAME_FILE@();
+42
View File
@@ -0,0 +1,42 @@
#[[
Copyright (c) 2019-2021, Arm Limited and Contributors
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 the "License";
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
function(scan_dirs)
set(options)
set(oneValueArgs LIST DIR)
set(multiValueArgs)
cmake_parse_arguments(TARGET "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT EXISTS ${TARGET_DIR})
message(FATAL_ERROR "Directory not found `${TARGET_DIR}`")
endif()
file(GLOB DIR_FILES RELATIVE ${TARGET_DIR} ${TARGET_DIR}/*)
set(DIR_LIST)
foreach(FILE_NAME ${DIR_FILES})
if(IS_DIRECTORY ${TARGET_DIR}/${FILE_NAME})
list(APPEND DIR_LIST ${FILE_NAME})
endif()
endforeach()
set(${TARGET_LIST} ${DIR_LIST} PARENT_SCOPE)
endfunction()
+49
View File
@@ -0,0 +1,49 @@
#[[
Copyright (c) 2022, Arm Limited and Contributors
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 the "License";
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
set(CMAKE_SYSTEM_NAME Android)
set(ANDROID_NDK_HOME CACHE STRING "")
if(DEFINED ENV{ANDROID_NDK_HOME} AND NOT ANDROID_NDK_HOME)
file(TO_CMAKE_PATH $ENV{ANDROID_NDK_HOME} ANDROID_NDK_HOME)
set(ANDROID_NDK_HOME ${ANDROID_NDK_HOME} CACHE STRING "" FORCE)
else()
set(ANDROID_STANDALONE_TOOLCHAIN CACHE STRING "")
if(DEFINED ENV{ANDROID_STANDALONE_TOOLCHAIN})
file(TO_CMAKE_PATH $ENV{ANDROID_STANDALONE_TOOLCHAIN} ANDROID_STANDALONE_TOOLCHAIN)
set(ANDROID_STANDALONE_TOOLCHAIN ${ANDROID_STANDALONE_TOOLCHAIN} CACHE STRING "" FORCE)
endif()
endif()
if(NOT ANDROID_NDK_HOME AND NOT ANDROID_STANDALONE_TOOLCHAIN)
message(FATAL_ERROR "Required ANDROID_NDK_HOME or ANDROID_STANDALONE_TOOLCHAIN environment variable to point to your Android NDK Root/Android Standalone Toolchain.")
endif()
set(CMAKE_ANDROID_NDK ${ANDROID_NDK_HOME})
set(CMAKE_ANDROID_STANDALONE_TOOLCHAIN ${ANDROID_STANDALONE_TOOLCHAIN})
set(CMAKE_ANDROID_API 24 CACHE STRING "")
set(CMAKE_ANDROID_ARCH_ABI "arm64-v8a" CACHE STRING "")
set(CMAKE_ANDROID_STL_TYPE "c++_static" CACHE STRING "")
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION "clang" CACHE STRING "")
@@ -0,0 +1,66 @@
#[[
Copyright (c) 2022, Arm Limited and Contributors
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 the "License";
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
# Android Nsight Tegra version requirement
set(REQUIRED_NSIGHT_TEGRA_VERSION "3.4")
# Get Android Nsight Tegra environment
set(NSIGHT_TEGRA_VERSION ${CMAKE_VS_NsightTegra_VERSION})
if( "${NSIGHT_TEGRA_VERSION}" STREQUAL "" )
get_filename_component(NSIGHT_TEGRA_VERSION "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\NVIDIA Corporation\\Nsight Tegra;Version]" NAME)
endif()
# Report and check version if it exist
if(NOT "${NSIGHT_TEGRA_VERSION}" STREQUAL "")
message(STATUS "Android Nsight Tegra version found: ${NSIGHT_TEGRA_VERSION}")
if(NOT "${NSIGHT_TEGRA_VERSION}" VERSION_GREATER_EQUAL "${REQUIRED_NSIGHT_TEGRA_VERSION}+")
message(FATAL_ERROR "Expected Android Nsight Tegra version: ${REQUIRED_NSIGHT_TEGRA_VERSION}")
endif()
endif()
# We are building Android platform, fail if Android Nsight Tegra not found
if( NOT NSIGHT_TEGRA_VERSION )
message(FATAL_ERROR "Engine requires Android Nsight Tegra to be installed in order to build Android platform.")
endif()
file(TO_CMAKE_PATH $ENV{ANDROID_NDK_HOME} CMAKE_ANDROID_NDK)
if(NOT CMAKE_ANDROID_NDK)
message(FATAL_ERROR "Engine requires CMAKE_ANDROID_NDK environment variable to point to your Android NDK.")
endif()
# Tell CMake we are cross-compiling to Android
set(CMAKE_SYSTEM_NAME Android)
# Tell CMake which version of the Android API we are targeting
set(CMAKE_ANDROID_API_MIN 24 CACHE STRING "")
set(CMAKE_ANDROID_API 24 CACHE STRING "")
set(CMAKE_ANDROID_ARCH "arm64-v8a" CACHE STRING "")
# Tell CMake we don't want to skip Ant step
set(CMAKE_ANDROID_SKIP_ANT_STEP 0)
# Use Clang as the C/C++ compiler
set(CMAKE_GENERATOR_TOOLSET DefaultClang)
# Tell CMake we have our java source in the 'java' directory
set(CMAKE_ANDROID_JAVA_SOURCE_DIR ${CMAKE_SOURCE_DIR}/bldsys/android/vulkan_samples/src/main/java)
# Tell CMake we have use Gradle as our default build system
set(CMAKE_ANDROID_BUILD_SYSTEM GradleBuild)