Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building/Linking with CPM #405

Open
cfabrito opened this issue Jul 5, 2021 · 3 comments
Open

Building/Linking with CPM #405

cfabrito opened this issue Jul 5, 2021 · 3 comments

Comments

@cfabrito
Copy link

cfabrito commented Jul 5, 2021

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
Copy link

golxzn commented Nov 28, 2022

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

@golxzn
Copy link

golxzn commented Nov 28, 2022

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

@scheibel
Copy link
Member

scheibel commented Feb 5, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants