title: CMake Tests for a library intended as a git submodule
body: <p>Situation: You develop a library which uses CMake as its (meta-)buildsystem. The library is header-only (actually it does need to, the question still applies), has tests and examples (like benchmarks). The library can be used by installing it and using the resulting package files or (which is often easier to avoid mismatches in ABIs) by adding it as a <code>git submodule</code> and simply <code>add_subdirectory</code> it.</p>
  
  <p>Question: What is the best way to handle tests in that library?</p>
  
  <p>Usually the top-level CMake will look like this:</p>
  
  <pre><code>[...setup code, project(...)`]
  add_library(foo src/foo.cpp)
  target_include_libraries(foo PUBLIC include)
  
  include(CTest)
  if(BUILD_TESTING)
    add_subdirectory(tests)
  endif()
  if(FOO_BUILD_EXAMPLES)
    add_subdirectory(examples)
  endif()
  install(TARGETS foo ...)
  install(...)
  </code></pre>
  
  <p>The issue I have with this is that when this is used as a submodule and the super project also uses <code>include(CTest)</code> and <code>BUILD_TESTING</code> then enabling the super projects tests enables also the submodule tests.</p>
  
  <p>Is this what should be done and expected?</p>
  
  <p>Similar for the install commands: Installing the super project installs also the submodule (I think) which may be wrong as the <code>CMAKE_INSTALL_PREFIX</code> given was intended for the super project and might not be appropriate for the submodule.</p>
  
  <p>This would lead to using prefixes and options like <code>FOO_BUILD_TESTING</code> and <code>FOO_INSTALL</code> but I don't see them used often.</p>
  
  <p>Am I worrying to much or missing anything? What is the way to go with building (and running) tests and installs for git submodules?</p>