You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nheko/CMakeLists.txt

372 lines
11 KiB

8 years ago
cmake_minimum_required(VERSION 3.1)
option(APPVEYOR_BUILD "Build on appveyor" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(GNUInstallDirs)
# Include Qt basic functions
include(QtCommon)
project(nheko LANGUAGES C CXX)
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "2")
set(CPACK_PACKAGE_VERSION_PATCH "1")
# Set PROJECT_VERSION_PATCH and PROJECT_VERSION_TWEAK to 0 if not present, needed by add_project_meta
fix_project_version()
# Set additional project information
set(COMPANY "Nheko")
set(COPYRIGHT "Copyright (c) 2017 Mujx")
set(IDENTIFIER "com.mujx.nheko")
add_project_meta(META_FILES_TO_INCLUDE)
#
# LMDB
#
if(APPVEYOR_BUILD)
set(LMDB_VERSION "LMDB_0.9.21")
set(NTDLIB "C:/WINDDK/7600.16385.1/lib/win7/amd64/ntdll.lib")
execute_process(
COMMAND git clone --depth=1 --branch ${LMDB_VERSION} https://github.com/LMDB/lmdb)
set(LMDB_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb)
add_library(lmdb
${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb/lmdb.h
${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb/mdb.c
${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb/midl.h
${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb/midl.c)
else()
find_path (LMDB_INCLUDE_DIR NAMES lmdb.h PATHS "$ENV{LMDB_DIR}/include")
find_library (LMDB_LIBRARY NAMES lmdb PATHS "$ENV{LMDB_DIR}/lib" )
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LMDB DEFAULT_MSG LMDB_INCLUDE_DIR LMDB_LIBRARY)
endif()
#
# Discover Qt dependencies.
#
8 years ago
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
find_package(Qt5Concurrent REQUIRED)
find_package(Qt5Multimedia REQUIRED)
8 years ago
if (APPLE)
find_package(Qt5MacExtras REQUIRED)
endif(APPLE)
if (Qt5Widgets_FOUND)
if (Qt5Widgets_VERSION VERSION_LESS 5.7.0)
message(STATUS "Qt version ${Qt5Widgets_VERSION}")
message(WARNING "Minimum supported Qt5 version is 5.7!")
endif()
endif(Qt5Widgets_FOUND)
#
# Set up compiler flags.
#
8 years ago
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_STANDARD 14)
8 years ago
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
message("Setting build type to '${CMAKE_BUILD_TYPE}'")
else(NOT CMAKE_BUILD_TYPE)
message("Build type set to '${CMAKE_BUILD_TYPE}'")
endif(NOT CMAKE_BUILD_TYPE)
find_program(GIT git)
if(GIT)
execute_process(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${GIT} rev-parse --short HEAD
OUTPUT_VARIABLE GIT_OUT OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH}-${GIT_OUT}")
endif(GIT)
set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
set(PROJECT_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR})
set(PROJECT_VERSION ${CPACK_PACKAGE_VERSION})
message(STATUS "Version: ${PROJECT_VERSION}")
cmake_host_system_information(RESULT BUILD_HOST QUERY HOSTNAME)
set(BUILD_USER $ENV{USER})
configure_file(cmake/version.hpp config/version.hpp)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Wall \
-Wextra \
-Werror \
7 years ago
-pipe \
-pedantic \
-Wunreachable-code")
8 years ago
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (GCC_VERSION VERSION_GREATER 4.9)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always" )
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always" )
endif()
8 years ago
endif()
8 years ago
#
# Declare source and header files.
#
8 years ago
set(SRC_FILES
# Dialogs
src/dialogs/CreateRoom.cc
src/dialogs/ImageOverlay.cc
src/dialogs/PreviewUploadOverlay.cc
src/dialogs/InviteUsers.cc
src/dialogs/JoinRoom.cc
src/dialogs/LeaveRoom.cc
src/dialogs/Logout.cc
src/dialogs/ReadReceipts.cc
src/dialogs/ReCaptcha.cpp
# Emoji
src/emoji/Category.cc
src/emoji/ItemDelegate.cc
src/emoji/Panel.cc
src/emoji/PickButton.cc
src/emoji/Provider.cc
# Timeline
src/timeline/TimelineViewManager.cc
src/timeline/TimelineItem.cc
src/timeline/TimelineView.cc
src/timeline/widgets/AudioItem.cc
src/timeline/widgets/FileItem.cc
src/timeline/widgets/ImageItem.cc
src/timeline/widgets/VideoItem.cc
# UI components
src/ui/Avatar.cc
src/ui/Badge.cc
src/ui/LoadingIndicator.cc
src/ui/FlatButton.cc
src/ui/FloatingButton.cc
src/ui/Label.cc
src/ui/OverlayModal.cc
src/ui/ScrollBar.cc
src/ui/SnackBar.cc
src/ui/RaisedButton.cc
src/ui/Ripple.cc
src/ui/RippleOverlay.cc
src/ui/OverlayWidget.cc
src/ui/TextField.cc
src/ui/ToggleButton.cc
src/ui/Theme.cc
src/ui/ThemeManager.cc
src/AvatarProvider.cc
src/Cache.cc
src/ChatPage.cc
src/CommunitiesListItem.cc
src/CommunitiesList.cc
src/Community.cc
8 years ago
src/Deserializable.cc
src/InviteeItem.cc
8 years ago
src/LoginPage.cc
src/MainWindow.cc
src/MatrixClient.cc
src/QuickSwitcher.cc
src/RegisterPage.cc
8 years ago
src/RoomInfoListItem.cc
src/RoomList.cc
src/RoomState.cc
src/RunGuard.cc
src/SideBarActions.cc
src/Splitter.cc
8 years ago
src/TextInputWidget.cc
src/TopRoomBar.cc
src/TrayIcon.cc
src/TypingDisplay.cc
src/Utils.cc
8 years ago
src/UserInfoWidget.cc
src/UserSettingsPage.cc
8 years ago
src/WelcomePage.cc
src/main.cc
)
#
# matrix-structs
#
include(MatrixStructs)
include_directories(${MATRIX_STRUCTS_INCLUDE_DIRS})
#
# libtweeny
#
include(Tweeny)
include_directories(${TWEENY_INCLUDE_DIRS})
#
# lmdbxx
#
include(LMDBXX)
include_directories(${LMDBXX_INCLUDE_DIRS})
8 years ago
include_directories(include)
include_directories(include/ui)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/config)
include_directories(${LMDB_INCLUDE_DIR})
8 years ago
qt5_wrap_cpp(MOC_HEADERS
# Dialogs
include/dialogs/CreateRoom.h
include/dialogs/ImageOverlay.h
include/dialogs/PreviewUploadOverlay.h
include/dialogs/InviteUsers.h
include/dialogs/JoinRoom.h
include/dialogs/LeaveRoom.h
include/dialogs/Logout.h
include/dialogs/ReadReceipts.h
include/dialogs/ReCaptcha.hpp
# Emoji
include/emoji/Category.h
include/emoji/ItemDelegate.h
include/emoji/Panel.h
include/emoji/PickButton.h
# Timeline
include/timeline/TimelineItem.h
include/timeline/TimelineView.h
include/timeline/TimelineViewManager.h
include/timeline/widgets/AudioItem.h
include/timeline/widgets/FileItem.h
include/timeline/widgets/ImageItem.h
include/timeline/widgets/VideoItem.h
# UI components
include/ui/Avatar.h
include/ui/Badge.h
include/ui/LoadingIndicator.h
include/ui/FlatButton.h
include/ui/Label.h
include/ui/FloatingButton.h
include/ui/OverlayWidget.h
include/ui/ScrollBar.h
include/ui/SnackBar.h
include/ui/RaisedButton.h
include/ui/Ripple.h
include/ui/RippleOverlay.h
include/ui/TextField.h
include/ui/ToggleButton.h
include/ui/Theme.h
include/ui/ThemeManager.h
include/AvatarProvider.h
include/Cache.h
8 years ago
include/ChatPage.h
include/CommunitiesListItem.h
include/CommunitiesList.h
include/Community.h
8 years ago
include/LoginPage.h
include/MainWindow.h
include/InviteeItem.h
8 years ago
include/MatrixClient.h
include/QuickSwitcher.h
8 years ago
include/RegisterPage.h
include/RoomInfoListItem.h
include/RoomList.h
include/SideBarActions.h
include/Splitter.h
include/TextInputWidget.h
8 years ago
include/TopRoomBar.h
8 years ago
include/TrayIcon.h
include/TypingDisplay.h
include/UserInfoWidget.h
include/UserSettingsPage.h
8 years ago
include/WelcomePage.h
)
#
# Bundle translations.
#
FILE(GLOB LANG_TS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/langs/*.ts")
qt5_add_translation(QM_SRC ${LANG_TS_SRC})
add_custom_target(LANG_QRC ALL DEPENDS ${QM_SRC})
# Generate a qrc file for the translations
set(_qrc ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc)
if(NOT EXISTS ${_qrc})
file(WRITE ${_qrc} "<RCC> <qresource prefix=\"/translations\">")
foreach(_lang ${QM_SRC})
get_filename_component(_filename ${_lang} NAME)
file(APPEND ${_qrc} "<file>${_filename}</file>")
endforeach(_lang)
file(APPEND ${_qrc} "</qresource> </RCC>")
endif()
qt5_add_resources(LANG_QRC ${_qrc})
8 years ago
qt5_add_resources(QRC resources/res.qrc)
set(COMMON_LIBS matrix_structs Qt5::Widgets Qt5::Network Qt5::Concurrent)
if(APPVEYOR_BUILD)
set(NHEKO_LIBS ${COMMON_LIBS} lmdb)
else()
set(NHEKO_LIBS ${COMMON_LIBS} ${LMDB_LIBRARY})
endif()
set (NHEKO_DEPS ${SRC_FILES} ${UI_HEADERS} ${MOC_HEADERS} ${QRC} ${LANG_QRC} ${QM_SRC} ${META_FILES_TO_INCLUDE})
7 years ago
if(APPLE)
add_executable (nheko ${OS_BUNDLE} ${NHEKO_DEPS})
target_link_libraries (nheko ${NHEKO_LIBS} Qt5::MacExtras Qt5::Multimedia)
7 years ago
elseif(WIN32)
add_executable (nheko ${OS_BUNDLE} ${ICON_FILE} ${NHEKO_DEPS})
target_link_libraries (nheko ${NTDLIB} ${NHEKO_LIBS} Qt5::WinMain Qt5::Multimedia)
7 years ago
else()
add_executable (nheko ${OS_BUNDLE} ${NHEKO_DEPS})
target_link_libraries (nheko ${NHEKO_LIBS} Qt5::Multimedia)
endif()
add_dependencies(nheko MatrixStructs Tweeny lmdbxx)
if(UNIX AND NOT APPLE)
install (TARGETS nheko RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install (FILES "resources/nheko-16.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/16x16/apps" RENAME "nheko.png")
install (FILES "resources/nheko-32.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/32x32/apps" RENAME "nheko.png")
install (FILES "resources/nheko-48.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps" RENAME "nheko.png")
install (FILES "resources/nheko-64.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/64x64/apps" RENAME "nheko.png")
install (FILES "resources/nheko-128.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps" RENAME "nheko.png")
install (FILES "resources/nheko-256.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/256x256/apps" RENAME "nheko.png")
install (FILES "resources/nheko-512.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/512x512/apps" RENAME "nheko.png")
install (FILES "resources/nheko.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
install (FILES "resources/nheko.appdata.xml" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo")
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
endif()