Skip to content

Commit

Permalink
added support for building unit tests with local gtest/gmock librarie…
Browse files Browse the repository at this point in the history
…s in new cmake option USE_SHARED_GTEST_GMOCK (#2089)
  • Loading branch information
giuspen committed Oct 23, 2022
1 parent e0ddad8 commit e589133
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ endif()

option(USE_NLS "Add locales support" ON)
option(USE_SHARED_FMT_SPDLOG "Use shared fmt and spdlog (not those bundled)" ON)
option(USE_SHARED_GTEST_GMOCK "Use shared gtest and gmock (not those bundled)" OFF)
if(WIN32)
option(USE_VTE "Add virtual terminal support" OFF)
else()
Expand Down
53 changes: 41 additions & 12 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@

add_compile_options(-Wall -Wextra -Wunreachable-code -Wuninitialized)

add_subdirectory(
googletest
)
if(USE_SHARED_GTEST_GMOCK)
message("Using gtest, gmock from: SHARED LIB")
pkg_check_modules(GTEST gtest REQUIRED)
pkg_check_modules(GMOCK gmock REQUIRED)
else()
message("Using gtest, gmock from: BUNDLED SRC")
add_subdirectory(
googletest
)
endif()

include_directories(
${CMAKE_SOURCE_DIR}/src/ct
)

mark_as_advanced(
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
gmock_build_tests gtest_build_samples gtest_build_tests
gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols
)
if(USE_SHARED_GTEST_GMOCK)
include_directories(
SYSTEM ${GTEST_INCLUDE_DIRS}
SYSTEM ${GMOCK_INCLUDE_DIRS}
)
else()
mark_as_advanced(
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
gmock_build_tests gtest_build_samples gtest_build_tests
gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols
)

set_target_properties(gtest PROPERTIES FOLDER extern)
set_target_properties(gtest_main PROPERTIES FOLDER extern)
set_target_properties(gmock PROPERTIES FOLDER extern)
set_target_properties(gmock_main PROPERTIES FOLDER extern)
set_target_properties(gtest PROPERTIES FOLDER extern)
set_target_properties(gtest_main PROPERTIES FOLDER extern)
set_target_properties(gmock PROPERTIES FOLDER extern)
set_target_properties(gmock_main PROPERTIES FOLDER extern)
endif()

macro(package_add_test TESTNAME)
# create an exectuable in which the tests will be stored
Expand Down Expand Up @@ -77,6 +91,21 @@ if(AUTO_RUN_TESTING)
endif()
endif()

if(USE_SHARED_GTEST_GMOCK)
target_link_libraries(run_tests_no_x
${GTEST_LIBRARIES}
${GMOCKLIBRARIES}
)
target_link_libraries(run_tests_with_x_1
${GTEST_LIBRARIES}
${GMOCKLIBRARIES}
)
target_link_libraries(run_tests_with_x_2
${GTEST_LIBRARIES}
${GMOCKLIBRARIES}
)
endif()

set_target_properties(run_tests_no_x PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
set_target_properties(run_tests_with_x_1 PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
set_target_properties(run_tests_with_x_2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")

0 comments on commit e589133

Please sign in to comment.