From b303fc6d99d22bb88518a3085099061f3c74c13d Mon Sep 17 00:00:00 2001 From: Christian Gruber Date: Sun, 18 Aug 2019 00:30:42 +0200 Subject: [PATCH] Use target gtest instead of GTEST_LIB and GTEST_INCLUDE_DIR This simplifies usage of GoogleTest, since independent handling of GTEST_LIB and GTEST_INCLUDE_DIR is not necessary anymore. Additionally CMake creates a dependency now between target gtest and all test applications using it. This improves build process when building GoogleTest from source code. When any test application is built, GoogleTest library is automatically rebuilt if necessary now for instance. --- common/cmake_modules/GncAddTest.cmake | 4 ---- common/test-core/CMakeLists.txt | 7 +++++++ gnucash/import-export/csv-imp/test/CMakeLists.txt | 5 ++--- libgnucash/core-utils/test/CMakeLists.txt | 3 +-- libgnucash/engine/test/CMakeLists.txt | 5 ++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/common/cmake_modules/GncAddTest.cmake b/common/cmake_modules/GncAddTest.cmake index f5794734c1..5efc410fee 100644 --- a/common/cmake_modules/GncAddTest.cmake +++ b/common/cmake_modules/GncAddTest.cmake @@ -139,13 +139,9 @@ function(gnc_gtest_configure) "${GTEST_SRC_DIR}/src/gtest_main.cc" "${GTEST_SRC_DIR}/src/gtest-all.cc" PARENT_SCOPE) - set(GTEST_LIB "${CMAKE_BINARY_DIR}/common/test-core/libgtest.a" PARENT_SCOPE) else() find_library(GTEST_SHARED_LIB gtest) find_library(GTEST_MAIN_LIB gtest_main) - if (GTEST_MAIN_LIB AND GTEST_SHARED_LIB) - set(GTEST_LIB "${GTEST_MAIN_LIB};${GTEST_SHARED_LIB}" PARENT_SCOPE) - endif() endif() if ((GTEST_SHARED_LIB OR GTEST_SRC_DIR) AND GTEST_INCLUDE_DIR) set(THREADS_PREFER_PTHREAD_FLAG ON) diff --git a/common/test-core/CMakeLists.txt b/common/test-core/CMakeLists.txt index 36946976fe..ef02718c43 100644 --- a/common/test-core/CMakeLists.txt +++ b/common/test-core/CMakeLists.txt @@ -82,6 +82,13 @@ if (GTEST_SRC_DIR) target_compile_options(gtest PRIVATE -Wno-missing-declarations) endif() target_include_directories(gtest PUBLIC ${GTEST_INCLUDE_DIR} ${GTEST_SRC_DIR}) +else() + add_library(gtest UNKNOWN IMPORTED GLOBAL) + set_target_properties(gtest PROPERTIES + IMPORTED_LOCATION ${GTEST_SHARED_LIB} + INTERFACE_INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIR} + INTERFACE_LINK_LIBRARIES ${GTEST_MAIN_LIB} + ) endif() if (GMOCK_SRC_DIR) set (lib_gmock_SOURCES ${GMOCK_SRC}) diff --git a/gnucash/import-export/csv-imp/test/CMakeLists.txt b/gnucash/import-export/csv-imp/test/CMakeLists.txt index 217cbf3ed7..52b11cbcba 100644 --- a/gnucash/import-export/csv-imp/test/CMakeLists.txt +++ b/gnucash/import-export/csv-imp/test/CMakeLists.txt @@ -12,11 +12,10 @@ set(CSV_IMP_TEST_LIBS gncmod-csv-import gncmod-engine test-core) # This test does not run in Win32 if (NOT WIN32) set(MODULEPATH ${CMAKE_SOURCE_DIR}/gnucash/import-export/csv-imp) - set(gtest_csv_imp_LIBS gncmod-csv-import ${GLIB2_LDFLAGS} ${GTEST_LIB}) + set(gtest_csv_imp_LIBS gncmod-csv-import ${GLIB2_LDFLAGS} gtest) set(gtest_csv_imp_INCLUDES ${MODULEPATH} - ${CSV_IMP_TEST_INCLUDE_DIRS} - ${GTEST_INCLUDE_DIR}) + ${CSV_IMP_TEST_INCLUDE_DIRS}) set(test_tokenizer_SOURCES test-tokenizer.cpp) diff --git a/libgnucash/core-utils/test/CMakeLists.txt b/libgnucash/core-utils/test/CMakeLists.txt index 6da6d16a59..ce9da85730 100644 --- a/libgnucash/core-utils/test/CMakeLists.txt +++ b/libgnucash/core-utils/test/CMakeLists.txt @@ -33,14 +33,13 @@ set(gtest_core_utils_INCLUDES ${CMAKE_SOURCE_DIR}/common # for platform.h ${CMAKE_BINARY_DIR}/libgnucash/core-utils # for gncla-dir.h ${GLIB2_INCLUDE_DIRS} - ${GTEST_INCLUDE_DIR} ) set(gtest_core_utils_LIBS ${GLIB2_LDFLAGS} ${Boost_LIBRARIES} ${GTHREAD_LDFLAGS} - ${GTEST_LIB}) + gtest) set(test_gnc_path_util_SOURCES ${MODULEPATH}/gnc-path.c diff --git a/libgnucash/engine/test/CMakeLists.txt b/libgnucash/engine/test/CMakeLists.txt index c3f2c67b30..5e64393347 100644 --- a/libgnucash/engine/test/CMakeLists.txt +++ b/libgnucash/engine/test/CMakeLists.txt @@ -92,7 +92,7 @@ set(gtest_old_engine_LIBS gncmod-engine ${GLIB2_LDFLAGS} ${Boost_LIBRARIES} - ${GTEST_LIB}) + gtest) set(gtest_qof_LIBS ${GLIB2_LDFLAGS} @@ -101,7 +101,7 @@ set(gtest_qof_LIBS ${GTHREAD_LDFLAGS} ${ICU4C_I18N_LDFLAGS} ${Boost_LIBRARIES} - ${GTEST_LIB}) + gtest) set(gtest_engine_INCLUDES ${MODULEPATH} @@ -109,7 +109,6 @@ set(gtest_engine_INCLUDES ${CMAKE_BINARY_DIR}/common # for config.h ${CMAKE_SOURCE_DIR}/common # for platform.h ${GLIB2_INCLUDE_DIRS} - ${GTEST_INCLUDE_DIR} ../../../borrowed/libc )