Skip to content

Commit

Permalink
changes to support msvc builds with qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Mar 27, 2024
1 parent 66c716d commit ce3f743
Show file tree
Hide file tree
Showing 25 changed files with 122 additions and 52 deletions.
20 changes: 9 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,15 @@ if (USE_OPENCL)
endif()

# Configure CCache if available
if(NOT MSVC)
option(USE_CCACHE "Use ccache" ON)
if (USE_CCACHE)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
message(STATUS "ccache found")
endif(CCACHE_FOUND)
endif(USE_CCACHE)
endif(NOT MSVC)
option(USE_CCACHE "Use ccache" ON)
if (USE_CCACHE)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
message(STATUS "ccache found")
endif(CCACHE_FOUND)
endif(USE_CCACHE)

if (IOS)
set (DEFAULT_FORCE_STATIC_LIBS TRUE)
Expand Down
2 changes: 1 addition & 1 deletion external/mdal/frmts/mdal_h2i.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ bool MDAL::DriverH2i::parseJsonFile( const std::string filePath, MetadataH2i &me
metadata.dirPath = MDAL::dirName( filePath );

}
catch ( Json::exception &e )
catch ( Json::exception & )
{
return false;
}
Expand Down
14 changes: 8 additions & 6 deletions external/mdal/mdal_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include <stdlib.h>

#ifdef _MSC_VER
#ifndef UNICODE
#define UNICODE
#endif
#include <locale>
#include <codecvt>
#include <stringapiset.h>
Expand Down Expand Up @@ -1113,12 +1115,12 @@ std::vector<std::string> MDAL::Library::libraryFilesInDir( const std::string &di
{
std::vector<std::string> filesList;
#ifdef _WIN32
WIN32_FIND_DATA data;
WIN32_FIND_DATAA data;
HANDLE hFind;
std::string pattern = dirPath;
pattern.push_back( '*' );

hFind = FindFirstFile( pattern.c_str(), &data );
hFind = FindFirstFileA( pattern.c_str(), &data );

if ( hFind == INVALID_HANDLE_VALUE )
return filesList;
Expand All @@ -1129,7 +1131,7 @@ std::vector<std::string> MDAL::Library::libraryFilesInDir( const std::string &di
if ( !fileName.empty() && fileExtension( fileName ) == ".dll" )
filesList.push_back( fileName );
}
while ( FindNextFile( hFind, &data ) != 0 );
while ( FindNextFileA( hFind, &data ) != 0 );

FindClose( hFind );
#else
Expand All @@ -1140,8 +1142,8 @@ std::vector<std::string> MDAL::Library::libraryFilesInDir( const std::string &di
std::string fileName( de->d_name );
if ( !fileName.empty() )
{
std::string extentsion = fileExtension( fileName );
if ( extentsion == ".so" || extentsion == ".dylib" )
std::string extension = fileExtension( fileName );
if ( extension == ".so" || extension == ".dylib" )
filesList.push_back( fileName );
}
de = readdir( dir );
Expand All @@ -1160,7 +1162,7 @@ bool MDAL::Library::loadLibrary()
#ifdef _WIN32
UINT uOldErrorMode =
SetErrorMode( SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS );
d->mLibrary = LoadLibrary( d->mLibraryFile.c_str() );
d->mLibrary = LoadLibraryA( d->mLibraryFile.c_str() );
SetErrorMode( uOldErrorMode );
#else
d->mLibrary = dlopen( d->mLibraryFile.c_str(), RTLD_LAZY );
Expand Down
14 changes: 7 additions & 7 deletions external/qspatialite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ add_definitions(-DQT_SHARED)

include_directories(SYSTEM
${SQLITE3_INCLUDE_DIR}
${Qt5Sql_PRIVATE_INCLUDE_DIRS}
${${QT_VERSION_BASE}Sql_PRIVATE_INCLUDE_DIRS}
)

set(QSQLSPATIALITE_SRC qsql_spatialite.cpp smain.cpp)
QT5_WRAP_CPP(QSQLSPATIALITE_SRC qsql_spatialite.h smain.h)
set(QSQLSPATIALITE_SRC qsql_spatialite.cpp smain.cpp qsql_spatialite.h smain.h)

add_library(qsqlspatialite SHARED ${QSQLSPATIALITE_SRC})

target_link_libraries(qsqlspatialite
${Qt5Core_LIBRARIES}
${Qt5Sql_LIBRARIES}
spatialite::spatialite
qgis_core
${QT_VERSION_BASE}::Core
${QT_VERSION_BASE}::Sql
spatialite::spatialite
qgis_core
)

install(TARGETS qsqlspatialite
Expand Down
2 changes: 1 addition & 1 deletion external/qspatialite/qsql_spatialite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ bool QSpatiaLiteDriver::open( const QString &db, const QString &, const QString
bool openReadOnlyOption = false;
bool openUriOption = false;

const auto opts = conOpts.splitRef( QLatin1Char( ';' ) );
const auto opts = conOpts.split( QLatin1Char( ';' ) );
for ( auto option : opts )
{
option = option.trimmed();
Expand Down
2 changes: 1 addition & 1 deletion external/untwine/api/QgisUntwine_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool QgisUntwine::start(Options& options)
cmdline += "--" + op.first + " \"" + op.second + "\" ";

PROCESS_INFORMATION processInfo;
STARTUPINFO startupInfo;
STARTUPINFOA startupInfo;

ZeroMemory(&processInfo, sizeof(PROCESS_INFORMATION));
ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
Expand Down
2 changes: 2 additions & 0 deletions python/PyQt6/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@
%Include auto_generated/editorwidgets/qgsdefaultsearchwidgetwrapper.sip
%Include auto_generated/editorwidgets/qgsdoublespinbox.sip
%Include auto_generated/editorwidgets/qgshtmlwidgetwrapper.sip
%If ( HAVE_QSCI_SIP )
%Include auto_generated/editorwidgets/qgsjsoneditwidget.sip
%End
%Include auto_generated/editorwidgets/qgsmultiedittoolbutton.sip
%Include auto_generated/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.sip
%Include auto_generated/editorwidgets/qgsrelationreferencesearchwidgetwrapper.sip
Expand Down
2 changes: 2 additions & 0 deletions python/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@
%Include auto_generated/editorwidgets/qgsdefaultsearchwidgetwrapper.sip
%Include auto_generated/editorwidgets/qgsdoublespinbox.sip
%Include auto_generated/editorwidgets/qgshtmlwidgetwrapper.sip
%If ( HAVE_QSCI_SIP )
%Include auto_generated/editorwidgets/qgsjsoneditwidget.sip
%End
%Include auto_generated/editorwidgets/qgsmultiedittoolbutton.sip
%Include auto_generated/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.sip
%Include auto_generated/editorwidgets/qgsrelationreferencesearchwidgetwrapper.sip
Expand Down
4 changes: 4 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ if (ANDROID)
else()
add_executable(${QGIS_APP_NAME} MACOSX_BUNDLE WIN32 ${QGIS_APPMAIN_SRCS})

if(MSVC AND BUILD_WITH_QT6)
qt_disable_unicode_defines(${QGIS_APP_NAME})
endif(MSVC AND BUILD_WITH_QT6)

# require c++17
target_compile_features(${QGIS_APP_NAME} PRIVATE cxx_std_17)
target_compile_definitions(${QGIS_APP_NAME} PRIVATE "QT_PLUGINS_DIR=\"${QT_PLUGINS_DIR}\"")
Expand Down
10 changes: 5 additions & 5 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ void usage( const QString &appName )
<< QStringLiteral( " the PostGIS extension\n" ) ; // OK

#ifdef Q_OS_WIN
MessageBox( nullptr,
msg.join( QString() ).toLocal8Bit().constData(),
"QGIS command line options",
MB_OK );
MessageBoxA( nullptr,
msg.join( QString() ).toLocal8Bit().constData(),
"QGIS command line options",
MB_OK );
#else
std::cout << msg.join( QString() ).toLocal8Bit().constData();
#endif
Expand Down Expand Up @@ -219,7 +219,7 @@ void myPrint( const char *fmt, ... )
#if defined(Q_OS_WIN)
char buffer[1024];
vsnprintf( buffer, sizeof buffer, fmt, ap );
OutputDebugString( buffer );
OutputDebugStringA( buffer );
#else
vfprintf( stderr, fmt, ap );
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13038,7 +13038,7 @@ void QgisApp::openURL( QString url, bool useQgisDocDirectory )
CFRelease( urlRef );
#elif defined(Q_OS_WIN)
if ( url.startsWith( "file://", Qt::CaseInsensitive ) )
ShellExecute( 0, 0, url.mid( 7 ).toLocal8Bit().constData(), 0, 0, SW_SHOWNORMAL );
ShellExecuteA( 0, 0, url.mid( 7 ).toLocal8Bit().constData(), 0, 0, SW_SHOWNORMAL );
else
QDesktopServices::openUrl( url );
#else
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitemlegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ void QgsLayoutItemLegend::doUpdateFilterByMap()
{
mapExtent.transform( mapTransform );
}
catch ( QgsCsException &cse )
catch ( QgsCsException & )
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/mesh/qgstopologicalmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ QgsMeshEditingError QgsTopologicalMesh::counterClockwiseFaces( QgsMeshFace &face
if ( error != QgsMeshEditingError() )
return error;

if ( clockwise > 0 )// clockwise --> reverse the order of the index;
if ( clockwise )// clockwise --> reverse the order of the index;
{
for ( int i = 0; i < faceSize / 2; ++i )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/pal/labelposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ double LabelPosition::getDistanceToPoint( double xp, double yp, bool useOuterBou
geos::unique_ptr point( GEOSGeom_createPointFromXY_r( geosctxt, xp, yp ) );
contains = ( GEOSPreparedContainsProperly_r( geosctxt, mPreparedOuterBoundsGeos, point.get() ) == 1 );
}
catch ( GEOSException &e )
catch ( GEOSException & )
{
contains = false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/pointcloud/qgslazdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
#include "lazperf/readers.hpp"

#if defined(_MSC_VER)
#ifndef UNICODE
#define UNICODE
#endif
#include <locale>
#include <codecvt>
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/pointcloud/qgspointcloudlayerrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ void QgsPointCloudLayerRenderer::renderTriangulatedSurface( QgsPointCloudRenderC
{
delaunator.reset( new delaunator::Delaunator( points ) );
}
catch ( std::exception &e )
catch ( std::exception & )
{
// something went wrong, better to retrieve initial state
QgsDebugMsgLevel( QStringLiteral( "Error with triangulation" ), 4 );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsattributetableconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CORE_EXPORT QgsAttributeTableConfig
/**
* Defines the configuration of a column in the attribute table.
*/
struct ColumnConfig
struct CORE_EXPORT ColumnConfig
{
//! Constructor for ColumnConfig
ColumnConfig() = default;
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsexpressioncontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ void QgsExpressionContextScope::addVariable( const QgsExpressionContextScope::St

bool QgsExpressionContextScope::removeVariable( const QString &name )
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return mVariables.remove( name );
#else
return mVariables.remove( name ) > 0;
#endif
}

bool QgsExpressionContextScope::hasVariable( const QString &name ) const
Expand Down
27 changes: 23 additions & 4 deletions src/core/qgsopenclutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <QDebug>

#ifdef Q_OS_WIN
#if defined(UNICODE) && !defined(_UNICODE)
#pragma message(_UNICODE undefined)
#define _UNICODE
#endif
#include <windows.h>
#include <tchar.h>
#endif
Expand Down Expand Up @@ -100,7 +104,12 @@ void QgsOpenClUtils::init()
}

#ifdef Q_OS_WIN
HMODULE hModule = GetModuleHandle( "OpenCL.dll" );
#ifdef _UNICODE
#define _T(x) L##x
#else
#define _T(x) x
#endif
HMODULE hModule = GetModuleHandle( _T( "OpenCL.dll" ) );
if ( hModule )
{
TCHAR pszFileName[1024];
Expand All @@ -114,13 +123,13 @@ void QgsOpenClUtils::init()
DWORD dwLen = GetFileVersionInfoSize( pszFileName, &dwUseless );
if ( dwLen )
{
LPTSTR lpVI = ( LPSTR ) malloc( dwLen );
LPTSTR lpVI = ( LPTSTR ) malloc( dwLen * sizeof( TCHAR ) );
if ( lpVI )
{
if ( GetFileVersionInfo( pszFileName, 0, dwLen, lpVI ) )
{
VS_FIXEDFILEINFO *lpFFI;
if ( VerQueryValue( lpVI, "\\", ( LPVOID * ) &lpFFI, ( UINT * ) &dwUseless ) )
if ( VerQueryValue( lpVI, _T( "\\" ), ( LPVOID * ) &lpFFI, ( UINT * ) &dwUseless ) )
{
QgsMessageLog::logMessage( QObject::tr( "OpenCL Product version: %1.%2.%3.%4" )
.arg( lpFFI->dwProductVersionMS >> 16 )
Expand Down Expand Up @@ -163,13 +172,23 @@ void QgsOpenClUtils::init()

QgsDebugMsgLevel( QString( "d:%1 subBlock:%2" ).arg( d ).arg( subBlock ), 2 );

BOOL r = VerQueryValue( lpVI, subBlock.toUtf8(), ( LPVOID * )&lpBuffer, ( UINT * )&dwUseless );
BOOL r = VerQueryValue( lpVI,
#ifdef UNICODE
subBlock.toStdWString().c_str(),
#else
subBlock.toUtf8(),
#endif
( LPVOID * )&lpBuffer, ( UINT * )&dwUseless );

if ( r && lpBuffer && lpBuffer != INVALID_HANDLE_VALUE && dwUseless < 1023 )
{
QgsMessageLog::logMessage( QObject::tr( "Found OpenCL version info %1: %2" )
.arg( d )
#ifdef UNICODE
.arg( QString::fromUtf16( ( const ushort * ) lpBuffer ) ),
#else
.arg( QString::fromLocal8Bit( lpBuffer ) ),
#endif
LOGMESSAGE_TAG, Qgis::MessageLevel::Info );
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,13 @@ else()
PROPERTIES COMPILE_FLAGS "-w -Wno-deprecated-declarations")
endif()

if(MSVC)
set_source_files_properties(
${CMAKE_BINARY_DIR}/src/gui/qgis_gui_autogen/mocs_compilation.cpp
PROPERTIES COMPILE_FLAGS "/bigobj"
)
endif()

#############################################################
# qgis_gui library

Expand Down Expand Up @@ -1707,7 +1714,7 @@ GENERATE_EXPORT_HEADER(
set(QGIS_GUI_HDRS ${QGIS_GUI_HDRS} ${CMAKE_CURRENT_BINARY_DIR}/qgis_gui.h)

if(NOT APPLE OR NOT QGIS_MACAPP_FRAMEWORK)
if (WIN32 )
if (WIN32)
include_directories(${CMAKE_SOURCE_DIR}/src/native/win)
elseif (APPLE)
include_directories(${CMAKE_SOURCE_DIR}/src/native/mac)
Expand Down
2 changes: 1 addition & 1 deletion src/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ if (UNIX AND NOT APPLE AND NOT ANDROID)
target_link_libraries(qgis_native ${QT_VERSION_BASE}::DBus)
endif()

if (MSVC)
if (MSVC AND NOT BUILD_WITH_QT6)
find_package(${QT_VERSION_BASE}WinExtras)

target_link_libraries(qgis_native shell32)
Expand Down
Loading

0 comments on commit ce3f743

Please sign in to comment.