diff --git a/CMakeLists.txt b/CMakeLists.txt index 623d9a6516a..71d69e21621 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -705,9 +705,14 @@ add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050800) # For fast string concatenation add_definitions(-DQT_USE_QSTRINGBUILDER) -if (WITH_GEOREFERENCER OR WITH_ANALYSIS) +set(WITH_GSL TRUE CACHE BOOL "Determines whether GSL library should be used") + +if (WITH_ANALYSIS AND WITH_GSL) find_package(GSL REQUIRED) - set(HAVE_GEOREFERENCER TRUE) + set(HAVE_GSL TRUE) + if (WITH_GEOREFERENCER) + set(HAVE_GEOREFERENCER TRUE) + endif() endif() if(ENABLE_COVERAGE) diff --git a/cmake_templates/qgsconfig.h.in b/cmake_templates/qgsconfig.h.in index a8fa97d4bba..b5e01a5808d 100644 --- a/cmake_templates/qgsconfig.h.in +++ b/cmake_templates/qgsconfig.h.in @@ -76,6 +76,8 @@ #cmakedefine HAVE_3D +#cmakedefine HAVE_GSL + #cmakedefine HAVE_GEOREFERENCER #cmakedefine USE_THREAD_LOCAL diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 3681af82845..da1d46cc327 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -258,6 +258,7 @@ if(WITH_ANALYSIS) # analysis module file(GLOB_RECURSE sip_files_analysis analysis/*.sip analysis/*.sip.in) + set(SIP_EXTRA_FILES_DEPEND ${sip_files_core} ${sip_files_analysis}) set(SIP_EXTRA_OPTIONS ${PYQT_SIP_FLAGS} -g -o -a ${CMAKE_BINARY_DIR}/python/qgis.analysis.api) if((${SIP_VERSION_STR} VERSION_EQUAL 4.19.11) OR (${SIP_VERSION_STR} VERSION_GREATER 4.19.11)) diff --git a/src/analysis/CMakeLists.txt b/src/analysis/CMakeLists.txt index 89ac88e3c63..56f698adfce 100644 --- a/src/analysis/CMakeLists.txt +++ b/src/analysis/CMakeLists.txt @@ -401,10 +401,13 @@ find_package(EXIV2 REQUIRED) include_directories(SYSTEM ${SPATIALITE_INCLUDE_DIR}) include_directories(SYSTEM ${SPATIALINDEX_INCLUDE_DIR}) include_directories(SYSTEM ${SQLITE3_INCLUDE_DIR}) -include_directories(SYSTEM ${GSL_INCLUDE_DIR}) include_directories(BEFORE raster) include_directories(BEFORE mesh) +if(HAVE_GSL) + include_directories(SYSTEM ${GSL_INCLUDE_DIR}) +endif() + ADD_FLEX_FILES_PREFIX(QGIS_ANALYSIS_SRCS raster raster/qgsrastercalclexer.ll) ADD_BISON_FILES_PREFIX(QGIS_ANALYSIS_SRCS raster raster/qgsrastercalcparser.yy) @@ -520,9 +523,12 @@ target_link_libraries( qgis_analysis qgis_core ${EXIV2_LIBRARY} - ${GSL_LIBRARIES} ) +if(HAVE_GSL) + target_link_libraries(qgis_analysis ${GSL_LIBRARIES}) +endif() + if(HAVE_OPENCL) target_link_libraries(qgis_analysis ${OpenCL_LIBRARIES}) endif() diff --git a/src/analysis/georeferencing/qgsleastsquares.cpp b/src/analysis/georeferencing/qgsleastsquares.cpp index dd74bc94411..a6d64c978d5 100644 --- a/src/analysis/georeferencing/qgsleastsquares.cpp +++ b/src/analysis/georeferencing/qgsleastsquares.cpp @@ -12,16 +12,20 @@ * (at your option) any later version. * * * ***************************************************************************/ -#include -#include -#include -#include +#include "qgsleastsquares.h" +#include "qgsconfig.h" +#include "qgsexception.h" #include -#include "qgsleastsquares.h" +#include +#include +#ifdef HAVE_GSL +#include +#include +#endif void QgsLeastSquares::linear( const QVector &sourceCoordinates, const QVector &destinationCoordinates, @@ -67,6 +71,14 @@ void QgsLeastSquares::helmert( const QVector &sourceCoordinates, QgsPointXY &origin, double &pixelSize, double &rotation ) { +#ifndef HAVE_GSL + ( void )sourceCoordinates; + ( void )destinationCoordinates; + ( void )origin; + ( void )pixelSize; + ( void )rotation; + throw QgsNotSupportedException( QStringLiteral( "Calculating a helmert transformation requires a QGIS build based GSL" ) ); +#else int n = destinationCoordinates.size(); if ( n < 2 ) { @@ -125,6 +137,7 @@ void QgsLeastSquares::helmert( const QVector &sourceCoordinates, pixelSize = std::sqrt( std::pow( gsl_vector_get( x, 0 ), 2 ) + std::pow( gsl_vector_get( x, 1 ), 2 ) ); rotation = std::atan2( gsl_vector_get( x, 1 ), gsl_vector_get( x, 0 ) ); +#endif } #if 0 @@ -245,6 +258,12 @@ void QgsLeastSquares::projective( const QVector &sourceCoordinates, const QVector &destinationCoordinates, double H[9] ) { +#ifndef HAVE_GSL + ( void )sourceCoordinates; + ( void )destinationCoordinates; + ( void )H; + throw QgsNotSupportedException( QStringLiteral( "Calculating a projective transformation requires a QGIS build based GSL" ) ); +#else Q_ASSERT( sourceCoordinates.size() == destinationCoordinates.size() ); if ( destinationCoordinates.size() < 4 ) @@ -341,4 +360,5 @@ void QgsLeastSquares::projective( const QVector &sourceCoordinates, gsl_matrix_free( V ); gsl_vector_free( singular_values ); gsl_vector_free( work ); +#endif } diff --git a/src/analysis/georeferencing/qgsleastsquares.h b/src/analysis/georeferencing/qgsleastsquares.h index 6beb6e8b1d0..8a6a2853a10 100644 --- a/src/analysis/georeferencing/qgsleastsquares.h +++ b/src/analysis/georeferencing/qgsleastsquares.h @@ -42,6 +42,7 @@ class ANALYSIS_EXPORT QgsLeastSquares /** * Transforms the point at \a origin in-place, using a helmert transformation calculated from the list of source and destination Ground Control Points (GCPs). + * \throws QgsNotSupportedException on QGIS built without GSL. */ static void helmert( const QVector &sourceCoordinates, const QVector &destinationCoordinates, @@ -55,6 +56,7 @@ class ANALYSIS_EXPORT QgsLeastSquares /** * Calculates projective parameters from the list of source and destination Ground Control Points (GCPs). + * \throws QgsNotSupportedException on QGIS built without GSL. */ static void projective( const QVector &sourceCoordinates, const QVector &destinationCoordinates, diff --git a/tests/src/analysis/CMakeLists.txt b/tests/src/analysis/CMakeLists.txt index f659354b353..180257e23af 100644 --- a/tests/src/analysis/CMakeLists.txt +++ b/tests/src/analysis/CMakeLists.txt @@ -48,7 +48,6 @@ endmacro (ADD_QGIS_TEST) ############################################################# # Tests: set(TESTS - testqgsgcptransformer.cpp testqgsgeometrysnapper.cpp testqgsinterpolator.cpp testqgsprocessing.cpp @@ -64,6 +63,13 @@ set(TESTS testqgstriangulation.cpp ) +if(HAVE_GSL) + set(TESTS + ${TESTS} + testqgsgcptransformer.cpp + ) +endif() + foreach(TESTSRC ${TESTS}) ADD_QGIS_TEST(${TESTSRC}) endforeach(TESTSRC)