aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Ramos <juan@lunarg.com>2023-10-10 15:30:07 -0600
committerJuan Ramos <114601453+juan-lunarg@users.noreply.github.com>2023-10-10 16:34:17 -0600
commit72291571c8e569cbcd5d924e0b1ad24cdefa4442 (patch)
tree660bab896d025f7036699d64f0d8cf8764986bc9
parent09d1b5ed777d8f89bbe7bbe72a65a54a868689db (diff)
downloadusermoji-72291571c8e569cbcd5d924e0b1ad24cdefa4442.tar.xz
cmake: vkcube/vulkaninfo successfully compile for Android
-rw-r--r--.github/workflows/tools.yml32
-rw-r--r--CMakeLists.txt6
-rw-r--r--cube/CMakeLists.txt69
-rw-r--r--cube/android/CMakeLists.txt62
-rw-r--r--cube/macOS/cube/cube.cmake3
-rw-r--r--icd/CMakeLists.txt2
-rw-r--r--tests/CMakeLists.txt10
7 files changed, 153 insertions, 31 deletions
diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml
index 99c4b727..b9efdb75 100644
--- a/.github/workflows/tools.yml
+++ b/.github/workflows/tools.yml
@@ -192,7 +192,7 @@ jobs:
- name: Build the tools
run: ninja -C out/${{matrix.config}}
- android:
+ ndk-build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
@@ -209,6 +209,36 @@ jobs:
cd build-android
./build_all.sh
+ android:
+ runs-on: ubuntu-22.04
+ strategy:
+ matrix:
+ abi: [ armeabi-v7a, arm64-v8a ]
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-python@v4
+ with:
+ python-version: '3.8'
+ - uses: lukka/get-cmake@latest
+ - name: Configure
+ run: |
+ cmake -S . -B build/ --toolchain $ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake \
+ -D ANDROID_PLATFORM=23 \
+ -D CMAKE_ANDROID_ARCH_ABI=${{matrix.abi}} \
+ -D CMAKE_ANDROID_STL_TYPE=c++_static \
+ -D ANDROID_USE_LEGACY_TOOLCHAIN_FILE=NO \
+ -D CMAKE_BUILD_TYPE=Release \
+ -D UPDATE_DEPS=ON \
+ -D BUILD_TESTS=ON \
+ -G "Ninja"
+ - name: Build
+ run: cmake --build build
+ - name: Test
+ working-directory: ./build
+ run: ctest --output-on-failure -C Release
+ - name: Install
+ run: cmake --install build --prefix /tmp
+
tools_codegen:
runs-on: ubuntu-latest
steps:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 53042b60..4e6b24e2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,10 +65,8 @@ if(APPLE)
message(STATUS "Using MoltenVK repo location at ${MOLTENVK_REPO_ROOT}")
endif()
-find_package(VulkanHeaders REQUIRED CONFIG)
-if (NOT ANDROID)
- find_package(VulkanLoader REQUIRED CONFIG)
-endif()
+find_package(VulkanHeaders QUIET CONFIG)
+find_package(VulkanLoader QUIET CONFIG)
include(GNUInstallDirs)
diff --git a/cube/CMakeLists.txt b/cube/CMakeLists.txt
index 61440492..8ab409e9 100644
--- a/cube/CMakeLists.txt
+++ b/cube/CMakeLists.txt
@@ -171,40 +171,55 @@ endif()
if(APPLE)
include(macOS/cube/cube.cmake)
-elseif(NOT WIN32)
- add_executable(vkcube
- cube.c
- ${PROJECT_SOURCE_DIR}/cube/cube.vert
- ${PROJECT_SOURCE_DIR}/cube/cube.frag
- cube.vert.inc
- cube.frag.inc
- ${OPTIONAL_WAYLAND_DATA_FILES})
- target_link_libraries(vkcube Vulkan::Headers Vulkan::Loader)
+elseif (ANDROID)
+ add_library(vkcube MODULE)
+
+ target_sources(vkcube PRIVATE cube.c)
+
+ add_subdirectory(android)
+
+ target_link_libraries(vkcube PRIVATE Vulkan::Headers)
+elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|BSD")
+ add_executable(vkcube)
+ target_sources(vkcube PRIVATE
+ cube.c
+ ${PROJECT_SOURCE_DIR}/cube/cube.vert
+ ${PROJECT_SOURCE_DIR}/cube/cube.frag
+ cube.vert.inc
+ cube.frag.inc
+ ${OPTIONAL_WAYLAND_DATA_FILES}
+ )
target_compile_definitions(vkcube PUBLIC ${CUBE_PLATFORM})
include(CheckLibraryExists)
CHECK_LIBRARY_EXISTS("rt" clock_gettime "" NEED_RT)
if (NEED_RT)
- target_link_libraries(vkcube rt)
+ target_link_libraries(vkcube PRIVATE rt)
endif()
-
- if (ENABLE_ADDRESS_SANITIZER)
- target_compile_options(vkcube PUBLIC -fsanitize=address)
- target_link_options(vkcube PUBLIC -fsanitize=address)
- endif ()
+ target_link_libraries(vkcube PRIVATE Vulkan::Headers Vulkan::Loader)
+elseif(WIN32)
+ add_executable(vkcube WIN32)
+ target_sources(vkcube PRIVATE
+ cube.c
+ ${PROJECT_SOURCE_DIR}/cube/cube.vert
+ ${PROJECT_SOURCE_DIR}/cube/cube.frag
+ cube.vert.inc
+ cube.frag.inc
+ )
+ target_link_libraries(vkcube PRIVATE Vulkan::Headers Vulkan::Loader)
else()
- add_executable(vkcube
- WIN32
- cube.c
- ${PROJECT_SOURCE_DIR}/cube/cube.vert
- ${PROJECT_SOURCE_DIR}/cube/cube.frag
- cube.vert.inc
- cube.frag.inc)
- target_link_libraries(vkcube Vulkan::Headers Vulkan::Loader)
+ message(FATAL_ERROR "Unsupported Platform!")
+endif()
+
+if (ENABLE_ADDRESS_SANITIZER)
+ target_compile_options(vkcube PUBLIC -fsanitize=address)
+ target_link_options(vkcube PUBLIC -fsanitize=address)
endif()
target_include_directories(vkcube PRIVATE .)
-if(APPLE)
+if (ANDROID)
+ install(TARGETS vkcube DESTINATION ${CMAKE_INSTALL_LIBDIR})
+elseif(APPLE)
# Keep RPATH so fixup_bundle can use it to find libraries
set_target_properties(vkcube PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
install(TARGETS vkcube BUNDLE DESTINATION "cube")
@@ -217,12 +232,16 @@ else()
install(TARGETS vkcube)
endif()
+if (ANDROID)
+ return()
+endif()
+
# ----------------------------------------------------------------------------
# vkcubepp
if(APPLE)
include(macOS/cubepp/cubepp.cmake)
-elseif(NOT WIN32)
+elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|BSD")
add_executable(vkcubepp
cube.cpp
${PROJECT_SOURCE_DIR}/cube/cube.vert
diff --git a/cube/android/CMakeLists.txt b/cube/android/CMakeLists.txt
new file mode 100644
index 00000000..9d4e69c8
--- /dev/null
+++ b/cube/android/CMakeLists.txt
@@ -0,0 +1,62 @@
+# ~~~
+# Copyright (c) 2023 Valve Corporation
+# Copyright (c) 2023 LunarG, Inc.
+#
+# 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.
+# ~~~
+
+target_sources(vkcube PRIVATE
+ android_util.cpp
+ android_util.h
+ vulkan_wrapper.cpp
+ vulkan_wrapper.h
+)
+
+target_include_directories(vkcube PRIVATE
+ include
+ .
+)
+
+target_compile_options(vkcube PRIVATE
+ --include=${CMAKE_CURRENT_SOURCE_DIR}/vulkan_wrapper.h
+)
+
+set_directory_properties(PROPERTIES "COMPILE_OPTIONS" "") # Disable compiler warnings for android glue
+
+set(native_app_glue_dir "${CMAKE_ANDROID_NDK}/sources/android/native_app_glue")
+
+if (NOT EXISTS ${native_app_glue_dir})
+ message(FATAL_ERROR "Couldn't find Android Native Glue directory!")
+endif()
+
+# https://stackoverflow.com/questions/57189936/compiling-native-app-glue-c-results-in-an-invalid-library-file/76963564#76963564
+add_library(android_glue OBJECT)
+
+target_include_directories(android_glue PUBLIC ${native_app_glue_dir})
+target_sources(android_glue PRIVATE
+ ${native_app_glue_dir}/android_native_app_glue.c
+ ${native_app_glue_dir}/android_native_app_glue.h
+)
+
+target_link_libraries(vkcube PRIVATE
+ android_glue
+ log
+ android
+)
+
+# https://stackoverflow.com/questions/76631917/cmake-how-to-install-shared-stl-libraries-for-android/76656492#76656492
+if ("${CMAKE_ANDROID_STL_TYPE}" MATCHES "shared")
+ file(READ "${CMAKE_ANDROID_NDK}/meta/abis.json" JSON_FILE)
+ string(JSON TRIPLE GET "${JSON_FILE}" "${CMAKE_ANDROID_ARCH_ABI}" "triple")
+ install(FILES "${CMAKE_SYSROOT}/usr/lib/${TRIPLE}/libc++_shared.so" DESTINATION "${CMAKE_INSTALL_LIBDIR}")
+endif()
diff --git a/cube/macOS/cube/cube.cmake b/cube/macOS/cube/cube.cmake
index 15a56849..a3c5624e 100644
--- a/cube/macOS/cube/cube.cmake
+++ b/cube/macOS/cube/cube.cmake
@@ -57,6 +57,9 @@ target_include_directories(vkcube PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MOLTENVK
# We do this so vulkaninfo is linked to an individual library and NOT a framework.
target_link_libraries(vkcube Vulkan::Loader "-framework Cocoa -framework QuartzCore")
+# Disable warnings about sprintf
+target_compile_options(vkcube PRIVATE -Wno-deprecated-declarations)
+
set_target_properties(vkcube PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/macOS/cube/Info.plist)
# The RESOURCE target property cannot be used in conjunction with the MACOSX_PACKAGE_LOCATION property. We need fine-grained
diff --git a/icd/CMakeLists.txt b/icd/CMakeLists.txt
index 8ffed4e2..52ec92fc 100644
--- a/icd/CMakeLists.txt
+++ b/icd/CMakeLists.txt
@@ -122,7 +122,7 @@ add_custom_command(TARGET VkICD_mock_icd POST_BUILD
# Require the user to ask that it be installed if they really want it.
option(INSTALL_ICD "Install Mock icd")
if (INSTALL_ICD)
- message(NOTICE "Installing Mock ICD")
+ message(NOTICE "INSTALL_ICD enabled!")
else()
return()
endif()
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 9e419c9c..8d299ee5 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -16,6 +16,16 @@
# ~~~
if (ANDROID)
+
+ # Ensure ANativeActivity_onCreate is being exported from vkcube
+ find_program(GNU_NM NAMES nm)
+ if (GNU_NM)
+ add_test(NAME ANativeActivity_onCreate COMMAND ${GNU_NM} --dynamic $<TARGET_FILE:vkcube>)
+ set_tests_properties(ANativeActivity_onCreate
+ PROPERTIES PASS_REGULAR_EXPRESSION "T ANativeActivity_onCreate"
+ )
+ endif()
+
return()
endif()