xref: /glogg/tests/CMakeLists.txt (revision c1f737e476dd5f2427c03f48844bf9ed87cac11b)
1INCLUDE (CheckSymbolExists)
2INCLUDE (CheckCXXSourceCompiles)
3INCLUDE (CheckCXXCompilerFlag)
4
5cmake_minimum_required(VERSION 2.8.12)
6project(glogg_tests)
7
8# Qt
9
10find_program(QT_QMAKE_EXECUTABLE NAMES qmake PATHS $ENV{QT_DIR}/bin)
11find_package(Qt5Core 5.8 REQUIRED)
12find_package(Qt5Widgets 5.8 REQUIRED)
13find_package(Qt5Test 5.8 REQUIRED)
14
15set(CMAKE_AUTOMOC ON)
16set(CMAKE_AUTOUIC ON)
17set(CMAKE_INCLUDE_CURRENT_DIR ON)
18
19check_cxx_compiler_flag(-Wall HAS_WALL)
20
21if(HAS_WALL)
22    set(PARANOID_FLAGS "${PARANOID_FLAGS} -Wall")
23endif(HAS_WALL)
24
25# Compiler
26check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
27check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
28if(COMPILER_SUPPORTS_CXX11)
29    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
30elseif(COMPILER_SUPPORTS_CXX0X)
31    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
32else()
33    message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
34endif()
35
36set(CMAKE_REQUIRED_FLAGS "-std=c++11")
37check_cxx_source_compiles("
38    #include <memory>
39    int main(int, int)
40    {
41        auto test = std::make_unique<void>();
42        return 0;
43    }
44" HAVE_MAKE_UNIQUE)
45
46check_cxx_source_compiles("
47    #include <memory>
48    struct Base {
49        virtual void func() {}
50    };
51    struct Derived : public Base {
52        void func() override {}
53    }
54    int main(int, int)
55    {
56        return 0;
57    }
58" HAVE_OVERRIDE)
59
60configure_file(../config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
61
62# Configuration
63check_symbol_exists( symlink "unistd.h" HAVE_SYMLINK )
64
65# find_library(WS2_LIBRARY NAMES ws2_32)
66
67# Libs
68
69set(LIBS gmock gtest)
70
71# Setup testing
72enable_testing()
73include_directories(
74    $ENV{GMOCK_HOME}/include
75    $ENV{GMOCK_HOME}/gtest/include
76    $ENV{BOOST_ROOT}/
77    ../src/
78)
79link_directories($ENV{GMOCK_HOME}/mybuild $ENV{GMOCK_HOME}/mybuild/gtest)
80
81# Sources
82set(glogg_SOURCES
83    ../src/session.cpp
84    ../src/data/abstractlogdata.cpp
85    ../src/data/logdata.cpp
86    ../src/data/logfiltereddata.cpp
87    ../src/data/logfiltereddataworkerthread.cpp
88    ../src/data/logdataworkerthread.cpp
89    ../src/data/compressedlinestorage.cpp
90    ../src/mainwindow.cpp
91    ../src/crawlerwidget.cpp
92    ../src/abstractlogview.cpp
93    ../src/logmainview.cpp
94    ../src/filteredview.cpp
95    ../src/optionsdialog.cpp
96    ../src/persistentinfo.cpp
97    ../src/configuration.cpp
98    ../src/filtersdialog.cpp
99    ../src/filterset.cpp
100    ../src/savedsearches.cpp
101    ../src/infoline.cpp
102    ../src/menuactiontooltipbehavior.cpp
103    ../src/selection.cpp
104    ../src/quickfind.cpp
105    ../src/quickfindpattern.cpp
106    ../src/quickfindwidget.cpp
107    ../src/sessioninfo.cpp
108    ../src/recentfiles.cpp
109    ../src/overview.cpp
110    ../src/overviewwidget.cpp
111    ../src/marks.cpp
112    ../src/quickfindmux.cpp
113    ../src/signalmux.cpp
114    ../src/tabbedcrawlerwidget.cpp
115    ../src/watchtowerlist.cpp
116    ../src/watchtower.cpp
117    ../src/viewtools.cpp
118    ../src/encodingspeculator.cpp
119    ../src/platformfilewatcher.cpp
120    ../src/filewatcher.cpp
121)
122
123set(glogg_HEADERS
124    ../src/mainwindow.h
125    ../src/marks.h
126    ../src/platformfilewatcher.h
127    ../src/filewatcher.h
128)
129
130# Unit tests
131set(glogg_UTESTS
132    watchtowerTest.cpp
133    linepositionarrayTest.cpp
134    encodingspeculatorTest.cpp
135)
136
137# Integration tests
138set(glogg_ITESTS
139    logdataTest.cpp
140    logfiltereddataTest.cpp
141)
142
143# Performance tests
144set(glogg_PTESTS
145    logdataPerfTest.cpp
146    logfiltereddataPerfTest.cpp
147)
148
149
150# Options
151if (WIN32)
152    set(FileWatcherEngine_SOURCES
153        ../src/winwatchtowerdriver.cpp
154    )
155elseif (LINUX)
156    # set(FileWatcherEngine_SOURCES ../src/inotifywatchtowerdriver.cpp)
157elseif (APPLE)
158    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGLOGG_SUPPORTS_KQUEUE")
159    set(FileWatcherEngine_SOURCES
160         ../src/kqueuewatchtowerdriver.cpp
161    )
162endif (WIN32)
163
164# Compiler flags
165set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PARANOID_FLAGS} -fPIC -DGLOGG_VERSION=\\\"unit_tests\\\" -g -gdwarf-2")
166
167# Add test cpp file
168add_executable(glogg_tests
169    ${glogg_SOURCES}
170    ${FileWatcherEngine_SOURCES}
171    ${glogg_UTESTS}
172)
173
174# Link test executable against gtest & gtest_main
175target_link_libraries(glogg_tests ${LIBS} gtest_main pthread Qt5::Widgets)
176
177add_executable(glogg_itests
178    ${glogg_SOURCES}
179    ${FileWatcherEngine_SOURCES}
180    ${glogg_ITESTS}
181    itests.cpp
182)
183
184target_link_libraries(glogg_itests ${LIBS} pthread Qt5::Widgets Qt5::Test)
185
186add_executable(glogg_ptests
187    ${glogg_SOURCES}
188    ${FileWatcherEngine_SOURCES}
189    ${glogg_PTESTS}
190    itests.cpp
191)
192
193target_link_libraries(glogg_ptests ${LIBS} pthread Qt5::Widgets Qt5::Test)
194
195add_test(
196    NAME glogg_tests
197    COMMAND glogg_tests
198)
199