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/viewtools.cpp 120 ../src/encodingspeculator.cpp 121 # ../src/platformfilewatcher.cpp 122) 123 124set(glogg_HEADERS 125 ../src/mainwindow.h 126 ../src/marks.h 127 ../src/filewatcher.h) 128 129# Unit tests 130set(glogg_UTESTS 131 # watchtowerTest.cpp 132 linepositionarrayTest.cpp 133 encodingspeculatorTest.cpp 134) 135 136# Integration tests 137set(glogg_ITESTS 138 logdataTest.cpp 139 logfiltereddataTest.cpp 140) 141 142# Performance tests 143set(glogg_PTESTS 144 logdataPerfTest.cpp 145 logfiltereddataPerfTest.cpp 146) 147 148 149# Options 150if (WIN32) 151 set(FileWatcherEngine_SOURCES 152 ../src/winwatchtowerdriver.cpp 153 ) 154elseif (LINUX) 155 # set(FileWatcherEngine_SOURCES ../src/inotifywatchtowerdriver.cpp) 156endif (WIN32) 157 158# Compiler flags 159set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PARANOID_FLAGS} -fPIC -DGLOGG_VERSION=\\\"unit_tests\\\" -g -gdwarf-2") 160 161# Add test cpp file 162add_executable(glogg_tests 163 ${glogg_SOURCES} 164 ${FileWatcherEngine_SOURCES} 165 ${glogg_UTESTS} 166) 167 168# Link test executable against gtest & gtest_main 169target_link_libraries(glogg_tests ${LIBS} gtest_main pthread Qt5::Widgets) 170 171add_executable(glogg_itests 172 ${glogg_SOURCES} 173 ${FileWatcherEngine_SOURCES} 174 ${glogg_ITESTS} 175 itests.cpp 176) 177 178target_link_libraries(glogg_itests ${LIBS} pthread Qt5::Widgets Qt5::Test) 179 180add_executable(glogg_ptests 181 ${glogg_SOURCES} 182 ${FileWatcherEngine_SOURCES} 183 ${glogg_PTESTS} 184 itests.cpp 185) 186 187target_link_libraries(glogg_ptests ${LIBS} pthread Qt5::Widgets Qt5::Test) 188 189add_test( 190 NAME glogg_tests 191 COMMAND glogg_tests 192) 193