CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. cmake_minimum_required(VERSION 3.16)
  2. set(CMAKE_CXX_STANDARD 17)
  3. cmake_policy(SET CMP0071 NEW) # Enable use of QtQuick compiler/generated code
  4. find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
  5. if (CLANG_TIDY_EXE)
  6. set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE} -checks=-*,modernize-use-auto,modernize-use-using,modernize-use-nodiscard,modernize-use-nullptr,modernize-use-override,cppcoreguidelines-pro-type-static-cast-downcast,modernize-use-default-member-init,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-init-variables)
  7. endif()
  8. project(client)
  9. include(FeatureSummary)
  10. set(BIN_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  11. include(${CMAKE_SOURCE_DIR}/NEXTCLOUD.cmake)
  12. # CfAPI Shell Extensions
  13. set( CFAPI_SHELL_EXTENSIONS_LIB_NAME CfApiShellExtensions )
  14. set( CFAPI_SHELLEXT_APPID_REG "{E314A650-DCA4-416E-974E-18EA37C213EA}")
  15. set( CFAPI_SHELLEXT_APPID_DISPLAY_NAME "${APPLICATION_NAME} CfApi Shell Extensions" )
  16. set( CFAPI_SHELLEXT_CUSTOM_STATE_HANDLER_CLASS_ID "1E62D59A-6EA4-476C-B707-4A32E88ED822" )
  17. set( CFAPI_SHELLEXT_CUSTOM_STATE_HANDLER_CLASS_ID_REG "{${CFAPI_SHELLEXT_CUSTOM_STATE_HANDLER_CLASS_ID}}" )
  18. set( CFAPI_SHELLEXT_CUSTOM_STATE_HANDLER_DISPLAY_NAME "${APPLICATION_NAME} Custom State Handler" )
  19. set( CFAPI_SHELLEXT_THUMBNAIL_HANDLER_CLASS_ID "6FF9B5B6-389F-444A-9FDD-A286C36EA079" )
  20. set( CFAPI_SHELLEXT_THUMBNAIL_HANDLER_CLASS_ID_REG "{${CFAPI_SHELLEXT_THUMBNAIL_HANDLER_CLASS_ID}}" )
  21. set( CFAPI_SHELLEXT_THUMBNAIL_HANDLER_DISPLAY_NAME "${APPLICATION_NAME} Thumbnail Handler" )
  22. # URI Handler Scheme for Local File Editing
  23. set( APPLICATION_URI_HANDLER_SCHEME "nc")
  24. # Default suffix if the theme doesn't define one
  25. if(NOT DEFINED APPLICATION_VIRTUALFILE_SUFFIX)
  26. set(APPLICATION_VIRTUALFILE_SUFFIX "${APPLICATION_SHORTNAME}_virtual" CACHE STRING "Virtual file suffix (not including the .)")
  27. endif()
  28. # need this logic to not mess with re/uninstallations via macosx.pkgproj
  29. if(${APPLICATION_REV_DOMAIN} STREQUAL "com.owncloud.desktopclient")
  30. set(APPLICATION_REV_DOMAIN_INSTALLER "com.ownCloud.client")
  31. else()
  32. set(APPLICATION_REV_DOMAIN_INSTALLER ${APPLICATION_REV_DOMAIN})
  33. endif()
  34. # For usage in XML files we preprocess
  35. string(REPLACE "&" "&" APPLICATION_NAME_XML_ESCAPED "${APPLICATION_NAME}")
  36. string(REPLACE "<" "&lt;" APPLICATION_NAME_XML_ESCAPED "${APPLICATION_NAME_XML_ESCAPED}")
  37. string(REPLACE ">" "&gt;" APPLICATION_NAME_XML_ESCAPED "${APPLICATION_NAME_XML_ESCAPED}")
  38. if (NOT DEFINED LINUX_PACKAGE_SHORTNAME)
  39. set(LINUX_PACKAGE_SHORTNAME "${APPLICATION_SHORTNAME}")
  40. endif()
  41. if (NOT DEFINED PACKAGE)
  42. set(PACKAGE "${LINUX_PACKAGE_SHORTNAME}-client")
  43. endif()
  44. set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules )
  45. include(ECMCoverageOption)
  46. if(NOT CRASHREPORTER_EXECUTABLE)
  47. set(CRASHREPORTER_EXECUTABLE "${APPLICATION_EXECUTABLE}_crash_reporter")
  48. endif()
  49. include(Warnings)
  50. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  51. add_compile_options(-fdiagnostics-color=always)
  52. elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  53. add_compile_options(-fcolor-diagnostics)
  54. endif()
  55. include(${CMAKE_SOURCE_DIR}/VERSION.cmake)
  56. # For config.h
  57. include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
  58. # Allows includes based on src/ like #include "common/utility.h" or #include "csync/csync.h"
  59. include_directories(
  60. ${CMAKE_CURRENT_SOURCE_DIR}/src
  61. ${CMAKE_CURRENT_BINARY_DIR}/src
  62. )
  63. # disable the crashreporter if libcrashreporter-qt is not available or we're building for ARM
  64. if( CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/3rdparty/libcrashreporter-qt/CMakeLists.txt")
  65. set( WITH_CRASHREPORTER OFF )
  66. endif()
  67. if(NOT WITH_CRASHREPORTER)
  68. message(STATUS "Build of crashreporter disabled.")
  69. endif()
  70. include(GNUInstallDirs)
  71. include(DefineInstallationPaths)
  72. include(GenerateExportHeader)
  73. include(GetGitRevisionDescription)
  74. get_git_head_revision(GIT_REFSPEC GIT_SHA1)
  75. add_definitions(
  76. -DQT_DISABLE_DEPRECATED_BEFORE=0x000000
  77. -DQT_USE_QSTRINGBUILDER
  78. -DQT_MESSAGELOGCONTEXT #enable function name and line number in debug output
  79. )
  80. # if we cannot get it from git, directly try .tag (packages)
  81. # this will work if the tar balls have been properly created
  82. # via git-archive.
  83. if ("${GIT_SHA1}" STREQUAL "GITDIR-NOTFOUND")
  84. file(READ ${CMAKE_SOURCE_DIR}/.tag sha1_candidate)
  85. string(REPLACE "\n" "" sha1_candidate ${sha1_candidate})
  86. if (NOT ${sha1_candidate} STREQUAL "$Format:%H$")
  87. message("${sha1_candidate}")
  88. set (GIT_SHA1 "${sha1_candidate}")
  89. endif()
  90. endif()
  91. message(STATUS "GIT_SHA1 ${GIT_SHA1}")
  92. set(SYSCONFDIR ${SYSCONF_INSTALL_DIR})
  93. set(SHAREDIR ${CMAKE_INSTALL_FULL_DATADIR})
  94. # Build MacOS app bundle if wished
  95. if(APPLE AND BUILD_OWNCLOUD_OSX_BUNDLE)
  96. message(STATUS "Build MacOS app bundle")
  97. set(OWNCLOUD_OSX_BUNDLE "${APPLICATION_NAME}.app")
  98. set(LIB_INSTALL_DIR "${APPLICATION_NAME}.app/Contents/MacOS")
  99. set(BIN_INSTALL_DIR "${APPLICATION_NAME}.app/Contents/MacOS")
  100. add_definitions(-DBUILD_OWNCLOUD_OSX_BUNDLE)
  101. endif()
  102. option(QUICK_COMPILER "Use QtQuick compiler to improve performance" OFF)
  103. # this option removes Http authentication, keychain, shibboleth etc and is intended for
  104. # external authentication mechanisms
  105. option(TOKEN_AUTH_ONLY "TOKEN_AUTH_ONLY" OFF)
  106. if(TOKEN_AUTH_ONLY)
  107. message("Compiling with token authentication")
  108. add_definitions(-DTOKEN_AUTH_ONLY=1)
  109. endif()
  110. option(NO_MSG_HANDLER "Don't redirect QDebug outputs to the log window/file" OFF)
  111. if(NO_MSG_HANDLER)
  112. add_definitions(-DNO_MSG_HANDLER=1)
  113. endif()
  114. if(BUILD_UPDATER)
  115. message("Compiling with updater")
  116. else()
  117. message("Compiling without updater")
  118. endif()
  119. # this option builds the shell integration
  120. option(BUILD_SHELL_INTEGRATION "BUILD_SHELL_INTEGRATION" ON)
  121. # this option builds/installs the generic shell integration icons
  122. option(BUILD_SHELL_INTEGRATION_ICONS "BUILD_SHELL_INTEGRATION_ICONS" ON)
  123. # this options builds the dolphin integration plugin
  124. option(BUILD_SHELL_INTEGRATION_DOLPHIN "BUILD_SHELL_INTEGRATION_DOLPHIN" ON)
  125. # this options builds the nautilus (like) integration plugins
  126. option(BUILD_SHELL_INTEGRATION_NAUTILUS "BUILD_SHELL_INTEGRATION_NAUTILUS" ON)
  127. # this option builds the client
  128. option(BUILD_CLIENT "BUILD_CLIENT" ON)
  129. # this option creates only libocsync and libowncloudsync (NOTE: BUILD_CLIENT needs to be on)
  130. option(BUILD_LIBRARIES_ONLY "BUILD_LIBRARIES_ONLY" OFF)
  131. # build the GUI component, when disabled only nextcloudcmd is built
  132. option(BUILD_GUI "BUILD_GUI" ON)
  133. # build the tests
  134. option(BUILD_TESTING "BUILD_TESTING" ON)
  135. option(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY" OFF)
  136. if(ENABLE_CLANG_TIDY)
  137. find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
  138. if (CLANG_TIDY_EXE)
  139. set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE} -checks=-*,modernize-use-auto,modernize-use-using,modernize-use-nodiscard,modernize-use-nullptr,modernize-use-override,cppcoreguidelines-pro-type-static-cast-downcast,modernize-use-default-member-init,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-init-variables)
  140. endif()
  141. else()
  142. unset(CLANG_TIDY_EXE)
  143. unset(CMAKE_CXX_CLANG_TIDY)
  144. endif()
  145. if (APPLE)
  146. # build macOS File Provider module
  147. option(BUILD_FILE_PROVIDER_MODULE "BUILD_FILE_PROVIDER_MODULE" ON)
  148. endif()
  149. # When this option is enabled, 5xx errors are not added to the blacklist
  150. # Normally you don't want to enable this option because if a particular file
  151. # triggers a bug on the server, you want the file to be blacklisted.
  152. option(OWNCLOUD_5XX_NO_BLACKLIST "OWNCLOUD_5XX_NO_BLACKLIST" OFF)
  153. if(OWNCLOUD_5XX_NO_BLACKLIST)
  154. add_definitions(-DOWNCLOUD_5XX_NO_BLACKLIST=1)
  155. endif()
  156. if(APPLE)
  157. set( SOCKETAPI_TEAM_IDENTIFIER_PREFIX "" CACHE STRING "SocketApi prefix (including a following dot) that must match the codesign key's TeamIdentifier/Organizational Unit" )
  158. endif()
  159. if(BUILD_CLIENT)
  160. OPTION(GUI_TESTING "Build with gui introspection features of socket api" OFF)
  161. if(APPLE AND BUILD_UPDATER)
  162. find_package(Sparkle)
  163. endif()
  164. if(UNIX AND NOT APPLE)
  165. find_package(Inotify REQUIRED)
  166. endif()
  167. find_package(Sphinx)
  168. find_package(PdfLatex)
  169. find_package(OpenSSL 1.1 REQUIRED )
  170. find_package(ZLIB REQUIRED)
  171. if(NOT WIN32 AND NOT APPLE)
  172. find_package(PkgConfig REQUIRED)
  173. pkg_check_modules(CLOUDPROVIDERS cloudproviders IMPORTED_TARGET)
  174. if(CLOUDPROVIDERS_FOUND)
  175. pkg_check_modules(DBUS-1 REQUIRED dbus-1 IMPORTED_TARGET)
  176. pkg_check_modules(GIO REQUIRED gio-2.0 IMPORTED_TARGET)
  177. pkg_check_modules(GLIB2 REQUIRED glib-2.0 IMPORTED_TARGET)
  178. endif()
  179. endif()
  180. endif()
  181. if (NOT DEFINED APPLICATION_ICON_NAME)
  182. set(APPLICATION_ICON_NAME ${APPLICATION_SHORTNAME})
  183. endif()
  184. include(NextcloudCPack.cmake)
  185. add_definitions(-DUNICODE)
  186. add_definitions(-D_UNICODE)
  187. if( WIN32 )
  188. add_definitions( -D__USE_MINGW_ANSI_STDIO=1 )
  189. add_definitions( -DNOMINMAX )
  190. # Get APIs from from Vista onwards.
  191. add_definitions(-D_WIN32_WINNT=0x0601)
  192. add_definitions(-DWINVER=0x0601)
  193. add_definitions(-DNTDDI_VERSION=0x0A000004)
  194. if( MSVC )
  195. # Use automatic overload for suitable CRT safe-functions
  196. # See https://docs.microsoft.com/de-de/cpp/c-runtime-library/security-features-in-the-crt?view=vs-2019
  197. add_definitions( -D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1 )
  198. # Also: Disable compiler warnings because we don't use Windows CRT safe-functions explicitly and don't intend to
  199. # as this is a pure cross-platform source the only alternative would be a ton of ifdefs with calls to the _s version
  200. add_definitions( -D_CRT_SECURE_NO_WARNINGS )
  201. endif( MSVC )
  202. endif( WIN32 )
  203. if (APPLE)
  204. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  205. endif()
  206. # Handle Translations, pick all client_* files from trans directory.
  207. file( GLOB TRANS_FILES ${CMAKE_SOURCE_DIR}/translations/client_*.ts)
  208. set(TRANSLATIONS ${TRANS_FILES})
  209. if(BUILD_CLIENT)
  210. add_subdirectory(src)
  211. if(NOT BUILD_LIBRARIES_ONLY)
  212. add_subdirectory(man)
  213. add_subdirectory(doc)
  214. add_subdirectory(doc/dev)
  215. if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/admin)
  216. add_subdirectory(admin)
  217. endif(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/admin)
  218. endif(NOT BUILD_LIBRARIES_ONLY)
  219. endif()
  220. if(BUILD_SHELL_INTEGRATION)
  221. add_subdirectory(shell_integration)
  222. endif()
  223. if(BUILD_TESTING)
  224. include(CTest)
  225. enable_testing()
  226. add_subdirectory(test)
  227. endif()
  228. configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
  229. configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
  230. if(BUILD_OWNCLOUD_OSX_BUNDLE)
  231. install(FILES sync-exclude.lst DESTINATION ${OWNCLOUD_OSX_BUNDLE}/Contents/Resources/)
  232. configure_file(sync-exclude.lst bin/${OWNCLOUD_OSX_BUNDLE}/Contents/Resources/sync-exclude.lst COPYONLY)
  233. elseif(BUILD_CLIENT)
  234. install( FILES sync-exclude.lst DESTINATION ${SYSCONFDIR}/${APPLICATION_SHORTNAME} )
  235. configure_file(sync-exclude.lst bin/sync-exclude.lst COPYONLY)
  236. endif()
  237. feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES INCLUDE_QUIET_PACKAGES)