blob: b74b2c3baf058183ed145230f818556606e8fad8 [file] [log] [blame]
# Copyright (C) 2016 The Android Open Source Project
#
# 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(sources "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp")
set(android_sources
${CMAKE_CURRENT_SOURCE_DIR}/android/build.gradle
${CMAKE_CURRENT_SOURCE_DIR}/android/gradle.properties
${CMAKE_CURRENT_SOURCE_DIR}/android/gradlew
${CMAKE_CURRENT_SOURCE_DIR}/android/gradlew.bat
${CMAKE_CURRENT_SOURCE_DIR}/android/settings.gradle
${CMAKE_CURRENT_SOURCE_DIR}/android/gradle/wrapper/gradle-wrapper.jar
${CMAKE_CURRENT_SOURCE_DIR}/android/gradle/wrapper/gradle-wrapper.properties
${CMAKE_CURRENT_SOURCE_DIR}/android/app/build.gradle
${CMAKE_CURRENT_SOURCE_DIR}/android/app/proguard-rules.pro
${CMAKE_CURRENT_SOURCE_DIR}/android/app/src/main/res/values/strings.xml
)
set(android_configure_sources
${CMAKE_CURRENT_SOURCE_DIR}/android/app/src/main/AndroidManifest.xml
)
foreach(abi ${ANDROID_ACTIVE_ABI_LIST})
set(dst "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${ANDROID_BUILD_PATH_${abi}}/")
add_cmake_target(${abi} gapirapk ${dst} "gapir.apk"
DEPENDS ${sources}
${android_sources}
${android_configure_sources}
gapir
VkLayer_VirtualSwapchain
DESTINATION "android/${ANDROID_ABI_PATH_${abi}}"
SOURCE_PATH "gapir/app/build/outputs/apk/app-debug.apk"
)
endforeach()
if(NOT DISABLED_CXX)
if(ANDROID)
get_filename_component(glue "${CMAKE_CURRENT_SOURCE_DIR}/../third_party/ndk/native_app_glue" ABSOLUTE)
add_library(gapir SHARED ${sources} "${glue}/android_native_app_glue.c")
target_include_directories(gapir PRIVATE "${glue}")
set(TARGET_SOURCES)
set(EXTRA_ANDROID_PARAM "")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(EXTRA_ANDROID_PARAM "android:debuggable=\"true\"")
endif()
foreach (source ${android_sources})
file(RELATIVE_PATH rooted_source ${CMAKE_CURRENT_SOURCE_DIR}/android ${source})
configure_file(${source} ${CMAKE_CURRENT_BINARY_DIR}/gapir/${rooted_source} COPYONLY)
list(APPEND TARGET_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/gapir/${rooted_source})
endforeach()
foreach (source ${android_configure_sources})
file(RELATIVE_PATH rooted_source ${CMAKE_CURRENT_SOURCE_DIR}/android ${source})
configure_file(${source} ${CMAKE_CURRENT_BINARY_DIR}/gapir/${rooted_source} @ONLY)
list(APPEND TARGET_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/gapir/${rooted_source})
endforeach()
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/gapir/app/src/main/jniLibs/${ANDROID_ABI_PATH}/libgapir.so
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/bin/libgapir.so
${CMAKE_CURRENT_BINARY_DIR}/gapir/app/src/main/jniLibs/${ANDROID_ABI_PATH}/
DEPENDS
gapir
)
set(virtual_swapchain_dest
${CMAKE_CURRENT_BINARY_DIR}/gapir/app/src/main/jniLibs/${ANDROID_ABI_PATH}/libVkLayer_VirtualSwapchain.so)
add_custom_command(
OUTPUT ${virtual_swapchain_dest}
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/bin/libVkLayer_VirtualSwapchain.so
${virtual_swapchain_dest}
DEPENDS
VkLayer_VirtualSwapchain
)
set(apk "${CMAKE_CURRENT_BINARY_DIR}/gapir/app/build/outputs/apk/app-debug.apk")
gradle(gapirapk
OUTPUT ${apk}
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gapir
DEPENDS
${TARGET_SOURCES}
${CMAKE_CURRENT_BINARY_DIR}/gapir/app/src/main/jniLibs/${ANDROID_ABI_PATH}/libgapir.so
${virtual_swapchain_dest}
)
else()
add_executable(gapir ${sources})
install(TARGETS gapir DESTINATION ${TARGET_INSTALL_PATH})
endif()
target_link_libraries(gapir gapir_static)
endif()