cginternals / globjects

C++ library strictly wrapping OpenGL objects.
https://globjects.org
MIT License
538 stars 59 forks source link

Building/Linking with CPM #405

Open cfabrito opened 3 years ago

cfabrito commented 3 years ago

Hello! I'm attempting to build&link globjects to my project via CPM. This is an incredibly convenient tool given that as soon as you clone you're ready to build the project without worrying about dependencies. It's close to working, however due to some shared target names between glbinding and globjects, I'm unable to do so:

Error       CMake Error at out/build/x64-Debug/_deps/globjects-src/deploy/CMakeLists.txt:6 (add_custom_target):
  add_custom_target cannot create target "pack" because another target with
  the same name already exists.  The existing target is a custom target
  created in source directory
out/build/x64-Debug/_deps/glbinding-src/deploy".
  See documentation for policy CMP0002 for more details.
Error       CMake Error at out/build/x64-Debug/_deps/globjects-src/source/tests/CMakeLists.txt:37 (add_custom_command):
  TARGET 'test' was not created in this directory.  ${META_PROJECT_NAME}-tests  C:\Users\Utilizador\Documents\Repos\sdl_cpm_test\out/build/x64-Debug/_deps/globjects-src/source/tests/CMakeLists.txt    37  
Error       CMake Error at out/build/x64-Debug/_deps/globjects-src/source/tests/CMakeLists.txt:52 (add_library):
  add_library cannot create target "gmock-dev" because another target with
  the same name already exists.  The existing target is an interface library
  created in source directory
  "/out/build/x64-Debug/_deps/glbinding-src/source/tests".
  See documentation for policy CMP0002 for more details.    ${META_PROJECT_NAME}-tests  C:\Users\Utilizador\Documents\Repos\sdl_cpm_test\out/build/x64-Debug/_deps/globjects-src/source/tests/CMakeLists.txt    52  
Error       CMake Error at out/build/x64-Debug/_deps/globjects-src/source/tests/CMakeLists.txt:70 (add_custom_target):
  add_custom_target cannot create target "test" because another target with
  the same name already exists.  The existing target is a custom target
  created in source directory
  "/out/build/x64-Debug/_deps/glbinding-src/source/tests".
  See documentation for policy CMP0002 for more details.    ${META_PROJECT_NAME}-tests  C:\Users\Utilizador\Documents\Repos\sdl_cpm_test\out/build/x64-Debug/_deps/globjects-src/source/tests/CMakeLists.txt    70  
Error       CMake Error at out/build/x64-Debug/_deps/globjects-src/source/tests/googletest/googletest/cmake/internal_utils.cmake:145 (add_library):
  add_library cannot create target "gmock_main" because another target with
  the same name already exists.  The existing target is a shared library
  created in source directory
  "/out/build/x64-Debug/_deps/glbinding-src/source/tests/googletest/googlemock".
  See documentation for policy CMP0002 for more details.        C:\Users\Utilizador\Documents\Repos\sdl_cpm_test\out/build/x64-Debug/_deps/globjects-src/source/tests/googletest/googletest/cmake/internal_utils.cmake  145 
Error       CMake Error at out/build/x64-Debug/_deps/globjects-src/source/tests/googletest/googletest/cmake/internal_utils.cmake:145 (add_library):
  add_library cannot create target "gtest_main" because another target with
  the same name already exists.  The existing target is a shared library
  created in source directory
  "/out/build/x64-Debug/_deps/glbinding-src/source/tests/googletest/googletest".
  See documentation for policy CMP0002 for more details.        C:\Users\Utilizador\Documents\Repos\sdl_cpm_test\out/build/x64-Debug/_deps/globjects-src/source/tests/googletest/googletest/cmake/internal_utils.cmake  145 
Error       CMake Error at out/build/x64-Debug/_deps/globjects-src/source/tests/googletest/googletest/cmake/internal_utils.cmake:145 (add_library):
  add_library cannot create target "gmock" because another target with the
  same name already exists.  The existing target is a shared library created
  in source directory
  "/out/build/x64-Debug/_deps/glbinding-src/source/tests/googletest/googlemock".
  See documentation for policy CMP0002 for more details.        C:\Users\Utilizador\Documents\Repos\sdl_cpm_test\out/build/x64-Debug/_deps/globjects-src/source/tests/googletest/googletest/cmake/internal_utils.cmake  145 
Error       CMake Error at out/build/x64-Debug/_deps/globjects-src/source/tests/googletest/googletest/cmake/internal_utils.cmake:145 (add_library):
  add_library cannot create target "gtest" because another target with the
  same name already exists.  The existing target is a shared library created
  in source directory
  "/out/build/x64-Debug/_deps/glbinding-src/source/tests/googletest/googletest".
  See documentation for policy CMP0002 for more details.        C:\Users\Utilizador\Documents\Repos\sdl_cpm_test\out/build/x64-Debug/_deps/globjects-src/source/tests/googletest/googletest/cmake/internal_utils.cmake  145 
Error       CMake Error at out/build/x64-Debug/_deps/globjects-src/source/tests/googletest/googletest/CMakeLists.txt:95 (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.   gtest   C:\Users\Utilizador\Documents\Repos\sdl_cpm_test\out/build/x64-Debug/_deps/globjects-src/source/tests/googletest/googletest/CMakeLists.txt  95

This is the CMakeLists I'm using:

cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

# ---- Project ----
project(avf)

#including CPM.cmake, a package manager:
#https://github.com/TheLartians/CPM.cmake
include(cmake/CPM.cmake)

CPMAddPackage(
  NAME SDL2
  VERSION 2.0.12
  URL https://libsdl.org/release/SDL2-2.0.12.zip
)

if (SDL2_ADDED)
  add_library(SDL2::SDL2 ALIAS SDL2)
endif()

set(ALLOW_DUPLICATE_CUSTOM_TARGETS True )

CPMAddPackage(
  NAME glm
  GITHUB_REPOSITORY g-truc/glm
  GIT_TAG origin/master
)

CPMAddPackage(
  NAME glbinding
  GITHUB_REPOSITORY cginternals/glbinding
  GIT_TAG origin/master
)

CPMAddPackage(
  NAME globjects
  GITHUB_REPOSITORY cginternals/globjects
  GIT_TAG origin/v2.0
)

# OpenGL
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS})

# ---- Create executable target ----
add_executable(avf src/main.cpp)

target_link_libraries(avf SDL2 ${OPENGL_LIBRARIES} glbinding globjects)

I would really appreciate it if you could take a look. Thanks in advance.

golxzn commented 1 year ago

Hi! Did someone fix this issue? I have the same problem and it's annoying.

golxzn commented 1 year ago

Actually, we can solve this annoying problem by adding simple check of targets exist in the src/globjects/CMakeLists.txt file: image

scheibel commented 1 year ago

Maintainer of globjects here: does the proposal of @golxzn fix the issue? Is a corresponding release of globjects desirable?