CMakeLists.txt 6.6 KB

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