Skip to content

Commit

Permalink
Added support for building on android
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLazarescu committed Feb 19, 2024
1 parent 8ba0ee7 commit 0f72181
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 19 deletions.
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ project(Librum VERSION 0.1


# Set output directory
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}")
if(NOT ANDROID AND NOT IOS)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}")
endif()


# Configuration
Expand All @@ -28,7 +30,6 @@ set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)


# Create a set of warnings for windows systems
if(WIN32)
add_compile_options(-Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -permissive- -Zc:__cplusplus -Zc:externConstexpr -utf-8 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458)
Expand Down Expand Up @@ -75,7 +76,6 @@ add_subdirectory(libs/rapidfuzz-cpp)
# Build
add_subdirectory(src/)


# Tests
if(BUILD_TESTS)
include(CTest)
Expand Down
2 changes: 1 addition & 1 deletion libs/googletest
Submodule googletest updated 45 files
+1 −0 .gitignore
+17 −0 BUILD.bazel
+9 −0 CMakeLists.txt
+1 −0 CONTRIBUTORS
+57 −0 MODULE.bazel
+14 −12 WORKSPACE
+35 −0 WORKSPACE.bzlmod
+6 −4 ci/linux-presubmit.sh
+2 −1 ci/macos-presubmit.sh
+2 −2 ci/windows-presubmit.bat
+15 −5 docs/advanced.md
+6 −0 docs/gmock_cook_book.md
+2 −0 docs/gmock_for_dummies.md
+9 −9 docs/primer.md
+2 −2 docs/reference/mocking.md
+3 −1 docs/reference/testing.md
+21 −3 googlemock/include/gmock/gmock-actions.h
+14 −13 googlemock/include/gmock/gmock-matchers.h
+1 −1 googlemock/include/gmock/gmock-more-actions.h
+1 −0 googlemock/include/gmock/gmock.h
+2 −1 googlemock/src/gmock-spec-builders.cc
+9 −0 googlemock/test/gmock-matchers-comparisons_test.cc
+13 −1 googlemock/test/gmock-more-actions_test.cc
+9 −0 googlemock/test/gmock_link_test.h
+1 −1 googletest/CMakeLists.txt
+4 −0 googletest/cmake/Config.cmake.in
+3 −1 googletest/cmake/internal_utils.cmake
+35 −21 googletest/include/gtest/gtest-printers.h
+13 −11 googletest/include/gtest/gtest.h
+2 −4 googletest/include/gtest/internal/gtest-death-test-internal.h
+1 −1 googletest/include/gtest/internal/gtest-internal.h
+2 −2 googletest/include/gtest/internal/gtest-param-util.h
+16 −7 googletest/include/gtest/internal/gtest-port.h
+8 −6 googletest/src/gtest-death-test.cc
+13 −2 googletest/src/gtest-port.cc
+40 −11 googletest/src/gtest.cc
+39 −37 googletest/test/googletest-death-test-test.cc
+4 −1 googletest/test/googletest-options-test.cc
+0 −5 googletest/test/googletest-output-test-golden-lin.txt
+2 −2 googletest/test/googletest-port-test.cc
+52 −44 googletest/test/gtest_environment_test.cc
+1 −3 googletest/test/gtest_repeat_test.cc
+8 −4 googletest/test/gtest_unittest.cc
+9 −6 googletest/test/gtest_xml_output_unittest.py
+8 −8 googletest_deps.bzl
2 changes: 1 addition & 1 deletion libs/mupdf
Submodule mupdf updated 359 files
2 changes: 1 addition & 1 deletion libs/rapidfuzz-cpp
16 changes: 13 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ get_target_property(ADAPTERS_BIN_DIR adapters CMAKE_BINARY_DIR)

add_subdirectory(presentation/)




# Building
set(app_icon_resource_windows "${CMAKE_CURRENT_SOURCE_DIR}/resources.rc")
qt_add_executable(librum
Expand All @@ -44,6 +41,19 @@ if(WIN32)
set_target_properties(librum PROPERTIES WIN32_EXECUTABLE true)
endif()

# On android, we need to manually move the mupdf and openssl libraries to the apk
# by setting QT_ANDROID_EXTRA_LIBS
if(ANDROID)
list(APPEND CUSTOM_ANDROID_EXTRA_LIBS "${PROJECT_SOURCE_DIR}/libs/mupdf/build/shared-debug/libmupdf.so")
list(APPEND CUSTOM_ANDROID_EXTRA_LIBS "${PROJECT_SOURCE_DIR}/libs/mupdf/build/shared-debug/libmupdfcpp.so")
string(REPLACE ";" "," CUSTOM_ANDROID_EXTRA_LIBS_STRING "${CUSTOM_ANDROID_EXTRA_LIBS}")

set_property(TARGET librum PROPERTY QT_ANDROID_EXTRA_LIBS
${ANDROID_SDK_ROOT}/android_openssl/ssl_3/arm64-v8a/libcrypto_3.so
${ANDROID_SDK_ROOT}/android_openssl/ssl_3/arm64-v8a/libssl_3.so
${CUSTOM_ANDROID_EXTRA_LIBS_STRING})
endif()

target_compile_definitions(librum
PRIVATE
$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>
Expand Down
25 changes: 20 additions & 5 deletions src/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,22 @@ set(application_SRC
)


# Build mupdf

########## Build mupdf ##########
set(VENV_OPTION "")
if(NOT ${NO_VENV})
set(VENV_OPTION "--venv")
endif()

if(ANDROID)
set(EXTRA_MAKE_AGRS --m-vars 'HAVE_OBJCOPY=no HAVE_LIBCRYPTO=no')
endif()

if(UNIX)
set(MUPDF_OUTPUT_DIR "${PROJECT_SOURCE_DIR}/libs/mupdf/build/$<IF:$<CONFIG:Debug>,shared-debug,shared-release>")
set(MUPDF_OUTPUT "${MUPDF_OUTPUT_DIR}/libmupdfcpp.so")
set(MUPDF_OUTPUT "${MUPDF_OUTPUT_DIR}/libmupdfcpp.so" PARENT_SCOPE)
set(MUPDF_BUILD_COMMAND ./scripts/mupdfwrap.py ${VENV_OPTION} -d build/$<IF:$<CONFIG:Debug>,shared-debug,shared-release> -b -j 0 m01)
set(MUPDF_BUILD_COMMAND ./scripts/mupdfwrap.py ${VENV_OPTION} -d build/$<IF:$<CONFIG:Debug>,shared-debug,shared-release> -b --m-target libs ${EXTRA_MAKE_AGRS} -j 0 m01)
elseif(WIN32)
set(MUPDF_OUTPUT_DIR "${PROJECT_SOURCE_DIR}/libs/mupdf/platform/win32/x64/$<IF:$<CONFIG:Debug>,Debug,Release>")
set(MUPDF_OUTPUT "${MUPDF_OUTPUT_DIR}/mupdfcpp64.lib" PARENT_SCOPE)
Expand All @@ -107,6 +112,14 @@ endif()
message("MuPdf build command: " ${MUPDF_BUILD_COMMAND})


set(CC_COMMAND "${CMAKE_C_COMPILER}")
set(CXX_COMMAND "${CMAKE_CXX_COMPILER}")

if(ANDROID)
string(APPEND CC_COMMAND " --target=aarch64-none-linux-android23 --sysroot=/home/creapermann/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/sysroot")
string(APPEND CXX_COMMAND " --target=aarch64-none-linux-android23 --sysroot=/home/creapermann/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/sysroot")
endif()


# On linux, we want to use the system provided libjpeg,
# since the one that comes with mupdf is not compatible with the one that comes with Qt.
Expand All @@ -119,6 +132,8 @@ endif()

add_custom_target(mupdf
COMMAND ${CMAKE_COMMAND} -E env
"CC=${CC_COMMAND}"
"CXX=${CXX_COMMAND}"
"USE_SYSTEM_LIBJPEG=${USE_SYSTEM_LIBJPEG_VALUE}"
${MUPDF_BUILD_COMMAND}
BYPRODUCTS ${MUPDF_OUTPUT}
Expand All @@ -127,7 +142,7 @@ add_custom_target(mupdf
)


###### Copy the mupdf dlls to the build directory for windows ######
#Copy the mupdf dlls to the build directory for windows
if(WIN32)
add_custom_command(
TARGET mupdf POST_BUILD
Expand All @@ -141,13 +156,13 @@ endif()



# Build application
########## Build application ##########
add_library(application
SHARED
${application_SRC}
)

add_dependencies(application mupdf)
add_dependencies(application mupdf) # Ensure the mupdf target is built before the application target

target_compile_definitions(application PRIVATE APPLICATION_LIBRARY)

Expand Down

0 comments on commit 0f72181

Please sign in to comment.