Skip to content

Building/Linking with CPM #405

@cfabrito

Description

@cfabrito

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions