squawk/CMakeLists.txt

242 lines
7.3 KiB
CMake

cmake_minimum_required(VERSION 3.16)
project(squawk VERSION 0.2.3 LANGUAGES CXX)
cmake_policy(SET CMP0076 NEW)
cmake_policy(SET CMP0077 NEW)
cmake_policy(SET CMP0079 NEW)
set(CMAKE_CXX_STANDARD 17)
set(QT_VERSION_MAJOR 5)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
include(GNUInstallDirs)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
set(WIN32_FLAG "")
set(MACOSX_BUNDLE_FLAG "")
if (CMAKE_BUILD_TYPE STREQUAL "Release")
if (WIN32)
set(WIN32_FLAG WIN32)
endif(WIN32)
if (APPLE)
set(MACOSX_BUNDLE_FLAG MACOSX_BUNDLE)
endif(APPLE)
endif()
add_executable(squawk ${WIN32_FLAG} ${MACOSX_BUNDLE_FLAG})
target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR})
option(SYSTEM_QXMPP "Use system qxmpp lib" ON)
option(SYSTEM_LMDBAL "Use system lmdbal lib" ON)
option(WITH_KWALLET "Build KWallet support module" ON)
option(WITH_KIO "Build KIO support module" ON)
option(WITH_KCONFIG "Build KConfig support module" ON)
option(WITH_OMEMO "Build OMEMO support module" OFF) #it should be off by default untill I sourt the problems out
# Dependencies
## Qt
if (NOT DEFINED QT_VERSION_MAJOR)
find_package(QT NAMES Qt6 Qt5 CONFIG REQUIRED COMPONENTS Widgets DBus Gui Xml Network Core)
else ()
find_package(Qt${QT_VERSION_MAJOR} CONFIG REQUIRED COMPONENTS Widgets DBus Gui Xml Network Core)
endif()
find_package(Boost COMPONENTS)
target_include_directories(squawk PRIVATE ${Boost_INCLUDE_DIRS})
## OMEMO
if (WITH_OMEMO)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(OMEMO libomemo-c)
if (OMEMO_FOUND)
target_compile_definitions(squawk PRIVATE WITH_OMEMO)
message("Building with support of OMEMO")
else ()
message("libomemo-c package wasn't found, trying to build without OMEMO support")
set(WITH_OMEMO OFF)
endif ()
else ()
message("PKG_CONFIG module wasn't found, can not check libomemo-c support, trying to build without OMEMO support")
set(WITH_OMEMO OFF)
endif ()
endif ()
## KIO
if (WITH_KIO)
find_package(KF5KIO CONFIG)
if (NOT KF5KIO_FOUND)
set(WITH_KIO OFF)
message("KIO package wasn't found, KIO support modules wouldn't be built")
else ()
target_compile_definitions(squawk PRIVATE WITH_KIO)
message("Building with support of KIO")
endif ()
endif ()
## KWallet
if (WITH_KWALLET)
find_package(KF5Wallet CONFIG)
if (NOT KF5Wallet_FOUND)
set(WITH_KWALLET OFF)
message("KWallet package wasn't found, KWallet support module wouldn't be built")
else ()
target_compile_definitions(squawk PRIVATE WITH_KWALLET)
message("Building with support of KWallet")
endif ()
endif ()
## KConfig
if (WITH_KCONFIG)
find_package(KF5Config CONFIG)
if (NOT KF5Config_FOUND)
set(WITH_KCONFIG OFF)
message("KConfig package wasn't found, KConfig support modules wouldn't be built")
else()
find_package(KF5ConfigWidgets CONFIG)
if (NOT KF5ConfigWidgets_FOUND)
set(WITH_KCONFIG OFF)
message("KConfigWidgets package wasn't found, KConfigWidgets support modules wouldn't be built")
else()
target_compile_definitions(squawk PRIVATE WITH_KCONFIG)
message("Building with support of KConfig")
message("Building with support of KConfigWidgets")
endif()
endif()
endif()
## QXmpp
if (SYSTEM_QXMPP)
if (WITH_OMEMO)
find_package(QXmpp CONFIG COMPONENTS Omemo)
else ()
find_package(QXmpp CONFIG)
endif ()
if (NOT QXmpp_FOUND)
set(SYSTEM_QXMPP OFF)
message("QXmpp package wasn't found, trying to build with bundled QXmpp")
else ()
message("Building with system QXmpp")
endif ()
endif () #it's endif() + if() and not else() because I want it to have a fallback behaviour
if (NOT SYSTEM_QXMPP) #we can fail finding system QXmpp and this way we'll check bundled before failing completely
message("Building with bundled QXmpp")
target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}/external/qxmpp/src/base)
target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}/external/qxmpp/src/client)
target_include_directories(squawk PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/qxmpp/src)
if (WITH_OMEMO)
target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}/external/qxmpp/src/omemo)
target_include_directories(squawk PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/qxmpp/src/omemo)
set(BUILD_OMEMO ON)
set(BUILD_TESTS OFF)
else ()
set(BUILD_OMEMO OFF)
endif ()
add_subdirectory(external/qxmpp)
add_library(QXmpp::QXmpp ALIAS QXmppQt${QT_VERSION_MAJOR})
if (WITH_OMEMO)
target_include_directories(QXmppOmemoQt${QT_VERSION_MAJOR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/qxmpp/src)
add_library(QXmpp::Omemo ALIAS QXmppOmemoQt${QT_VERSION_MAJOR})
endif ()
endif ()
## LMDBAL
if (SYSTEM_LMDBAL)
find_package(lmdbal)
if (NOT lmdbal_FOUND)
set(SYSTEM_LMDBAL OFF)
message("LMDBAL package wasn't found, trying to build with bundled LMDBAL")
else ()
message("Building with system LMDBAL")
endif ()
else()
message("Building with bundled LMDBAL")
set(BUILD_STATIC ON)
add_subdirectory(external/lmdbal)
add_library(LMDBAL::LMDBAL ALIAS LMDBAL)
endif()
## Linking
target_link_libraries(squawk
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Xml
LMDBAL::LMDBAL
QXmpp::QXmpp
simpleCrypt
)
if (WITH_OMEMO)
target_link_libraries(squawk PRIVATE QXmpp::Omemo)
endif ()
## Link thread libraries on Linux
if(UNIX AND NOT APPLE)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(squawk PRIVATE Threads::Threads)
endif()
## Build type
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif ()
message("Build type: ${CMAKE_BUILD_TYPE}")
if(CMAKE_COMPILER_IS_GNUCXX)
set (COMPILE_OPTIONS -fno-sized-deallocation) # for eliminating _ZdlPvm
if (CMAKE_BUILD_TYPE STREQUAL "Release")
list(APPEND COMPILE_OPTIONS -O3)
endif()
if (CMAKE_BUILD_TYPE STREQUAL Debug)
list(APPEND COMPILE_OPTIONS -g)
list(APPEND COMPILE_OPTIONS -Wall)
list(APPEND COMPILE_OPTIONS -Wextra)
endif()
message("Compilation options: " ${COMPILE_OPTIONS})
target_compile_options(squawk PRIVATE ${COMPILE_OPTIONS})
endif(CMAKE_COMPILER_IS_GNUCXX)
# I am not really sure about this solution
# This should enable plugins to be found in path like /usr/lib/squawk instead of just /usr/lib
set(PLUGIN_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/squawk")
add_compile_definitions(PLUGIN_PATH="${PLUGIN_PATH}")
add_subdirectory(main)
add_subdirectory(core)
add_subdirectory(external/simpleCrypt)
add_subdirectory(packaging)
add_subdirectory(plugins)
add_subdirectory(resources)
add_subdirectory(shared)
add_subdirectory(translations)
add_subdirectory(ui)
## Install the executable
install(TARGETS squawk DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES README.md DESTINATION ${CMAKE_INSTALL_DATADIR}/macaw.me/squawk)
install(FILES LICENSE.md DESTINATION ${CMAKE_INSTALL_DATADIR}/macaw.me/squawk)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
if (APPLE)
add_custom_command(TARGET squawk POST_BUILD COMMENT "Running macdeployqt..."
COMMAND "${Qt${QT_VERSION_MAJOR}Widgets_DIR}/../../../bin/macdeployqt" "${CMAKE_CURRENT_BINARY_DIR}/squawk.app"
)
endif(APPLE)
endif()