CMakeLists.txt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. cmake_minimum_required(VERSION 3.13)
  2. # cmake_policy(SET CMP0076 OLD)
  3. set(FLAMESHOT_VERSION 12.1.0)
  4. # Flameshot-org
  5. set(GIT_API_URL "https://api.github.com/repos/flameshot-org/flameshot/releases/latest")
  6. # Namecheap
  7. # set(GIT_API_URL "https://api.github.com/repos/namecheap/flameshot/releases/latest")
  8. # TODO - fix it for all linux distros
  9. #find_package (Git)
  10. #if (GIT_FOUND)
  11. # message("git found: ${GIT_EXECUTABLE} in version ${GIT_VERSION_STRING}")
  12. #
  13. # # set flameshot updates url
  14. # execute_process(COMMAND ${GIT_EXECUTABLE} ls-remote --get-url OUTPUT_VARIABLE GIT_ORIGIN_REMOTE)
  15. # message("GIT_ORIGIN_REMOTE: ${GIT_ORIGIN_REMOTE}")
  16. # string(REGEX REPLACE ".git\r*\n*$" "/releases/latest" GIT_API_URL ${GIT_ORIGIN_REMOTE})
  17. # string(REGEX REPLACE "^.*:" "https://api.github.com/repos/" GIT_API_URL ${GIT_API_URL})
  18. # message("GIT_API_URL: '${GIT_API_URL}'")
  19. #
  20. # # get application version
  21. # execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 --match v[0-9]* OUTPUT_VARIABLE FLAMESHOT_VERSION)
  22. # string(REGEX REPLACE "\r" "" FLAMESHOT_VERSION ${FLAMESHOT_VERSION})
  23. # string(REGEX REPLACE "\n" "" FLAMESHOT_VERSION ${FLAMESHOT_VERSION})
  24. # string(REGEX REPLACE "^v" "" FLAMESHOT_VERSION ${FLAMESHOT_VERSION})
  25. # message("FLAMESHOT_VERSION: '${FLAMESHOT_VERSION}'")
  26. #else()
  27. # message("git command is not found")
  28. #endif ()
  29. project(
  30. flameshot
  31. VERSION ${FLAMESHOT_VERSION}
  32. LANGUAGES CXX)
  33. set(PROJECT_NAME_CAPITALIZED "Flameshot")
  34. # This can be read from ${PROJECT_NAME} after project() is called
  35. if (APPLE)
  36. set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")
  37. endif()
  38. # Configuration options
  39. set(DEFAULT_RUN_IN_PLACE FALSE)
  40. if(WIN32)
  41. set(DEFAULT_RUN_IN_PLACE TRUE)
  42. # For Windows RC file.
  43. add_definitions(-DFLAMESHOT_VERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR})
  44. add_definitions(-DFLAMESHOT_VERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR})
  45. add_definitions(-DFLAMESHOT_VERSION_BUGFIX=${CMAKE_PROJECT_VERSION_PATCH})
  46. add_definitions(-DFLAMESHOT_VERSION_BUILD=1)
  47. add_definitions(-DFLAMESHOT_VERSION_STRING="${PROJECT_VERSION}")
  48. elseif(APPLE)
  49. set(Qt5_DIR "$(brew --prefix qt5)/lib/cmake/Qt5/" CACHE PATH "directory where Qt5Config.cmake exists.")
  50. set(CMAKE_MACOSX_BUNDLE ON)
  51. set(CMAKE_MACOSX_RPATH ON)
  52. endif()
  53. set(RUN_IN_PLACE
  54. ${DEFAULT_RUN_IN_PLACE}
  55. CACHE BOOL "Run directly in source directory structure")
  56. option(FLAMESHOT_DEBUG_CAPTURE "Enable mode to make debugging easier" OFF)
  57. option(USE_MONOCHROME_ICON "Build using monochrome icon as default" OFF)
  58. option(GENERATE_TS "Regenerate translation source files" OFF)
  59. option(USE_EXTERNAL_SINGLEAPPLICATION "Use external QtSingleApplication library" OFF)
  60. option(USE_LAUNCHER_ABSOLUTE_PATH "Use absolute path for the desktop launcher" ON)
  61. option(USE_WAYLAND_CLIPBOARD "USE KF Gui Wayland Clipboard" OFF)
  62. option(DISABLE_UPDATE_CHECKER "Disable check for updates" OFF)
  63. if (DISABLE_UPDATE_CHECKER)
  64. add_compile_definitions(DISABLE_UPDATE_CHECKER)
  65. endif ()
  66. include(cmake/StandardProjectSettings.cmake)
  67. add_library(project_options INTERFACE)
  68. target_compile_features(project_options INTERFACE cxx_std_17)
  69. add_library(project_warnings INTERFACE)
  70. # enable cache system
  71. include(cmake/Cache.cmake)
  72. # standard compiler warnings
  73. include(cmake/CompilerWarnings.cmake)
  74. # set_project_warnings(project_warnings)
  75. # sanitizer options if supported by compiler
  76. include(cmake/Sanitizers.cmake)
  77. enable_sanitizers(project_options)
  78. # allow for static analysis options include(cmake/StaticAnalyzers.cmake)
  79. set(QAPPLICATION_CLASS
  80. QApplication
  81. CACHE STRING "Inheritance class for SingleApplication")
  82. if(USE_EXTERNAL_SINGLEAPPLICATION)
  83. # look for external QtSingleApplication
  84. # package dev-qt/qtsingleapplication provides no symlink to current version
  85. set(qtsingleapplication_libs libQt5Solutions_SingleApplication-2.6 Qt5Solutions_SingleApplication-2.6)
  86. find_library(QTSINGLEAPPLICATION_LIBRARY NAMES ${qtsingleapplication_libs})
  87. message(STATUS "Using external SingleApplication library")
  88. else()
  89. add_subdirectory(external/singleapplication)
  90. set(QTSINGLEAPPLICATION_LIBRARY SingleApplication::SingleApplication)
  91. endif()
  92. option(BUILD_STATIC_LIBS ON)
  93. option(BUILD_SHARED_LIBS OFF)
  94. add_subdirectory(external/Qt-Color-Widgets EXCLUDE_FROM_ALL)
  95. if (APPLE)
  96. add_subdirectory(external/QHotkey)
  97. endif()
  98. add_subdirectory(src)
  99. # CPack
  100. set(CPACK_PACKAGE_VENDOR "flameshot-org")
  101. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Powerful yet simple to use screenshot software.")
  102. set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
  103. set(CPACK_PACKAGE_HOMEPAGE_URL "https://flameshot.org")
  104. set(CPACK_PACKAGE_CONTACT "flameshot-org developers <info@flameshot.org>")
  105. set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/data/img/app/org.flameshot.Flameshot.svg") # TODO: Can any generator make
  106. # use of this?
  107. set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md") # TODO: Where is this used? Do we need a better
  108. # source?
  109. if(WIN32)
  110. # Include all dynamically linked runtime libraries such as MSVCRxxx.dll
  111. include(InstallRequiredSystemLibraries)
  112. if(RUN_IN_PLACE)
  113. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  114. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win64")
  115. else()
  116. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win32")
  117. endif()
  118. set(CPACK_GENERATOR ZIP)
  119. else()
  120. set(CPACK_GENERATOR WIX ZIP)
  121. set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
  122. set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME_CAPITALIZED}")
  123. set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
  124. set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
  125. # WIX (Windows .msi installer)
  126. # 48x48 pixels
  127. set(CPACK_WIX_PRODUCT_ICON "${CMAKE_SOURCE_DIR}/data/img/app/flameshot.ico")
  128. # Supported languages can be found at http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
  129. # set(CPACK_WIX_CULTURES "ar-SA,bg-BG,ca-ES,hr-HR,cs-CZ,da-DK,nl-NL,en-US,et-EE,fi-FI,fr-FR,de-DE")
  130. set(CPACK_WIX_UI_BANNER "${CMAKE_SOURCE_DIR}/packaging/win-installer/Bitmaps/CPACK_WIX_UI_BANNER.BMP")
  131. set(CPACK_WIX_UI_DIALOG "${CMAKE_SOURCE_DIR}/packaging/win-installer/Bitmaps/CPACK_WIX_UI_DIALOG.BMP")
  132. set(CPACK_WIX_PROPERTY_ARPHELPLINK "${CPACK_PACKAGE_HOMEPAGE_URL}")
  133. set(CPACK_WIX_PROPERTY_ARPURLINFOABOUT "${CPACK_PACKAGE_HOMEPAGE_URL}")
  134. set(CPACK_WIX_ROOT_FEATURE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
  135. set(CPACK_WIX_LIGHT_EXTRA_FLAGS "-dcl:high") # set high compression
  136. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/packaging/win-installer/LICENSE/GPL-3.0.txt")
  137. set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
  138. # The correct way would be to include both x32 and x64 into one installer and install the appropriate one. CMake
  139. # does not support that, so there are two separate GUID's
  140. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  141. set(CPACK_WIX_UPGRADE_GUID "26D8062A-66D9-48D9-8924-42090FB9B3F9")
  142. else()
  143. set(CPACK_WIX_UPGRADE_GUID "2C53E1B9-51D9-4429-AAE4-B02221959AA5")
  144. endif()
  145. endif()
  146. elseif(APPLE)
  147. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  148. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-osx")
  149. set(CPACK_GENERATOR ZIP)
  150. else()
  151. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-linux")
  152. set(CPACK_GENERATOR TGZ)
  153. set(CPACK_SOURCE_GENERATOR TGZ)
  154. endif()
  155. include(CPack)