Skip to content

Commit

Permalink
Configuration, CMake - building of APK file
Browse files Browse the repository at this point in the history
  • Loading branch information
gkv311 committed Jan 8, 2025
1 parent 7d7a189 commit e9aa38f
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 28 deletions.
24 changes: 21 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ project (sView)

set (APP_VERSION_MAJOR 1)
set (APP_VERSION_MINOR 0)
# Android APK version
set (SVIEW_APK_VERSIONCODE "1")
set (SVIEW_APK_VERSIONNAME "20.1")

if (MSVC)
set (BUILD_FORCE_RelWithDebInfo ON CACHE BOOL "Build release target with debug symbols")
Expand Down Expand Up @@ -287,6 +290,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# install options
set (SVIEW_BUNDLE_EXT "")
set (SVIEW_BUNDLE_BIN "")
set (SVIEW_BUNDLE_RES "")
if (WIN32)
set (USR_BIN "")
set (USR_LIB "")
Expand All @@ -295,11 +299,14 @@ if (WIN32)
elseif (APPLE)
set (SVIEW_BUNDLE_EXT ".app")
set (SVIEW_BUNDLE_BIN ".app/Contents/MacOS")
set (SVIEW_BUNDLE_RES ".app/Contents/MacOS")
set (USR_BIN "/Contents/MacOS")
set (USR_LIB "/Contents/MacOS")
set (USR_SHARE "/Contents/MacOS")
set (USR_SVIEW "")
elseif (ANDROID)
set (SVIEW_BUNDLE_BIN "/lib/${CMAKE_ANDROID_ARCH_ABI}")
set (SVIEW_BUNDLE_RES "/assets")
set (USR_BIN "/bin")
set (USR_LIB "/lib")
set (USR_SHARE "/assets")
Expand Down Expand Up @@ -330,9 +337,20 @@ set (aLangMap_chinese ChineseS)
set (aLangMap_chineset ChineseT)
set (aLangMap_korean Korean)
set (aLangMap_czech Czech)
if (ANDROID)
set (aLangMap_english English)
set (aLangMap_spanish Spanish)
set (aLangMap_russian Russian)
set (aLangMap_french French)
set (aLangMap_german German)
set (aLangMap_chinese ChineseS)
set (aLangMap_chineset ChineseT)
set (aLangMap_korean Korean)
set (aLangMap_czech Czech)
endif()
foreach (aCfgIter ${CMAKE_CONFIGURATION_TYPES})
foreach (aLangIter ${aLangList})
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/lang/${aLangMap_${aLangIter}}")
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/lang/${aLangMap_${aLangIter}}")
endforeach()
endforeach()

Expand Down Expand Up @@ -372,9 +390,9 @@ function (st_set_target_output_dirs theTarget)
if (EXISTS "${PROJECT_SOURCE_DIR}/lang/")
foreach (aCfgIter ${CMAKE_CONFIGURATION_TYPES})
foreach (aLangIter ${aLangList})
configure_file ("${PROJECT_SOURCE_DIR}/lang/${aLangIter}/${theTarget}.lng" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/lang/${aLangMap_${aLangIter}}/" COPYONLY)
configure_file ("${PROJECT_SOURCE_DIR}/lang/${aLangIter}/${theTarget}.lng" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/lang/${aLangMap_${aLangIter}}/" COPYONLY)
if (EXISTS "${PROJECT_SOURCE_DIR}/lang/${aLangIter}/language.lng")
configure_file ("${PROJECT_SOURCE_DIR}/lang/${aLangIter}/language.lng" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/lang/${aLangMap_${aLangIter}}/" COPYONLY)
configure_file ("${PROJECT_SOURCE_DIR}/lang/${aLangIter}/language.lng" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/lang/${aLangMap_${aLangIter}}/" COPYONLY)
endif()
endforeach()
endforeach()
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,8 @@ endif

$(sViewApkManifest):
cp -f -r $(SRCDIR)/sview/AndroidManifest.xml.in $(SRCDIR)/build/AndroidManifest.xml
sed -i "s/__SVIEW_APK_VER_CODE__/$(SVIEW_APK_CODE)/gi" $(SRCDIR)/build/AndroidManifest.xml
sed -i "s/__SVIEW_SDK_VER_STRING__/$(SVIEW_SDK_VER_STRING)/gi" $(SRCDIR)/build/AndroidManifest.xml
sed -i "s/@SVIEW_APK_VERSIONCODE@/$(SVIEW_APK_CODE)/gi" $(SRCDIR)/build/AndroidManifest.xml
sed -i "s/@SVIEW_APK_VERSIONNAME@/$(SVIEW_SDK_VER_STRING)/gi" $(SRCDIR)/build/AndroidManifest.xml

$(sViewApk): $(sViewApkSigned)
$(ANDROID_BUILD_TOOLS)/zipalign -v -f 4 $< $(sViewApk)
Expand Down
10 changes: 5 additions & 5 deletions StMoviePlayer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ endif()
# copy web resources to build folder
file (GLOB TEXTURE_FILES ../textures/*.svg)
foreach (aCfgIter ${CMAKE_CONFIGURATION_TYPES})
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/textures")
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/textures")
foreach (aFileIter ${TEXTURE_FILES})
configure_file ("${aFileIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/textures/" COPYONLY)
configure_file ("${aFileIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/textures/" COPYONLY)
endforeach()

file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/web")
configure_file ("web/index.htm" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/web/" COPYONLY)
configure_file ("web/favicon.ico" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/web/" COPYONLY)
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/web")
configure_file ("web/index.htm" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/web/" COPYONLY)
configure_file ("web/favicon.ico" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/web/" COPYONLY)
endforeach()
2 changes: 1 addition & 1 deletion StOutAnaglyph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ target_link_libraries (${PROJECT_NAME} PRIVATE ${ST_OPENGL_LIBRARIES})
# copy resources to build folder
foreach (aCfgIter ${CMAKE_CONFIGURATION_TYPES})
foreach (aShaderIter ${USED_SHADERFILES})
configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/shaders/${aShaderIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/shaders/${PROJECT_NAME}/${aShaderIter}" COPYONLY)
configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/shaders/${aShaderIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/shaders/${PROJECT_NAME}/${aShaderIter}" COPYONLY)
endforeach()
endforeach()
2 changes: 1 addition & 1 deletion StOutIZ3D/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ target_link_libraries (${PROJECT_NAME} PRIVATE ${ST_OPENGL_LIBRARIES})
# copy resources to build folder
foreach (aCfgIter ${CMAKE_CONFIGURATION_TYPES})
foreach (aShaderIter ${USED_SHADERFILES})
configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/shaders/${aShaderIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/shaders/${PROJECT_NAME}/${aShaderIter}" COPYONLY)
configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/shaders/${aShaderIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/shaders/${PROJECT_NAME}/${aShaderIter}" COPYONLY)
endforeach()
endforeach()
2 changes: 1 addition & 1 deletion StOutInterlace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ target_link_libraries (${PROJECT_NAME} PRIVATE ${ST_OPENGL_LIBRARIES})
# copy resources to build folder
foreach (aCfgIter ${CMAKE_CONFIGURATION_TYPES})
foreach (aShaderIter ${USED_SHADERFILES})
configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/shaders/${aShaderIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/shaders/${PROJECT_NAME}/${aShaderIter}" COPYONLY)
configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/shaders/${aShaderIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/shaders/${PROJECT_NAME}/${aShaderIter}" COPYONLY)
endforeach()
endforeach()
6 changes: 5 additions & 1 deletion StShared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set (USED_SRCFILES
StAVImage.cpp
StAVIOContext.cpp
StAVIOFileContext.cpp
StAVIOJniHttpContext.cpp
StAVIOMemContext.cpp
StAVPacket.cpp
StAVVideoMuxer.cpp
Expand Down Expand Up @@ -52,6 +53,7 @@ set (USED_SRCFILES
StImage.cpp
StImageFile.cpp
StImagePlane.cpp
StJNIEnv.cpp
StJpegParser.cpp
StLangMap.cpp
StLibrary.cpp
Expand Down Expand Up @@ -93,6 +95,7 @@ set (USED_INCFILES
../include/StAV/StAVImage.h
../include/StAV/StAVIOContext.h
../include/StAV/StAVIOFileContext.h
../include/StAV/StAVIOJniHttpContext.h
../include/StAV/StAVIOMemContext.h
../include/StAV/StAVPacket.h
../include/StAV/StAVVideoMuxer.h
Expand All @@ -108,6 +111,7 @@ set (USED_INCFILES
../include/StFT/StFTFont.h
../include/StFT/StFTFontRegistry.h
../include/StFT/StFTLibrary.h
../include/StJNI/StJNIEnv.h
../include/StGL/StGLArbFbo.h
../include/StGL/StGLBrightnessMatrix.h
../include/StGL/StGLContext.h
Expand Down Expand Up @@ -271,7 +275,7 @@ if (WIN32)
elseif (APPLE)
target_link_libraries (${PROJECT_NAME} PRIVATE "-framework CoreGraphics" "-framework Appkit" objc)
elseif (ANDROID)
target_link_libraries (${PROJECT_NAME} PRIVATE android)
target_link_libraries (${PROJECT_NAME} PRIVATE log android)
endif()
if (USE_GTK)
target_link_libraries (${PROJECT_NAME} PRIVATE GTK2::gtk GTK2::gthread)
Expand Down
4 changes: 2 additions & 2 deletions sview/AndroidManifest.xml.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sview"
android:versionCode="__SVIEW_APK_VER_CODE__"
android:versionName="__SVIEW_SDK_VER_STRING__"
android:versionCode="@SVIEW_APK_VERSIONCODE@"
android:versionName="@SVIEW_APK_VERSIONNAME@"
android:installLocation="auto">
<application android:label="@string/app_name"
android:hasCode="true"
Expand Down
141 changes: 129 additions & 12 deletions sview/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ set (USED_SRCFILES
set (USED_MMFILES
main.ObjC.mm
)
set (USED_JNIFILES
jni/main.cpp
)

set (USED_INCFILES
StAppResponder.h
Expand All @@ -27,18 +30,15 @@ if (NOT APPLE)
endforeach()
endif()

source_group ("Source Files" FILES ${USED_SRCFILES} ${USED_MMFILES})
source_group ("Source Files" FILES ${USED_SRCFILES} ${USED_MMFILES} ${USED_JNIFILES})
source_group ("Header Files" FILES ${USED_INCFILES})
source_group ("Resource Files" FILES ${USED_RESFILES} ${USED_MANFILES})

if (APPLE)
endif()

# library to build
if (ANDROID)
set (PROJECT_NAME "sview")
add_library (${PROJECT_NAME} SHARED
${USED_SRCFILES} ${USED_MMFILES} ${USED_INCFILES} ${USED_RESFILES}
${USED_SRCFILES} ${USED_JNIFILES} ${USED_INCFILES} ${USED_RESFILES}
)
else()
add_executable (${PROJECT_NAME} WIN32
Expand Down Expand Up @@ -77,6 +77,10 @@ endforeach()
# external dependencies
target_link_libraries (${PROJECT_NAME} PRIVATE freetype)

if (ANDROID)
target_link_libraries (${PROJECT_NAME} PRIVATE log android EGL GLESv2 c)
endif()

if (APPLE)
target_link_libraries (${PROJECT_NAME} PRIVATE "-framework Appkit" objc)
endif()
Expand All @@ -90,11 +94,11 @@ endif()
# copy common resources to build folder
file (GLOB TEXTURE_FILES ../textures/*.png)
foreach (aCfgIter ${CMAKE_CONFIGURATION_TYPES})
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/textures")
#file (CREATE_LINK "${PROJECT_SOURCE_DIR}/textures" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/textures" SYMBOLIC)
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/textures")
#file (CREATE_LINK "${PROJECT_SOURCE_DIR}/textures" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/textures" SYMBOLIC)
foreach (aFileIter ${TEXTURE_FILES})
#message (FATAL_ERROR "aFileIter= ${aFileIter}")
configure_file ("${aFileIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/textures/" COPYONLY)
configure_file ("${aFileIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/textures/" COPYONLY)
endforeach()
endforeach()

Expand Down Expand Up @@ -125,13 +129,13 @@ if (APPLE)
file (GLOB OPENAL_HRFT_FILES ${OPENAL_LIBRARY_DIR}/../share/openal/hrtf/*.mhr)
file (GLOB OPENAL_PRST_FILES ${OPENAL_LIBRARY_DIR}/../share/openal/presets/*.ambdec)
foreach (aCfgIter ${CMAKE_CONFIGURATION_TYPES})
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/openal/hrtf")
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/openal/presets")
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/openal/hrtf")
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/openal/presets")
foreach (aFileIter ${OPENAL_HRFT_FILES})
configure_file ("${aFileIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/openal/hrtf/" COPYONLY)
configure_file ("${aFileIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/openal/hrtf/" COPYONLY)
endforeach()
foreach (aFileIter ${OPENAL_PRST_FILES})
configure_file ("${aFileIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_BIN}/openal/presets/" COPYONLY)
configure_file ("${aFileIter}" "${CMAKE_BINARY_DIR}/${aCfgIter}${SVIEW_BUNDLE_RES}/openal/presets/" COPYONLY)
endforeach()
endforeach()
endif()
Expand All @@ -147,9 +151,122 @@ if (APPLE)
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND cp -R -f "${FFMPEG_LIBRARY_DIR}/lib${aLibIter}*.dylib" "$<TARGET_FILE_DIR:${PROJECT_NAME}>/../Frameworks")
endforeach()
elseif (ANDROID)
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND cp -R -f "${FREETYPE_LIBRARY_DIR}/libfreetype.so" "$<TARGET_FILE_DIR:${PROJECT_NAME}>/")
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND cp -R -f "${OPENAL_LIBRARY_DIR}/libopenal.so" "$<TARGET_FILE_DIR:${PROJECT_NAME}>/")

foreach (aLibIter ${FFMPEG_TKLIST})
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND cp -R -f "${FFMPEG_LIBRARY_DIR}/lib${aLibIter}.so" "$<TARGET_FILE_DIR:${PROJECT_NAME}>/")
endforeach()

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND cp -R -f "${CMAKE_ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.9/libs/${CMAKE_ANDROID_ARCH_ABI}/libgnustl_shared.so" "$<TARGET_FILE_DIR:${PROJECT_NAME}>/"
#COMMAND ${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}strip${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX} --strip-unneeded "$<TARGET_FILE_DIR:${PROJECT_NAME}>/libgnustl_shared.so"
)
endif()

# install target
install (TARGETS "${PROJECT_NAME}"
RUNTIME DESTINATION "${SVIEW_INSTALL_BIN}"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE)

if (ANDROID)
find_package (Java REQUIRED)
set (ANDROID_PLATFORM "android-26.jar" CACHE FILEPATH "Path to android-26.jar")
set (ANDROID_BUILD_TOOLS "" CACHE PATH "Path to Android build tools (aapt, dx, zipalign, etc.)")
find_program (TOOL_AAPT NAMES aapt PATHS ${ANDROID_BUILD_TOOLS} NO_DEFAULT_PATH)
find_program (TOOL_DX NAMES dx PATHS ${ANDROID_BUILD_TOOLS} NO_DEFAULT_PATH)
find_program (TOOL_ZIPALIGN NAMES zipalign PATHS ${ANDROID_BUILD_TOOLS} NO_DEFAULT_PATH)
if (NOT TOOL_AAPT)
message (FATAL_ERROR "could not find aapt, please set ANDROID_BUILD_TOOLS variable" )
endif()
if (NOT TOOL_DX)
message (FATAL_ERROR "could not find dx, please set ANDROID_BUILD_TOOLS variable" )
endif()
if (NOT TOOL_ZIPALIGN)
message (FATAL_ERROR "could not find zipalign, please set ANDROID_BUILD_TOOLS variable" )
endif()

# generate APK manifest file with version codes (should be incremented for each build)
set (SVIEW_APK_MANIFEST "${CMAKE_BINARY_DIR}/AndroidManifest.xml")
set (SVIEW_APK_VERSIONCODE "1")
set (SVIEW_APK_VERSIONNAME "20.1")
configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/AndroidManifest.xml.in" "${SVIEW_APK_MANIFEST}")

# compile APK resources
set (AAPT_RESOURCES_OUTPUT_DIR "${CMAKE_BINARY_DIR}/java/gen")
set (AAPT_RESOURCES_OUTPUT "${AAPT_RESOURCES_OUTPUT_DIR}/com/sview/R.java")
add_custom_command (OUTPUT ${AAPT_RESOURCES_OUTPUT} DEPENDS ${SVIEW_APK_MANIFEST} VERBATIM
COMMAND ${TOOL_AAPT} package -v -f -m -S ${CMAKE_CURRENT_SOURCE_DIR}/res -J ${AAPT_RESOURCES_OUTPUT_DIR} -M ${SVIEW_APK_MANIFEST} -I ${ANDROID_PLATFORM}
COMMENT "Calling aapt to generate R.java for APK resources...")
add_custom_target (genjavares ALL DEPENDS ${AAPT_RESOURCES_OUTPUT})

# compile Java files
set (USED_JAVAFILES
src/com/sview/CrashReportActivity.java
src/com/sview/MainActivity.java
src/com/sview/StActivity.java
src/com/sview/StImageActivity.java
src/com/sview/StMovieActivity.java
src/com/sview/StMovieService.java
src/com/sview/StS3dvSurface.java
)

set (JAVAC_INPUT)
set (JAVAC_OUTPUT)
set (JAVAC_OUTPUT_DIR "${CMAKE_BINARY_DIR}/java/classes")
foreach (aJavaFile ${USED_JAVAFILES})
get_filename_component (aFileBase ${aJavaFile} NAME_WE)
list (APPEND JAVAC_INPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/com/sview/${aFileBase}.java)
# actually javac might generate multiple '.class' files out of a single '.java' (like 'StMovieActivity.class', 'StMovieActivity$1.class' and more)
list (APPEND JAVAC_OUTPUT ${JAVAC_OUTPUT_DIR}/com/sview/${aFileBase}.class)
endforeach()
# R.java -> R.class, R$attr.class, R$drawable.class, R$mipmap.class, R$string.class
list (APPEND JAVAC_INPUT ${AAPT_RESOURCES_OUTPUT})
list (APPEND JAVAC_OUTPUT ${JAVAC_OUTPUT_DIR}/com/sview/R.class)

#set (CMAKE_JAVA_COMPILE_FLAGS "-source" "1.7" "-target" "1.7")
add_custom_command (OUTPUT ${JAVAC_OUTPUT} DEPENDS ${JAVAC_INPUT} VERBATIM
COMMAND ${Java_JAVAC_EXECUTABLE} -source 1.7 -target 1.7 -d ${JAVAC_OUTPUT_DIR} -classpath ${ANDROID_PLATFORM} -sourcepath ${CMAKE_CURRENT_SOURCE_DIR}/src:${AAPT_RESOURCES_OUTPUT_DIR} ${JAVAC_INPUT}
COMMENT "Calling Java compiler ${Java_JAVAC_EXECUTABLE}...")
add_custom_target (javac ALL DEPENDS ${JAVAC_OUTPUT})

# compile .class files into .dx
set (SVIEW_DEX_OUTPUT "${CMAKE_BINARY_DIR}/classes.dex")
add_custom_command (OUTPUT ${SVIEW_DEX_OUTPUT} DEPENDS ${JAVAC_OUTPUT} VERBATIM
COMMAND ${TOOL_DX} --dex --verbose --output=${SVIEW_DEX_OUTPUT} ${JAVAC_OUTPUT_DIR}
COMMENT "Calling dx compiler...")
add_custom_target (javadx ALL DEPENDS ${SVIEW_DEX_OUTPUT})

# generate debug APK signing key
set (ANDROID_KEYSTORE "${CMAKE_BINARY_DIR}/sview_debug.key" CACHE STRING "Path to keystore file")
set (ANDROID_KEYSTORE_PASSWORD "sview_pswd" CACHE STRING "Keystore password")
set (ANDROID_KEY "sview android key" CACHE STRING "Signing key name in keystore")
set (ANDROID_KEY_PASSWORD "sview_pswd" CACHE STRING "Signing key password")
find_program (TOOL_KEYTOOL NAMES keytool PATHS ${JAVA_HOME})
add_custom_command (OUTPUT ${ANDROID_KEYSTORE} VERBATIM
COMMAND ${TOOL_KEYTOOL} -genkeypair -validity 1000 -dname "CN=sview_dummy,O=Android,C=JPN" -keystore ${ANDROID_KEYSTORE} -storepass ${ANDROID_KEYSTORE_PASSWORD} -keypass ${ANDROID_KEY_PASSWORD} -alias ${ANDROID_KEY} -keyalg RSA -v
COMMENT "Generating debug signing key...")
add_custom_target (sView_keystore_debug DEPENDS ${ANDROID_KEYSTORE})

# build unsigned APK file
set (SVIEW_APK_ROOT "$<TARGET_FILE_DIR:${PROJECT_NAME}>/../..")
set (SVIEW_APK_UNSIGNED "${CMAKE_BINARY_DIR}/sView-$<CONFIG>.unsigned.apk.tmp")
set (SVIEW_APK_SIGNED "${CMAKE_BINARY_DIR}/sView-$<CONFIG>.signed.apk.tmp")
set (SVIEW_APK_FINAL "${CMAKE_BINARY_DIR}/sView-$<CONFIG>.apk")
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD VERBATIM
COMMAND ${CMAKE_COMMAND} -E remove -f ${SVIEW_APK_UNSIGNED}
COMMAND ${CMAKE_COMMAND} -E copy ${SVIEW_DEX_OUTPUT} ${SVIEW_APK_ROOT}/
#COMMAND ${TOOL_AAPT} package -v -f -M ${SVIEW_APK_MANIFEST} -S ${CMAKE_CURRENT_SOURCE_DIR}/res -I ${ANDROID_PLATFORM} -F ${SVIEW_APK_UNSIGNED} ${SVIEW_APK_ROOT}
COMMAND ${TOOL_AAPT} package -f -M ${SVIEW_APK_MANIFEST} -S ${CMAKE_CURRENT_SOURCE_DIR}/res -I ${ANDROID_PLATFORM} -F ${SVIEW_APK_UNSIGNED} ${SVIEW_APK_ROOT}
COMMAND ${Java_JARSIGNER_EXECUTABLE} -sigalg SHA1withRSA -digestalg SHA1 -keystore ${ANDROID_KEYSTORE} -storepass ${ANDROID_KEYSTORE_PASSWORD} -keypass ${ANDROID_KEY_PASSWORD}
-verbose
-signedjar ${SVIEW_APK_SIGNED} ${SVIEW_APK_UNSIGNED} ${ANDROID_KEY}
COMMAND ${TOOL_ZIPALIGN} -v -f 4 ${SVIEW_APK_SIGNED} ${SVIEW_APK_FINAL}
COMMENT "Building APK...")
add_dependencies (${PROJECT_NAME} javadx)

endif()

0 comments on commit e9aa38f

Please sign in to comment.