0

I am trying to integrate GTest to my existing project. Below is my following project structure:

--trunk(folder)
  --sources(folder)
    --Prj1
    --Prj2
    --CMakeLists.txt
  --test(folder)
    --test1(folder)
      --test1.h
      --test1.cpp
      --main.cpp
      --CMakeLists.txt(1)
    --test2(folder)
      --test2.h
      --test2.cpp
      --main.cpp
      --CMakeLists.txt(2)
  --CMakeLists.txt(3)
--CMakeLists.txt

Now i want to integerate the GTest for this project. I would have probably 10 tests to be carried out. i would like to know the best way to write /integrate my project.

CMakeList.txt(1)

cmake_minimum_required(VERSION 2.6)
add_test(dummy dummy)
add_executable(dummy main.cpp test1.cpp test1.h)
target_link_libraries(dummy gtest gtest_main)

CMakeList.txt(3)

find_package(Threads REQUIRED)
ADD_SUBDIRECTORY ("C:/gtest/1.7.0"${CMAKE_CURRENT_BINARY_DIR}/gtest")
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})  
add_subdirectory(test)

main.cpp

#include<gtest/gtest.h>

int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

With this i am able to create gtest and gtest_main librabry, but would like to create only one time and link them with all the tests. And moreover i would like to have the test in a folder view in my visual studio project. Could anyone help me to achieve this

aerkenemesis
  • 672
  • 4
  • 16
  • 1
    Possible duplicate of [How to start working with GTest and CMake](https://stackoverflow.com/questions/8507723/how-to-start-working-with-gtest-and-cmake) – usr1234567 Aug 30 '17 at 08:02
  • @usr1234567: With add_subdirectory() i am getting two projects gtest and gtest_main. Is there a possible that i use my own main and use gtest libraries as dependencies but not as a project? –  Aug 30 '17 at 08:24

0 Answers0