cmake: Modernize build system
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 2 Aug 2018 21:16:22 +0000 (23:16 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 18 Nov 2018 10:06:43 +0000 (11:06 +0100)
Move to the modern, property-based way of using CMake. This
simplifies a lot of things:
 - No need to manually specify interface include dirs and libraries
   of dependencies
 - No need to carry around variables
 - Clear separation of local and global dependencies and definitions
 - No need for hacks to make the triple-executable thing work

Provide convenience functions to set up library and executable
targets. This will make it very easy in the future to split up
some modules, as well as move towards using shared libraries.

Use the modern, property-based way of using Qt, too. This removes
the need for the deprecated qt5_use_modules() macro, and a bunch
of manual things we had to do to get the compile flags right
for the different Quassel executables.
Also make use of CMake's AUTOUIC and AUTORCC to avoid a bunch of
boilerplate for dealing with .ui files and Qt resources.

Move the .ui files from their subdirectory into the qtui directory,
since the separation doesn't really make too much sense. We'd rather
want to split the QtUi module into smaller parts/libraries.

Remove a bunch of unnecessary stuff from the CMake files.

46 files changed:
CMakeLists.txt
cmake/QuasselCompileSettings.cmake
cmake/QuasselInstallDirs.cmake
cmake/QuasselMacros.cmake
src/CMakeLists.txt
src/client/CMakeLists.txt
src/common/CMakeLists.txt
src/common/quassel.cpp
src/core/CMakeLists.txt
src/main/CMakeLists.txt [new file with mode: 0644]
src/main/main.cpp [moved from src/common/main.cpp with 100% similarity]
src/main/monoapplication.cpp [moved from src/qtui/monoapplication.cpp with 100% similarity]
src/main/monoapplication.h [moved from src/qtui/monoapplication.h with 100% similarity]
src/qtui/CMakeLists.txt
src/qtui/aboutdlg.ui [moved from src/qtui/ui/aboutdlg.ui with 100% similarity]
src/qtui/bufferviewwidget.ui [moved from src/qtui/ui/bufferviewwidget.ui with 100% similarity]
src/qtui/bufferwidget.ui [moved from src/qtui/ui/bufferwidget.ui with 100% similarity]
src/qtui/channellistdlg.ui [moved from src/qtui/ui/channellistdlg.ui with 100% similarity]
src/qtui/chatviewsearchbar.ui [moved from src/qtui/ui/chatviewsearchbar.ui with 100% similarity]
src/qtui/coreconfigwizardadminuserpage.ui [moved from src/qtui/ui/coreconfigwizardadminuserpage.ui with 100% similarity]
src/qtui/coreconfigwizardauthenticationselectionpage.ui [moved from src/qtui/ui/coreconfigwizardauthenticationselectionpage.ui with 100% similarity]
src/qtui/coreconfigwizardintropage.ui [moved from src/qtui/ui/coreconfigwizardintropage.ui with 100% similarity]
src/qtui/coreconfigwizardstorageselectionpage.ui [moved from src/qtui/ui/coreconfigwizardstorageselectionpage.ui with 100% similarity]
src/qtui/coreconfigwizardsyncpage.ui [moved from src/qtui/ui/coreconfigwizardsyncpage.ui with 100% similarity]
src/qtui/coreconnectauthdlg.ui [moved from src/qtui/ui/coreconnectauthdlg.ui with 100% similarity]
src/qtui/coreconnectionstatuswidget.ui [moved from src/qtui/ui/coreconnectionstatuswidget.ui with 100% similarity]
src/qtui/coreinfodlg.ui [moved from src/qtui/ui/coreinfodlg.ui with 100% similarity]
src/qtui/coresessionwidget.ui [moved from src/qtui/ui/coresessionwidget.ui with 100% similarity]
src/qtui/debugbufferviewoverlay.ui [moved from src/qtui/ui/debugbufferviewoverlay.ui with 100% similarity]
src/qtui/debugconsole.ui [moved from src/qtui/ui/debugconsole.ui with 100% similarity]
src/qtui/debuglogdlg.ui [moved from src/qtui/ui/debuglogdlg.ui with 100% similarity]
src/qtui/inputwidget.ui [moved from src/qtui/ui/inputwidget.ui with 100% similarity]
src/qtui/msgprocessorstatuswidget.ui [moved from src/qtui/ui/msgprocessorstatuswidget.ui with 100% similarity]
src/qtui/nicklistwidget.ui [moved from src/qtui/ui/nicklistwidget.ui with 100% similarity]
src/qtui/passwordchangedlg.ui [moved from src/qtui/ui/passwordchangedlg.ui with 100% similarity]
src/qtui/qtmultimedianotificationconfigwidget.ui [moved from src/qtui/ui/qtmultimedianotificationconfigwidget.ui with 100% similarity]
src/qtui/receivefiledlg.ui [moved from src/qtui/ui/receivefiledlg.ui with 100% similarity]
src/qtui/settingsdlg.ui [moved from src/qtui/ui/settingsdlg.ui with 100% similarity]
src/qtui/settingspagedlg.ui [moved from src/qtui/ui/settingspagedlg.ui with 100% similarity]
src/qtui/settingspages/settingspages.cmake
src/qtui/simplenetworkeditor.ui [moved from src/qtui/ui/simplenetworkeditor.ui with 100% similarity]
src/qtui/snorentificationconfigwidget.ui [moved from src/qtui/ui/snorentificationconfigwidget.ui with 100% similarity]
src/qtui/sslinfodlg.ui [moved from src/qtui/ui/sslinfodlg.ui with 100% similarity]
src/qtui/systrayanimationconfigwidget.ui [moved from src/qtui/ui/systrayanimationconfigwidget.ui with 100% similarity]
src/qtui/topicwidget.ui [moved from src/qtui/ui/topicwidget.ui with 100% similarity]
src/uisupport/CMakeLists.txt

index 310cf8f..c162ec4 100644 (file)
@@ -41,8 +41,12 @@ endif()
 # Set up project
 project(Quassel CXX)
 
-# General conveniences
+# Let CMake handle file generation for Qt
 set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+set(CMAKE_AUTOUIC ON)
+
+# Needed, otherwise some .moc files won't be found with older CMake versions
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 # Include various CMake modules...
@@ -127,23 +131,11 @@ option(WITH_LDAP "Enable LDAP authentication support if present on system" ON)
 # Setup CMake
 #####################################################################
 
-# Setting COMPILE_DEFINITIONS_<CONFIG> is deprecated since CMake 3.0 in favor of generator expressions.
-# These have existed since CMake 2.8.10; until we depend on that, we have to explicitly enable the old policy.
-if (POLICY CMP0043)
-    cmake_policy(SET CMP0043 OLD)
-endif()
-
-# Honor visibility settings for all target types
-if (POLICY CMP0063)
-    cmake_policy(SET CMP0063 NEW)
-endif()
-
-# Don't automoc generated files
+# Let automoc/autouic process generated files
 if (POLICY CMP0071)
-    cmake_policy(SET CMP0071 OLD)
+    cmake_policy(SET CMP0071 NEW)
 endif()
 
-
 # Simplify later checks
 #####################################################################
 
@@ -426,8 +418,6 @@ if (WITH_LDAP)
     find_package(Ldap)
     if (LDAP_FOUND)
         message(STATUS "Enabling LDAP authentication support")
-        set(HAVE_LDAP true)
-        add_definitions(-DHAVE_LDAP)
     else()
         message(STATUS "Disabling LDAP authentication support")
     endif()
@@ -543,11 +533,6 @@ configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
 # Prepare the build
 #####################################################################
 
-# These variables will be added to the main targets (CORE, QTCLIENT, MONO)
-set(COMMON_DEPS ${RC_WIN32})
-set(CORE_DEPS )
-set(CLIENT_DEPS )
-
 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
 add_subdirectory(data)
 add_subdirectory(icons)
index 38ce135..7d6f71a 100644 (file)
@@ -7,16 +7,6 @@
 
 include(CheckCXXCompilerFlag)
 
-# Qt debug flags
-set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG QT_DEBUG)
-set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG NDEBUG)
-set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO QT_NO_DEBUG NDEBUG)
-set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL QT_NO_DEBUG NDEBUG)
-
-if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
-    set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_DEBUG NDEBUG)
-endif()
-
 # Enable various flags on gcc
 if (CMAKE_COMPILER_IS_GNUCXX)
     if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8")
index c03895c..9e9dac4 100644 (file)
@@ -20,6 +20,9 @@ if (NOT WITH_KDE)
         if (NOT DEFINED CMAKE_INSTALL_BINDIR)
             set(CMAKE_INSTALL_BINDIR "${CMAKE_INSTALL_PREFIX}" CACHE PATH "Install path for binaries")
         endif()
+        if (NOT DEFINED CMAKE_INSTALL_LIBDIR)
+            set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}" CACHE PATH "Install path for libraries")
+        endif()
         if (NOT DEFINED CMAKE_INSTALL_DATADIR)
             set(CMAKE_INSTALL_DATADIR "$ENV{APPDATA}/quassel-irc.org/share/apps" CACHE PATH "Install path for data files")
         endif()
index bc66572..8512866 100644 (file)
@@ -1,50 +1,46 @@
-# This file contains various macros useful for building Quassel.
+# This file contains various functions and macros useful for building Quassel.
 #
-# (C) 2014 by the Quassel Project <devel@quassel-irc.org>
-#
-# The qt5_use_modules function was taken from Qt 5.10.1 (and modified):
-# (C) 2005-2011 Kitware, Inc.
+# (C) 2014-2018 by the Quassel Project <devel@quassel-irc.org>
 #
 # Redistribution and use is allowed according to the terms of the BSD license.
 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+###################################################################################################
+
+###################################################################################################
+# Adds a library target for a Quassel module.
+#
+# It expects the (CamelCased) module name as a parameter, and derives various
+# strings from it. For example, quassel_add_module(Client) produces
+#  - a library target named quassel_client with output name (lib)quassel-client(.so)
+#  - an alias target named Quassel::Client in global scope
+#
+# The function exports the TARGET variable which can be used in the current scope
+# for setting source files, properties, link dependencies and so on.
+# To refer to the target outside of the current scope, e.g. for linking, use
+# the alias name.
+#
+function(quassel_add_module _module)
+    # Derive target, alias target, output name from the given module name
+    set(alias "Quassel::${_module}")
+    set(target ${alias})
+    string(TOLOWER ${target} target)
+    string(REPLACE "::" "_" target ${target})
+    string(REPLACE "_" "-" output_name ${target})
+
+    add_library(${target} STATIC "")
+    add_library(${alias} ALIAS ${target})
 
-############################
-# Macros for dealing with Qt
-############################
+    set_target_properties(${target} PROPERTIES
+        OUTPUT_NAME ${output_name}
+    )
 
-# Qt 5.11 removed the qt5_use_modules function, so we need to provide it until we can switch to a modern CMake version.
-# If present, the Qt-provided version will be used automatically instead.
-function(qt5_use_modules _target _link_type)
-    if (NOT TARGET ${_target})
-        message(FATAL_ERROR "The first argument to qt5_use_modules must be an existing target.")
-    endif()
-    if ("${_link_type}" STREQUAL "LINK_PUBLIC" OR "${_link_type}" STREQUAL "LINK_PRIVATE" )
-        set(_qt5_modules ${ARGN})
-        set(_qt5_link_type ${_link_type})
-    else()
-        set(_qt5_modules ${_link_type} ${ARGN})
-    endif()
+    target_include_directories(${target}
+        PUBLIC  ${CMAKE_CURRENT_SOURCE_DIR}
+        PRIVATE ${CMAKE_CURRENT_BINARY_DIR} # for generated files
+    )
 
-    if ("${_qt5_modules}" STREQUAL "")
-        message(FATAL_ERROR "qt5_use_modules requires at least one Qt module to use.")
-    endif()
-    foreach(_module ${_qt5_modules})
-        if (NOT Qt5${_module}_FOUND)
-            find_package(Qt5${_module} PATHS "${_Qt5_COMPONENT_PATH}" NO_DEFAULT_PATH)
-            if (NOT Qt5${_module}_FOUND)
-                message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
-            endif()
-        endif()
-        target_link_libraries(${_target} ${_qt5_link_type} ${Qt5${_module}_LIBRARIES})
-        set_property(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${Qt5${_module}_INCLUDE_DIRS})
-        set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS ${Qt5${_module}_COMPILE_DEFINITIONS})
-        if (Qt5_POSITION_INDEPENDENT_CODE
-                AND (CMAKE_VERSION VERSION_LESS 2.8.12
-                    AND (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
-                    OR CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)))
-            set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ${Qt5_POSITION_INDEPENDENT_CODE})
-        endif()
-    endforeach()
+    # Export the target name for further use
+    set(TARGET ${target} PARENT_SCOPE)
 endfunction()
 
 ######################################
index 24a6aa7..7b2a512 100644 (file)
@@ -1,84 +1,10 @@
-# Builds the three main targets
-
 add_subdirectory(common)
-include_directories(BEFORE common)
-if(BUILD_CORE)
-  add_subdirectory(core)
-  include_directories(BEFORE core)
-endif()
-if(BUILD_GUI)
-  add_subdirectory(client)
-  add_subdirectory(uisupport)
-  add_subdirectory(qtui)
-  include_directories(BEFORE client)
-  include_directories(BEFORE uisupport)
-  include_directories(BEFORE qtui)
-endif()
-
-include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) # for version.gen
-
-# We need to initialize the appropriate resources, so let's give our main.cpp some hints
-if (EMBED_DATA)
-    add_definitions(-DEMBED_DATA)
-endif()
-
-# For KAboutData
-if (WITH_KF5)
-    set(CLIENT_LIBRARIES ${CLIENT_LIBRARIES} KF5::CoreAddons)
-endif()
-
-# Needed for showing the cli option if appropriate
-if (HAVE_SYSLOG)
-    add_definitions(-DHAVE_SYSLOG)
-endif()
-
-if(WANT_CORE)
-  add_executable(quasselcore common/main.cpp ${CORE_DEPS} ${COMMON_DEPS})
-  qt5_use_modules(quasselcore Core Network ${CORE_QT_MODULES})
-  add_dependencies(quasselcore po)
-  set_target_properties(quasselcore PROPERTIES
-                                    COMPILE_FLAGS "-DBUILD_CORE"
-                                    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
-  target_link_libraries(quasselcore mod_core mod_common ${COMMON_LIBRARIES} ${QUASSEL_SSL_LIBRARIES} ${QT_QTMAIN_LIBRARY})
-  install(TARGETS quasselcore RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-endif()
-
-if(WANT_QTCLIENT)
-  add_executable(quasselclient WIN32 common/main.cpp ${CLIENT_DEPS} ${COMMON_DEPS})
-  qt5_use_modules(quasselclient Core Gui Network ${CLIENT_QT_MODULES})
-  add_dependencies(quasselclient po)
-  set_target_properties(quasselclient PROPERTIES
-                                      COMPILE_FLAGS "-DBUILD_QTUI"
-                                      RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
-  target_link_libraries(quasselclient mod_qtui mod_uisupport mod_client mod_common ${COMMON_LIBRARIES} ${CLIENT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES} ${QT_QTMAIN_LIBRARY})
-  install(TARGETS quasselclient RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-endif()
-
-if(WANT_MONO)
-  add_executable(quassel WIN32 common/main.cpp qtui/monoapplication.cpp ${CLIENT_DEPS} ${CORE_DEPS} ${COMMON_DEPS})
-  qt5_use_modules(quassel Core Gui Network ${CLIENT_QT_MODULES} ${CORE_QT_MODULES})
-  add_dependencies(quassel po)
-  set_target_properties(quassel PROPERTIES
-                                COMPILE_FLAGS "-DBUILD_MONO"
-                                RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
-  target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common ${COMMON_LIBRARIES} ${CLIENT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES} ${QT_QTMAIN_LIBRARY})
-  install(TARGETS quassel RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-endif()
-
-# Build bundles for MacOSX
-if(APPLE)
-  add_custom_command(TARGET quasselclient POST_BUILD
-                     COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
-                             ${CMAKE_SOURCE_DIR} "Quassel Client" ../quasselclient)
-  add_custom_command(TARGET quassel POST_BUILD
-                     COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
-                             ${CMAKE_SOURCE_DIR} "Quassel" ../quassel)
-  if(DEPLOY)
-    add_custom_command(TARGET quasselclient POST_BUILD
-                       COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makePackage.sh Client .. qsvgicon)
-    add_custom_command(TARGET quasselcore POST_BUILD
-                       COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makePackage.sh Core ..)
-    add_custom_command(TARGET quassel POST_BUILD
-                       COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makePackage.sh Mono .. qsvgicon)
-  endif()
+add_subdirectory(main)
+if (BUILD_CORE)
+    add_subdirectory(core)
+endif()
+if (BUILD_GUI)
+    add_subdirectory(client)
+    add_subdirectory(uisupport)
+    add_subdirectory(qtui)
 endif()
index 783e8dd..f23c62c 100644 (file)
@@ -1,8 +1,6 @@
-# Builds the client module
+quassel_add_module(Client)
 
-# We still have a minor dep to QtWidgets: QAbstractItemView in BufferModel
-
-set(SOURCES
+target_sources(${TARGET} PRIVATE
     abstractmessageprocessor.cpp
     backlogrequester.cpp
     buffermodel.cpp
@@ -35,11 +33,15 @@ set(SOURCES
 
     # needed for automoc
     abstractui.h
-)
-
-qt5_add_resources(SOURCES ${CLIENT_RCS})
 
-add_library(mod_client STATIC ${SOURCES})
-qt5_use_modules(mod_client Network Core Gui Widgets)
+    ${CLIENT_RCS}
+)
 
-target_link_libraries(mod_client mod_common)
+target_link_libraries(${TARGET}
+    PUBLIC
+        Qt5::Core
+        Qt5::Gui
+        Qt5::Network
+        Qt5::Widgets  # QAbstractItemView in BufferModel
+        Quassel::Common
+)
index 1b77daf..ebc626f 100644 (file)
@@ -1,6 +1,6 @@
-# Builds the common module
+quassel_add_module(Common)
 
-set(SOURCES
+target_sources(${TARGET} PRIVATE
     abstractsignalwatcher.h
     aliasmanager.cpp
     authhandler.cpp
@@ -56,39 +56,41 @@ set(SOURCES
     # needed for automoc
     irccap.h
     protocol.h
-)
 
-if (HAVE_SYSLOG)
-    add_definitions(-DHAVE_SYSLOG)
-endif()
+    ${COMMON_RCS}
+)
 
-if (APPLE)
-    set(SOURCES ${SOURCES} mac_utils.cpp)
-endif()
+# Needed for finding the generated version.h
+target_include_directories(${TARGET} PRIVATE ${CMAKE_BINARY_DIR})
 
-qt5_add_resources(SOURCES ${COMMON_RCS})
+target_link_libraries(${TARGET} PUBLIC
+    ${CMAKE_DL_LIBS}
+    Qt5::Core
+    Qt5::Network
+    ZLIB::ZLIB
+)
 
-add_library(mod_common STATIC ${SOURCES})
-qt5_use_modules(mod_common Core Network)
+if (HAVE_SYSLOG)
+    target_compile_definitions(${TARGET} PRIVATE -DHAVE_SYSLOG)
+endif()
 
 if (WIN32)
-    target_sources(mod_common PRIVATE logbacktrace_win.cpp windowssignalwatcher.cpp)
+    target_sources(${TARGET} PRIVATE logbacktrace_win.cpp windowssignalwatcher.cpp)
 else()
     if (Backtrace_FOUND)
         configure_file(backtrace_config.h.in backtrace_config.h)
-        target_compile_definitions(mod_common PRIVATE -DHAVE_BACKTRACE)
-        target_include_directories(mod_common PRIVATE ${Backtrace_INCLUDE_DIRS})
-        target_link_libraries(mod_common PRIVATE ${Backtrace_LIBRARIES})
+        target_include_directories(${TARGET} PRIVATE ${Backtrace_INCLUDE_DIRS})
+        target_link_libraries(${TARGET} PRIVATE ${Backtrace_LIBRARIES})
+        set_property(SOURCE logbacktrace_unix.cpp posixsignalwatcher.cpp APPEND PROPERTY COMPILE_DEFINITIONS HAVE_BACKTRACE)
     endif()
-    target_sources(mod_common PRIVATE logbacktrace_unix.cpp posixsignalwatcher.cpp)
+    target_sources(${TARGET} PRIVATE logbacktrace_unix.cpp posixsignalwatcher.cpp)
 endif()
 
 if (APPLE)
-    target_link_libraries(mod_common "-framework CoreServices" "-framework CoreFoundation")
+    target_sources(${TARGET} PRIVATE mac_utils.cpp)
+    target_link_libraries(${TARGET} PUBLIC "-framework CoreServices" "-framework CoreFoundation")
 endif()
 
-target_link_libraries(mod_common ${CMAKE_DL_LIBS} ZLIB::ZLIB)
-
 # This is needed so translations are generated before trying to build the qrc.
 # Should probably find a nicer solution with proper dependencies between the involved files, though...
-add_dependencies(mod_common po)
+add_dependencies(${TARGET} po)
index f83cbc7..ae39b03 100644 (file)
@@ -44,6 +44,7 @@
 #include "protocol.h"
 #include "syncableobject.h"
 #include "types.h"
+#include "version.h"
 
 #ifndef Q_OS_WIN
 #    include "posixsignalwatcher.h"
@@ -51,8 +52,6 @@
 #    include "windowssignalwatcher.h"
 #endif
 
-#include "../../version.h"
-
 Quassel::Quassel()
     : Singleton<Quassel>{this}
     , _logger{new Logger{this}}
index 634af92..d898277 100644 (file)
@@ -1,6 +1,6 @@
-# Builds the core module
+quassel_add_module(Core)
 
-set(SOURCES
+target_sources(${TARGET} PRIVATE
     abstractsqlstorage.cpp
     authenticator.cpp
     core.cpp
@@ -42,38 +42,33 @@ set(SOURCES
 
     # needed for automoc
     coreeventmanager.h
-)
 
-set(LIBS )
+    # Resources
+    sql.qrc
+)
 
-if(HAVE_SSL)
-  set(SOURCES ${SOURCES} sslserver.cpp)
-  include_directories(${OPENSSL_INCLUDE_DIR})
+if (HAVE_SSL)
+    target_sources(${TARGET} PRIVATE sslserver.cpp)
 endif()
 
-# Build with LDAP if told to do so.
-if(HAVE_LDAP)
-    include_directories(${LDAP_INCLUDE_DIR})
-    set(SOURCES ${SOURCES} ldapauthenticator.cpp)
-    set(MOC_HDRS ${MOC_HDRS} ldapauthenticator.h)
-endif(HAVE_LDAP)
-
-include_directories(${CMAKE_SOURCE_DIR}/src/common)
-
-set(CORE_RCS ${CORE_RCS} ${CMAKE_CURRENT_SOURCE_DIR}/sql.qrc)
-qt5_add_resources(SOURCES ${CORE_RCS})
-
-add_library(mod_core STATIC ${SOURCES})
-qt5_use_modules(mod_core Core Network Script Sql)
-
-target_link_libraries(mod_core mod_common ${LIBS})
+if (LDAP_FOUND)
+    target_sources(${TARGET} PRIVATE ldapauthenticator.cpp)
+    target_link_libraries(${TARGET} PRIVATE ${LDAP_LIBRARIES})
+    target_include_directories(${TARGET} PRIVATE ${LDAP_INCLUDE_DIR})
+    target_compile_definitions(${TARGET} PRIVATE -DHAVE_LDAP)
+endif()
 
 if (Qca-qt5_FOUND)
-    target_sources(mod_core PRIVATE cipher.cpp keyevent.cpp)
-    target_link_libraries(mod_core qca-qt5)
-    target_compile_definitions(mod_core PUBLIC -DHAVE_QCA2)
+    target_sources(${TARGET} PRIVATE cipher.cpp keyevent.cpp)
+    target_link_libraries(${TARGET} PUBLIC qca-qt5)
+    target_compile_definitions(${TARGET} PUBLIC -DHAVE_QCA2)
 endif()
 
-if(HAVE_LDAP)
-    target_link_libraries(mod_core ${LDAP_LIBRARIES})
-endif(HAVE_LDAP)
+target_link_libraries(${TARGET}
+    PUBLIC
+        Qt5::Core
+        Qt5::Network
+        Qt5::Script
+        Qt5::Sql
+        Quassel::Common
+)
diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt
new file mode 100644 (file)
index 0000000..60efe51
--- /dev/null
@@ -0,0 +1,55 @@
+# Convenience function to avoid boilerplate
+function(setup_executable _target _define)
+    set_target_properties(${_target} PROPERTIES
+        COMPILE_FLAGS ${_define}
+        RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
+    )
+    target_link_libraries(${_target} PRIVATE ${ARGN})
+    install(TARGETS ${_target} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+endfunction()
+
+# We need to initialize the appropriate resources, so let's give our main.cpp some hints
+if (EMBED_DATA)
+    set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS EMBED_DATA)
+endif()
+
+# Build the executables
+if (WANT_CORE)
+    add_executable(quasselcore main.cpp)
+    setup_executable(quasselcore -DBUILD_CORE Qt5::Core Quassel::Core)
+endif()
+
+if (WANT_CLIENT OR WANT_QTCLIENT)
+    add_executable(quasselclient WIN32 main.cpp)
+    setup_executable(quasselclient -DBUILD_QTUI Qt5::Core Qt5::Gui Quassel::QtUi)
+    if (WITH_KDE)
+        target_link_libraries(quasselclient PRIVATE KF5::CoreAddons)
+    endif()
+endif()
+
+if (WANT_MONO)
+    add_executable(quassel WIN32 main.cpp monoapplication.cpp)
+    setup_executable(quassel -DBUILD_MONO Qt5::Core Qt5::Gui Quassel::Core Quassel::QtUi)
+    if (WITH_KDE)
+        target_link_libraries(quassel PRIVATE KF5::CoreAddons)
+    endif()
+endif()
+
+# Build bundles for MacOSX
+if (APPLE)
+    add_custom_command(TARGET quasselclient POST_BUILD
+                       COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
+                               ${CMAKE_SOURCE_DIR} "Quassel Client" ${CMAKE_BINARY_DIR}/quasselclient)
+
+    add_custom_command(TARGET quassel POST_BUILD
+                       COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
+                               ${CMAKE_SOURCE_DIR} "Quassel" ${CMAKE_BINARY_DIR}/quassel)
+    if (DEPLOY)
+        add_custom_command(TARGET quasselclient POST_BUILD WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+                           COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makePackage.sh Client ${CMAKE_BINARY_DIR} qsvgicon)
+        add_custom_command(TARGET quasselcore POST_BUILD WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+                           COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makePackage.sh Core ${CMAKE_BINARY_DIR})
+        add_custom_command(TARGET quassel POST_BUILD WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+                           COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makePackage.sh Mono ${CMAKE_BINARY_DIR} qsvgicon)
+    endif()
+endif()
similarity index 100%
rename from src/common/main.cpp
rename to src/main/main.cpp
index 21fc833..1c0f072 100644 (file)
@@ -1,6 +1,6 @@
-# Builds the qtui module
+quassel_add_module(QtUi)
 
-set(SOURCES
+target_sources(${TARGET} PRIVATE
     aboutdlg.cpp
     awaylogfilter.cpp
     awaylogview.cpp
@@ -53,9 +53,8 @@ set(SOURCES
     topicwidget.cpp
     verticaldock.cpp
     webpreviewitem.cpp
-)
 
-set(FORMS
+    # UI files
     aboutdlg.ui
     bufferviewwidget.ui
     bufferwidget.ui
@@ -85,97 +84,112 @@ set(FORMS
     topicwidget.ui
 )
 
-set(LIBS )
-set(QT_MODULES )
+# Handle settingspages
+target_include_directories(${TARGET} PRIVATE settingspages)
+include(settingspages/settingspages.cmake)
+foreach(page ${SETTINGSPAGES})
+    target_sources(${TARGET} PRIVATE
+        settingspages/${page}settingspage.cpp
+        settingspages/${page}settingspage.ui
+    )
+endforeach()
+foreach(src ${SP_SOURCES})
+    target_sources(${TARGET} PRIVATE settingspages/${src})
+endforeach()
+foreach(form ${SP_FORMS})
+    target_sources(${TARGET} PRIVATE settingspages/${form})
+endforeach()
+
+target_link_libraries(${TARGET}
+    PUBLIC
+        Qt5::Core
+        Qt5::Gui
+        Qt5::Network
+        Qt5::Widgets
+        Quassel::UiSupport
+        Quassel::Client
+        Quassel::Common
+)
 
-if (WITH_KF5)
-    list(APPEND SOURCES knotificationbackend.cpp)
-    list(APPEND LIBS KF5::ConfigWidgets KF5::Notifications KF5::NotifyConfig KF5::WidgetsAddons KF5::XmlGui)
+if (WITH_KDE)
+    target_sources(${TARGET} PRIVATE knotificationbackend.cpp)
+    target_link_libraries(${TARGET} PUBLIC
+        KF5::ConfigWidgets
+        KF5::Notifications
+        KF5::NotifyConfig
+        KF5::WidgetsAddons
+        KF5::XmlGui
+    )
 endif()
 
-if (LibsnoreQt5_FOUND)
-    add_definitions(-DHAVE_LIBSNORE)
-    list(APPEND SOURCES snorenotificationbackend.cpp)
-    list(APPEND FORMS   snorentificationconfigwidget.ui)
-    list(APPEND LIBS    Snore::Libsnore Snore::LibsnoreSettings)
+if (KF5Sonnet_FOUND)
+    target_compile_definitions(${TARGET} PRIVATE -DHAVE_SONNET)
+    target_sources(${TARGET} PRIVATE settingspages/sonnetsettingspage.cpp)
+    target_link_libraries(${TARGET} PRIVATE KF5::SonnetUi)
 endif()
 
 if (Qt5Multimedia_FOUND)
-    add_definitions(-DHAVE_QTMULTIMEDIA)
-    list(APPEND QT_MODULES Multimedia)
-    set(SOURCES ${SOURCES} qtmultimedianotificationbackend.cpp)
-    set(FORMS ${FORMS}     qtmultimedianotificationconfigwidget.ui)
+    target_compile_definitions(${TARGET} PRIVATE -DHAVE_QTMULTIMEDIA)
+    target_sources(${TARGET} PRIVATE
+        qtmultimedianotificationbackend.cpp
+        qtmultimedianotificationconfigwidget.ui
+    )
+    target_link_libraries(${TARGET} PRIVATE Qt5::Multimedia)
 endif()
 
 if (Qt5DBus_FOUND)
-    add_definitions(-DHAVE_DBUS)
-    list(APPEND QT_MODULES DBus)
+    target_compile_definitions(${TARGET} PRIVATE -DHAVE_DBUS)
+    target_link_libraries(${TARGET} PRIVATE Qt5::DBus)
     if (dbusmenu-qt5_FOUND)
-        add_definitions(-DHAVE_DBUSMENU)
-        include_directories(${dbusmenu-qt5_INCLUDE_DIRS})
-        list(APPEND LIBS dbusmenu-qt5)
+        target_compile_definitions(${TARGET} PRIVATE -DHAVE_DBUSMENU)
+        target_link_libraries(${TARGET} PRIVATE dbusmenu-qt5)
     endif()
 
-    list(APPEND SOURCES statusnotifieritem.cpp statusnotifieritemdbus.cpp dockmanagernotificationbackend.cpp)
-    qt5_add_dbus_interface(SOURCES ../../interfaces/org.kde.StatusNotifierWatcher.xml statusnotifierwatcher)
-    qt5_add_dbus_interface(SOURCES ../../interfaces/org.freedesktop.Notifications.xml notificationsclient)
-    qt5_add_dbus_adaptor  (SOURCES ../../interfaces/org.kde.StatusNotifierItem.xml statusnotifieritemdbus.h StatusNotifierItemDBus)
+    qt5_add_dbus_interface(DBUS_SOURCES ../../interfaces/org.kde.StatusNotifierWatcher.xml statusnotifierwatcher)
+    qt5_add_dbus_interface(DBUS_SOURCES ../../interfaces/org.freedesktop.Notifications.xml notificationsclient)
+    qt5_add_dbus_adaptor  (DBUS_SOURCES ../../interfaces/org.kde.StatusNotifierItem.xml statusnotifieritemdbus.h StatusNotifierItemDBus)
+
+    target_sources(${TARGET} PRIVATE
+        dockmanagernotificationbackend.cpp
+        statusnotifieritem.cpp
+        statusnotifieritemdbus.cpp
+        ${DBUS_SOURCES}
+    )
 endif()
 
 if (HAVE_WEBKIT)
-    add_definitions(-DHAVE_WEBKIT)
-    list(APPEND QT_MODULES WebKit WebKitWidgets)
+    target_compile_definitions(${TARGET} PRIVATE -DHAVE_WEBKIT)
+    target_link_libraries(${TARGET} PRIVATE
+        Qt5::WebKit
+        Qt5::WebKitWidgets
+    )
 endif()
 
 if (HAVE_WEBENGINE)
-    add_definitions(-DHAVE_WEBENGINE)
-    list(APPEND QT_MODULES WebEngine WebEngineWidgets)
+    target_compile_definitions(${TARGET} PRIVATE -DHAVE_WEBENGINE)
+    target_link_libraries(${TARGET} PRIVATE
+        Qt5::WebEngine
+        Qt5::WebEngineWidgets)
 endif()
 
-if(HAVE_SSL)
-  set(SOURCES ${SOURCES} sslinfodlg.cpp)
-  set(FORMS ${FORMS} sslinfodlg.ui)
+if (HAVE_SSL)
+    target_sources(${TARGET} PRIVATE
+        sslinfodlg.cpp
+        sslinfodlg.ui
+    )
 endif()
 
-if (WITH_NOTIFICATION_CENTER)
-    add_definitions(-DHAVE_NOTIFICATION_CENTER)
-    list(APPEND SOURCES osxnotificationbackend.mm)
-    list(APPEND LIBS "/System/Library/Frameworks/Foundation.framework")
+if (LibsnoreQt5_FOUND)
+    target_compile_definitions(${TARGET} PRIVATE -DHAVE_LIBSNORE)
+    target_sources(${TARGET} PRIVATE
+        snorenotificationbackend.cpp
+        snorentificationconfigwidget.ui
+    )
+    target_link_libraries(${TARGET} PRIVATE Snore::Libsnore Snore::LibsnoreSettings)
 endif()
 
-if (KF5Sonnet_FOUND)
-    add_definitions(-DHAVE_SONNET)
-    list(APPEND SOURCES settingspages/sonnetsettingspage.cpp)
-    list(APPEND LIBS KF5::SonnetUi)
+if (WITH_NOTIFICATION_CENTER)
+    target_compile_definitions(${TARGET} PRIVATE -DHAVE_NOTIFICATION_CENTER)
+    target_sources(${TARGET} PRIVATE osxnotificationbackend.mm)
+    target_link_libraries(${TARGET} PRIVATE "/System/Library/Frameworks/Foundation.framework")
 endif()
-
-foreach(FORM ${FORMS})
-  set(FORMPATH ${FORMPATH} ui/${FORM})
-endforeach(FORM ${FORMS})
-
-# handle settingspages
-include(settingspages/settingspages.cmake)
-foreach(SP ${SETTINGSPAGES})
-  set(SPSRC ${SPSRC} settingspages/${SP}settingspage.cpp)
-  set(SPFRM ${SPFRM} settingspages/${SP}settingspage.ui)
-endforeach(SP ${SETTINGSPAGES})
-foreach(SRC ${SP_SOURCES})
-  set(SPSRC ${SPSRC} settingspages/${SRC})
-endforeach(SRC ${SP_SOURCES})
-foreach(FRM ${SP_FORMS})
-  set(SPFRM ${SPFRM} settingspages/${FRM})
-endforeach(FRM ${SP_FORMS})
-
-include_directories(${CMAKE_SOURCE_DIR}/src/common
-                    ${CMAKE_SOURCE_DIR}/src/client
-                    ${CMAKE_SOURCE_DIR}/src/qtui
-                    ${CMAKE_SOURCE_DIR}/src/qtui/settingspages
-                    ${CMAKE_SOURCE_DIR}/src/uisupport
-)
-
-qt5_wrap_ui(UI ${FORMPATH} ${SPFRM})
-
-add_library(mod_qtui STATIC ${SOURCES} ${SPSRC} ${UI})
-qt5_use_modules(mod_qtui Core Gui Network Widgets ${QT_MODULES})
-
-target_link_libraries(mod_qtui mod_client mod_common mod_uisupport ${LIBS})
similarity index 100%
rename from src/qtui/ui/aboutdlg.ui
rename to src/qtui/aboutdlg.ui
index f278982..3a72fc5 100644 (file)
@@ -47,7 +47,7 @@ set(SP_FORMS
     servereditdlg.ui
 )
 
-if (NOT KDE4_FOUND)
+if (NOT WITH_KDE)
     list(APPEND SETTINGSPAGES shortcuts)
     list(APPEND SP_SOURCES keysequencewidget.cpp shortcutsmodel.cpp)
 endif()
index 0347423..345c4d1 100644 (file)
@@ -1,6 +1,6 @@
-# Builds the uisupport module
+quassel_add_module(UiSupport)
 
-set(SOURCES
+target_sources(${TARGET} PRIVATE
     aboutdata.cpp
     abstractbuffercontainer.cpp
     abstractitemview.cpp
@@ -37,20 +37,26 @@ set(SOURCES
     abstractnotificationbackend.h
 )
 
-include_directories(${CMAKE_SOURCE_DIR}/src/common
-                    ${CMAKE_SOURCE_DIR}/src/client
+target_link_libraries(${TARGET}
+    PUBLIC
+        Qt5::Core
+        Qt5::Gui
+        Qt5::Network
+        Qt5::Widgets
+        Quassel::Client
+        Quassel::Common
 )
 
-add_library(mod_uisupport STATIC ${SOURCES})
-qt5_use_modules(mod_uisupport Core Gui Network Widgets)
-
-target_link_libraries(mod_uisupport mod_client mod_common)
-
 if (WITH_KF5)
-    target_link_libraries(mod_uisupport KF5::CoreAddons KF5::TextWidgets KF5::XmlGui)
+    target_link_libraries(${TARGET}
+        PUBLIC
+            KF5::CoreAddons
+            KF5::TextWidgets
+            KF5::XmlGui
+    )
 endif()
 
 if (KF5Sonnet_FOUND)
-    add_definitions(-DHAVE_SONNET)
-    target_link_libraries(mod_uisupport KF5::SonnetUi)
+    target_link_libraries(${TARGET} PRIVATE KF5::SonnetUi)
+    target_compile_definitions(${TARGET} PRIVATE -DHAVE_SONNET)
 endif()