Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Add cmake build system #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
cmake_minimum_required(VERSION 3.5)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")

project(rrcc VERSION 0.8.2 LANGUAGES C CXX)

include(GNUInstallDirs)

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed
set(CMAKE_AUTOMOC ON)
# Create code from a list of Qt designer ui files
#set(CMAKE_AUTOUIC ON)

find_package(Qt5Core CONFIG REQUIRED)
find_package(Qt5Widgets CONFIG REQUIRED)
find_package(Qt5Network CONFIG REQUIRED)
find_package(Qt5Concurrent CONFIG REQUIRED)
find_package(Qt5LinguistTools CONFIG REQUIRED)

find_package(libssh CONFIG REQUIRED)
find_package(libarchive REQUIRED)

# Checks for config.h
include(ConfigureChecks.cmake)
configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)

set(rrcc_SRCS
mainwindow.cpp
history.cpp
timer.cpp
setup.cpp
logger.cpp
upload.cpp
packager.cpp
unpackager.cpp
converter.cpp
about.cpp
zones.cpp
installer.cpp
uninstaller.cpp
update.cpp
download.cpp)

set(qarchive_SRCS
ext/qarchive/qarchive.cpp)

set(qaes_SRCS
ext/qaes/qaesencryption.cpp)

set(qsshsocket_SRCS
ext/qsshsocket/qsshsocket.cpp)

set(ccrypt_SRCS
ext/ccrypt/ccryptlib.c
ext/ccrypt/rijndael.c
ext/ccrypt/tables.c
ext/ccrypt/platform.c)

qt5_wrap_ui(rrcc_FORMS
res/ui/about.ui
res/ui/converter.ui
res/ui/download.ui
res/ui/history.ui
res/ui/installer.ui
res/ui/logger.ui
res/ui/mainwindow.ui
res/ui/packager.ui
res/ui/setup.ui
res/ui/timer.ui
res/ui/uninstaller.ui
res/ui/unpackager.ui
res/ui/update.ui
res/ui/upload.ui
res/ui/zones.ui)

qt5_add_resources(rrcc_RSCS
res/rrcc.qrc)

add_executable(rrcc
${rrcc_SRCS}
${qarchive_SRCS}
${qaes_SRCS}
${qsshsocket_SRCS}
${ccrypt_SRCS}
${rrcc_FORMS}
${rrcc_RSCS})

target_include_directories(rrcc
PRIVATE
ext/ccrypt
ext/qaes
ext/qarchive
ext/qsshsocket
${LIBSSH_INCLUDE_DIR}
${LIBARCHIVE_INCLUDE_DIR})

target_link_libraries(rrcc
Qt5::Core
Qt5::Widgets
Qt5::Concurrent
Qt5::Network
${LIBSSH_LIBRARIES}
${LIBARCHIVE_LIBRARIES})

install(TARGETS
rrcc
ARCHIVE DESTINATION
${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION
${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION
${CMAKE_INSTALL_BINDIR}
COMPONENT ${PROJECT_NAME})

add_subdirectory(res)
3 changes: 3 additions & 0 deletions ConfigureChecks.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# in-tree and installation resource directories
set(RRCC_INSOURCE_RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res")
set(RRCC_INSTALL_RESOURCE_DIR ${CMAKE_INSTALL_FULL_DATADIR}/resources)
54 changes: 54 additions & 0 deletions cmake/Modules/Findlibarchive.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# - Try to find libarchive
# Once done this will define
#
# LIBARCHIVE_FOUND - system has libarchive
# LIBARCHIVE_INCLUDE_DIR - the libarchive include directory
# LIBARCHIVE_LIBRARIES - Link these to use libarchive
# LIBARCHIVE_DEFINITIONS - Compiler switches required for using libarchive
#
#=============================================================================
# Copyright (c) 2018 Andreas Schneider <[email protected]>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
#

if (UNIX)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_LIBARCHIVE libarchive)
endif (PKG_CONFIG_FOUND)
endif (UNIX)

find_path(LIBARCHIVE_INCLUDE_DIR
NAMES
archive.h
PATHS
${_LIBARCHIVE_INCLUDEDIR}
)

find_library(ARCHIVE_LIBRARY
NAMES
archive
PATHS
${_LIBARCHIVE_LIBDIR}
)

if (ARCHIVE_LIBRARY)
set(LIBARCHIVE_LIBRARIES
${LIBARCHIVE_LIBRARIES}
${ARCHIVE_LIBRARY}
)
endif (ARCHIVE_LIBRARY)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(libarchive DEFAULT_MSG LIBARCHIVE_LIBRARIES LIBARCHIVE_INCLUDE_DIR)

# show the LIBARCHIVE_INCLUDE_DIR and LIBARCHIVE_LIBRARIES variables only in the advanced view
mark_as_advanced(LIBARCHIVE_INCLUDE_DIR LIBARCHIVE_LIBRARIES)

2 changes: 2 additions & 0 deletions config.h.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#cmakedefine RRCC_INSOURCE_RESOURCE_DIR "${RRCC_INSOURCE_RESOURCE_DIR}"
#cmakedefine RRCC_INSTALL_RESOURCE_DIR "${RRCC_INSTALL_RESOURCE_DIR}"
17 changes: 14 additions & 3 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "mainwindow.h"
#include "config.h"

int main(int argc, char *argv[])
{
Expand All @@ -17,15 +18,25 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)

if(!QLocale::system().name().startsWith("en_"))
{
if(appTranslator.load("rrcc_" + QLocale::system().name(), QApplication::applicationDirPath() + "/lng"))
QString resource_dir;

resource_dir = QString::fromUtf8(RRCC_INSOURCE_RESOURCE_DIR);
if (!QDir(resource_dir).exists()) {
resource_dir = QString::fromUtf8(RRCC_INSTALL_RESOURCE_DIR);
if (!QDir(resource_dir).exists()) {
resource_dir = QApplication::applicationDirPath();
}
}

if(appTranslator.load("rrcc_" + QLocale::system().name(), resource_dir + "/lang"))
{
QApplication::installTranslator(&appTranslator);

if(baseTranslator.load("qtbase_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
{
QApplication::installTranslator(&baseTranslator);
}
else if(baseTranslator.load("qtbase_" + QLocale::system().name(), QApplication::applicationDirPath() + "/lng"))
else if(baseTranslator.load("qtbase_" + QLocale::system().name(), resource_dir + "/lang"))
{
QApplication::installTranslator(&baseTranslator);
}
Expand All @@ -34,7 +45,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
QApplication::installTranslator(&helpTranslator);
}
else if(helpTranslator.load("qt_help_" + QLocale::system().name(), QApplication::applicationDirPath() + "/lng"))
else if(helpTranslator.load("qt_help_" + QLocale::system().name(), resource_dir + "/lang"))
{
QApplication::installTranslator(&helpTranslator);
}
Expand Down
2 changes: 2 additions & 0 deletions res/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(ico)
add_subdirectory(lang)
11 changes: 11 additions & 0 deletions res/ico/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
install(FILES
app.png
DESTINATION
${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/resources/icons)

install(FILES
app.png
RENAME
${PROJECT_NAME}.png
DESTINATION
${CMAKE_INSTALL_DATADIR}/icons/hicolor/256x256/apps)
8 changes: 8 additions & 0 deletions res/lang/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
qt5_add_translation(rrcc_QM_FILES
rrcc_de.ts)
add_custom_target(translations ALL DEPENDS ${rrcc_QM_FILES})

install(FILES
${rrcc_QM_FILES}
DESTINATION
${CMAKE_INSTALL_DATADIR}/rrcc/resources/lang)
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion rrcc.pro
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LIBS += -lssh
FORMS += res/ui/mainwindow.ui res/ui/history.ui res/ui/timer.ui res/ui/setup.ui res/ui/logger.ui res/ui/upload.ui res/ui/packager.ui res/ui/unpackager.ui res/ui/converter.ui res/ui/about.ui res/ui/zones.ui res/ui/installer.ui res/ui/uninstaller.ui res/ui/update.ui res/ui/download.ui
RESOURCES += res/rrcc.qrc

TRANSLATIONS+= lng/rrcc_de.ts
TRANSLATIONS+= res/lang/rrcc_de.ts

unix:!macx {
QMAKE_LFLAGS+= -Wl,-rpath=.
Expand Down