title: CMake pybind11 cannot create target because another target with the same name already exists, how to bypass?
body: <p>I have code which successfully runs. Its CmakeLists.txt is:</p>
  
  <p><code>cmake_minimum_required(VERSION 3.15)
  project(rotapro3)
  set(CMAKE_CXX_STANDARD 14)
  add_executable(rotapro3 main.cpp)</code>:</p>
  
  <p>I want to use pybind for this project, and following the instructions, I add these lines:</p>
  
  <pre><code>add_subdirectory(pybind)
  pybind11_add_module(rotapro3 main.cpp)
  </code></pre>
  
  <p>It successfully launches, but I am getting an error:</p>
  
  <pre><code> add_executable cannot create target "rotapro3" because another target with
    the same name already exists.  The existing target is a module library
    created in source directory "C:/Users/Alex/Dropbox/rotapro3".
  </code></pre>
  
  <p>I barely have knowledge in CMake. How could I rewrite these lines to allow me use <code>add_executable</code>?</p>
  
  <p>UPDATE:</p>
  
  <p>I have another more complex case:</p>
  
  <pre><code>    set(SOURCE_FILES
          unit_test/geometry/monomer_test.cpp
          unit_test/geometry/monomer_test.hpp
          unit_test/geometry/polymer_test.cpp
          unit_test/geometry/polymer_test.hpp
          unit_test/geometry/unit_box_test.cpp
          unit_test/geometry/unit_box_test.hpp
          unit_test/geometry/rect_shape_3d_test.cpp
          unit_test/geometry/rect_shape_3d_test.hpp
          src/general/guard.cpp
          src/general/guard.hpp
          src/general/fmt_enum.hpp
          src/general/string_format.cpp
          src/general/string_format.hpp
          src/geometry/monomer.cpp
          src/geometry/monomer.hpp
          src/geometry/polymer.cpp
          src/geometry/polymer.hpp
          src/geometry/unit_box.cpp
          src/geometry/unit_box.hpp
          src/geometry/rect_shape_3d.cpp
          src/geometry/rect_shape_3d.hpp
          )
  include_directories(src/general)
  include_directories(src/geometry)
  include_directories(unit_test/general)
  include_directories(unit_test/geometry)
  
  add_executable(
          grapoli_lap ${SOURCE_FILES}
          unit_test/general/string_format_test.cpp
          unit_test/general/string_format_test.hpp
          unit_test/geometry/monomer_test.cpp
          unit_test/geometry/monomer_test.hpp
          unit_test/geometry/polymer_test.cpp
          unit_test/geometry/polymer_test.hpp
          unit_test/geometry/unit_box_test.cpp
          unit_test/geometry/unit_box_test.hpp
          unit_test/geometry/rect_shape_3d_test.cpp
          unit_test/geometry/rect_shape_3d_test.cpp
  )
  
  add_subdirectory(pybind11)
  pybind11_add_module(grapoli_lap grapoli_lib.cpp)
  
  target_link_libraries(grapoli_lap gtest gtest_main)
  </code></pre>
  
  <p>I am getting the same error.</p>