Skip to content

Commit 50f8995

Browse files

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed
 

‎CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ SET (BINDINGS_GLOBAL_INSTALL FALSE CACHE BOOL "Install bindings to global python
4040
# Compile flag. Make it posible to turn it off.
4141
SET (PEDANTIC TRUE CACHE BOOL "Determines if we should compile with -Wall -Werror.")
4242

43+
# whether unit tests should be build
44+
SET (ENABLE_TESTS FALSE CACHE BOOL "Build unit tests?")
45+
4346
# hide this variable because building of python bindings might fail
4447
# if set to other directory than expected
4548
MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH)
@@ -102,6 +105,10 @@ SET( QT_USE_QT3SUPPORT TRUE )
102105
SET( QT_USE_QTXML TRUE )
103106
SET( QT_USE_QTNETWORK TRUE )
104107
SET( QT_USE_QTSVG TRUE )
108+
IF (ENABLE_TESTS)
109+
SET( QT_USE_QTTESTS TRUE )
110+
ENABLE_TESTING()
111+
ENDIF (ENABLE_TESTS)
105112
# TODO: should not be needed, report it to CMake devs
106113
IF (APPLE AND QT_USE_QT3SUPPORT)
107114
SET( QT_USE_QTSQL TRUE )
@@ -222,6 +229,9 @@ IF (HAVE_PYTHON)
222229
SUBDIRS (python)
223230
ENDIF (HAVE_PYTHON)
224231

232+
IF (ENABLE_TESTS)
233+
SUBDIRS(tests)
234+
ENDIF (ENABLE_TESTS)
225235

226236
#############################################################
227237
# install stuff

‎tests/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
IF (ENABLE_TESTS)
2+
SUBDIRS(src)
3+
ENDIF (ENABLE_TESTS)

‎tests/src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
IF (ENABLE_TESTS)
2+
SUBDIRS(core)
3+
ENDIF (ENABLE_TESTS)

‎tests/src/core/CMakeLists.txt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#############################################################
2+
# sources
3+
4+
# application test
5+
6+
SET(applicationtest_SRCS testqgsapplication.cpp)
7+
SET(applicationtest_MOC_CPPS testqgsapplication.cpp)
8+
QT4_WRAP_CPP(applicationtest_MOC_SRCS ${applicationtest_MOC_CPPS})
9+
ADD_CUSTOM_TARGET(applicationtestmoc ALL DEPENDS ${applicationtest_MOC_SRCS})
10+
#QT4_GENERATE_MOC(${CMAKE_CURRENT_SOURCE_DIR}/testqgsapplication.cpp moc_testqgsapplication.cxx)
11+
12+
#####################################################
13+
14+
# Don't forget to include output directory, otherwise
15+
# the UI file won't be wrapped!
16+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
17+
${CMAKE_CURRENT_BINARY_DIR}
18+
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core
19+
${QT_INCLUDE_DIR}
20+
${GDAL_INCLUDE_DIR}
21+
${PROJ_INCLUDE_DIR}
22+
${GEOS_INCLUDE_DIR}
23+
)
24+
25+
# expect that classes are being IMPORTED for the exe
26+
IF (WIN32)
27+
# expect that classes are being imported
28+
# Note: MSVC doesn't like when the macros are quotes
29+
# and MSYS doesn't like them unqouted (bacause of braces)
30+
IF (MSVC)
31+
ADD_DEFINITIONS("-DCORE_EXPORT=__declspec(dllimport)")
32+
#ADD_DEFINITIONS("-DPLUGIN_EXPORT=__declspec(dllimport)")
33+
#next needed for qgis gui includes
34+
ADD_DEFINITIONS("-DGUI_EXPORT=__declspec(dllexport)")
35+
ELSE (MSVC)
36+
ADD_DEFINITIONS("\"-DCORE_EXPORT=__declspec(dllimport)\"")
37+
#ADD_DEFINITIONS("\"-DPLUGIN_EXPORT=__declspec(dllimport)\"")
38+
#next needed for qgis gui includes
39+
ADD_DEFINITIONS("\"-DGUI_EXPORT=__declspec(dllexport)\"")
40+
ENDIF (MSVC)
41+
ENDIF (WIN32)
42+
43+
#############################################################
44+
# libraries
45+
46+
# because of htonl
47+
IF (WIN32)
48+
SET(PLATFORM_LIBRARIES wsock32)
49+
ENDIF (WIN32)
50+
51+
52+
#note for tests we should not include the moc of our
53+
#qtests as they are directly included in teh sources
54+
#and should not be compiled twice. Trying to include
55+
#them in below will cause an error at build time
56+
57+
ADD_EXECUTABLE(applicationtest
58+
${applicationtest_SRCS}
59+
)
60+
TARGET_LINK_LIBRARIES(applicationtest
61+
${QT_LIBRARIES}
62+
qgis_core
63+
)
64+
65+
# Since the tests are not actually installed, but rather
66+
# run directly from the build/src/tests dir we need to
67+
# ensure the libs can be found.
68+
IF (APPLE)
69+
# For Mac OS X, the executable must be at the root of the bundle's executable folder
70+
SET (CMAKE_INSTALL_NAME_DIR @executable_path/../lib)
71+
INSTALL(TARGETS applicationtest RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
72+
ELSE (APPLE)
73+
INSTALL(TARGETS applicationtest RUNTIME DESTINATION ${OMG_BIN_DIR})
74+
ENDIF (APPLE)
75+
76+
ADD_TEST(application ${CMAKE_CURRENT_BINARY_DIR}/applicationtest)

0 commit comments

Comments
 (0)
Please sign in to comment.