Skip to content
Permalink
Browse files
Merge pull request #43793 from 3nids/cmake-test-macro-targets-rebased
[cmake] use single macro QGIS_ADD_TEST and modernize cmake code
  • Loading branch information
3nids committed Jun 21, 2021
2 parents db4ddb9 + 05e2cef commit de6ef9672ae8e44f45d1dc6b020dedcc486f0a83
@@ -15,13 +15,10 @@ PyQgsAuthManagerOgrPostgresTest
PyQgsDbManagerPostgis

# Needs an OpenCL device, the library is not enough
qgis_openclutilstest
test_core_openclutils

# Relies on a broken/unreliable 3rd party service
qgis_layerdefinition
test_core_layerdefinition

# MSSQL requires the MSSQL docker
PyQgsProviderConnectionMssql



@@ -1,8 +1,8 @@
# flaky
qgis_filedownloader
qgis_wcsprovidertest
test_gui_filedownloader
test_provider_wcsprovider
PyQgsWFSProviderGUI
qgis_ziplayertest
test_core_ziplayer

# Flaky, the ms odbc driver crashes a lot on the ubuntu docker image. Retest when
# the docker base image is upgraded
@@ -32,37 +32,40 @@ set (WMS_HDRS
########################################################
# Build

add_library (wms MODULE ${WMS_SRCS} ${WMS_HDRS})
set(_library_suffix_MODULE "")
set(_library_suffix_STATIC "_static")

# require c++17
target_compile_features(wms PRIVATE cxx_std_17)
foreach(_library_type MODULE STATIC)
set(_library_name "wms${_library_suffix_${_library_type}}")

include_directories(SYSTEM
${GDAL_INCLUDE_DIR}
${POSTGRES_INCLUDE_DIR}
)
add_library(${_library_name} ${_library_type} ${WMS_SRCS} ${WMS_HDRS})

include_directories(
${CMAKE_SOURCE_DIR}/src/server
${CMAKE_SOURCE_DIR}/src/server/services
${CMAKE_SOURCE_DIR}/src/server/services/wms
# require c++17
target_compile_features(${_library_name} PRIVATE cxx_std_17)

${CMAKE_BINARY_DIR}/src/python
${CMAKE_BINARY_DIR}/src/analysis
${CMAKE_BINARY_DIR}/src/server
${CMAKE_CURRENT_BINARY_DIR}
)
include_directories(${_library_name} SYSTEM PUBLIC
${GDAL_INCLUDE_DIR}
${POSTGRES_INCLUDE_DIR}
)

target_include_directories(${_library_name} PUBLIC
${CMAKE_SOURCE_DIR}/src/server
${CMAKE_SOURCE_DIR}/src/server/services
${CMAKE_SOURCE_DIR}/src/server/services/wms

target_link_libraries(wms
qgis_core
qgis_server
)
${CMAKE_BINARY_DIR}/src/python
${CMAKE_BINARY_DIR}/src/analysis
${CMAKE_BINARY_DIR}/src/server
${CMAKE_CURRENT_BINARY_DIR}
)

target_link_libraries(${_library_name}
qgis_core
qgis_server
)
endforeach()

########################################################
# Install

# only install module, static library is for testing only
install(TARGETS wms
RUNTIME DESTINATION ${QGIS_SERVER_MODULE_DIR}
LIBRARY DESTINATION ${QGIS_SERVER_MODULE_DIR}
@@ -1,7 +1,6 @@
# Standard includes and utils to compile into all tests.
set (util_SRCS)


#####################################################
# Don't forget to include output directory, otherwise
# the UI file won't be wrapped!
@@ -18,48 +17,21 @@ include_directories(SYSTEM
${QT5_3DEXTRA_INCLUDE_DIR}
)

#note for tests we should not include the moc of our
#qtests in the executable file list as the moc is
#directly included in the sources
#and should not be compiled twice. Trying to include
#them in will cause an error at build time
#############################################################
# Tests:

macro (ADD_QGIS_TEST testname testsrc)
set(qgis_${testname}_SRCS ${testsrc} ${util_SRCS})
set(qgis_${testname}_MOC_CPPS ${testsrc})
add_executable(qgis_${testname} ${qgis_${testname}_SRCS})
# require c++17
target_compile_features(qgis_${testname} PRIVATE cxx_std_17)
set_target_properties(qgis_${testname} PROPERTIES AUTORCC TRUE)
target_link_libraries(qgis_${testname}
${Qt5Xml_LIBRARIES}
${Qt5Core_LIBRARIES}
${Qt5Svg_LIBRARIES}
${Qt5Network_LIBRARIES}
${Qt5Test_LIBRARIES}
${PROJ_LIBRARY}
${GEOS_LIBRARY}
${GDAL_LIBRARY}
qgis_core
qgis_3d
qgis_native)
add_test(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname} -maxwarnings 10000)
target_link_libraries(qgis_${testname} qgis_native)
add_test(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname})
#set_target_properties(qgis_${testname} PROPERTIES
# INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
# INSTALL_RPATH_USE_LINK_PATH true )
endmacro (ADD_QGIS_TEST)

add_subdirectory(sandbox)

ADD_QGIS_TEST(3dutilstest testqgs3dutils.cpp)
ADD_QGIS_TEST(3drenderingtest testqgs3drendering.cpp)
ADD_QGIS_TEST(layout3dmaptest testqgslayout3dmap.cpp)
ADD_QGIS_TEST(materialregistrytest testqgsmaterialregistry.cpp)
ADD_QGIS_TEST(3dmaterialtest testqgs3dmaterial.cpp)
ADD_QGIS_TEST(tessellatortest testqgstessellator.cpp)
ADD_QGIS_TEST(3dsymbolregistrytest testqgs3dsymbolregistry.cpp)
set(TESTS
testqgs3dutils.cpp
testqgs3drendering.cpp
testqgslayout3dmap.cpp
testqgsmaterialregistry.cpp
testqgs3dmaterial.cpp
testqgstessellator.cpp
testqgs3dsymbolregistry.cpp
)


foreach(TESTSRC ${TESTS})
add_qgis_test(${TESTSRC} MODULE 3d LINKEDLIBRARIES qgis_3d)
endforeach(TESTSRC)

@@ -1,4 +1,34 @@
if (ENABLE_TESTS)


macro (add_qgis_test TESTSRC)
set(options OPTIONAL)
set(oneValueArgs MODULE LABELS)
set(multiValueArgs LINKEDLIBRARIES DEPENDENCIES)
cmake_parse_arguments(ARG_QGIS_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

set (TESTNAME ${TESTSRC})
string(REPLACE "test" "" TESTNAME ${TESTNAME})
string(REPLACE "qgs" "" TESTNAME ${TESTNAME})
string(REPLACE ".cpp" "" TESTNAME ${TESTNAME})
set (TESTNAME "test_${ARG_QGIS_TEST_MODULE}_${TESTNAME}")
add_executable(${TESTNAME} ${TESTSRC} ${util_SRCS})
# add_custom_target(${TESTNAME}moc ALL DEPENDS ${${TESTNAME}_MOC_SRCS})
target_compile_features(${TESTNAME} PRIVATE cxx_std_17)
set_target_properties(${TESTNAME} PROPERTIES AUTORCC TRUE)
target_link_libraries(${TESTNAME} ${ARG_QGIS_TEST_LINKEDLIBRARIES})
target_link_libraries(${TESTNAME} ${Qt5Test_LIBRARIES})
add_test(${TESTNAME} ${CMAKE_BINARY_DIR}/output/bin/${TESTNAME} -maxwarnings 10000)
if (DEFINED ARG_QGIS_TEST_DEPENDENCIES)
add_dependencies(${TESTNAME} ${ARG_QGIS_TEST_DEPENDENCIES})
endif()
if (DEFINED ARG_QGIS_TEST_LABELS)
set_tests_properties(${TESTNAME} PROPERTIES LABELS ${ARG_QGIS_TEST_LABELS})
endif()
endmacro()



#############################################################
# Compiler defines

@@ -5,7 +5,8 @@ set (util_SRCS)
#####################################################
# Don't forget to include output directory, otherwise
# the UI file won't be wrapped!
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/src/test
)
@@ -14,43 +15,11 @@ if(HAVE_OPENCL)
include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
endif()

#note for tests we should not include the moc of our
#qtests in the executable file list as the moc is
#directly included in the sources
#and should not be compiled twice. Trying to include
#them in will cause an error at build time

#No relinking and full RPATH for the install tree
#See: http://www.cmake.org/Wiki/CMake_RPATH_handling#No_relinking_and_full_RPATH_for_the_install_tree

macro (ADD_QGIS_TEST TESTSRC)
set (TESTNAME ${TESTSRC})
string(REPLACE "test" "" TESTNAME ${TESTNAME})
string(REPLACE "qgs" "" TESTNAME ${TESTNAME})
string(REPLACE ".cpp" "" TESTNAME ${TESTNAME})
set (TESTNAME "qgis_${TESTNAME}test")

set(${TESTNAME}_SRCS ${TESTSRC} ${util_SRCS})
set(${TESTNAME}_MOC_CPPS ${TESTSRC})
add_executable(${TESTNAME} ${${TESTNAME}_SRCS})
# require c++17
target_compile_features(${TESTNAME} PRIVATE cxx_std_17)
target_link_libraries(${TESTNAME}
${Qt5Core_LIBRARIES}
${Qt5Test_LIBRARIES}
qgis_analysis)
add_test(${TESTNAME} ${CMAKE_BINARY_DIR}/output/bin/${TESTNAME} -maxwarnings 10000)
#set_target_properties(qgis_${testname} PROPERTIES
# INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
# INSTALL_RPATH_USE_LINK_PATH true )
endmacro (ADD_QGIS_TEST)

#############################################################
# Tests:
set(TESTS
testqgsgeometrysnapper.cpp
testqgsinterpolator.cpp
testqgsprocessing.cpp
testqgsprocessingalgs.cpp
testqgszonalstatistics.cpp
testqgsrastercalculator.cpp
@@ -62,17 +31,11 @@ set(TESTS
testqgsmeshcontours.cpp
testqgstriangulation.cpp
)

if(HAVE_GSL)
set(TESTS
${TESTS}
testqgsgcptransformer.cpp
)
set(TESTS ${TESTS} testqgsgcptransformer.cpp)
endif()

foreach(TESTSRC ${TESTS})
ADD_QGIS_TEST(${TESTSRC})
add_qgis_test(${TESTSRC} MODULE analysis LINKEDLIBRARIES qgis_analysis)
endforeach(TESTSRC)

SET_TESTS_PROPERTIES(qgis_processingtest
PROPERTIES LABELS "POSTGRES")
add_qgis_test(testqgsprocessing.cpp MODULE analysis LINKEDLIBRARIES qgis_analysis LABELS "POSTGRES")
Loading

0 comments on commit de6ef96

Please sign in to comment.