Sync translations from Transifex and run lupdate
[qBittorrent.git] / src / app / CMakeLists.txt
bloba531f7fd1cdee3f2b28c010c275bc5780f98348e
1 file(GLOB QBT_TS_FILES "${qBittorrent_SOURCE_DIR}/src/lang/*.ts")
2 # Custom target to update .ts files and include new strings from source files
3 # Depends on Qt's LinguistTools
4 get_target_property(QT_LUPDATE_EXECUTABLE Qt::lupdate IMPORTED_LOCATION)
5 add_custom_target(qbt_update_translations
6                     COMMAND ${QT_LUPDATE_EXECUTABLE} -extensions ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx
7                                                      ${qBittorrent_SOURCE_DIR}
8                                                      -ts ${QBT_TS_FILES}
9                     WORKING_DIRECTORY "${qBittorrent_SOURCE_DIR}"
10                     VERBATIM
11                     COMMAND_EXPAND_LISTS)
13 # Generate and configure translation files
14 # -----------------------------------------------------------------------------
15 # -----------------------------------------------------------------------------
16 # Based on https://gist.github.com/giraldeau/546ba5512a74dfe9d8ea0862d66db412
17 set_source_files_properties(${QBT_TS_FILES} PROPERTIES OUTPUT_LOCATION "${qBittorrent_BINARY_DIR}/src/lang")
18 qt_add_translation(QBT_QM_FILES ${QBT_TS_FILES} OPTIONS -silent)
19 configure_file("${qBittorrent_SOURCE_DIR}/src/lang/lang.qrc" "${qBittorrent_BINARY_DIR}/src/lang/lang.qrc" COPYONLY)
21 if (WEBUI)
22     file(GLOB QBT_WEBUI_TS_FILES "${qBittorrent_SOURCE_DIR}/src/webui/www/translations/*.ts")
23     set_source_files_properties(${QBT_WEBUI_TS_FILES}
24         PROPERTIES OUTPUT_LOCATION "${qBittorrent_BINARY_DIR}/src/webui/www/translations")
25     qt_add_translation(QBT_WEBUI_QM_FILES ${QBT_WEBUI_TS_FILES} OPTIONS -silent)
26     configure_file("${qBittorrent_SOURCE_DIR}/src/webui/www/translations/webui_translations.qrc"
27         "${qBittorrent_BINARY_DIR}/src/webui/www/translations/webui_translations.qrc" COPYONLY)
28 endif()
30 # Executable target configuration
31 # -----------------------------------------------------------------------------
32 # -----------------------------------------------------------------------------
33 add_executable(qbt_app)
35 target_sources(qbt_app PRIVATE
36     # headers
37     application.h
38     applicationinstancemanager.h
39     cmdoptions.h
40     filelogger.h
41     qtlocalpeer/qtlocalpeer.h
42     signalhandler.h
43     upgrade.h
45     # sources
46     application.cpp
47     applicationinstancemanager.cpp
48     cmdoptions.cpp
49     filelogger.cpp
50     main.cpp
51     qtlocalpeer/qtlocalpeer.cpp
52     signalhandler.cpp
53     upgrade.cpp
55     # resources
56     "${qBittorrent_SOURCE_DIR}/src/icons/icons.qrc"
57     "${qBittorrent_SOURCE_DIR}/src/searchengine/searchengine.qrc"
58     ${QBT_QM_FILES}
59     "${qBittorrent_BINARY_DIR}/src/lang/lang.qrc" # yes, it's supposed to be "*_BINARY_DIR"
62 target_link_libraries(qbt_app PRIVATE
63     qbt_base
66 set_target_properties(qbt_app PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
67 if (GUI)
68     set_target_properties(qbt_app PROPERTIES OUTPUT_NAME qbittorrent)
69 else()
70     set_target_properties(qbt_app PROPERTIES OUTPUT_NAME qbittorrent-nox)
71 endif()
73 # Additional platform specific configuration
74 # -----------------------------------------------------------------------------
75 # -----------------------------------------------------------------------------
76 if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
77     include(FindQtTranslations)
78     qbt_get_qt_translations(QT_TRANSLATIONS)
79     set_source_files_properties(${QT_TRANSLATIONS} PROPERTIES MACOSX_PACKAGE_LOCATION translations)
80     set_source_files_properties(
81         "${qBittorrent_SOURCE_DIR}/dist/mac/qt.conf"
82         "${qBittorrent_SOURCE_DIR}/dist/mac/qBitTorrentDocument.icns"
83         "${qBittorrent_SOURCE_DIR}/dist/mac/qbittorrent_mac.icns"
84             PROPERTIES
85                 MACOSX_PACKAGE_LOCATION Resources
86     )
87     # provide variables for substitution in dist/mac/Info.plist
88     get_target_property(EXECUTABLE_NAME qbt_app OUTPUT_NAME)
89     # This variable name should be changed once qmake is no longer used. Refer to the discussion in PR #14813
90     set(MACOSX_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET})
91     set_target_properties(qbt_app PROPERTIES
92         MACOSX_BUNDLE ON
93         MACOSX_BUNDLE_BUNDLE_NAME "qBittorrent"
94         MACOSX_BUNDLE_INFO_PLIST ${qBittorrent_SOURCE_DIR}/dist/mac/Info.plist
95     )
96     target_sources(qbt_app PRIVATE
97         ${QT_TRANSLATIONS}
98         ${qBittorrent_SOURCE_DIR}/dist/mac/qt.conf
99         ${qBittorrent_SOURCE_DIR}/dist/mac/qBitTorrentDocument.icns
100         ${qBittorrent_SOURCE_DIR}/dist/mac/qbittorrent_mac.icns
101     )
102 elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
103     set_target_properties(qbt_app PROPERTIES WIN32_EXECUTABLE ON)
104     if (MINGW)
105         target_sources(qbt_app PRIVATE ${qBittorrent_SOURCE_DIR}/src/qbittorrent_mingw.rc)
106     else()
107         target_sources(qbt_app PRIVATE ${qBittorrent_SOURCE_DIR}/src/qbittorrent.rc)
108     endif()
109     target_sources(qbt_app PRIVATE ${qBittorrent_SOURCE_DIR}/src/qbittorrent.exe.manifest)
110 endif()
112 # Additional feature dependent configuration
113 # -----------------------------------------------------------------------------
114 # -----------------------------------------------------------------------------
115 if (GUI)
116     target_link_libraries(qbt_app PRIVATE qbt_gui)
117     if ((CMAKE_SYSTEM_NAME STREQUAL "Windows") OR (CMAKE_SYSTEM_NAME STREQUAL "Darwin"))
118         qt_import_plugins(qbt_app INCLUDE Qt::QSvgIconPlugin Qt::QSvgPlugin)
119     endif()
120 endif()
122 if (STACKTRACE)
123     target_compile_definitions(qbt_app PRIVATE STACKTRACE)
125     target_sources(qbt_app PRIVATE
126         stacktrace.h
127         stacktrace.cpp
128     )
130     if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
131         target_compile_definitions(qbt_app PRIVATE BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED)
132         target_link_options(qbt_app PUBLIC -rdynamic)
133     elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
134         target_link_libraries(qbt_app PUBLIC ${CMAKE_DL_LIBS})
135         target_link_options(qbt_app PUBLIC -rdynamic)
136     elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
137         if (MSVC)
138             target_compile_options(qbt_app PRIVATE /Zi)
139             target_link_options(qbt_app PUBLIC
140                 /DEBUG
141                 /PDBALTPATH:$<TARGET_PDB_FILE_NAME:qbt_app>
142             )
144             if (CMAKE_SIZEOF_VOID_P EQUAL 4)
145                 target_compile_options(qbt_app PRIVATE /Oy-)
146             endif()
147         else()
148             target_link_options(qbt_app PUBLIC LINKER:--export-dynamic)
150             if (CMAKE_SIZEOF_VOID_P EQUAL 4)
151                 target_compile_options(qbt_app PRIVATE -fno-omit-frame-pointer)
152             endif()
153         endif()
154     endif()
155 endif()
157 if (WEBUI)
158     target_sources(qbt_app PRIVATE
159         ${QBT_WEBUI_QM_FILES}
160         ${qBittorrent_BINARY_DIR}/src/webui/www/translations/webui_translations.qrc # yes, it's supposed to be "*_BINARY_DIR"
161     )
162     target_link_libraries(qbt_app PRIVATE qbt_webui)
163 endif()
165 # Installation
166 # -----------------------------------------------------------------------------
167 # -----------------------------------------------------------------------------
168 install(TARGETS qbt_app
169     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
170     BUNDLE  DESTINATION .
171     COMPONENT runtime
174 if (MSVC)
175     install(FILES $<TARGET_PDB_FILE:qbt_app>
176         DESTINATION ${CMAKE_INSTALL_BINDIR}
177         OPTIONAL
178     )
179 endif()