Skip to content

Commit

Permalink
Compile nextcoud gui as separate library
Browse files Browse the repository at this point in the history
Compiling nextcoud gui as a separate library. This is needed to more
easily write tests. The whole nextcloud application can now be linked
against the tests.

Signed-off-by: Felix Weilbach <felix.weilbach@nextcloud.com>
  • Loading branch information
Felix Weilbach committed Jan 16, 2021
1 parent 12053c9 commit d26200f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 86 deletions.
1 change: 1 addition & 0 deletions NEXTCLOUD.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set( APPLICATION_NAME "Nextcloud" )
set( APPLICATION_SHORTNAME "Nextcloud" )
set( APPLICATION_EXECUTABLE "nextcloud" )
set( APPLICATION_LIB "libnextcloud" )
set( APPLICATION_DOMAIN "nextcloud.com" )
set( APPLICATION_VENDOR "Nextcloud GmbH" )
set( APPLICATION_UPDATE_URL "https://updates.nextcloud.org/client/" CACHE STRING "URL for updater" )
Expand Down
64 changes: 42 additions & 22 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,31 @@ if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
endif()

add_library(${APPLICATION_LIB} ${final_src})
target_link_libraries(${APPLICATION_LIB}
PUBLIC
Qt5::Widgets
Qt5::GuiPrivate
Qt5::Svg
Qt5::Network
Qt5::Xml
Qt5::Qml
Qt5::Quick
Qt5::QuickControls2
Qt5::WebEngineWidgets
${synclib_NAME}
)

target_include_directories(${APPLICATION_LIB}
PUBLIC
${CMAKE_SOURCE_DIR}/src/3rdparty/QProgressIndicator
${CMAKE_SOURCE_DIR}/src/3rdparty/qtlockedfile
${CMAKE_SOURCE_DIR}/src/3rdparty/qtsingleapplication
${CMAKE_SOURCE_DIR}/src/3rdparty/kmessagewidget
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)

if(NOT BUILD_OWNCLOUD_OSX_BUNDLE)
if(NOT WIN32)
file(GLOB _icons "${theme_dir}/colored/*-${APPLICATION_ICON_NAME}-icon.png")
Expand All @@ -279,15 +304,13 @@ if(NOT BUILD_OWNCLOUD_OSX_BUNDLE)
endif()

# we may not add MACOSX_BUNDLE here, if not building one

# add_executable( ${APPLICATION_EXECUTABLE} main.cpp ${final_src})
add_executable( ${APPLICATION_EXECUTABLE} WIN32 main.cpp ${final_src})
add_executable(${APPLICATION_EXECUTABLE} WIN32 main.cpp)
else()
# set(CMAKE_INSTALL_PREFIX ".") # Examples use /Applications. hurmpf.
set(MACOSX_BUNDLE_ICON_FILE "${APPLICATION_ICON_NAME}.icns")

# we must add MACOSX_BUNDLE only if building a bundle
add_executable( ${APPLICATION_EXECUTABLE} WIN32 MACOSX_BUNDLE main.cpp ${final_src})
add_executable(${APPLICATION_EXECUTABLE} WIN32 MACOSX_BUNDLE main.cpp)

set (QM_DIR ${OWNCLOUD_OSX_BUNDLE}/Contents/Resources/Translations)
install(FILES ${client_I18N} DESTINATION ${QM_DIR})
Expand All @@ -314,12 +337,14 @@ set_target_properties( ${APPLICATION_EXECUTABLE} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIRECTORY}
)

target_link_libraries( ${APPLICATION_EXECUTABLE} Qt5::Widgets Qt5::GuiPrivate Qt5::Svg Qt5::Network Qt5::Xml Qt5::Qml Qt5::Quick Qt5::QuickControls2 Qt5::WebEngineWidgets)
target_link_libraries( ${APPLICATION_EXECUTABLE} ${synclib_NAME} )
target_link_libraries(${APPLICATION_EXECUTABLE} ${APPLICATION_LIB})

IF(BUILD_UPDATER)
target_link_libraries( ${APPLICATION_EXECUTABLE} updater )
target_link_libraries(${APPLICATION_LIB} PUBLIC updater)
endif()
target_link_libraries( ${APPLICATION_EXECUTABLE} ${OS_SPECIFIC_LINK_LIBRARIES} )

target_link_libraries(${APPLICATION_LIB} PUBLIC ${OS_SPECIFIC_LINK_LIBRARIES})

IF( LIBCLOUDPROVIDERS_FOUND )
string(TOLOWER "${APPLICATION_VENDOR}" DBUS_VENDOR)
string(REGEX REPLACE "[^A-z0-9]" "" DBUS_VENDOR "${DBUS_VENDOR}")
Expand All @@ -331,24 +356,19 @@ IF( LIBCLOUDPROVIDERS_FOUND )
set(LIBCLOUDPROVIDERS_DBUS_OBJECT_PATH "/${DBUS_PREFIX}/${DBUS_VENDOR}/${DBUS_APPLICATION_NAME}")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cloudproviders/cloudproviderconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/cloudproviderconfig.h)
target_link_libraries( ${APPLICATION_EXECUTABLE} ${GLib2_LDFLAGS} ${GIO_LDFLAGS} ${LIBCLOUDPROVIDERS_LIBRARY} )
target_link_libraries(${APPLICATION_LIB}
PUBLIC
${GLib2_LDFLAGS}
${GIO_LDFLAGS}
${LIBCLOUDPROVIDERS_LIBRARY}
)
ENDIF()


target_include_directories(${APPLICATION_EXECUTABLE} PRIVATE
${CMAKE_SOURCE_DIR}/src/3rdparty/QProgressIndicator
${CMAKE_SOURCE_DIR}/src/3rdparty/qtlockedfile
${CMAKE_SOURCE_DIR}/src/3rdparty/qtsingleapplication
${CMAKE_SOURCE_DIR}/src/3rdparty/kmessagewidget
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)

## handle DBUS for Fdo notifications
if( UNIX AND NOT APPLE )
find_package(Qt5 COMPONENTS DBus)
target_link_libraries( ${APPLICATION_EXECUTABLE} Qt5::DBus)
target_compile_definitions(${APPLICATION_EXECUTABLE} PRIVATE "USE_FDO_NOTIFICATIONS")
target_link_libraries(${APPLICATION_LIB} PUBLIC Qt5::DBus)
target_compile_definitions(${APPLICATION_LIB} PUBLIC "USE_FDO_NOTIFICATIONS")
endif()

if (APPLE)
Expand All @@ -366,7 +386,7 @@ if(WITH_CRASHREPORTER)
endif()

# application.cpp still uses QDesktopServices::storageLocation
target_compile_definitions(${APPLICATION_EXECUTABLE} PRIVATE "QT_DISABLE_DEPRECATED_BEFORE=0")
target_compile_definitions(${APPLICATION_LIB} PRIVATE "QT_DISABLE_DEPRECATED_BEFORE=0")


install(TARGETS ${APPLICATION_EXECUTABLE}
Expand Down
64 changes: 5 additions & 59 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,41 +1,19 @@
find_package(SQLite3 3.8.0 REQUIRED)
include_directories(${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/3rdparty/qtokenizer
${CMAKE_SOURCE_DIR}/src/csync
${CMAKE_SOURCE_DIR}/src/csync/std
${CMAKE_SOURCE_DIR}/src/gui
${CMAKE_SOURCE_DIR}/src/libsync
${CMAKE_BINARY_DIR}/src/csync
${CMAKE_BINARY_DIR}/src/libsync
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${SQLITE3_INCLUDE_DIR}
)

include(nextcloud_add_test.cmake)

set(CMAKE_AUTOMOC TRUE)

add_library(syncenginetestutils STATIC syncenginetestutils.cpp)
target_link_libraries(syncenginetestutils PUBLIC ${APPLICATION_EXECUTABLE}sync Qt5::Test)
target_include_directories(syncenginetestutils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

nextcloud_add_test(NextcloudPropagator "")

IF(BUILD_UPDATER)
nextcloud_add_test(Updater "")
endif()

SET(FolderWatcher_SRC ../src/gui/folderwatcher.cpp)

IF( NOT WIN32 AND NOT APPLE )
list(APPEND FolderWatcher_SRC ../src/gui/folderwatcher_linux.cpp)
ENDIF()
IF( WIN32 )
list(APPEND FolderWatcher_SRC ../src/gui/folderwatcher_win.cpp)
ENDIF()
IF( APPLE )
list(APPEND FolderWatcher_SRC ../src/gui/folderwatcher_mac.cpp)
list(APPEND FolderWatcher_SRC ../src/gui/socketapisocket_mac.mm)
ENDIF()
nextcloud_add_test(NetrcParser ../src/cmd/netrcparser.cpp)
nextcloud_add_test(OwnSql "")
nextcloud_add_test(SyncJournalDB "")
Expand Down Expand Up @@ -67,7 +45,7 @@ nextcloud_add_test(Permissions "")
nextcloud_add_test(SelectiveSync "")
nextcloud_add_test(DatabaseError "")
nextcloud_add_test(LockedFiles "../src/gui/lockwatcher.cpp")
nextcloud_add_test(FolderWatcher "${FolderWatcher_SRC}")
nextcloud_add_test(FolderWatcher "")

if( UNIX AND NOT APPLE )
nextcloud_add_test(InotifyWatcher "${FolderWatcher_SRC}")
Expand All @@ -80,40 +58,8 @@ endif()

nextcloud_add_benchmark(LargeSync "")

SET(FolderMan_SRC ../src/gui/folderman.cpp)
list(APPEND FolderMan_SRC ../src/gui/folder.cpp )
list(APPEND FolderMan_SRC ../src/gui/conflictsolver.cpp )
list(APPEND FolderMan_SRC ../src/gui/socketapi.cpp )
list(APPEND FolderMan_SRC ../src/gui/syncrunfilelog.cpp )
list(APPEND FolderMan_SRC ../src/gui/lockwatcher.cpp )
list(APPEND FolderMan_SRC ../src/gui/guiutility.cpp )
list(APPEND FolderMan_SRC ../src/gui/navigationpanehelper.cpp )
list(APPEND FolderMan_SRC ../src/gui/userinfo.cpp )
list(APPEND FolderMan_SRC ../src/gui/connectionvalidator.cpp )
list(APPEND FolderMan_SRC ../src/gui/ocsjob.cpp )
list(APPEND FolderMan_SRC ../src/gui/ocsnavigationappsjob.cpp )
list(APPEND FolderMan_SRC ../src/gui/accountstate.cpp )
list(APPEND FolderMan_SRC ../src/gui/remotewipe.cpp )
list(APPEND FolderMan_SRC ${FolderWatcher_SRC})
list(APPEND FolderMan_SRC stubfolderman.cpp )
nextcloud_add_test(FolderMan "${FolderMan_SRC}")

SET(RemoteWipe_SRC ../src/gui/remotewipe.cpp)
list(APPEND RemoteWipe_SRC ../src/gui/guiutility.cpp )
list(APPEND RemoteWipe_SRC ../src/gui/userinfo.cpp )
list(APPEND RemoteWipe_SRC ../src/gui/connectionvalidator.cpp )
list(APPEND RemoteWipe_SRC ../src/gui/ocsjob.cpp )
list(APPEND RemoteWipe_SRC ../src/gui/ocsnavigationappsjob.cpp )
list(APPEND RemoteWipe_SRC ../src/gui/accountstate.cpp )
list(APPEND RemoteWipe_SRC ../src/gui/conflictsolver.cpp )
list(APPEND RemoteWipe_SRC ../src/gui/socketapi.cpp )
list(APPEND RemoteWipe_SRC ../src/gui/folder.cpp )
list(APPEND RemoteWipe_SRC ../src/gui/syncrunfilelog.cpp )
list(APPEND RemoteWipe_SRC ${FolderWatcher_SRC} )
list(APPEND RemoteWipe_SRC ../src/gui/folderwatcher.cpp )
list(APPEND RemoteWipe_SRC ${RemoteWipe_SRC})
list(APPEND RemoteWipe_SRC stubremotewipe.cpp )
nextcloud_add_test(RemoteWipe "${RemoteWipe_SRC}")
nextcloud_add_test(FolderMan "")
nextcloud_add_test(RemoteWipe "")

nextcloud_add_test(OAuth "../src/gui/creds/oauth.cpp")

Expand Down
4 changes: 2 additions & 2 deletions test/csync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${CMOCKA_INCLUDE_DIR}
${CHECK_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}/src/csync
)

include_directories(${CHECK_INCLUDE_DIRS})
# create test library
add_library(${TORTURE_LIBRARY} STATIC torture.c cmdline.c)
target_link_libraries(${TORTURE_LIBRARY} ${CMOCKA_LIBRARIES})
Expand All @@ -23,4 +24,3 @@ add_cmocka_test(check_std_c_jhash std_tests/check_std_c_jhash.c ${TEST_TARGET_LI

# vio
add_cmocka_test(check_vio_ext vio_tests/check_vio_ext.cpp ${TEST_TARGET_LIBRARIES})

13 changes: 10 additions & 3 deletions test/nextcloud_add_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ macro(nextcloud_add_test test_class additional_cpp)
set_target_properties(${OWNCLOUD_TEST_CLASS}Test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIRECTORY})

target_link_libraries(${OWNCLOUD_TEST_CLASS}Test
${APPLICATION_EXECUTABLE}sync syncenginetestutils
Qt5::Core Qt5::Test Qt5::Xml Qt5::Network Qt5::Qml Qt5::Quick
${APPLICATION_EXECUTABLE}sync
syncenginetestutils
${APPLICATION_LIB}
Qt5::Test
Qt5::Quick
)

IF(BUILD_UPDATER)
Expand All @@ -25,7 +28,11 @@ macro(nextcloud_add_test test_class additional_cpp)
COMMAND ${OWNCLOUD_TEST_CLASS}Test
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

target_include_directories(${OWNCLOUD_TEST_CLASS}Test PRIVATE "${CMAKE_SOURCE_DIR}/test/")
target_include_directories(${OWNCLOUD_TEST_CLASS}Test
PRIVATE
"${CMAKE_SOURCE_DIR}/test/"
${CMAKE_SOURCE_DIR}/src/3rdparty/qtokenizer
)
endmacro()

macro(nextcloud_add_benchmark test_class additional_cpp)
Expand Down

0 comments on commit d26200f

Please sign in to comment.