From: Uwe Hermann Date: Sat, 29 Nov 2014 16:42:10 +0000 (+0100) Subject: Build system: Fix issue with unit tests, simplify code. X-Git-Tag: pulseview-0.3.0~414 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=226a15274c4b0f3374bed48c0c4684484762ccf5 Build system: Fix issue with unit tests, simplify code. Drop some unneeded lines from test/CMakeLists.txt. Most of the variables are inherited from the main CMakeLists.txt file. This reduces the amount of duplicated code and the likelyhood that the two CMakeLists.txt files get out of sync. This fixes the following issues when building the unit tests (related to mixing Qt4 and Qt5 apparently): [ 69%] Building CXX object CMakeFiles/pulseview.dir/signalhandler.cpp.o [...]/test/__/pv/moc_sigsession.cxx:13:2: error: #error "This file was generated using the moc from 4.8.6. It" #error "This file was generated using the moc from 4.8.6. It" ^ [...]/test/__/pv/moc_sigsession.cxx:14:2: error: #error "cannot be used with the include files from this version of Qt." #error "cannot be used with the include files from this version of Qt." ^ [...]/test/__/pv/moc_sigsession.cxx:15:2: error: #error "(The moc has changed too much.)" #error "(The moc has changed too much.)" ^ [...]/test/__/pv/moc_sigsession.cxx:64:7: error: ‘QMetaObjectExtraData’ does not name a type const QMetaObjectExtraData pv::SigSession::staticMetaObjectExtraData = { ^ [...]/test/__/pv/moc_sigsession.cxx:70:37: error: ‘staticMetaObjectExtraData’ was not declared in this scope qt_meta_data_pv__SigSession, &staticMetaObjectExtraData } ^ [...]/test/__/pv/moc_sigsession.cxx: In member function ‘virtual const QMetaObject* pv::SigSession::metaObject() const’: [...]/test/__/pv/moc_sigsession.cxx:79:71: error: conditional expression between distinct pointer types ‘QDynamicMetaObjectData*’ and ‘const QMetaObject*’ lacks a cast return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; ^ [...]/test/__/pv/moc_sigsession.cxx:80:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ test/CMakeFiles/pulseview-test.dir/build.make:1362: recipe for target 'test/CMakeFiles/pulseview-test.dir/__/pv/moc_sigsession.cxx.o' failed make[2]: *** [test/CMakeFiles/pulseview-test.dir/__/pv/moc_sigsession.cxx.o] Error 1 CMakeFiles/Makefile2:110: recipe for target 'test/CMakeFiles/pulseview-test.dir/all' failed make[1]: *** [test/CMakeFiles/pulseview-test.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 49358505..eb5d0f15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,12 +96,20 @@ else() endif() if(WIN32) +if(ENABLE_TESTS) # On Windows/MinGW we need to use 'thread_win32' instead of 'thread'. # The library is named libboost_thread_win32* (not libboost_thread*). + find_package(Boost 1.42 COMPONENTS filesystem system thread_win32 unit_test_framework REQUIRED) +else() find_package(Boost 1.42 COMPONENTS filesystem system thread_win32 REQUIRED) +endif() +else() +if(ENABLE_TESTS) + find_package(Boost 1.42 COMPONENTS filesystem system thread unit_test_framework REQUIRED) else() find_package(Boost 1.42 COMPONENTS filesystem system thread REQUIRED) endif() +endif() # Find the platform's thread library (needed for C++11 threads). # This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7c454c02..22612b91 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,32 +18,6 @@ ## along with this program. If not, see . ## -option(ENABLE_DECODE "Build with libsigrokdecode" FALSE) - -list(APPEND PKGDEPS libsigrok>=0.3.0) - -if(ENABLE_DECODE) - list(APPEND PKGDEPS libsigrokdecode>=0.3.0) -endif() - -find_package(PkgConfig) -pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS}) - -if(WIN32) - # On Windows/MinGW we need to use 'thread_win32' instead of 'thread'. - # The library is named libboost_thread_win32* (not libboost_thread*). - find_package(Boost 1.42 COMPONENTS filesystem system thread_win32 unit_test_framework REQUIRED) -else() - find_package(Boost 1.42 COMPONENTS filesystem system thread unit_test_framework REQUIRED) -endif() - -# Find the platform's thread library (needed for C++11 threads). -# This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value. -find_package(Threads REQUIRED) - -find_program(QT_QMAKE_EXECUTABLE NAMES qmake4 qmake-qt4 qmake-mac) -find_package(Qt4 REQUIRED) - set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/devicemanager.cpp ${PROJECT_SOURCE_DIR}/pv/sigsession.cpp @@ -134,10 +108,11 @@ if(ENABLE_DECODE) ) endif() -qt4_wrap_cpp(pulseview_TEST_HEADERS_MOC ${pulseview_TEST_HEADERS}) - -if(ENABLE_DECODE) - add_definitions(-DENABLE_DECODE) +if(Qt5Core_FOUND) + qt5_wrap_cpp(pulseview_TEST_HEADERS_MOC ${pulseview_TEST_HEADERS}) +else() + qt4_wrap_cpp(pulseview_TEST_HEADERS_MOC ${pulseview_TEST_HEADERS}) + include(${QT_USE_FILE}) endif() # On MinGW we need to use static linking. @@ -145,25 +120,6 @@ if(NOT WIN32) add_definitions(-DBOOST_TEST_DYN_LINK) endif() -add_definitions(${QT_DEFINITIONS}) - -include_directories( - ${Boost_INCLUDE_DIRS} - ${PKGDEPS_INCLUDE_DIRS} -) - -set(PULSEVIEW_LINK_LIBS - ${Boost_LIBRARIES} - ${PKGDEPS_LIBRARIES} - ${QT_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} -) - -if(WIN32) - # Workaround for a MinGW linking issue. - list(APPEND PULSEVIEW_LINK_LIBS "-llzma -llcms2") -endif() - add_executable(pulseview-test ${pulseview_TEST_SOURCES} ${pulseview_TEST_HEADERS_MOC}