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(FileWatcherEngine_SOURCES 159 ../src/kqueuewatchtowerdriver.cpp 160 ) 161endif (WIN32) 162 163# Compiler flags 164set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PARANOID_FLAGS} -fPIC -DGLOGG_VERSION=\\\"unit_tests\\\" -g -gdwarf-2") 165 166# Add test cpp file 167add_executable(glogg_tests 168 ${glogg_SOURCES} 169 ${FileWatcherEngine_SOURCES} 170 ${glogg_UTESTS} 171) 172 173# Link test executable against gtest & gtest_main 174target_link_libraries(glogg_tests ${LIBS} gtest_main pthread Qt5::Widgets) 175 176add_executable(glogg_itests 177 ${glogg_SOURCES} 178 ${FileWatcherEngine_SOURCES} 179 ${glogg_ITESTS} 180 itests.cpp 181) 182 183target_link_libraries(glogg_itests ${LIBS} pthread Qt5::Widgets Qt5::Test) 184 185add_executable(glogg_ptests 186 ${glogg_SOURCES} 187 ${FileWatcherEngine_SOURCES} 188 ${glogg_PTESTS} 189 itests.cpp 190) 191 192target_link_libraries(glogg_ptests ${LIBS} pthread Qt5::Widgets Qt5::Test) 193 194add_test( 195 NAME glogg_tests 196 COMMAND glogg_tests 197) 198