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(Qt5Widgets REQUIRED) 12find_package(Qt5Test REQUIRED) 13 14set(CMAKE_AUTOMOC ON) 15set(CMAKE_AUTOUIC ON) 16set(CMAKE_INCLUDE_CURRENT_DIR ON) 17 18check_cxx_compiler_flag(-Wall HAS_WALL) 19 20if(HAS_WALL) 21 set(PARANOID_FLAGS "${PARANOID_FLAGS} -Wall") 22endif(HAS_WALL) 23 24# Compiler 25check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11) 26check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X) 27if(COMPILER_SUPPORTS_CXX11) 28 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 29elseif(COMPILER_SUPPORTS_CXX0X) 30 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") 31else() 32 message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.") 33endif() 34 35set(CMAKE_REQUIRED_FLAGS "-std=c++11") 36check_cxx_source_compiles(" 37 #include <memory> 38 int main(int, int) 39 { 40 auto test = std::make_unique<void>(); 41 return 0; 42 } 43" HAVE_MAKE_UNIQUE) 44 45check_cxx_source_compiles(" 46 #include <memory> 47 struct Base { 48 virtual void func() {} 49 }; 50 struct Derived : public Base { 51 void func() override {} 52 } 53 int main(int, int) 54 { 55 return 0; 56 } 57" HAVE_OVERRIDE) 58 59configure_file(../config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) 60 61# Configuration 62check_symbol_exists( symlink "unistd.h" HAVE_SYMLINK ) 63check_symbol_exists( htons "arpa/inet.h" HAVE_HTONS ) 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/qtfilewatcher.cpp 115 ../src/tabbedcrawlerwidget.cpp 116 ../src/filewatcher.cpp 117 ../src/watchtowerlist.cpp 118 ../src/watchtower.cpp 119 ../src/platformfilewatcher.cpp 120) 121 122set(glogg_HEADERS 123 ../src/mainwindow.h 124 ../src/marks.h 125 ../src/filewatcher.h) 126 127# Unit tests 128set(glogg_UTESTS 129 watchtowerTest.cpp 130 linepositionarrayTest.cpp 131) 132 133# Integration tests 134set(glogg_ITESTS 135 logdataTest.cpp 136 logfiltereddataTest.cpp 137) 138 139# Performance tests 140set(glogg_PTESTS 141 logdataPerfTest.cpp 142 logfiltereddataPerfTest.cpp 143) 144 145 146# Options 147if (WIN32) 148 set(FileWatcherEngine_SOURCES 149 ../src/winwatchtowerdriver.cpp 150 ) 151else (WIN32) 152 set(FileWatcherEngine_SOURCES ../src/inotifywatchtowerdriver.cpp) 153endif (WIN32) 154 155# Compiler flags 156set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PARANOID_FLAGS} -fPIC -DGLOGG_VERSION=\\\"unit_tests\\\" -g -gdwarf-2") 157 158# Add test cpp file 159add_executable(glogg_tests 160 ${glogg_SOURCES} 161 ${FileWatcherEngine_SOURCES} 162 ${glogg_UTESTS} 163) 164 165# Link test executable against gtest & gtest_main 166target_link_libraries(glogg_tests ${LIBS} gtest_main pthread Qt5::Widgets) 167 168add_executable(glogg_itests 169 ${glogg_SOURCES} 170 ${FileWatcherEngine_SOURCES} 171 ${glogg_ITESTS} 172 itests.cpp 173) 174 175target_link_libraries(glogg_itests ${LIBS} pthread Qt5::Widgets Qt5::Test) 176 177add_executable(glogg_ptests 178 ${glogg_SOURCES} 179 ${FileWatcherEngine_SOURCES} 180 ${glogg_PTESTS} 181 itests.cpp 182) 183 184target_link_libraries(glogg_ptests ${LIBS} pthread Qt5::Widgets Qt5::Test) 185 186add_test( 187 NAME glogg_tests 188 COMMAND glogg_tests 189) 190