0

I get this error, which I've been trying to understand for some time now but getting nowhere.

add_library cannot create target "Plugin" because another target
with the same name already exists.  The existing target is a shared library created 
in source directory "D:/CHAI3D/SOFA/src/applications/plugins/plugin". 
See documentation for policy CMP0002 for more details.

Below is the CMakelists.txt added for reference. I tried to remove the unnecessary code. So far, I've tried allowing duplicate targets with set(ALLOW_DUPLICATE_CUSTOM_TARGETS TRUE) But to no avail

cmake_minimum_required(VERSION 3.1)
project(Plugin VERSION 21.06.99)

# Policies
cmake_policy(SET CMP0079 NEW)

set(ALLOW_DUPLICATE_CUSTOM_TARGETS TRUE)

set (PLUGIN_VERSION ${PROJECT_VERSION})

set(HEADER_FILES
    src/initPlugin.h
    ...
    )
set(SOURCE_FILES
    src/initPlugin.cpp
    ...
)

file(GLOB_RECURSE RESOURCE_FILES  "*.md" "*.psl" "*.py" "*.pyscn" "*.scn" "*.ah")

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${RESOURCE_FILES} )

target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")

set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-DSOFA_BUILD_PLUGIN")
target_link_libraries(${PROJECT_NAME} SofaCore SofaConstraint SofaSimpleFem SofaBaseMechanics SofaRigid SofaBaseVisual SofaOpenglVisual)


## Install rules for the library and headers; CMake package configurations files
sofa_create_package_with_targets(
    PACKAGE_NAME ${PROJECT_NAME}
    PACKAGE_VERSION ${PROJECT_VERSION}
    TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
    INCLUDE_SOURCE_DIR "src"
    INCLUDE_INSTALL_DIR ${PROJECT_NAME}
    RELOCATABLE "plugins"
    )
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY FOLDER "plugins")
B_M
  • 23
  • 5
  • It sounds like you have two rules that both create a target named `Plugin`. Consider including `applications/plugins/CMakeLists.txt` in your question. – Bill Lynch Jul 17 '21 at 16:28
  • @BillLynch, I have added the CMakeLists.txt – B_M Jul 17 '21 at 16:57
  • sofa_create_package_with_targets() create a library the same way you are doing it. add_library(${PROJECT_NAME} ... change your own add_library to use a different target name than ${PROJECT_NAME} – phe Jul 21 '21 at 23:47

0 Answers0