CMakeLists.txt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. cmake_minimum_required(VERSION 3.13)
  2. # cmake_policy(SET CMP0076 OLD)
  3. set(FLAMESHOT_VERSION 11.0.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. include(cmake/StandardProjectSettings.cmake)
  62. add_library(project_options INTERFACE)
  63. target_compile_features(project_options INTERFACE cxx_std_17)
  64. add_library(project_warnings INTERFACE)
  65. # enable cache system
  66. include(cmake/Cache.cmake)
  67. # standard compiler warnings
  68. include(cmake/CompilerWarnings.cmake)
  69. # set_project_warnings(project_warnings)
  70. # sanitizer options if supported by compiler
  71. include(cmake/Sanitizers.cmake)
  72. enable_sanitizers(project_options)
  73. # allow for static analysis options include(cmake/StaticAnalyzers.cmake)
  74. set(QAPPLICATION_CLASS
  75. QApplication
  76. CACHE STRING "Inheritance class for SingleApplication")
  77. if(USE_EXTERNAL_SINGLEAPPLICATION)
  78. # look for external QtSingleApplication
  79. # package dev-qt/qtsingleapplication provides no symlink to current version
  80. set(qtsingleapplication_libs libQt5Solutions_SingleApplication-2.6 Qt5Solutions_SingleApplication-2.6)
  81. find_library(QTSINGLEAPPLICATION_LIBRARY NAMES ${qtsingleapplication_libs})
  82. message(STATUS "Using external SingleApplication library")
  83. else()
  84. add_subdirectory(external/singleapplication)
  85. set(QTSINGLEAPPLICATION_LIBRARY SingleApplication::SingleApplication)
  86. endif()
  87. option(BUILD_STATIC_LIBS ON)
  88. option(BUILD_SHARED_LIBS OFF)
  89. add_subdirectory(external/Qt-Color-Widgets EXCLUDE_FROM_ALL)
  90. if (APPLE)
  91. add_subdirectory(external/QHotkey)
  92. endif()
  93. add_subdirectory(src)
  94. # CPack
  95. set(CPACK_PACKAGE_VENDOR "flameshot-org")
  96. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Powerful yet simple to use screenshot software.")
  97. set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
  98. set(CPACK_PACKAGE_HOMEPAGE_URL "https://flameshot.org")
  99. set(CPACK_PACKAGE_CONTACT "flameshot-org developers <info@flameshot.org>")
  100. set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/data/img/app/org.flameshot.Flameshot.svg") # TODO: Can any generator make
  101. # use of this?
  102. set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md") # TODO: Where is this used? Do we need a better
  103. # source?
  104. if(WIN32)
  105. # Include all dynamically linked runtime libraries such as MSVCRxxx.dll
  106. include(InstallRequiredSystemLibraries)
  107. if(RUN_IN_PLACE)
  108. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  109. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win64")
  110. else()
  111. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win32")
  112. endif()
  113. set(CPACK_GENERATOR ZIP)
  114. else()
  115. set(CPACK_GENERATOR WIX ZIP)
  116. set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
  117. set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME_CAPITALIZED}")
  118. set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
  119. set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
  120. # WIX (Windows .msi installer)
  121. # 48x48 pixels
  122. set(CPACK_WIX_PRODUCT_ICON "${CMAKE_SOURCE_DIR}/data/img/app/flameshot.ico")
  123. # Supported languages can be found at http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
  124. # 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")
  125. set(CPACK_WIX_UI_BANNER "${CMAKE_SOURCE_DIR}/packaging/win-installer/Bitmaps/CPACK_WIX_UI_BANNER.BMP")
  126. set(CPACK_WIX_UI_DIALOG "${CMAKE_SOURCE_DIR}/packaging/win-installer/Bitmaps/CPACK_WIX_UI_DIALOG.BMP")
  127. set(CPACK_WIX_PROPERTY_ARPHELPLINK "${CPACK_PACKAGE_HOMEPAGE_URL}")
  128. set(CPACK_WIX_PROPERTY_ARPURLINFOABOUT "${CPACK_PACKAGE_HOMEPAGE_URL}")
  129. set(CPACK_WIX_ROOT_FEATURE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
  130. set(CPACK_WIX_LIGHT_EXTRA_FLAGS "-dcl:high") # set high compression
  131. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/packaging/win-installer/LICENSE/GPL-3.0.txt")
  132. set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
  133. # The correct way would be to include both x32 and x64 into one installer and install the appropriate one. CMake
  134. # does not support that, so there are two separate GUID's
  135. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  136. set(CPACK_WIX_UPGRADE_GUID "26D8062A-66D9-48D9-8924-42090FB9B3F9")
  137. else()
  138. set(CPACK_WIX_UPGRADE_GUID "2C53E1B9-51D9-4429-AAE4-B02221959AA5")
  139. endif()
  140. endif()
  141. elseif(APPLE)
  142. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  143. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-osx")
  144. set(CPACK_GENERATOR ZIP)
  145. else()
  146. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-linux")
  147. set(CPACK_GENERATOR TGZ)
  148. set(CPACK_SOURCE_GENERATOR TGZ)
  149. endif()
  150. include(CPack)