Skip to content

Commit 9170ab1

Browse files
build: init cmake
1 parent b658190 commit 9170ab1

File tree

10 files changed

+177
-1
lines changed

10 files changed

+177
-1
lines changed

CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Preamble
2+
cmake_minimum_required(VERSION 3.20)
3+
project(trik-desktop-gamepad VERSION 1.0.0 LANGUAGES CXX)
4+
5+
# Project wide setup
6+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
7+
8+
set(CMAKE_CXX_STANDARD 14)
9+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
10+
set(CMAKE_CXX_EXTENSIONS OFF)
11+
12+
set(CMAKE_AUTOUIC ON)
13+
set(CMAKE_AUTOMOC ON)
14+
set(CMAKE_AUTORCC ON)
15+
16+
# Prevent from build in source dir
17+
include(NoInSourceBuilds)
18+
19+
# Externally provided content
20+
include(QtHelper)
21+
add_subdirectory(dependencies)
22+
23+
# Main targets built by this project
24+
add_subdirectory(src)
25+
26+
# Process fonts, images, translations
27+
add_subdirectory(share)
28+
29+
# TO DO:
30+
# add_subdirectory(tests)
31+
32+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
33+
add_subdirectory(packaging)
34+
endif()

cmake/NoInSourceBuilds.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
2+
message(FATAL_ERROR
3+
"\n"
4+
"In-source builds are not allowed.\n"
5+
"Instead, provide a path to build tree like so:\n"
6+
"cmake -B <destination>\n"
7+
"\n"
8+
"To remove files you accidentally created execute:\n"
9+
"rm -rf CMakeFiles CMakeCache.txt\n"
10+
)
11+
endif()

cmake/QtHelper.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
set(QT_COMPONENTS
2+
Core
3+
Gui
4+
Network
5+
Widgets
6+
Multimedia
7+
MultimediaWidgets
8+
LinguistTools)
9+
10+
#find_package(Qt6 COMPONENTS ${QT_COMPONENTS})
11+
#if (NOT Qt6_FOUND)
12+
# find_package(Qt5 5.15 REQUIRED ${QT_COMPONENTS})
13+
#endif()
14+
15+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS ${QT_COMPONENTS})
16+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ${QT_COMPONENTS})
17+
18+
message("FOUND QT (default): ${QT_DEFAULT_MAJOR_VERSION}")
19+
message("FOUND QT: ${QT_VERSION_MAJOR}")
20+
21+
set(QT_LIBRARIES
22+
Qt${QT_VERSION_MAJOR}::Core
23+
Qt${QT_VERSION_MAJOR}::Gui
24+
Qt${QT_VERSION_MAJOR}::Network
25+
Qt${QT_VERSION_MAJOR}::Widgets
26+
Qt${QT_VERSION_MAJOR}::Multimedia
27+
Qt${QT_VERSION_MAJOR}::MultimediaWidgets)

cmake/TranslationUtils.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function(ADD_TRANSLATIONS_RESOURCE res_file)
2+
set(QM_FILES ${ARGN})
3+
set(RES_FILE ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc)
4+
5+
file(WRITE ${RES_FILE} "<!DOCTYPE RCC><RCC version=\"1.0\">\n <qresource prefix=\"/\">\n")
6+
foreach(LANG ${QM_FILES})
7+
get_filename_component(FILENAME ${LANG} NAME)
8+
file(APPEND ${RES_FILE} " <file>${FILENAME}</file>\n")
9+
endforeach()
10+
file(APPEND ${RES_FILE} " </qresource>\n</RCC>\n")
11+
12+
set(${res_file} ${RES_FILE} PARENT_SCOPE)
13+
endfunction()

dependencies/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SingleApplication
2+
set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication")
3+
add_subdirectory(singleapplication)

packaging/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
2+
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
3+
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
4+
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
5+
6+
# Generate file name in deb format:
7+
# <PackageName>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb
8+
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
9+
10+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
11+
"A remote control for controlling TRIK programmable educational robots")
12+
set(CPACK_PACKAGE_VENDOR "TRIK")
13+
14+
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
15+
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/${PROJECT_NAME}")
16+
17+
set(CPACK_PACKAGE_CONTACT $ENV{DEBMAIL})
18+
set(CPACK_DEBIAN_PACKAGE_MAINTAINER $ENV{DEBFULLNAME})
19+
20+
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
21+
22+
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
23+
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
24+
25+
# Values of variables prefixed with CPACK_ will be escaped before being written to the configuration files,
26+
# so that the cpack program receives them exactly as they were specified
27+
set(CPACK_VERBATIM_VARIABLES YES)
28+
29+
# Generate defined format of packages in case running cpack without arguments
30+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
31+
set(CPACK_GENERATOR DEB)
32+
else()
33+
set(CPACK_GENERATOR TGZ)
34+
endif()
35+
36+
include(CPack)

share/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include(GNUInstallDirs)
2+
install(
3+
DIRECTORY fonts images
4+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}
5+
)
6+
7+
add_subdirectory(translations)

share/translations/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set(TS_FILES
2+
trikDesktopGamepad_de.ts
3+
trikDesktopGamepad_en.ts
4+
trikDesktopGamepad_ru.ts
5+
trikDesktopGamepad_fr.ts)
6+
7+
if(Qt6_FOUND)
8+
qt_add_translations(${PROJECT_NAME} TS_FILES ${TS_FILES})
9+
else()
10+
qt5_add_translation(QM_FILES ${TS_FILES})
11+
include(TranslationUtils)
12+
add_translations_resource(QRC_FILE ${QM_FILES})
13+
target_sources(${PROJECT_NAME} PRIVATE ${QM_FILES} ${QRC_FILE})
14+
endif()
15+
16+
install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/translations)

src/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
set(SOURCES
2+
accelerateStrategy.cpp
3+
connectForm.cpp
4+
connectionManager.cpp
5+
gamepadForm.cpp
6+
main.cpp
7+
standardStrategy.cpp
8+
strategy.cpp
9+
../share/fonts.qrc
10+
../share/images.qrc)
11+
12+
add_executable(${PROJECT_NAME} ${SOURCES})
13+
14+
target_link_libraries(${PROJECT_NAME}
15+
PRIVATE
16+
${QT_LIBRARIES}
17+
SingleApplication
18+
)
19+
20+
if(Qt6_FOUND)
21+
target_compile_definitions(${PROJECT_NAME} PRIVATE TRIK_USE_QT6)
22+
endif()
23+
24+
set_target_properties(${PROJECT_NAME}
25+
PROPERTIES
26+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
27+
)
28+
29+
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BIN})

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* "pad 1 0 -100\n", excluding quotes.
3333
* */
3434

35-
#include "thirdparty/SingleApplication/singleapplication.h"
35+
#include "../dependencies/singleapplication/singleapplication.h"
3636

3737
#include "gamepadForm.h"
3838

0 commit comments

Comments
 (0)