Skip to content

Commit 71ccb07

Browse files
添加fireshot初始版本
1 parent 410791d commit 71ccb07

File tree

628 files changed

+160385
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

628 files changed

+160385
-99
lines changed

CMakeLists.txt

Lines changed: 162 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,186 @@
1-
cmake_minimum_required(VERSION 3.12)
2-
project(fireshot)
1+
cmake_minimum_required(VERSION 3.13)
2+
# cmake_policy(SET CMP0076 OLD)
33

4-
set(CMAKE_CXX_STANDARD 11)
5-
set(CMAKE_AUTOMOC ON)
6-
set(CMAKE_AUTORCC ON)
7-
set(CMAKE_AUTOUIC ON)
4+
set(FLAMESHOT_VERSION 12.1.0)
85

9-
set(ui ${CMAKE_SOURCE_DIR}/forms)
10-
set(CMAKE_AUTOUIC_SEARCH_PATHS ${ui})
6+
# Flameshot-org
7+
set(GIT_API_URL "https://api.github.com/repos/flameshot-org/flameshot/releases/latest")
8+
# Namecheap
9+
# set(GIT_API_URL "https://api.github.com/repos/namecheap/flameshot/releases/latest")
1110

11+
# TODO - fix it for all linux distros
12+
#find_package (Git)
13+
#if (GIT_FOUND)
14+
# message("git found: ${GIT_EXECUTABLE} in version ${GIT_VERSION_STRING}")
15+
#
16+
# # set flameshot updates url
17+
# execute_process(COMMAND ${GIT_EXECUTABLE} ls-remote --get-url OUTPUT_VARIABLE GIT_ORIGIN_REMOTE)
18+
# message("GIT_ORIGIN_REMOTE: ${GIT_ORIGIN_REMOTE}")
19+
# string(REGEX REPLACE ".git\r*\n*$" "/releases/latest" GIT_API_URL ${GIT_ORIGIN_REMOTE})
20+
# string(REGEX REPLACE "^.*:" "https://api.github.com/repos/" GIT_API_URL ${GIT_API_URL})
21+
# message("GIT_API_URL: '${GIT_API_URL}'")
22+
#
23+
# # get application version
24+
# execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 --match v[0-9]* OUTPUT_VARIABLE FLAMESHOT_VERSION)
25+
# string(REGEX REPLACE "\r" "" FLAMESHOT_VERSION ${FLAMESHOT_VERSION})
26+
# string(REGEX REPLACE "\n" "" FLAMESHOT_VERSION ${FLAMESHOT_VERSION})
27+
# string(REGEX REPLACE "^v" "" FLAMESHOT_VERSION ${FLAMESHOT_VERSION})
28+
# message("FLAMESHOT_VERSION: '${FLAMESHOT_VERSION}'")
29+
#else()
30+
# message("git command is not found")
31+
#endif ()
32+
33+
project(
34+
flameshot
35+
VERSION ${FLAMESHOT_VERSION}
36+
LANGUAGES CXX)
37+
set(PROJECT_NAME_CAPITALIZED "Flameshot")
38+
39+
# This can be read from ${PROJECT_NAME} after project() is called
40+
if (APPLE)
41+
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")
42+
endif()
1243

13-
set(QT_VERSION 5)
14-
set(REQUIRED_LIBS Core Gui Widgets Network)
15-
set(REQUIRED_LIBS_QUALIFIED Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network)
16-
17-
#宏定义在这里添加
18-
add_definitions(
19-
-DPDLOG_ACTIVE_LEVEL=0
20-
)
21-
add_compile_options(-DUSE_SPDLOG_)
2244

45+
# Configuration options
46+
set(DEFAULT_RUN_IN_PLACE FALSE)
2347
if(WIN32)
24-
set(CMAKE_PREFIX_PATH "D:/software/Qt5.13.0/mingw73_64/lib/cmake/Qt5")
25-
set(QT_QMAKE_EXECUTABLE "D:/software/Qt/5.13.0/mingw73_64/bin")
26-
else()
27-
set(CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/cmake/Qt5")
48+
set(DEFAULT_RUN_IN_PLACE TRUE)
49+
# For Windows RC file.
50+
add_definitions(-DFLAMESHOT_VERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR})
51+
add_definitions(-DFLAMESHOT_VERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR})
52+
add_definitions(-DFLAMESHOT_VERSION_BUGFIX=${CMAKE_PROJECT_VERSION_PATCH})
53+
add_definitions(-DFLAMESHOT_VERSION_BUILD=1)
54+
add_definitions(-DFLAMESHOT_VERSION_STRING="${PROJECT_VERSION}")
55+
elseif(APPLE)
56+
set(Qt5_DIR "$(brew --prefix qt5)/lib/cmake/Qt5/" CACHE PATH "directory where Qt5Config.cmake exists.")
57+
set(CMAKE_MACOSX_BUNDLE ON)
58+
set(CMAKE_MACOSX_RPATH ON)
2859
endif()
29-
30-
31-
if (NOT CMAKE_PREFIX_PATH)
32-
message(WARNING "CMAKE_PREFIX_PATH is not defined, you may need to set it "
33-
"(-DCMAKE_PREFIX_PATH=\"path/to/Qt/lib/cmake\" or -DCMAKE_PREFIX_PATH=/usr/include/{host}/qt{version}/ on Ubuntu)")
60+
set(RUN_IN_PLACE
61+
${DEFAULT_RUN_IN_PLACE}
62+
CACHE BOOL "Run directly in source directory structure")
63+
64+
65+
option(FLAMESHOT_DEBUG_CAPTURE "Enable mode to make debugging easier" OFF)
66+
option(USE_MONOCHROME_ICON "Build using monochrome icon as default" OFF)
67+
option(GENERATE_TS "Regenerate translation source files" OFF)
68+
option(USE_EXTERNAL_SINGLEAPPLICATION "Use external QtSingleApplication library" OFF)
69+
option(USE_LAUNCHER_ABSOLUTE_PATH "Use absolute path for the desktop launcher" ON)
70+
option(USE_WAYLAND_CLIPBOARD "USE KF Gui Wayland Clipboard" OFF)
71+
option(DISABLE_UPDATE_CHECKER "Disable check for updates" OFF)
72+
if (DISABLE_UPDATE_CHECKER)
73+
add_compile_definitions(DISABLE_UPDATE_CHECKER)
3474
endif ()
3575

76+
include(cmake/StandardProjectSettings.cmake)
3677

37-
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB_DIR})
38-
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_DIR})
39-
#set(CMAKE_PDB_OUTPUT_DIRECTORY ${LIB_DIR})
40-
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIB_DIR})
78+
add_library(project_options INTERFACE)
79+
target_compile_features(project_options INTERFACE cxx_std_17)
4180

42-
#set(RESOURCE_SOURCES
43-
# source/qml/qml.qrc
44-
# # source/image/image.qrc
45-
# )
46-
#set(QML_SOURCES
47-
# source/qml/main.qml)
81+
add_library(project_warnings INTERFACE)
4882

49-
## 添加用户界面文件
50-
#set(FORMS
51-
# mainwindow.ui
52-
# )
83+
# enable cache system
84+
include(cmake/Cache.cmake)
5385

54-
# 自动生成用户界面文件的 C++ 代码
55-
#qt5_wrap_ui(UI_HEADERS ${FORMS})
86+
# standard compiler warnings
87+
include(cmake/CompilerWarnings.cmake)
88+
# set_project_warnings(project_warnings)
5689

57-
# 自动生成用户界面文件的 C++ 代码
58-
# 自动生成用户界面文件的 C++ 代码
59-
#set(UI_HEADERS)
60-
if(WIN32)
90+
# sanitizer options if supported by compiler
91+
include(cmake/Sanitizers.cmake)
92+
enable_sanitizers(project_options)
6193

94+
# allow for static analysis options include(cmake/StaticAnalyzers.cmake)
6295

63-
else(UNIX)
96+
set(QAPPLICATION_CLASS
97+
QApplication
98+
CACHE STRING "Inheritance class for SingleApplication")
6499

100+
if(USE_EXTERNAL_SINGLEAPPLICATION)
101+
# look for external QtSingleApplication
102+
# package dev-qt/qtsingleapplication provides no symlink to current version
103+
set(qtsingleapplication_libs libQt5Solutions_SingleApplication-2.6 Qt5Solutions_SingleApplication-2.6)
104+
find_library(QTSINGLEAPPLICATION_LIBRARY NAMES ${qtsingleapplication_libs})
105+
message(STATUS "Using external SingleApplication library")
106+
else()
107+
add_subdirectory(external/singleapplication)
108+
set(QTSINGLEAPPLICATION_LIBRARY SingleApplication::SingleApplication)
65109
endif()
66110

67-
set(ui_files
68-
${CMAKE_CURRENT_SOURCE_DIR}/forms/tray_settings.ui
69-
)
70-
71-
set(qrc_files
72-
${CMAKE_CURRENT_SOURCE_DIR}/resources/res.qrc)
73111

74-
#find_package(Qt5Widgets REQUIRED QUIET)
75-
#
76-
#QT5_WRAP_UI (project_FORMS_HEADERS forms/tray_setting.ui)
77-
#QT5_ADD_RESOURCES (project_RESOURCE_CPPS **.qrc)
78-
79-
80-
# add core
81-
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/core core_src)
82-
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/utils utils_src)
83-
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/config config_src)
84-
85-
add_executable(${PROJECT_NAME}
86-
main.cpp
87-
fireshot.cpp
88-
${core_src}
89-
${utils_src}
90-
${config_src}
91-
)
92-
93-
target_sources(
94-
${PROJECT_NAME}
95-
PRIVATE
96-
${CMAKE_CURRENT_SOURCE_DIR}/forms/tray_settings.ui
97-
${qrc_files}
98-
)
99-
#find_package(PkgConfig REQUIRED)
100-
#pkg_search_module(GTK REQUIRED gtk+-3.0)
101-
#
102-
#include_directories(${GTK_INCLUDE_DIRS})
103-
#link_directories(${GTK_LIBRARY_DIRS})
104-
#target_link_libraries(${PROJECT_NAME} ${GTK_LIBRARIES})
105-
106-
#if(WIN32)
107-
# target_link_libraries(${PROJECT_NAME} xcb xcb-util)
108-
#endif()
109-
110-
message(STATUS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_autogen/include)
111-
112-
target_include_directories(${PROJECT_NAME}
113-
PUBLIC ./
114-
${CMAKE_CURRENT_SOURCE_DIR}/include
115-
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_autogen/include
116-
${CMAKE_CURRENT_SOURCE_DIR}/3rd)
112+
option(BUILD_STATIC_LIBS ON)
113+
option(BUILD_SHARED_LIBS OFF)
114+
add_subdirectory(external/Qt-Color-Widgets EXCLUDE_FROM_ALL)
117115

118116

119-
find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
120-
target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED})
121-
117+
if (APPLE)
118+
add_subdirectory(external/QHotkey)
119+
endif()
120+
add_subdirectory(src)
121+
122+
# CPack
123+
set(CPACK_PACKAGE_VENDOR "flameshot-org")
124+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Powerful yet simple to use screenshot software.")
125+
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
126+
set(CPACK_PACKAGE_HOMEPAGE_URL "https://flameshot.org")
127+
set(CPACK_PACKAGE_CONTACT "flameshot-org developers <info@flameshot.org>")
128+
set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/data/img/app/org.flameshot.Flameshot.svg") # TODO: Can any generator make
129+
# use of this?
130+
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md") # TODO: Where is this used? Do we need a better
131+
# source?
122132

133+
if(WIN32)
134+
# Include all dynamically linked runtime libraries such as MSVCRxxx.dll
135+
include(InstallRequiredSystemLibraries)
136+
137+
if(RUN_IN_PLACE)
138+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
139+
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win64")
140+
else()
141+
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win32")
142+
endif()
143+
144+
set(CPACK_GENERATOR ZIP)
145+
146+
else()
147+
set(CPACK_GENERATOR WIX ZIP)
148+
set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
149+
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME_CAPITALIZED}")
150+
set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
151+
set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
152+
153+
# WIX (Windows .msi installer)
154+
# 48x48 pixels
155+
set(CPACK_WIX_PRODUCT_ICON "${CMAKE_SOURCE_DIR}/data/img/app/flameshot.ico")
156+
# Supported languages can be found at http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
157+
# 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")
158+
set(CPACK_WIX_UI_BANNER "${CMAKE_SOURCE_DIR}/packaging/win-installer/Bitmaps/CPACK_WIX_UI_BANNER.BMP")
159+
set(CPACK_WIX_UI_DIALOG "${CMAKE_SOURCE_DIR}/packaging/win-installer/Bitmaps/CPACK_WIX_UI_DIALOG.BMP")
160+
set(CPACK_WIX_PROPERTY_ARPHELPLINK "${CPACK_PACKAGE_HOMEPAGE_URL}")
161+
set(CPACK_WIX_PROPERTY_ARPURLINFOABOUT "${CPACK_PACKAGE_HOMEPAGE_URL}")
162+
set(CPACK_WIX_ROOT_FEATURE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
163+
set(CPACK_WIX_LIGHT_EXTRA_FLAGS "-dcl:high") # set high compression
164+
165+
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/packaging/win-installer/LICENSE/GPL-3.0.txt")
166+
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
167+
168+
# The correct way would be to include both x32 and x64 into one installer and install the appropriate one. CMake
169+
# does not support that, so there are two separate GUID's
170+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
171+
set(CPACK_WIX_UPGRADE_GUID "26D8062A-66D9-48D9-8924-42090FB9B3F9")
172+
else()
173+
set(CPACK_WIX_UPGRADE_GUID "2C53E1B9-51D9-4429-AAE4-B02221959AA5")
174+
endif()
175+
endif()
176+
elseif(APPLE)
177+
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
178+
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-osx")
179+
set(CPACK_GENERATOR ZIP)
180+
else()
181+
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-linux")
182+
set(CPACK_GENERATOR TGZ)
183+
set(CPACK_SOURCE_GENERATOR TGZ)
184+
endif()
123185

186+
include(CPack)

cmake/Cache.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
option(ENABLE_CACHE "Enable cache if available" ON)
2+
if(NOT ENABLE_CACHE)
3+
return()
4+
endif()
5+
6+
set(CACHE_OPTION
7+
"ccache"
8+
CACHE STRING "Compiler cache to be used")
9+
set(CACHE_OPTION_VALUES "ccache" "sccache")
10+
set_property(CACHE CACHE_OPTION PROPERTY STRINGS ${CACHE_OPTION_VALUES})
11+
list(
12+
FIND
13+
CACHE_OPTION_VALUES
14+
${CACHE_OPTION}
15+
CACHE_OPTION_INDEX)
16+
17+
if(${CACHE_OPTION_INDEX} EQUAL -1)
18+
message(
19+
STATUS
20+
"Using custom compiler cache system: '${CACHE_OPTION}', explicitly supported entries are ${CACHE_OPTION_VALUES}")
21+
endif()
22+
23+
find_program(CACHE_BINARY ${CACHE_OPTION})
24+
if(CACHE_BINARY)
25+
message(STATUS "${CACHE_OPTION} found and enabled")
26+
set(CMAKE_CXX_COMPILER_LAUNCHER ${CACHE_BINARY})
27+
else()
28+
message(WARNING "${CACHE_OPTION} is enabled but was not found. Not using it")
29+
endif()

cmake/CompilerWarnings.cmake

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# from here:
2+
#
3+
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md
4+
5+
function(set_project_warnings project_name)
6+
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE)
7+
8+
set(MSVC_WARNINGS
9+
/W4 # Baseline reasonable warnings
10+
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data
11+
/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
12+
/w14263 # 'function': member function does not override any base class virtual member function
13+
/w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not
14+
# be destructed correctly
15+
/w14287 # 'operator': unsigned/negative constant mismatch
16+
/we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside
17+
# the for-loop scope
18+
/w14296 # 'operator': expression is always 'boolean_value'
19+
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
20+
/w14545 # expression before comma evaluates to a function which is missing an argument list
21+
/w14546 # function call before comma missing argument list
22+
/w14547 # 'operator': operator before comma has no effect; expected operator with side-effect
23+
/w14549 # 'operator': operator before comma has no effect; did you intend 'operator'?
24+
/w14555 # expression has no effect; expected expression with side- effect
25+
/w14619 # pragma warning: there is no warning number 'number'
26+
/w14640 # Enable warning on thread un-safe static member initialization
27+
/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior.
28+
/w14905 # wide string literal cast to 'LPSTR'
29+
/w14906 # string literal cast to 'LPWSTR'
30+
/w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied
31+
/permissive- # standards conformance mode for MSVC compiler.
32+
)
33+
34+
set(CLANG_WARNINGS
35+
-Wall
36+
-Wextra # reasonable and standard
37+
-Wshadow # warn the user if a variable declaration shadows one from a parent context
38+
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps
39+
# catch hard to track down memory errors
40+
-Wold-style-cast # warn for c-style casts
41+
-Wcast-align # warn for potential performance problem casts
42+
-Wunused # warn on anything being unused
43+
-Woverloaded-virtual # warn if you overload (not override) a virtual function
44+
-Wpedantic # warn if non-standard C++ is used
45+
-Wconversion # warn on type conversions that may lose data
46+
-Wsign-conversion # warn on sign conversions
47+
-Wnull-dereference # warn if a null dereference is detected
48+
-Wdouble-promotion # warn if float is implicit promoted to double
49+
-Wformat=2 # warn on security issues around functions that format output (ie printf)
50+
)
51+
52+
if(WARNINGS_AS_ERRORS)
53+
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
54+
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
55+
endif()
56+
57+
set(GCC_WARNINGS
58+
${CLANG_WARNINGS}
59+
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
60+
-Wduplicated-cond # warn if if / else chain has duplicated conditions
61+
-Wduplicated-branches # warn if if / else branches have duplicated code
62+
-Wlogical-op # warn about logical operations being used where bitwise were probably wanted
63+
-Wuseless-cast # warn if you perform a cast to the same type
64+
)
65+
66+
if(MSVC)
67+
set(PROJECT_WARNINGS ${MSVC_WARNINGS})
68+
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
69+
set(PROJECT_WARNINGS ${CLANG_WARNINGS})
70+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
71+
set(PROJECT_WARNINGS ${GCC_WARNINGS})
72+
else()
73+
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
74+
endif()
75+
76+
target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS})
77+
78+
endfunction()

0 commit comments

Comments
 (0)