CMakeLists.txt 9.1 KB

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