CMakeLists.txt 8.9 KB

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