Work around FindGMock/Catkin target name clash (#1011)
Handle case with multiple invocations (avoid pasting ${CMAKE_THREAD_LIBS_INIT} multiple times). Also check if target 'gmock' already exists before building GMock to avoid failures if GMock was already find_packaged() from another subproject. FIXES=https://github.com/googlecartographer/cartographer_ros/issues/776master
parent
915ebb19a6
commit
ae05658ff7
|
@ -12,58 +12,64 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
find_path(GMOCK_INCLUDE_DIRS gmock/gmock.h
|
if(NOT GMock_FOUND)
|
||||||
HINTS
|
find_path(GMOCK_INCLUDE_DIRS gmock/gmock.h
|
||||||
ENV GMOCK_DIR
|
|
||||||
PATH_SUFFIXES include
|
|
||||||
PATHS
|
|
||||||
/usr
|
|
||||||
)
|
|
||||||
|
|
||||||
# Find system-wide installed gmock.
|
|
||||||
find_library(GMOCK_LIBRARIES
|
|
||||||
NAMES gmock_main
|
|
||||||
HINTS
|
|
||||||
ENV GMOCK_DIR
|
|
||||||
PATH_SUFFIXES lib
|
|
||||||
PATHS
|
|
||||||
/usr
|
|
||||||
)
|
|
||||||
|
|
||||||
# Find system-wide gtest header.
|
|
||||||
find_path(GTEST_INCLUDE_DIRS gtest/gtest.h
|
|
||||||
HINTS
|
|
||||||
ENV GTEST_DIR
|
|
||||||
PATH_SUFFIXES include
|
|
||||||
PATHS
|
|
||||||
/usr
|
|
||||||
)
|
|
||||||
list(APPEND GMOCK_INCLUDE_DIRS ${GTEST_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
if(NOT GMOCK_LIBRARIES)
|
|
||||||
# If no system-wide gmock found, then find src version.
|
|
||||||
# Ubuntu might have this.
|
|
||||||
find_path(GMOCK_SRC_DIR src/gmock.cc
|
|
||||||
HINTS
|
HINTS
|
||||||
ENV GMOCK_DIR
|
ENV GMOCK_DIR
|
||||||
|
PATH_SUFFIXES include
|
||||||
PATHS
|
PATHS
|
||||||
/usr/src/googletest/googlemock
|
/usr
|
||||||
/usr/src/gmock
|
|
||||||
)
|
)
|
||||||
if(GMOCK_SRC_DIR)
|
|
||||||
# If src version found, build it.
|
|
||||||
add_subdirectory(${GMOCK_SRC_DIR} "${CMAKE_CURRENT_BINARY_DIR}/gmock")
|
|
||||||
# The next line is needed for Ubuntu Trusty.
|
|
||||||
set(GMOCK_INCLUDE_DIRS "${GMOCK_SRC_DIR}/gtest/include")
|
|
||||||
set(GMOCK_LIBRARIES gmock_main)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# System-wide installed gmock library might require pthreads.
|
# Find system-wide installed gmock.
|
||||||
find_package(Threads REQUIRED)
|
find_library(GMOCK_LIBRARIES
|
||||||
list(APPEND GMOCK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
|
NAMES gmock_main
|
||||||
|
HINTS
|
||||||
|
ENV GMOCK_DIR
|
||||||
|
PATH_SUFFIXES lib
|
||||||
|
PATHS
|
||||||
|
/usr
|
||||||
|
)
|
||||||
|
|
||||||
|
# Find system-wide gtest header.
|
||||||
|
find_path(GTEST_INCLUDE_DIRS gtest/gtest.h
|
||||||
|
HINTS
|
||||||
|
ENV GTEST_DIR
|
||||||
|
PATH_SUFFIXES include
|
||||||
|
PATHS
|
||||||
|
/usr
|
||||||
|
)
|
||||||
|
list(APPEND GMOCK_INCLUDE_DIRS ${GTEST_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
if(NOT GMOCK_LIBRARIES)
|
||||||
|
# If no system-wide gmock found, then find src version.
|
||||||
|
# Ubuntu might have this.
|
||||||
|
find_path(GMOCK_SRC_DIR src/gmock.cc
|
||||||
|
HINTS
|
||||||
|
ENV GMOCK_DIR
|
||||||
|
PATHS
|
||||||
|
/usr/src/googletest/googlemock
|
||||||
|
/usr/src/gmock
|
||||||
|
)
|
||||||
|
if(GMOCK_SRC_DIR)
|
||||||
|
# If src version found, build it.
|
||||||
|
if(NOT TARGET gmock)
|
||||||
|
add_subdirectory(${GMOCK_SRC_DIR} "${CMAKE_CURRENT_BINARY_DIR}/gmock")
|
||||||
|
endif()
|
||||||
|
# The next line is needed for Ubuntu Trusty.
|
||||||
|
set(GMOCK_INCLUDE_DIRS "${GMOCK_SRC_DIR}/gtest/include")
|
||||||
|
set(GMOCK_LIBRARIES gmock_main)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# System-wide installed gmock library might require pthreads.
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
list(APPEND GMOCK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
endif()
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
find_package_handle_standard_args(GMock DEFAULT_MSG GMOCK_LIBRARIES
|
find_package_handle_standard_args(GMock DEFAULT_MSG GMOCK_LIBRARIES
|
||||||
GMOCK_INCLUDE_DIRS)
|
GMOCK_INCLUDE_DIRS)
|
||||||
|
|
||||||
|
# Mitigate build issue with Catkin
|
||||||
|
set(GMOCK_FOUND FALSE)
|
||||||
|
|
Loading…
Reference in New Issue