title: Is it possible to install different versions of a library in one place?
body: <h3>The Requirement</h3>
  <p>I want to have multi versions of a library installed in one place(e.g. the default system prefix path) using CMake to be used like: <code>find_package(Package 1.0.0 REQUIRED)</code>.</p>
  <ul>
  <li>Why just don't set some paths?
  <ul>
  <li>Because I'm an idiot at remembering paths and flags and other related stuff and I think it's the CMake's <code>find_package</code> job to handle it.</li>
  </ul>
  </li>
  </ul>
  <h3>The Problem</h3>
  <p>The <code>find_package</code>'s version parameter is just an ordinary parameter <a href="https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-version-selection:%7E:text=CMake%20does%20not%20establish%20any%20convention%20for%20the%20meaning%20of%20version%20numbers.%20Package%20version%20numbers%20are%20checked%20by%20%22version%22%20files%20provided%20by%20the%20packages%20themselves%20or%20by%20FetchContent." rel="nofollow noreferrer">that will be passed to the package <code>*VersionConfig.cmake</code></a> file for version checking and if that file doesn't exists <a href="https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-version-selection:%7E:text=assumed%20to%20not%20be%20compatible%20with%20any%20requested%20version" rel="nofollow noreferrer">CMake will treat it as an error</a>. So we couldn't install different version in the same place.</p>
  <h3>Minimal CMake Configuration</h3>
  <pre><code>file(WRITE Library.H &quot;void Function();&quot;)
  file(WRITE Library.C &quot;void Function() {}&quot;)
  
  add_library(Library SHARED Library.H Library.C)
  target_include_directories(Library 
    PUBLIC 
      $&lt;BUILD_INTERFACE:${PROJECT_SOURCE_DIR}&gt;
      $&lt;INSTALL_INTERFACE:include/Library&gt;
  )
  set_target_properties(Library PROPERTIES VERSION 1.0.0)
  
  install(TARGETS Library EXPORT LibraryConfig)
  install(FILES Library.H DESTINATION include/Library)
  install(EXPORT LibraryConfig DESTINATION lib/cmake/Library)
  
  include(CMakePackageConfigHelpers)
  write_basic_package_version_file(
    ${PROJECT_BINARY_DIR}/LibraryConfigVersion.cmake
    VERSION 1.0.0
    COMPATIBILITY SameMajorVersion
  )
  install(
    FILES ${PROJECT_BINARY_DIR}/LibraryConfigVersion.cmake 
    DESTINATION lib/cmake/Library
  )
  </code></pre>
  <h3>Possible Solution</h3>
  <p>I just apply version to the target name in form of <code>${PROJECT_NAME}-${PROJECT_VERSION}</code>:</p>
  <ol>
  <li>I changed the export name:</li>
  </ol>
  <pre><code>install(TARGETS Library EXPORT Library-1.0.0Config)
  install(
    EXPORT Library-1.0.0Config
    DESTINATION lib/cmake/Library-1.0.0Config
  )
  </code></pre>
  <ol start="2">
  <li>And the <code>INSTALL_INTERFACE</code> for the include directories:</li>
  </ol>
  <pre><code>target_include_directories(Library
    PUBLIC
      $&lt;INSTALL_INTERFACE:include/Library-1.0.0&gt;
  )
  </code></pre>
  <ol start="3">
  <li>And the <code>OUTPUT_NAME</code> property of the target:</li>
  </ol>
  <pre><code>set_target_properties(Library
    PROPERTIES
      OUTPUT_NAME Library-1.0.0
  )
  </code></pre>
  <p>The result:</p>
  <pre><code>file(WRITE Library.H &quot;void Function();&quot;)
  file(WRITE Library.C &quot;void Function() {}&quot;)
  
  add_library(Library SHARED Library.H Library.C)
  target_include_directories(Library 
    PUBLIC 
      $&lt;BUILD_INTERFACE:${PROJECT_SOURCE_DIR}&gt;
      $&lt;INSTALL_INTERFACE:include/Library-1.0.0&gt;
  )
  set_target_properties(Library PROPERTIES OUTPUT_NAME Library-1.0.0)
  
  install(TARGETS Library EXPORT Library-1.0.0Config)
  install(FILES Library.H DESTINATION include/Library-1.0.0)
  install(EXPORT Library-1.0.0Config DESTINATION lib/cmake/Library-1.0.0)
  </code></pre>
  <p>But with this approach, I always have to specify the version: <code>find_package(Target-1.0.0 REQUIRED)</code>.</p>