Skip to content

Commit

Permalink
build: init cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-talalai committed Dec 13, 2023
1 parent b658190 commit 33b11ec
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 1 deletion.
34 changes: 34 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Preamble
cmake_minimum_required(VERSION 3.20)
project(trik-desktop-gamepad VERSION 1.0.0 LANGUAGES CXX)

# Project wide setup
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

# Prevent from build in source dir
include(NoInSourceBuilds)

# Externally provided content
include(QtHelper)
add_subdirectory(dependencies)

# Main targets built by this project
add_subdirectory(src)

# Process fonts, images, translations
add_subdirectory(share)

# TO DO:
# add_subdirectory(tests)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
add_subdirectory(packaging)
endif()
11 changes: 11 additions & 0 deletions cmake/NoInSourceBuilds.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR
"\n"
"In-source builds are not allowed.\n"
"Instead, provide a path to build tree like so:\n"
"cmake -B <destination>\n"
"\n"
"To remove files you accidentally created execute:\n"
"rm -rf CMakeFiles CMakeCache.txt\n"
)
endif()
27 changes: 27 additions & 0 deletions cmake/QtHelper.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
set(QT_COMPONENTS
Core
Gui
Network
Widgets
Multimedia
MultimediaWidgets
LinguistTools)

#find_package(Qt6 COMPONENTS ${QT_COMPONENTS})
#if (NOT Qt6_FOUND)
# find_package(Qt5 5.15 REQUIRED ${QT_COMPONENTS})
#endif()

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS ${QT_COMPONENTS})
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ${QT_COMPONENTS})

message("FOUND QT (default): ${QT_DEFAULT_MAJOR_VERSION}")
message("FOUND QT: ${QT_VERSION_MAJOR}")

set(QT_LIBRARIES
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Multimedia
Qt${QT_VERSION_MAJOR}::MultimediaWidgets)
12 changes: 12 additions & 0 deletions cmake/TranslationUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function(ADD_TRANSLATIONS_RESOURCE res_file)
set(QM_FILES ${ARGN})
set(RES_FILE ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc)

file(WRITE ${RES_FILE} "<!DOCTYPE RCC><RCC version=\"1.0\">\n <qresource prefix=\"/\">\n")
foreach(LANG ${QM_FILES})
get_filename_component(FILENAME ${LANG} NAME)
file(APPEND ${RES_FILE} " <file alias=\"i18n/${FILENAME}\">${FILENAME}</file>\n")
endforeach()
file(APPEND ${RES_FILE} " </qresource>\n</RCC>\n")
set(${res_file} ${RES_FILE} PARENT_SCOPE)
endfunction()
3 changes: 3 additions & 0 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SingleApplication
set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication")
add_subdirectory(singleapplication)
36 changes: 36 additions & 0 deletions packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})

# Generate file name in deb format:
# <PackageName>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)

set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"A remote control for controlling TRIK programmable educational robots")
set(CPACK_PACKAGE_VENDOR "TRIK")

set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/${PROJECT_NAME}")

set(CPACK_PACKAGE_CONTACT $ENV{DEBMAIL})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER $ENV{DEBFULLNAME})

set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)

set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")

# Values of variables prefixed with CPACK_ will be escaped before being written to the configuration files,
# so that the cpack program receives them exactly as they were specified
set(CPACK_VERBATIM_VARIABLES YES)

# Generate defined format of packages in case running cpack without arguments
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CPACK_GENERATOR DEB)
else()
set(CPACK_GENERATOR TGZ)
endif()

include(CPack)
7 changes: 7 additions & 0 deletions share/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include(GNUInstallDirs)
install(
DIRECTORY fonts images
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}
)

add_subdirectory(translations)
20 changes: 20 additions & 0 deletions share/translations/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set(TS_FILES
trikDesktopGamepad_de.ts
trikDesktopGamepad_en.ts
trikDesktopGamepad_ru.ts
trikDesktopGamepad_fr.ts)

if(Qt6_FOUND)
qt_add_translations(${PROJECT_NAME} TS_FILES ${TS_FILES})
else()
qt5_add_translation(QM_FILES ${TS_FILES})
include(TranslationUtils)
add_translations_resource(QRC_FILE ${QM_FILES})
add_custom_target(create_qm ALL DEPENDS ${QM_FILES})
add_custom_target(create_qrc ALL DEPENDS ${QRC_FILE})
add_dependencies(create_qrc create_qm)
add_dependencies(${PROJECT_NAME} create_qrc)
target_sources(${PROJECT_NAME} PRIVATE ${QRC_FILE})
endif()

install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/translations)
29 changes: 29 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
set(SOURCES
accelerateStrategy.cpp
connectForm.cpp
connectionManager.cpp
gamepadForm.cpp
main.cpp
standardStrategy.cpp
strategy.cpp
../share/fonts.qrc
../share/images.qrc)

add_executable(${PROJECT_NAME} ${SOURCES})

target_link_libraries(${PROJECT_NAME}
PRIVATE
${QT_LIBRARIES}
SingleApplication
)

if(Qt6_FOUND)
target_compile_definitions(${PROJECT_NAME} PRIVATE TRIK_USE_QT6)
endif()

set_target_properties(${PROJECT_NAME}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BIN})
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* "pad 1 0 -100\n", excluding quotes.
* */

#include "thirdparty/SingleApplication/singleapplication.h"
#include "../dependencies/singleapplication/singleapplication.h"

#include "gamepadForm.h"

Expand Down

0 comments on commit 33b11ec

Please sign in to comment.