google / sandboxed-api

Generate sandboxes for C/C++ libraries automatically
https://developers.google.com/sandboxed-api/
Apache License 2.0
1.65k stars 189 forks source link

Build error due to CMake problem #128

Closed DemiMarie closed 2 years ago

DemiMarie commented 2 years ago
CMake Error at build/_deps/jsonnet-build/googletest-src/googletest/cmake/internal_utils.cmake:152 (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/user/sandboxed-api/build/_deps/googletest-src/googletest".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  build/_deps/jsonnet-build/googletest-src/googletest/cmake/internal_utils.cmake:209 (cxx_library_with_type)
  build/_deps/jsonnet-build/googletest-src/googletest/CMakeLists.txt:131 (cxx_library)

CMake Error at build/_deps/jsonnet-build/googletest-src/googletest/cmake/internal_utils.cmake:152 (add_library):
  add_library cannot create target "gtest_main" because another target with
  the same name already exists.  The existing target is a static library
  created in source directory
  "/home/user/sandboxed-api/build/_deps/googletest-src/googletest".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  build/_deps/jsonnet-build/googletest-src/googletest/cmake/internal_utils.cmake:209 (cxx_library_with_type)
  build/_deps/jsonnet-build/googletest-src/googletest/CMakeLists.txt:133 (cxx_library)

CMake Error at build/_deps/jsonnet-build/googletest-src/googletest/CMakeLists.txt:146 (target_link_libraries):
  Attempt to add link library "gtest" to target "gtest_main" which is not
  built in this directory.

  This is allowed only when policy CMP0079 is set to NEW.

CMake Error at build/_deps/jsonnet-build/googletest-src/googletest/cmake/internal_utils.cmake:152 (add_library):
  add_library cannot create target "gmock" because another target with the
  same name already exists.  The existing target is a static library created
  in source directory
  "/home/user/sandboxed-api/build/_deps/googletest-src/googlemock".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  build/_deps/jsonnet-build/googletest-src/googletest/cmake/internal_utils.cmake:209 (cxx_library_with_type)
  build/_deps/jsonnet-build/googletest-src/googlemock/CMakeLists.txt:101 (cxx_library)

CMake Error at build/_deps/jsonnet-build/googletest-src/googlemock/CMakeLists.txt:102 (target_link_libraries):
  Attempt to add link library "gtest" to target "gmock" which is not built in
  this directory.

  This is allowed only when policy CMP0079 is set to NEW.

CMake Error at build/_deps/jsonnet-build/googletest-src/googletest/cmake/internal_utils.cmake:152 (add_library):
  add_library cannot create target "gmock_main" because another target with
  the same name already exists.  The existing target is a static library
  created in source directory
  "/home/user/sandboxed-api/build/_deps/googletest-src/googlemock".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  build/_deps/jsonnet-build/googletest-src/googletest/cmake/internal_utils.cmake:209 (cxx_library_with_type)
  build/_deps/jsonnet-build/googletest-src/googlemock/CMakeLists.txt:104 (cxx_library)

CMake Error at build/_deps/jsonnet-build/googletest-src/googlemock/CMakeLists.txt:105 (target_link_libraries):
  Attempt to add link library "gmock" to target "gmock_main" which is not
  built in this directory.

  This is allowed only when policy CMP0079 is set to NEW.
cblichmann commented 2 years ago

Can you outline the exact commands you issued?

This looks like the build folder is in an odd state. Try deleting CMakeCache.txt and re-running cmake <PATH_TO_SAPI> -G Ninja -D SAPI_ENABLE_CONTRIB_TESTS=ON.

The same error may also happen when the GoogleTest module is included twice somewhere (usually via add_subdirectory(). Is jsonnet doing this?

DemiMarie commented 2 years ago

Can you outline the exact commands you issued?

This looks like the build folder is in an odd state. Try deleting CMakeCache.txt and re-running cmake <PATH_TO_SAPI> -G Ninja -D SAPI_ENABLE_CONTRIB_TESTS=ON.

I did find build -delete and re-ran CMake, and the problem persisted.

The same error may also happen when the GoogleTest module is included twice somewhere (usually via add_subdirectory(). Is jsonnet doing this?

I believe this is the cause.

DemiMarie commented 2 years ago

Duplicate of #153.