diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b25fd28..384f2268 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,8 @@ option(WITH_DLT_DBUS "Set to ON to build src/dbus binaries" option(WITH_DLT_TESTS "Set to ON to build src/test binaries" ON) option(WITH_DLT_UNIT_TESTS "Set to ON to build gtest framework and tests/binaries" OFF) option(WITH_DLT_COVERAGE "Set to ON to generate coverage report for dlt-daemon source code" OFF) +option(BUILD_GMOCK "Set to ON to enable gmock build" OFF) +option(WITH_GIT_SUBMODULE "Set to ON to update submodules during build" OFF) option(WITH_DLT_QNX_SYSTEM "Set to ON to build QNX system binary dlt-qnx-system" OFF) option(WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK "Set to ON to enable fallback to syslog if dlt logging to file fails" OFF) option(WITH_DLT_NETWORK_TRACE "Set to ON to enable network trace (if message queue is supported)" ON) @@ -211,7 +213,7 @@ if(WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK) endif() if(WITH_DLT_LOGSTORAGE_GZIP) - add_definitions(-DDLT_LOGSTORAGE_USE_GZIP) + add_definitions(-DDLT_LOGSTORAGE_USE_GZIP) endif() if(WITH_GPROF) @@ -358,7 +360,7 @@ else() set(DLT_JSON_LIBRARY "") endif() -if (WITH_DLT_LOG_LEVEL_APP_CONFIG) +if(WITH_DLT_LOG_LEVEL_APP_CONFIG) add_definitions(-DDLT_LOG_LEVEL_APP_CONFIG) endif() @@ -366,12 +368,47 @@ add_subdirectory(doc) add_subdirectory(src) add_subdirectory(include) add_subdirectory(testscripts) + +if(WITH_GIT_SUBMODULE) + add_definitions(-DWITH_GIT_SUBMODULE) +endif() + if(WITH_DLT_UNIT_TESTS) find_package(GTest) + if(GTEST_FOUND) + find_package(PkgConfig REQUIRED) + execute_process(COMMAND pkg-config --modversion gtest OUTPUT_VARIABLE GTEST_VERSION) + string(REPLACE "\n" "" GTEST_VERSION ${GTEST_VERSION}) + if(${GTEST_VERSION} VERSION_LESS 1.7.0) + message(WARNING "Please use Gtest version greater or equal to 1.7.0, or use option 'WITH_GIT_SUBMODULE' for latest version") + endif() + else() + message(STATUS "No Gtest package found, preparing submodule ...") + set(WITH_GIT_SUBMODULE ON) + endif() + + if(WITH_GIT_SUBMODULE) + find_package(Git QUIET) + if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") + message(STATUS "Submodule updating ...") + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE GIT_SUBMOD_RESULT) + if(NOT GIT_SUBMOD_RESULT EQUAL "0") + message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}. Please checkout submodule") + endif() + endif() - if(NOT GTEST_FOUND) - add_subdirectory(googletest) + if(NOT EXISTS "${PROJECT_SOURCE_DIR}/googletest/CMakeLists.txt") + message(FATAL_ERROR "The submodule preparation failed. Please update submodule and try again!") + else() + add_subdirectory(googletest) + if(NOT BUILD_GMOCK) + add_definitions(-DBUILD_GMOCK) + endif() + endif() endif() + enable_testing() add_subdirectory(tests) endif() @@ -395,9 +432,14 @@ message(STATUS "WITH_DLT_FILETRANSFER = ${WITH_DLT_FILETRANSFER}") message(STATUS "WITH_DLT_DBUS = ${WITH_DLT_DBUS}") message(STATUS "WITH_DLT_TESTS = ${WITH_DLT_TESTS}") message(STATUS "WITH_DLT_UNIT_TESTS = ${WITH_DLT_UNIT_TESTS}") +if(GTEST_FOUND) + message(STATUS "GTEST_VERSION = ${GTEST_VERSION}") +endif() message(STATUS "WITH_DLT_COVERAGE = ${WITH_DLT_COVERAGE}") message(STATUS "WITH_DLT_SHM_ENABLE = ${WITH_DLT_SHM_ENABLE}") message(STATUS "WITH_DLTTEST = ${WITH_DLTTEST}") +message(STATUS "BUILD_GMOCK = ${BUILD_GMOCK}") +message(STATUS "WITH_GIT_SUBMODULE = ${WITH_GIT_SUBMODULE}") message(STATUS "WITH_DLT_PKGCONFIG = ${WITH_DLT_PKGCONFIG}") message(STATUS "WITH_DLT_CXX11_EXT = ${WITH_DLT_CXX11_EXT}") message(STATUS "WITH_DLT_COREDUMPHANDLER = ${WITH_DLT_COREDUMPHANDLER}")