Skip to content

Commit

Permalink
improve mingw compatibility and free the console in additional places (
Browse files Browse the repository at this point in the history
…#588)

* add fixes for mingw compatibility and free the console in additional places

- the flags added using add_defnintions will be appended to all compiler
  tools including the resource compiler (rc) which breaks the build
  use CMAKE_CXX_FLAGS instead.

- close the windows consolewhen the user opens the dlt-viewer using a file
  doubleclick in the windows explorer

* c++17 flag not needed

* add the freeWindowsConsole function

Signed-off-by: sudomgamal <[email protected]>
  • Loading branch information
sudomgamal authored Jan 8, 2025
1 parent 5a66b24 commit 6eb4b0c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ endif()
# Injection of the GCC-specific compilation flags
if(CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "GCC detected, adding compile flags")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
add_definitions("-Wall" "-Wextra" "-pedantic" "-Wno-variadic-macros" "-Wno-strict-aliasing" "-fPIC")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-variadic-macros -Wno-strict-aliasing -fPIC")
endif()

add_compile_definitions(QT5)
Expand Down
41 changes: 27 additions & 14 deletions qdlt/qdltoptmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ void QDltOptManager::printUsage(const QString& helpText)
qDebug() << " dlt-viewer.exe -t -c output.txt input1.mf4 input2.mf4";
}

void QDltOptManager::freeWindowsConsole()
{
#if (WIN32 || WIN64)
HWND consoleWnd = GetConsoleWindow();
DWORD dwProcessId;
GetWindowThreadProcessId(consoleWnd, &dwProcessId);
if (GetCurrentProcessId() == dwProcessId)
{
FreeConsole();
}
#endif
}

void QDltOptManager::parse(const QStringList& args)
{
m_parser.parse(args);
Expand All @@ -120,18 +133,26 @@ void QDltOptManager::parse(const QStringList& args)
if (m_parser.optionNames().isEmpty() && m_parser.positionalArguments().size() == 1)
{
const QString& arg = m_parser.positionalArguments().at(0);
bool closeConsole = false;
if(arg.endsWith(".dlp") || arg.endsWith(".DLP"))
{
projectFile = arg;
project = true;
qDebug()<< "Project filename:" << projectFile;
return;
closeConsole = true;
}
if (arg.endsWith(".dlt") || arg.endsWith(".DLT"))
{
const QString logFile = arg;
logFiles += logFile;
qDebug()<< "DLT filename:" << logFile;
closeConsole = true;
}

if(closeConsole)
{
// user launched the application with a double click on a dlt/project file: we do not need console
freeWindowsConsole();
return;
}
}
Expand Down Expand Up @@ -246,19 +267,11 @@ void QDltOptManager::parse(const QStringList& args)
* Unfortunateley Windows opens a console anyway.
* So we have to close it in this case
*/
#if (WIN32)
if (!commandline_mode)
{
HWND consoleWnd = GetConsoleWindow();
DWORD dwProcessId;
GetWindowThreadProcessId(consoleWnd, &dwProcessId);
if (GetCurrentProcessId() == dwProcessId)
{
// user launched the application with a double click from explorer: we do not need console
FreeConsole();
}
}
#endif
if (!commandline_mode)
{
// user launched the application with a double click from explorer: we do not need console
freeWindowsConsole();
}
}

bool QDltOptManager::isProjectFile(){ return project;}
Expand Down
1 change: 1 addition & 0 deletions qdlt/qdltoptmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class QDLT_EXPORT QDltOptManager
void printUsage(const QString& helpText);
void printVersion(QString appname);
void parse(const QStringList& opt);
void freeWindowsConsole();

bool isProjectFile();
bool isTerminate();
Expand Down
13 changes: 7 additions & 6 deletions scripts/windows/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
)

set(VS_VERSION ${MSVC_TOOLSET_VERSION})
string(REPLACE "140" "msvc2015" VS_VERSION ${VS_VERSION})
string(REPLACE "141" "msvc2017" VS_VERSION ${VS_VERSION})
string(REPLACE "142" "msvc2019" VS_VERSION ${VS_VERSION})
string(REPLACE "143" "msvc2022" VS_VERSION ${VS_VERSION})

if(MSVC)
set(VS_VERSION ${MSVC_TOOLSET_VERSION})
string(REPLACE "140" "msvc2015" VS_VERSION ${VS_VERSION})
string(REPLACE "141" "msvc2017" VS_VERSION ${VS_VERSION})
string(REPLACE "142" "msvc2019" VS_VERSION ${VS_VERSION})
string(REPLACE "143" "msvc2022" VS_VERSION ${VS_VERSION})
endif()
set(DLT_VERSION_SUFFIX "STABLE-qt${DLT_QT_VERSION}-r${GIT_PATCH_VERSION}_${VS_VERSION}_${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")

0 comments on commit 6eb4b0c

Please sign in to comment.