CMakeLists.txt 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. cmake_minimum_required(VERSION 3.2)
  2. set(CMAKE_CXX_STANDARD 14)
  3. project(client)
  4. if(UNIT_TESTING)
  5. include(CTest)
  6. enable_testing()
  7. endif()
  8. set(BIN_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  9. set(OEM_THEME_DIR "" CACHE STRING "Define directory containing a custom theme")
  10. if ( EXISTS ${OEM_THEME_DIR}/OEM.cmake )
  11. include ( ${OEM_THEME_DIR}/OEM.cmake )
  12. else ()
  13. include ( ${CMAKE_SOURCE_DIR}/NEXTCLOUD.cmake )
  14. endif()
  15. # Default suffix if the theme doesn't define one
  16. if(NOT DEFINED APPLICATION_VIRTUALFILE_SUFFIX)
  17. set(APPLICATION_VIRTUALFILE_SUFFIX "${APPLICATION_SHORTNAME}_virtual" CACHE STRING "Virtual file suffix (not including the .)")
  18. endif()
  19. # need this logic to not mess with re/uninstallations via macosx.pkgproj
  20. if(${APPLICATION_REV_DOMAIN} STREQUAL "com.owncloud.desktopclient")
  21. set(APPLICATION_REV_DOMAIN_INSTALLER "com.ownCloud.client")
  22. else()
  23. set(APPLICATION_REV_DOMAIN_INSTALLER ${APPLICATION_REV_DOMAIN})
  24. endif()
  25. # For usage in XML files we preprocess
  26. string(REPLACE "&" "&" APPLICATION_NAME_XML_ESCAPED "${APPLICATION_NAME}")
  27. string(REPLACE "<" "&lt;" APPLICATION_NAME_XML_ESCAPED "${APPLICATION_NAME_XML_ESCAPED}")
  28. string(REPLACE ">" "&gt;" APPLICATION_NAME_XML_ESCAPED "${APPLICATION_NAME_XML_ESCAPED}")
  29. if (NOT DEFINED LINUX_PACKAGE_SHORTNAME)
  30. set(LINUX_PACKAGE_SHORTNAME "${APPLICATION_SHORTNAME}")
  31. endif()
  32. if (NOT DEFINED PACKAGE)
  33. set(PACKAGE "${LINUX_PACKAGE_SHORTNAME}-client")
  34. endif()
  35. set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules )
  36. if(NOT CRASHREPORTER_EXECUTABLE)
  37. set(CRASHREPORTER_EXECUTABLE "${APPLICATION_EXECUTABLE}_crash_reporter")
  38. endif()
  39. set(synclib_NAME "${APPLICATION_EXECUTABLE}sync")
  40. set(csync_NAME "${APPLICATION_EXECUTABLE}_csync")
  41. include(Warnings)
  42. include(${CMAKE_SOURCE_DIR}/VERSION.cmake)
  43. # For config.h
  44. include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
  45. # Allows includes based on src/ like #include "common/utility.h" or #include "csync/csync.h"
  46. include_directories(
  47. ${CMAKE_CURRENT_SOURCE_DIR}/src
  48. ${CMAKE_CURRENT_BINARY_DIR}/src
  49. )
  50. # disable the crashreporter if libcrashreporter-qt is not available or we're building for ARM
  51. if( CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/3rdparty/libcrashreporter-qt/CMakeLists.txt")
  52. set( WITH_CRASHREPORTER OFF )
  53. endif()
  54. if(NOT WITH_CRASHREPORTER)
  55. message(STATUS "Build of crashreporter disabled.")
  56. endif()
  57. include(GNUInstallDirs)
  58. include(DefineInstallationPaths)
  59. include(GenerateExportHeader)
  60. include(GetGitRevisionDescription)
  61. get_git_head_revision(GIT_REFSPEC GIT_SHA1)
  62. add_definitions(
  63. -DQT_USE_QSTRINGBUILDER
  64. -DQT_MESSAGELOGCONTEXT #enable function name and line number in debug output
  65. -DQT_DEPRECATED_WARNINGS
  66. )
  67. # if we cannot get it from git, directly try .tag (packages)
  68. # this will work if the tar balls have been properly created
  69. # via git-archive.
  70. if ("${GIT_SHA1}" STREQUAL "GITDIR-NOTFOUND")
  71. file(READ ${CMAKE_SOURCE_DIR}/.tag sha1_candidate)
  72. string(REPLACE "\n" "" sha1_candidate ${sha1_candidate})
  73. if (NOT ${sha1_candidate} STREQUAL "$Format:%H$")
  74. message("${sha1_candidate}")
  75. set (GIT_SHA1 "${sha1_candidate}")
  76. endif()
  77. endif()
  78. message(STATUS "GIT_SHA1 ${GIT_SHA1}")
  79. set(SYSCONFDIR ${SYSCONF_INSTALL_DIR})
  80. set(DATADIR ${DATA_INSTALL_DIR})
  81. if(WIN32)
  82. set(DATADIR "share")
  83. endif(WIN32)
  84. set(SHAREDIR ${DATADIR})
  85. if (NOT APPLE)
  86. set(PLUGINDIR "${CMAKE_INSTALL_FULL_LIBDIR}/${APPLICATION_SHORTNAME}/plugins" CACHE STRING "Extra path to look for Qt plugins like for VFS. May be relative to binary.")
  87. else()
  88. # Inside the .app bundle
  89. set(PLUGINDIR "../PlugIns" CACHE STRING "Extra path to look for Qt plugins like for VFS. May be relative to binary.")
  90. endif()
  91. #####
  92. ## handle BUILD_OWNCLOUD_OSX_BUNDLE
  93. # BUILD_OWNCLOUD_OSX_BUNDLE was not initialized OR set to true on OSX
  94. if(APPLE AND (NOT DEFINED BUILD_OWNCLOUD_OSX_BUNDLE OR BUILD_OWNCLOUD_OSX_BUNDLE))
  95. set(BUILD_OWNCLOUD_OSX_BUNDLE ON)
  96. set(OWNCLOUD_OSX_BUNDLE "${APPLICATION_EXECUTABLE}.app")
  97. set(LIB_INSTALL_DIR "${APPLICATION_EXECUTABLE}.app/Contents/MacOS")
  98. set(BIN_INSTALL_DIR "${APPLICATION_EXECUTABLE}.app/Contents/MacOS")
  99. # BUILD_OWNCLOUD_OSX_BUNDLE was disabled on OSX
  100. elseif(APPLE AND NOT BUILD_OWNCLOUD_OSX_BUNDLE)
  101. message(FATAL_ERROR "Building in non-bundle mode on OSX is currently not supported. Comment this error out if you want to work on/test it.")
  102. # any other platform
  103. else()
  104. set(BUILD_OWNCLOUD_OSX_BUNDLE OFF)
  105. endif()
  106. #####
  107. # this option removes Http authentication, keychain, shibboleth etc and is intended for
  108. # external authentication mechanisms
  109. option(TOKEN_AUTH_ONLY "TOKEN_AUTH_ONLY" OFF)
  110. if(TOKEN_AUTH_ONLY)
  111. message("Compiling with token authentication")
  112. add_definitions(-DTOKEN_AUTH_ONLY=1)
  113. endif()
  114. option(NO_MSG_HANDLER "Don't redirect QDebug outputs to the log window/file" OFF)
  115. if(NO_MSG_HANDLER)
  116. add_definitions(-DNO_MSG_HANDLER=1)
  117. endif()
  118. # this option builds the updater
  119. option(BUILD_UPDATER "BUILD_UPDATER" OFF)
  120. if(BUILD_UPDATER)
  121. message("Compiling with updater")
  122. add_definitions(-DBUILD_UPDATER=1)
  123. else()
  124. message("Compiling without updater")
  125. endif()
  126. # this option builds the shell integration
  127. option(BUILD_SHELL_INTEGRATION "BUILD_SHELL_INTEGRATION" ON)
  128. # this option builds/installs the generic shell integration icons
  129. option(BUILD_SHELL_INTEGRATION_ICONS "BUILD_SHELL_INTEGRATION_ICONS" ON)
  130. # this options builds the dolphin integration plugin
  131. option(BUILD_SHELL_INTEGRATION_DOLPHIN "BUILD_SHELL_INTEGRATION_DOLPHIN" ON)
  132. # this options builds the nautilus (like) integration plugins
  133. option(BUILD_SHELL_INTEGRATION_NAUTILUS "BUILD_SHELL_INTEGRATION_NAUTILUS" ON)
  134. # this option builds the client
  135. option(BUILD_CLIENT "BUILD_CLIENT" ON)
  136. # this option creates only libocsync and libowncloudsync (NOTE: BUILD_CLIENT needs to be on)
  137. option(BUILD_LIBRARIES_ONLY "BUILD_LIBRARIES_ONLY" OFF)
  138. # build the GUI component, when disabled only nextcloudcmd is built
  139. option(BUILD_GUI "BUILD_GUI" ON)
  140. # When this option is enabled, 5xx errors are not added to the blacklist
  141. # Normally you don't want to enable this option because if a particular file
  142. # triggers a bug on the server, you want the file to be blacklisted.
  143. option(OWNCLOUD_5XX_NO_BLACKLIST "OWNCLOUD_5XX_NO_BLACKLIST" OFF)
  144. if(OWNCLOUD_5XX_NO_BLACKLIST)
  145. add_definitions(-DOWNCLOUD_5XX_NO_BLACKLIST=1)
  146. endif()
  147. # Disable shibboleth.
  148. # So the client can be built without QtWebKit
  149. option(NO_SHIBBOLETH "Build without Shibboleth support. Allow to build the client without QtWebKit" OFF)
  150. if(NO_SHIBBOLETH)
  151. message("Compiling without shibboleth")
  152. add_definitions(-DNO_SHIBBOLETH=1)
  153. endif()
  154. if(APPLE)
  155. set( SOCKETAPI_TEAM_IDENTIFIER_PREFIX "" CACHE STRING "SocketApi prefix (including a following dot) that must match the codesign key's TeamIdentifier/Organizational Unit" )
  156. endif()
  157. if(BUILD_CLIENT)
  158. OPTION(GUI_TESTING "Build with gui introspection features of socket api" OFF)
  159. if(APPLE AND BUILD_UPDATER)
  160. find_package(Sparkle)
  161. endif()
  162. if(UNIX)
  163. find_package(INotify REQUIRED)
  164. else()
  165. find_package(INotify)
  166. endif()
  167. find_package(Sphinx)
  168. find_package(PdfLatex)
  169. find_package(OpenSSL 1.1 REQUIRED )
  170. find_package(ZLIB REQUIRED)
  171. find_package(GLib2)
  172. find_package(Gio)
  173. find_package(Libcloudproviders)
  174. endif()
  175. if (NOT DEFINED APPLICATION_ICON_NAME)
  176. set(APPLICATION_ICON_NAME ${APPLICATION_SHORTNAME})
  177. endif()
  178. include(NextcloudCPack.cmake)
  179. add_definitions(-DUNICODE)
  180. add_definitions(-D_UNICODE)
  181. if( WIN32 )
  182. add_definitions( -D__USE_MINGW_ANSI_STDIO=1 )
  183. add_definitions( -DNOMINMAX )
  184. # Get APIs from from Vista onwards.
  185. add_definitions(-D_WIN32_WINNT=0x0601)
  186. add_definitions(-DWINVER=0x0601)
  187. add_definitions(-DNTDDI_VERSION=0x0A000004)
  188. if( MSVC )
  189. # Use automatic overload for suitable CRT safe-functions
  190. # See https://docs.microsoft.com/de-de/cpp/c-runtime-library/security-features-in-the-crt?view=vs-2019
  191. add_definitions( -D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1 )
  192. # Also: Disable compiler warnings because we don't use Windows CRT safe-functions explicitly and don't intend to
  193. # as this is a pure cross-platform source the only alternative would be a ton of ifdefs with calls to the _s version
  194. add_definitions( -D_CRT_SECURE_NO_WARNINGS )
  195. endif( MSVC )
  196. endif( WIN32 )
  197. if (APPLE)
  198. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  199. endif()
  200. include(SanitizerFlags)
  201. # Handle Translations, pick all client_* files from trans directory.
  202. file( GLOB TRANS_FILES ${CMAKE_SOURCE_DIR}/translations/client_*.ts)
  203. set(TRANSLATIONS ${TRANS_FILES})
  204. if(BUILD_CLIENT)
  205. add_subdirectory(src)
  206. if(NOT BUILD_LIBRARIES_ONLY)
  207. add_subdirectory(man)
  208. add_subdirectory(doc)
  209. add_subdirectory(doc/dev)
  210. if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/admin)
  211. add_subdirectory(admin)
  212. endif(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/admin)
  213. endif(NOT BUILD_LIBRARIES_ONLY)
  214. endif()
  215. if(BUILD_SHELL_INTEGRATION)
  216. add_subdirectory(shell_integration)
  217. endif()
  218. include(CTest)
  219. if(BUILD_TESTING)
  220. enable_testing()
  221. add_subdirectory(test)
  222. endif()
  223. configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
  224. configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
  225. if(BUILD_OWNCLOUD_OSX_BUNDLE)
  226. install(FILES sync-exclude.lst DESTINATION ${OWNCLOUD_OSX_BUNDLE}/Contents/Resources/)
  227. configure_file(sync-exclude.lst bin/${OWNCLOUD_OSX_BUNDLE}/Contents/Resources/sync-exclude.lst COPYONLY)
  228. elseif(BUILD_CLIENT)
  229. install( FILES sync-exclude.lst DESTINATION ${SYSCONFDIR}/${APPLICATION_SHORTNAME} )
  230. configure_file(sync-exclude.lst bin/sync-exclude.lst COPYONLY)
  231. endif()