I’m trying to generate the tests projects with cmake on Windows machine. When I run this command to generate VS project:
cmake -G “Visual Studio 15 2017 Win64” -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES=“Release” … -DLLVM_DIR=“C:\Users\myusername\Desktop\llvm-6.0.1.src\mybuilddir\lib\cmake\llvm”
I get this message: GTEST_LIB is not found.
In order to make sure the gtest path is found, I add the following code in the cmakelists:
add_subdirectory(${PROJECT_SOURCE_DIR}/googletest EXCLUDE_FROM_ALL)
set_target_properties(gmock PROPERTIES FOLDER “External/GTest”)
set_target_properties(gmock_main PROPERTIES FOLDER “External/GTest”)
set_target_properties(gtest PROPERTIES FOLDER “External/GTest”)
set_target_properties(gtest_main PROPERTIES FOLDER “External/GTest”)
But, I’m getting this error:
CMake Error at googletest/googletest/cmake/internal_utils.cmake:157 (add_library):
add_library cannot create target “gtest” because an imported target with
the same name already exists.
Call Stack (most recent call first):
googletest/googletest/cmake/internal_utils.cmake:184 (cxx_library_with_type)
googletest/googletest/CMakeLists.txt:98 (cxx_library)
CMake Error at googletest/googletest/cmake/internal_utils.cmake:157 (add_library):
add_library cannot create target “gtest_main” because an imported target
with the same name already exists.
Call Stack (most recent call first):
googletest/googletest/cmake/internal_utils.cmake:184 (cxx_library_with_type)
googletest/googletest/CMakeLists.txt:99 (cxx_library)
CMake Error at googletest/googletest/CMakeLists.txt:100 (target_link_libraries):
Cannot specify link libraries for target “gtest_main” which is not built by
this project.
Any ideas on how to fix this?