This is my first post on StackOverflow, so I apologize if something is wrong with my question.
I am new to CMake, and I have a problem trying to import gtest (Google Test) into a C ++ project with an existing gtest file that is used in the library.
My root file CMakeLists.txtis this (My changes are made between βStart Changesβ and βEnd Changesβ):
cmake_minimum_required(VERSION 2.6)
project(nifi-minifi-cpp)
set(PROJECT_NAME "nifi-minifi-cpp")
set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 2)
set(PROJECT_VERSION_PATCH 0)
IF(POLICY CMP0048)
CMAKE_POLICY(SET CMP0048 OLD)
ENDIF(POLICY CMP0048)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Threads REQUIRED)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
add_subdirectory(thirdparty/yaml-cpp-yaml-cpp-0.5.3)
add_subdirectory(libminifi)
add_subdirectory(main)
set(ASSEMBLY_BASE_NAME "${CMAKE_PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${ASSEMBLY_BASE_NAME}-source")
set(CPACK_SOURCE_IGNORE_FILES "/build/;~$;${CPACK_SOURCE_IGNORE_FILES};${CMAKE_SOURCE_DIR}/.git/;${CMAKE_SOURCE_DIR}/.idea/;${CMAKE_SOURCE_DIR}/cmake-build-debug/")
install(FILES conf/minifi.properties conf/config.yml
DESTINATION conf
COMPONENT bin)
install(PROGRAMS bin/minifi.sh
DESTINATION bin
COMPONENT bin)
install(FILES LICENSE README.md NOTICE
DESTINATION .
COMPONENT bin)
set(CPACK_GENERATOR "TGZ")
set(CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY 1)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Apache NiFi MiNiFi C++ version ${VERSION}")
set(CPACK_PACKAGE_VENDOR "Apache NiFi")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_FILE_NAME "${ASSEMBLY_BASE_NAME}")
set(CPACK_BINARY_TGZ, "ON")
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_ALL bin)
include(CPack)
enable_testing()
set(GTEST_ROOT "thirdparty/googletest/googletest")
add_subdirectory(thirdparty/googletest)
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(tailFileTest
test/TailFileTest.cpp
)
target_link_libraries(tailFileTest ${GTEST_LIBRARY_DEBUG} ${GTEST_MAIN_LIBRARY_DEBUG})
add_test(
NAME tailFileTest
COMMAND tailFileTest
)
And CMake output at startup cmake ..(possibly a more relevant error message):
CMake Error at thirdparty/googletest/googletest/cmake/internal_utils.cmake:151 (add_library):
add_library cannot create target "gtest" because another target with the
same name already exists. The existing target is a static library created
in source directory
"/home/dev/nifi-minifi-cpp/thirdparty/yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest".
See documentation for policy CMP0002 for more details.
I currently have a copy of googletest in:
/home/g/dev/nifi-minifi-cpp/thirdparty/googletest
And the existing googletest directory is inside:
/home/g/dev/nifi-minifi-cpp/thirdparty/yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0
Here is a brief overview of the directory structure:
.
βββ CMakeLists.txt
βββ test [<- My directory to store and run tests]
βββ thirdparty
βββ googletest [<- My googletest directory]
βββ yaml-cpp-yaml-cpp-0.5.3
βββ test
β βββ CMakeLists.txt
β βββ gmock-1.7.0 [<- The existing googletest directory]
278 directories, 2096 files
The overall goal is to have a directory testto run tests.
, , , , . , , , , , , .