diff options
author | Kefu Chai <kchai@redhat.com> | 2018-08-14 10:11:13 +0200 |
---|---|---|
committer | Kefu Chai <kchai@redhat.com> | 2018-08-17 09:21:27 +0200 |
commit | 6f231ee8640a332b3a04808b7a5e9126369ebe57 (patch) | |
tree | 549de412fbc31661604e110028e76b3b6db8eefa /cmake | |
parent | Merge PR #23597 into master (diff) | |
download | ceph-6f231ee8640a332b3a04808b7a5e9126369ebe57.tar.xz ceph-6f231ee8640a332b3a04808b7a5e9126369ebe57.zip |
cmake: link against gtest in a better way
* add FindGMock.cmake which allows user to use the libgtest-dev
shipped by distro
* add GMock::{GMock,Main}, GTest::{GTest,Main} targets to be
compatible with FindGTest.cmake and FindGMock.cmake, which
expose the built libraries with properties adhered to
them. so the consumer of them can import them in a better way.
* update tests to drop the commands like
set_target_properties(foo PROPERTIES COMPILE_FLAGS ${UNITTEST_CXX_FLAGS}),
as they are already linked against gmock and gtest.
Signed-off-by: Kefu Chai <kchai@redhat.com>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/modules/AddCephTest.cmake | 1 | ||||
-rw-r--r-- | cmake/modules/FindGMock.cmake | 21 |
2 files changed, 21 insertions, 1 deletions
diff --git a/cmake/modules/AddCephTest.cmake b/cmake/modules/AddCephTest.cmake index a4ed7fbd88a..4ca83eabba0 100644 --- a/cmake/modules/AddCephTest.cmake +++ b/cmake/modules/AddCephTest.cmake @@ -49,5 +49,4 @@ function(add_ceph_unittest unittest_name) endif() add_ceph_test(${unittest_name} "${UNITTEST}") target_link_libraries(${unittest_name} ${UNITTEST_LIBS}) - set_target_properties(${unittest_name} PROPERTIES COMPILE_FLAGS ${UNITTEST_CXX_FLAGS}) endfunction() diff --git a/cmake/modules/FindGMock.cmake b/cmake/modules/FindGMock.cmake new file mode 100644 index 00000000000..ea53f648167 --- /dev/null +++ b/cmake/modules/FindGMock.cmake @@ -0,0 +1,21 @@ +find_path(GMock_INCLUDE_DIR NAMES gmock/gmock.h) +find_library(GMock_GMock_LIBRARY NAMES gmock) +find_library(GMock_Main_LIBRARY NAMES gmock_main) + +find_package_handle_standard_args(GMock + REQUIRED_VARS + GMock_GMock_LIBRARY + GMock_Main_LIBRARY + GMock_INCLUDE_DIR) + +if(GMock_FOUND) + foreach(c GMock Main) + if(NOT TARGET GMock::${c}) + add_library(GMock::${c} UNKNOWN IMPORTED) + set_target_properties(GMock::${c} PROPERTIES + IMPORTED_LOCATION "${GMock_${c}_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${GMock_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX") + endif() + endforeach() +endif() |