From c90f2c4e436d1bfb0e3065d0f68b537701c39f02 Mon Sep 17 00:00:00 2001 From: timlinux Date: Mon, 21 May 2007 17:28:53 +0000 Subject: [PATCH] Initial commits to build qtests from cmake / ctest. Non functional yet git-svn-id: http://svn.osgeo.org/qgis/trunk@6949 c8812cc2-4d05-0410-92ff-de0c093fc19c --- CMakeLists.txt | 10 +++++ tests/CMakeLists.txt | 3 ++ tests/src/CMakeLists.txt | 3 ++ tests/src/core/CMakeLists.txt | 76 +++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/src/CMakeLists.txt create mode 100644 tests/src/core/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index ecf72afbad4..c4e2f7794ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,9 @@ SET (BINDINGS_GLOBAL_INSTALL FALSE CACHE BOOL "Install bindings to global python # Compile flag. Make it posible to turn it off. SET (PEDANTIC TRUE CACHE BOOL "Determines if we should compile with -Wall -Werror.") +# whether unit tests should be build +SET (ENABLE_TESTS FALSE CACHE BOOL "Build unit tests?") + # hide this variable because building of python bindings might fail # if set to other directory than expected MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH) @@ -102,6 +105,10 @@ SET( QT_USE_QT3SUPPORT TRUE ) SET( QT_USE_QTXML TRUE ) SET( QT_USE_QTNETWORK TRUE ) SET( QT_USE_QTSVG TRUE ) +IF (ENABLE_TESTS) + SET( QT_USE_QTTESTS TRUE ) + ENABLE_TESTING() +ENDIF (ENABLE_TESTS) # TODO: should not be needed, report it to CMake devs IF (APPLE AND QT_USE_QT3SUPPORT) SET( QT_USE_QTSQL TRUE ) @@ -222,6 +229,9 @@ IF (HAVE_PYTHON) SUBDIRS (python) ENDIF (HAVE_PYTHON) +IF (ENABLE_TESTS) + SUBDIRS(tests) +ENDIF (ENABLE_TESTS) ############################################################# # install stuff diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000000..fb42fd987bc --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,3 @@ +IF (ENABLE_TESTS) + SUBDIRS(src) +ENDIF (ENABLE_TESTS) diff --git a/tests/src/CMakeLists.txt b/tests/src/CMakeLists.txt new file mode 100644 index 00000000000..8e858411881 --- /dev/null +++ b/tests/src/CMakeLists.txt @@ -0,0 +1,3 @@ +IF (ENABLE_TESTS) + SUBDIRS(core) +ENDIF (ENABLE_TESTS) diff --git a/tests/src/core/CMakeLists.txt b/tests/src/core/CMakeLists.txt new file mode 100644 index 00000000000..53df57097d2 --- /dev/null +++ b/tests/src/core/CMakeLists.txt @@ -0,0 +1,76 @@ +############################################################# +# sources + +# application test + +SET(applicationtest_SRCS testqgsapplication.cpp) +SET(applicationtest_MOC_CPPS testqgsapplication.cpp) +QT4_WRAP_CPP(applicationtest_MOC_SRCS ${applicationtest_MOC_CPPS}) +ADD_CUSTOM_TARGET(applicationtestmoc ALL DEPENDS ${applicationtest_MOC_SRCS}) +#QT4_GENERATE_MOC(${CMAKE_CURRENT_SOURCE_DIR}/testqgsapplication.cpp moc_testqgsapplication.cxx) + +##################################################### + +# Don't forget to include output directory, otherwise +# the UI file won't be wrapped! +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core + ${QT_INCLUDE_DIR} + ${GDAL_INCLUDE_DIR} + ${PROJ_INCLUDE_DIR} + ${GEOS_INCLUDE_DIR} + ) + +# expect that classes are being IMPORTED for the exe +IF (WIN32) + # expect that classes are being imported + # Note: MSVC doesn't like when the macros are quotes + # and MSYS doesn't like them unqouted (bacause of braces) + IF (MSVC) + ADD_DEFINITIONS("-DCORE_EXPORT=__declspec(dllimport)") + #ADD_DEFINITIONS("-DPLUGIN_EXPORT=__declspec(dllimport)") + #next needed for qgis gui includes + ADD_DEFINITIONS("-DGUI_EXPORT=__declspec(dllexport)") + ELSE (MSVC) + ADD_DEFINITIONS("\"-DCORE_EXPORT=__declspec(dllimport)\"") + #ADD_DEFINITIONS("\"-DPLUGIN_EXPORT=__declspec(dllimport)\"") + #next needed for qgis gui includes + ADD_DEFINITIONS("\"-DGUI_EXPORT=__declspec(dllexport)\"") + ENDIF (MSVC) +ENDIF (WIN32) + +############################################################# +# libraries + +# because of htonl +IF (WIN32) + SET(PLATFORM_LIBRARIES wsock32) +ENDIF (WIN32) + + +#note for tests we should not include the moc of our +#qtests as they are directly included in teh sources +#and should not be compiled twice. Trying to include +#them in below will cause an error at build time + +ADD_EXECUTABLE(applicationtest + ${applicationtest_SRCS} + ) +TARGET_LINK_LIBRARIES(applicationtest + ${QT_LIBRARIES} + qgis_core +) + +# Since the tests are not actually installed, but rather +# run directly from the build/src/tests dir we need to +# ensure the libs can be found. +IF (APPLE) + # For Mac OS X, the executable must be at the root of the bundle's executable folder + SET (CMAKE_INSTALL_NAME_DIR @executable_path/../lib) + INSTALL(TARGETS applicationtest RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +ELSE (APPLE) + INSTALL(TARGETS applicationtest RUNTIME DESTINATION ${OMG_BIN_DIR}) +ENDIF (APPLE) + +ADD_TEST(application ${CMAKE_CURRENT_BINARY_DIR}/applicationtest)