title: CMake: rebuild external project
body: <p>I have a project that uses an external library. The project's CMakeLists.txt looks like this:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.6.0)
  
  project(my-project)
  
  set(CMAKE_CXX_STANDARD 14)
  
  include(ExternalProject)
  find_package(Git REQUIRED)
  
  ExternalProject_Add(library
          PREFIX ${my-project_SOURCE_DIR}/lib/library
          GIT_REPOSITORY https://github.com/vendor/library
          GIT_TAG master
          UPDATE_COMMAND ""
          INSTALL_COMMAND ""
          )
  
  link_directories(${my-project_SOURCE_DIR}/lib/library/src/library-build/src)
  
  add_subdirectory(src)
  </code></pre>
  
  <p>And src/CMakeLists.txt like this:</p>
  
  <pre><code>include_directories(../lib/library/src/library/include)
  
  add_executable(my-project
          main.cpp
          )
  
  add_dependencies(my-project library)
  
  target_link_libraries(my-project liblibrary.a)
  </code></pre>
  
  <p>It pulls the library from Git and builds it for the first time without any problems.</p>
  
  <p><strong>I want to edit source code of the library and have the library .a file be recompiled automatically. What is the cleanest way I can achieve that?</strong> It currently ignores any updates to the source code, because it already has .a file of the library.</p>
  
  <p>When I try to add</p>
  
  <pre><code>add_subdirectory(lib/library/src/library/src)
  </code></pre>
  
  <p>to my main CMakeLists.txt, I get the following error:</p>
  
  <p>CMake Error at lib/library/src/library/src/CMakeLists.txt:55 (add_library): add_library cannot create target "library" because another target with the same name already exists.  The existing target is a custom target created in source directory "/cygdrive/c/Code/my-project".  See documentation for policy CMP0002 for more details.</p>
  
  <p>I guess it's caused by calling </p>
  
  <pre><code>add_library(gram STATIC ${SOURCE_FILES})
  </code></pre>
  
  <p>in the library CMakeLists.txt and then calling </p>
  
  <pre><code>ExternalProject_Add(library ...)
  </code></pre>
  
  <p>in the project CMakeLists.txt.</p>
  
  <p>Any ideas?</p>