CMakeLists.txt 6.4 KB

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