title: choose to build library or executable in cmake
body: <p>I'm building a library in c++ for which I generate project with CMake.
  However, I don't know how to write a good CMakeLists.txt at the top directory of the library.</p>
  
  <p>In fact, actually it works if I want to simply include the library in another project (adding library, linking sources, etc...), but I want that if I generate the library itself without other project, it generate a demo project provided by the library.
  So I would like a CMakeLists that </p>
  
  <ol>
  <li>link the library in the case of an inclusion in a project</li>
  <li>build a demo in the case of the CmakeLists is used as the top cmakelists.</li>
  </ol>
  
  <p>My first idea is to search if "project(xxx)" has already been called, but I don't know if this is a good idea. As I don't really know what is the good practice about this I have real difficulties to find information in the documentation.</p>