CMakeLists.txt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. cmake_minimum_required(VERSION 3.20.0)
  2. file(READ VERSION VERSION)
  3. string(REGEX MATCHALL "[0-9]+" VERSION_LIST ${VERSION})
  4. list(GET VERSION_LIST 0 VERSION_MAJOR)
  5. list(GET VERSION_LIST 1 VERSION_MINOR)
  6. list(GET VERSION_LIST 2 VERSION_PATCH)
  7. project(apk-editor-studio
  8. VERSION ${VERSION}
  9. HOMEPAGE_URL https://qwertycube.com/apk-editor-studio/
  10. LANGUAGES CXX
  11. )
  12. set(CMAKE_CXX_STANDARD 11)
  13. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  14. set(CMAKE_AUTOMOC ON)
  15. set(CMAKE_AUTORCC ON)
  16. if(UNIX AND NOT APPLE)
  17. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  18. endif()
  19. add_executable(apk-editor-studio)
  20. add_subdirectory(src)
  21. find_package(Qt5 COMPONENTS Widgets Xml Network LinguistTools REQUIRED)
  22. target_compile_definitions(apk-editor-studio PRIVATE
  23. APPLICATION="APK Editor Studio"
  24. VERSION="${VERSION}"
  25. )
  26. option(PORTABLE "Portable build" OFF)
  27. if(PORTABLE)
  28. target_compile_definitions(apk-editor-studio PRIVATE PORTABLE)
  29. endif()
  30. if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Release")
  31. set_property(TARGET apk-editor-studio PROPERTY WIN32_EXECUTABLE TRUE)
  32. endif()
  33. set(TS_FILES
  34. src/translations/apk-editor-studio.ar.ts
  35. src/translations/apk-editor-studio.az.ts
  36. src/translations/apk-editor-studio.ckb.ts
  37. src/translations/apk-editor-studio.cs.ts
  38. src/translations/apk-editor-studio.de.ts
  39. src/translations/apk-editor-studio.el.ts
  40. src/translations/apk-editor-studio.en_GB.ts
  41. src/translations/apk-editor-studio.es.ts
  42. src/translations/apk-editor-studio.es_MX.ts
  43. src/translations/apk-editor-studio.fa.ts
  44. src/translations/apk-editor-studio.fr.ts
  45. src/translations/apk-editor-studio.he.ts
  46. src/translations/apk-editor-studio.hu.ts
  47. src/translations/apk-editor-studio.id.ts
  48. src/translations/apk-editor-studio.it.ts
  49. src/translations/apk-editor-studio.ja.ts
  50. src/translations/apk-editor-studio.ko.ts
  51. src/translations/apk-editor-studio.pl.ts
  52. src/translations/apk-editor-studio.pt.ts
  53. src/translations/apk-editor-studio.ro.ts
  54. src/translations/apk-editor-studio.ru.ts
  55. src/translations/apk-editor-studio.sv.ts
  56. src/translations/apk-editor-studio.tr.ts
  57. src/translations/apk-editor-studio.zh_CN.ts
  58. )
  59. set_source_files_properties(${TS_FILES} PROPERTIES
  60. # TODO Output .qm files to build directory
  61. OUTPUT_LOCATION ${CMAKE_SOURCE_DIR}/dist/all/resources/translations
  62. )
  63. qt5_add_translation(QM_FILES ${TS_FILES})
  64. target_sources(apk-editor-studio PRIVATE ${QM_FILES})
  65. target_include_directories(apk-editor-studio PRIVATE src lib)
  66. # KSyntaxHighlighting
  67. add_subdirectory(lib/KSyntaxHighlighting EXCLUDE_FROM_ALL)
  68. # QtKeychain
  69. set(QTKEYCHAIN_STATIC ON CACHE BOOL "Build QtKeychain statically")
  70. set(BUILD_TRANSLATIONS OFF CACHE BOOL "Build QtKeychain translations")
  71. add_subdirectory(lib/QtKeychain EXCLUDE_FROM_ALL)
  72. target_compile_definitions(apk-editor-studio PRIVATE QTKEYCHAIN_NO_EXPORT)
  73. # SingleApplication
  74. set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication")
  75. add_subdirectory(lib/SingleApplication EXCLUDE_FROM_ALL)
  76. # DarkStyle
  77. target_sources(apk-editor-studio PRIVATE
  78. lib/DarkStyle/DarkStyle.cpp
  79. lib/DarkStyle/darkstyle.qrc
  80. )
  81. target_link_libraries(apk-editor-studio
  82. Qt5::Widgets
  83. Qt5::Xml
  84. Qt5::Network
  85. KSyntaxHighlighting
  86. SingleApplication::SingleApplication
  87. qt5keychain
  88. )
  89. # Deployment
  90. macro(deploy)
  91. add_custom_command(
  92. TARGET apk-editor-studio POST_BUILD
  93. COMMAND ${CMAKE_COMMAND} -E make_directory ${ARGV1}
  94. COMMAND ${CMAKE_COMMAND} -E copy_directory
  95. ${CMAKE_SOURCE_DIR}/dist/${ARGV0}
  96. ${ARGV1}
  97. )
  98. endmacro()
  99. function(find OUTPUT_VARIABLE FILE SEARCH_PATH)
  100. cmake_path(NORMAL_PATH SEARCH_PATH OUTPUT_VARIABLE SEARCH_PATH)
  101. find_file(${OUTPUT_VARIABLE} ${FILE} PATHS ${SEARCH_PATH}
  102. NO_DEFAULT_PATH NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH
  103. NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH
  104. )
  105. endfunction()
  106. if(NOT QT_QMAKE_EXECUTABLE)
  107. get_target_property(QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
  108. endif()
  109. get_filename_component(QT_BIN_DIR "${QT_QMAKE_EXECUTABLE}" DIRECTORY)
  110. if(WIN32)
  111. deploy(all $<TARGET_FILE_DIR:apk-editor-studio>)
  112. deploy(windows $<TARGET_FILE_DIR:apk-editor-studio>)
  113. # Qt libraries
  114. add_custom_command(
  115. TARGET apk-editor-studio POST_BUILD
  116. COMMAND ${QT_BIN_DIR}\\windeployqt
  117. --core
  118. --gui
  119. --network
  120. --widgets
  121. --no-quick-import
  122. --no-translations
  123. --no-system-d3d-compiler
  124. --no-compiler-runtime
  125. --no-angle
  126. --no-opengl-sw
  127. $<TARGET_FILE:apk-editor-studio>
  128. )
  129. # OpenSSL DLLs
  130. if(OPENSSL_ROOT_DIR)
  131. find(OPENSSL_LIBCRYPTO_DLL "libcrypto-1_1.dll" "${OPENSSL_ROOT_DIR}/bin")
  132. find(OPENSSL_LIBSSL_DLL "libssl-1_1.dll" "${OPENSSL_ROOT_DIR}/bin")
  133. add_custom_command(
  134. TARGET apk-editor-studio POST_BUILD
  135. COMMAND ${CMAKE_COMMAND} -E copy ${OPENSSL_LIBCRYPTO_DLL} $<TARGET_FILE_DIR:apk-editor-studio>
  136. COMMAND ${CMAKE_COMMAND} -E copy ${OPENSSL_LIBSSL_DLL} $<TARGET_FILE_DIR:apk-editor-studio>
  137. )
  138. else()
  139. message("OpenSSL deployment disabled: OPENSSL_ROOT_DIR is not provided")
  140. endif()
  141. # Windows icons, version info, etc.
  142. configure_file(
  143. src/windows.rc.in
  144. ${CMAKE_BINARY_DIR}/windows.rc
  145. @ONLY)
  146. target_sources(apk-editor-studio PRIVATE ${CMAKE_BINARY_DIR}/windows.rc)
  147. elseif(UNIX AND NOT APPLE)
  148. deploy(all ${CMAKE_BINARY_DIR}/share/apk-editor-studio)
  149. deploy(linux ${CMAKE_BINARY_DIR})
  150. elseif(APPLE)
  151. set_target_properties(apk-editor-studio PROPERTIES
  152. MACOSX_BUNDLE ON
  153. MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/dist/macos/Info.plist.in
  154. )
  155. deploy(all $<TARGET_FILE_DIR:apk-editor-studio>)
  156. deploy(macos/app $<TARGET_FILE_DIR:apk-editor-studio>/../..)
  157. add_custom_command(
  158. TARGET apk-editor-studio POST_BUILD
  159. COMMAND ${QT_BIN_DIR}/macdeployqt
  160. $<TARGET_FILE_DIR:apk-editor-studio>/../..
  161. )
  162. endif()
  163. # Installation
  164. if(WIN32)
  165. install(DIRECTORY $<TARGET_FILE_DIR:apk-editor-studio>/ DESTINATION .)
  166. elseif(UNIX AND NOT APPLE)
  167. install(DIRECTORY ${CMAKE_BINARY_DIR}/bin/ DESTINATION bin USE_SOURCE_PERMISSIONS)
  168. install(DIRECTORY ${CMAKE_BINARY_DIR}/share/ DESTINATION share)
  169. endif()