Skip to content

Commit

Permalink
Release for Linux
Browse files Browse the repository at this point in the history
Added Linux support
Improved build.py
Finalized README.md
  • Loading branch information
GTruf committed May 28, 2024
1 parent a358da8 commit daadfe5
Show file tree
Hide file tree
Showing 20 changed files with 315 additions and 224 deletions.
81 changes: 38 additions & 43 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,76 +1,62 @@
# +-----------------------------------------+
# | License: MIT |
# +-----------------------------------------+
# | Copyright (c) 2023 |
# | Copyright (c) 2024 |
# | Author: Gleb Trufanov (aka Glebchansky) |
# +-----------------------------------------+

cmake_minimum_required(VERSION 3.21)

project(ISS-Driver-Drowsiness-Detector)

include(cmake/CheckSystem.cmake)

set(MAIN_TARGET DDDetector)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

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

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_SOURCE_DIR}/src/ui)

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
if (WIN32)
message(STATUS "Windows operating system detected")

if (NOT MSVC)
message(FATAL_ERROR "The project is designed to work with the MSVC compiler when compiling on a Windows operating system")
endif ()

message(STATUS "Disabling the console at program start-up")
add_link_options(/SUBSYSTEM:windows /ENTRY:mainCRTStartup) # To hide the console window at program start-up on Windows
elseif (UNIX AND NOT APPLE)
message(STATUS "Linux kernel operating system detected")
else ()
message(FATAL_ERROR "At this point, the project is only designed to run on Windows or Linux operating systems")
endif ()
else ()
message(FATAL_ERROR "The project is designed to work with an operating system that supports 64-bit extensions")
check_system()

set(EXECUTABLE_DESTINATION_PATH ${CMAKE_BINARY_DIR})

if (UNIX)
set(EXECUTABLE_DESTINATION_PATH ${CMAKE_BINARY_DIR}/bin)
endif ()

set(RESOURCE_CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/resource)
set(RESOURCE_CMAKE_BINARY_DIR ${CMAKE_BINARY_DIR}/resource)
message(STATUS "Set the output directory for the executable to " ${EXECUTABLE_DESTINATION_PATH})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${EXECUTABLE_DESTINATION_PATH})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${EXECUTABLE_DESTINATION_PATH})

message(STATUS "Set the output directory for the executable to " ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(RESOURCE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/resource)
set(RESOURCE_BINARY_DIR ${CMAKE_BINARY_DIR}/resource)

# Project sources
set(TS_FILES ${RESOURCE_CMAKE_SOURCE_DIR}/translation/${PROJECT_NAME}_ru_RU.ts)
set(RC_FILES ${RESOURCE_CMAKE_SOURCE_DIR}/resource.qrc ${RESOURCE_CMAKE_SOURCE_DIR}/executable_icon_resource.rc)
set(TS_FILES ${RESOURCE_SOURCE_DIR}/translation/${PROJECT_NAME}_ru_RU.ts)
set(RC_FILES ${RESOURCE_SOURCE_DIR}/resource.qrc ${RESOURCE_SOURCE_DIR}/executable_icon_resource.rc)

set(PROJECT_SOURCES
${RC_FILES}
${CMAKE_SOURCE_DIR}/src/ui/mainwindow.ui
${CMAKE_SOURCE_DIR}/src/main.cpp
${CMAKE_SOURCE_DIR}/src/MainWindow.h
${CMAKE_SOURCE_DIR}/src/MainWindow.cpp
${CMAKE_SOURCE_DIR}/src/Camera.h
${CMAKE_SOURCE_DIR}/src/Camera.cpp
${CMAKE_SOURCE_DIR}/src/ImageRecognizer.h
${CMAKE_SOURCE_DIR}/src/ImageRecognizer.cpp
${CMAKE_SOURCE_DIR}/src/utils/Utils.h
${CMAKE_SOURCE_DIR}/src/utils/Utils.cpp
${CMAKE_SOURCE_DIR}/src/utils/RecognitionFrameCounter.h
${CMAKE_SOURCE_DIR}/src/utils/TextBrowserLogger.h
${CMAKE_SOURCE_DIR}/src/utils/TextBrowserLogger.cpp
${CMAKE_SOURCE_DIR}/src/ui/mainwindow.ui
)
#####################################################################################

# Find packages
find_package(Qt6 COMPONENTS REQUIRED
find_package(Qt6 6.3 REQUIRED COMPONENTS
LinguistTools
Widgets
Multimedia
Expand All @@ -79,18 +65,14 @@ find_package(Qt6 COMPONENTS REQUIRED
find_package(OpenCV 4.5.4 REQUIRED) # 4.5.4 is the minimum version
#####################################################################################

# Uncomment this to create a QM file based on the TS file.
# A deprecated but working way to update .ts files based on new translations in the source code
# qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})

add_executable(${MAIN_TARGET} ${PROJECT_SOURCES})

# Copying the neural network model and warning sound to the folder with the executable file
# It only works when running cmake command, not during actual build time
file(COPY ${RESOURCE_CMAKE_SOURCE_DIR}/neural_network_model DESTINATION ${RESOURCE_CMAKE_BINARY_DIR})
file(COPY ${RESOURCE_CMAKE_SOURCE_DIR}/sound DESTINATION ${RESOURCE_CMAKE_BINARY_DIR})
# It only works during CMake configuration (build generation), not during the actual build
file(COPY ${RESOURCE_SOURCE_DIR}/neural_network_model DESTINATION ${RESOURCE_BINARY_DIR})
file(COPY ${RESOURCE_SOURCE_DIR}/sound DESTINATION ${RESOURCE_BINARY_DIR})

set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION ${RESOURCE_CMAKE_BINARY_DIR}/translation)
set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION ${RESOURCE_BINARY_DIR}/translation)
qt6_add_translations(${MAIN_TARGET} TS_FILES ${TS_FILES})

target_include_directories(${MAIN_TARGET} PRIVATE
Expand All @@ -99,6 +81,19 @@ target_include_directories(${MAIN_TARGET} PRIVATE
${OpenCV_INCLUDE_DIRS}
)

if (UNIX)
set(RPATH_LIBRARY_DIRECTORIES Qt6 opencv cuda)

foreach (RPATH_DIRECTORY ${RPATH_LIBRARY_DIRECTORIES})
list(APPEND RPATH_LIST "$ORIGIN/../lib64/${RPATH_DIRECTORY}")
endforeach ()

list(JOIN RPATH_LIST ":" RPATH_LIST)

# Lots of problems with escaping $ORIGIN in CMake (target_link_options especially), but thanks https://stackoverflow.com/a/75790542
set_target_properties(${MAIN_TARGET} PROPERTIES LINK_FLAGS "-Wl,--enable-new-dtags,-rpath,'${RPATH_LIST}'")
endif ()

target_link_libraries(${MAIN_TARGET} PRIVATE
Qt6::Widgets
Qt6::Multimedia
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2023 Gleb Trufanov (aka Glebchansky)
Copyright (c) 2024 Gleb Trufanov (aka Glebchansky)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ using facial video surveillance.
- 🎮 Interactive interaction with the prototype:
- Start/stop the recognition system
- Interaction with a video camera
- Eye and gesture recognition ([V gesture ✌](#v-gesture), [Fist gesture ✊](#fist-gesture), [Palm gesture ✋](#palm-gesture))
- Eye and gesture recognition ([V gesture ✌](#v-gesture), [Fist gesture ✊](#fist-gesture), [Palm gesture ✋](#palm-gesture))
- Warning of a potential emergency situation using warning sound
- 🚀 Recognition (drowsiness, gestures, etc.) takes approximately one second
- ⚙️ Multi-language user interface
- ⚙️ Cross-platform (Windows/Linux)
- ⚙️ Multithreaded application

## Dependencies
## Dependencies (Ninja) TODO
- [C++17](https://en.cppreference.com/w/cpp/17):
- 64-bit MSVC since version 19.15 on Windows
- 64-bit GCC since version 11.2 on Linux
Expand Down
37 changes: 21 additions & 16 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# +-----------------------------------------+
# | License: MIT |
# +-----------------------------------------+
# | Copyright (c) 2023 |
# | Copyright (c) 2024 |
# | Author: Gleb Trufanov (aka Glebchansky) |
# +-----------------------------------------+

Expand All @@ -12,27 +12,30 @@
import subprocess

argParser = argparse.ArgumentParser(prog="Driver drowsiness detector")
argParser.add_argument("--qt-cmake-prefix-path", required=True, help="Qt CMake prefix path")
argParser.add_argument("--opencv-dir", required=True, help="Directory containing a CMake configuration file for OpenCV")
argParser.add_argument("-j", "--jobs", default=4, help="Number of threads used when building")

args = argParser.parse_args()

qtCmakePrefixPathDefaultValue = "C:\\Qt\\6.5.2\\msvc2019_64\\lib\\cmake" # Hardcoded default value
opencvDirDefaultValue = "C:\\opencv-4.8.0\\build\\install" # Hardcoded default value
cmakeConfigureArgs = ["cmake"]
cmakeBuildArgs = ["cmake", "--build", "."]

if platform.system() == "Linux":
needShell = False

# On Windows, the generator is not explicitly specified so that the required Visual Studio version of the
# generator is detected automatically
cmakeConfigureArgs.append("-G Ninja") # TODO: Build with Ninja in Linux

qtCmakePrefixPath = "qt_pass" # Hardcoded default value # TODO: Workability in Linux
opencvDir = "opencv_pass" # Hardcoded default value # TODO: Workability in Linux
elif platform.system() != "Windows":
cmakeConfigureArgs.append("-G=Ninja")
cmakeConfigureArgs.append("-DCMAKE_BUILD_TYPE=Release")
elif platform.system() == "Windows":
needShell = True

cmakeConfigureArgs.append("-DCMAKE_CONFIGURATION_TYPES=Release")
cmakeBuildArgs.append("--config=Release")
else:
raise Exception(f"Unexpected operating system. Got {platform.system()}, but expected Windows or Linux")

argParser.add_argument("--qt-cmake-prefix-path", default=qtCmakePrefixPathDefaultValue, help="Qt CMake prefix path")
argParser.add_argument("--opencv-dir", default=opencvDirDefaultValue, help="Directory containing a CMake "
"configuration file for OpenCV")
argParser.add_argument("-j", "--jobs", default=4, help="Number of threads used when building")
args = argParser.parse_args()

shutil.rmtree("build", ignore_errors=True)
os.mkdir("build")
os.chdir("build")
Expand All @@ -41,5 +44,7 @@
cmakeConfigureArgs.append(f"-DOpenCV_DIR={args.opencv_dir}")
cmakeConfigureArgs.append("..")

subprocess.run(cmakeConfigureArgs, shell=True, check=True) # CMake configure
subprocess.run(["cmake", "--build", ".", "--config", "Release", "-j", str(args.jobs)], shell=True, check=True) # Build
cmakeBuildArgs.append(f"-j={str(args.jobs)}")

subprocess.run(cmakeConfigureArgs, shell=needShell, check=True) # CMake configure
subprocess.run(cmakeBuildArgs, shell=needShell, check=True) # Build
24 changes: 24 additions & 0 deletions cmake/CheckSystem.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function(check_system)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
if (WIN32)
message(STATUS "Windows operating system detected")

if (NOT MSVC)
message(FATAL_ERROR "The project is designed to work with the MSVC compiler when compiling on Windows operating system")
endif ()

message(STATUS "Disabling the console at program start-up")
add_link_options(/SUBSYSTEM:windows /ENTRY:mainCRTStartup) # To hide the console window at program start-up on Windows
elseif (UNIX AND NOT APPLE)
message(STATUS "Linux kernel operating system detected")

if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(FATAL_ERROR "The project is designed to work with the GNU compiler (GCC) when compiling on Linux operating system")
endif ()
else ()
message(FATAL_ERROR "At this point, the project is only designed to run on Windows or Linux operating systems")
endif ()
else ()
message(FATAL_ERROR "The project is designed to work with an operating system that supports 64-bit extensions")
endif ()
endfunction()
2 changes: 1 addition & 1 deletion resource/resource.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<qresource prefix="/icons">
<file>images/Flag_of_Russia.svg</file>
<file>images/Flag_of_the_United_Kingdom.svg</file>
<file>images/Main_Window_Icon.png</file>
<file>images/Main_Window_Icon.png</file>
</qresource>
</RCC>
Loading

0 comments on commit daadfe5

Please sign in to comment.