title: CMake find_package Project Name Case
body: <p>I am messing around with importing/exporting CMake packages and came across something I cannot figure out. I have two libraries, <em>lib1</em> and <em>lib2</em> and the following folder structure</p>
  <pre><code>project/
  ├─ lib1/
  │  ├─ CMakeLists.txt
  │  ├─ include/
  │  │  ├─ lib1/
  │  │  │  ├─ lib1.hpp
  │  ├─ src/
  │  │  ├─ lib1.cpp
  ├─ lib2/
  │  ├─ CMakeLists.txt
  │  ├─ include/
  │  │  ├─ lib2/
  │  │  │  ├─ lib2.hpp
  │  ├─ src/
  │  │  ├─ lib2.cpp
  </code></pre>
  <p>I have the following <em>CMakeLists.txt</em> files</p>
  <pre><code>###################################################################################################
  # LIBRARY CREATION
  ###################################################################################################
  cmake_minimum_required(VERSION 3.11)
  
  project(lib1 VERSION 0.0.1 LANGUAGES CXX)
  set(CMAKE_CXX_STANDARD 11)
  set(CMAKE_DEBUG_POSTFIX d)
  include(GNUInstallDirs)
  
  # collect private library headers and implementation files
  file(GLOB LIBRARY_SOURCES CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/*)
  
  # add library
  add_library(${PROJECT_NAME} ${LIBRARY_SOURCES})
  
  # public header file usage for library
  target_include_directories(${PROJECT_NAME} PRIVATE
                             $&lt;BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}&gt;
                             $&lt;INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}&gt;)
  target_include_directories(${PROJECT_NAME} PUBLIC
                             $&lt;BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include&gt;
                             $&lt;INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}&gt;)
  
  # specify compile requirements
  target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
  ###################################################################################################
  
  ###################################################################################################
  # LIBRARY INSTALLATION
  ###################################################################################################
  include(CMakePackageConfigHelpers)
  
  # install library and create export form specifying build artifact installation locations
  install(TARGETS ${PROJECT_NAME}
          EXPORT ${PROJECT_NAME}_Targets
          ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
          RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
          INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  
  # install public headers
  install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}
          DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  
  # install cmake file specifying installation targets
  install(EXPORT ${PROJECT_NAME}_Targets
          FILE ${PROJECT_NAME}Targets.cmake
          NAMESPACE ${PROJECT_NAME}::
          DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
  
  # create version file for cmake project
  write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake
                                    VERSION ${PROJECT_VERSION}
                                    COMPATIBILITY SameMajorVersion)
  
  # create config file for cmake project
  configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
                                ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
                                INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
  
  # install cmake project config files
  install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
                ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
          DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/)
  ###################################################################################################
  </code></pre>
  <pre><code>###################################################################################################
  # LIBRARY CREATION
  ###################################################################################################
  cmake_minimum_required(VERSION 3.11)
  
  project(lib2 VERSION 0.0.1 LANGUAGES CXX)
  set(CMAKE_CXX_STANDARD 11)
  set(CMAKE_DEBUG_POSTFIX d)
  include(GNUInstallDirs)
  
  # collect private library headers and implementation files
  file(GLOB LIBRARY_SOURCES CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/*)
  
  # add library
  add_library(${PROJECT_NAME} ${LIBRARY_SOURCES})
  
  # public header file usage for library
  target_include_directories(${PROJECT_NAME} PRIVATE
                             $&lt;BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}&gt;
                             $&lt;INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}&gt;)
  target_include_directories(${PROJECT_NAME} PUBLIC
                             $&lt;BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include&gt;
                             $&lt;INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}&gt;)
  
  # specify compile requirements
  target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
  
  # link library 1
  find_package(lib1 CONFIG REQUIRED
               COMPONENTS lib1)
  target_link_libraries(${PROJECT_NAME} lib1::lib1)
  ###################################################################################################
  
  ###################################################################################################
  # LIBRARY INSTALLATION
  ###################################################################################################
  include(CMakePackageConfigHelpers)
  
  # install library and create export form specifying build artifact installation locations
  install(TARGETS ${PROJECT_NAME}
          EXPORT ${PROJECT_NAME}_Targets
          ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
          RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
          INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  
  # install public headers
  install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}
          DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  
  # install cmake file specifying installation targets
  install(EXPORT ${PROJECT_NAME}_Targets
          FILE ${PROJECT_NAME}Targets.cmake
          NAMESPACE ${PROJECT_NAME}::
          DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
  
  # create version file for cmake project
  write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake
                                    VERSION ${PROJECT_VERSION}
                                    COMPATIBILITY SameMajorVersion)
  
  # create config file for cmake project
  configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
                                ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
                                INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
  
  # install cmake project config files
  install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
                ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
          DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/)
  ###################################################################################################
  </code></pre>
  <p>and I run the following bash script</p>
  <pre><code>#!/bin/bash
  
  INSTALL_DIR=$PWD/install
  mkdir -p ${INSTALL_DIR}
  
  pushd lib1
  mkdir -p build
  pushd build
  
  cmake .. -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}/lib1 -DCMAKE_BUILD_TYPE=Release
  make install
  
  popd
  popd
  
  pushd lib2
  mkdir -p build
  pushd build
  
  cmake .. -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}/lib2 -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=${INSTALL_DIR}
  make install
  
  popd
  popd
  </code></pre>
  <p>I noticed that if I use &quot;lib1&quot; in the <em>find_package</em> call in CMakeLists.txt for lib2, I get the following error</p>
  <blockquote>
  <p>Make Error at CMakeLists.txt:29 (find_package):
  Found package configuration file:
  /project/install/lib1/lib/cmake/lib1/lib1Config.cmake
  but it set lib1_FOUND to FALSE so package &quot;lib1&quot; is considered to be NOT
  FOUND.</p>
  </blockquote>
  <p>while using &quot;LIB1&quot; results in successful compilation. Anyone know why this is?</p>
  <p><strong>UPDATE 04/21/2022</strong></p>
  <p>Contents of <em>lib1Config.cmake.in</em></p>
  <pre><code>@PACKAGE_INIT@
  include(&quot;${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake&quot;)
  check_required_components(&quot;@PROJECT_NAME@&quot;)
  </code></pre>
  <p>Contents of <em>lib1Config.cmake</em></p>
  <pre><code>####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
  ####### Any changes to this file will be overwritten by the next CMake run ####
  ####### The input file was lib1Config.cmake.in                            ########
  
  get_filename_component(PACKAGE_PREFIX_DIR &quot;${CMAKE_CURRENT_LIST_DIR}/../../../&quot; ABSOLUTE)
  
  macro(set_and_check _var _file)
    set(${_var} &quot;${_file}&quot;)
    if(NOT EXISTS &quot;${_file}&quot;)
      message(FATAL_ERROR &quot;File or directory ${_file} referenced by variable ${_var} does not exist !&quot;)
    endif()
  endmacro()
  
  macro(check_required_components _NAME)
    foreach(comp ${${_NAME}_FIND_COMPONENTS})
      if(NOT ${_NAME}_${comp}_FOUND)
        if(${_NAME}_FIND_REQUIRED_${comp})
          set(${_NAME}_FOUND FALSE)
        endif()
      endif()
    endforeach()
  endmacro()
  
  ####################################################################################
  include(&quot;${CMAKE_CURRENT_LIST_DIR}/lib1Targets.cmake&quot;)
  check_required_components(&quot;lib1&quot;)
  </code></pre>
  <p>Contents of <em>lib1Targets.cmake</em></p>
  <pre><code># Generated by CMake
  
  if(&quot;${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}&quot; LESS 2.5)
     message(FATAL_ERROR &quot;CMake &gt;= 2.6.0 required&quot;)
  endif()
  cmake_policy(PUSH)
  cmake_policy(VERSION 2.6...3.19)
  #----------------------------------------------------------------
  # Generated CMake target import file.
  #----------------------------------------------------------------
  
  # Commands may need to know the format version.
  set(CMAKE_IMPORT_FILE_VERSION 1)
  
  # Protect against multiple inclusion, which would fail when already imported targets are added once more.
  set(_targetsDefined)
  set(_targetsNotDefined)
  set(_expectedTargets)
  foreach(_expectedTarget lib1::lib1_static lib1::lib1_shared)
    list(APPEND _expectedTargets ${_expectedTarget})
    if(NOT TARGET ${_expectedTarget})
      list(APPEND _targetsNotDefined ${_expectedTarget})
    endif()
    if(TARGET ${_expectedTarget})
      list(APPEND _targetsDefined ${_expectedTarget})
    endif()
  endforeach()
  if(&quot;${_targetsDefined}&quot; STREQUAL &quot;${_expectedTargets}&quot;)
    unset(_targetsDefined)
    unset(_targetsNotDefined)
    unset(_expectedTargets)
    set(CMAKE_IMPORT_FILE_VERSION)
    cmake_policy(POP)
    return()
  endif()
  if(NOT &quot;${_targetsDefined}&quot; STREQUAL &quot;&quot;)
    message(FATAL_ERROR &quot;Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n&quot;)
  endif()
  unset(_targetsDefined)
  unset(_targetsNotDefined)
  unset(_expectedTargets)
  
  
  # Compute the installation prefix relative to this file.
  get_filename_component(_IMPORT_PREFIX &quot;${CMAKE_CURRENT_LIST_FILE}&quot; PATH)
  get_filename_component(_IMPORT_PREFIX &quot;${_IMPORT_PREFIX}&quot; PATH)
  get_filename_component(_IMPORT_PREFIX &quot;${_IMPORT_PREFIX}&quot; PATH)
  get_filename_component(_IMPORT_PREFIX &quot;${_IMPORT_PREFIX}&quot; PATH)
  if(_IMPORT_PREFIX STREQUAL &quot;/&quot;)
    set(_IMPORT_PREFIX &quot;&quot;)
  endif()
  
  # Create imported target lib1::lib1_static
  add_library(lib1::lib1_static STATIC IMPORTED)
  
  set_target_properties(lib1::lib1_static PROPERTIES
    INTERFACE_COMPILE_FEATURES &quot;cxx_std_11&quot;
    INTERFACE_INCLUDE_DIRECTORIES &quot;${_IMPORT_PREFIX}/include;${_IMPORT_PREFIX}/include&quot;
  )
  
  # Create imported target lib1::lib1_shared
  add_library(lib1::lib1_shared SHARED IMPORTED)
  
  set_target_properties(lib1::lib1_shared PROPERTIES
    INTERFACE_COMPILE_FEATURES &quot;cxx_std_11&quot;
    INTERFACE_INCLUDE_DIRECTORIES &quot;${_IMPORT_PREFIX}/include;${_IMPORT_PREFIX}/include&quot;
  )
  
  # Load information for each installed configuration.
  get_filename_component(_DIR &quot;${CMAKE_CURRENT_LIST_FILE}&quot; PATH)
  file(GLOB CONFIG_FILES &quot;${_DIR}/lib1Targets-*.cmake&quot;)
  foreach(f ${CONFIG_FILES})
    include(${f})
  endforeach()
  
  # Cleanup temporary variables.
  set(_IMPORT_PREFIX)
  
  # Loop over all imported files and verify that they actually exist
  foreach(target ${_IMPORT_CHECK_TARGETS} )
    foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )
      if(NOT EXISTS &quot;${file}&quot; )
        message(FATAL_ERROR &quot;The imported target \&quot;${target}\&quot; references the file
     \&quot;${file}\&quot;
  but this file does not exist.  Possible reasons include:
  * The file was deleted, renamed, or moved to another location.
  * An install or uninstall procedure did not complete successfully.
  * The installation package was faulty and contained
     \&quot;${CMAKE_CURRENT_LIST_FILE}\&quot;
  but not all the files it references.
  &quot;)
      endif()
    endforeach()
    unset(_IMPORT_CHECK_FILES_FOR_${target})
  endforeach()
  unset(_IMPORT_CHECK_TARGETS)
  
  # This file does not depend on other imported targets which have
  # been exported from the same project but in a separate export set.
  
  # Commands beyond this point should not need to know the version.
  set(CMAKE_IMPORT_FILE_VERSION)
  cmake_policy(POP)
  </code></pre>
  <p>Contents of <em>lib1Targets-release.cmake</em></p>
  <pre><code>#----------------------------------------------------------------
  # Generated CMake target import file for configuration &quot;Release&quot;.
  #----------------------------------------------------------------
  
  # Commands may need to know the format version.
  set(CMAKE_IMPORT_FILE_VERSION 1)
  
  # Import target &quot;lib1::lib1_static&quot; for configuration &quot;Release&quot;
  set_property(TARGET lib1::lib1_static APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  set_target_properties(lib1::lib1_static PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE &quot;CXX&quot;
    IMPORTED_LOCATION_RELEASE &quot;${_IMPORT_PREFIX}/lib/liblib1_static.a&quot;
    )
  
  list(APPEND _IMPORT_CHECK_TARGETS lib1::lib1_static )
  list(APPEND _IMPORT_CHECK_FILES_FOR_lib1::lib1_static &quot;${_IMPORT_PREFIX}/lib/liblib1_static.a&quot; )
  
  # Import target &quot;lib1::lib1_shared&quot; for configuration &quot;Release&quot;
  set_property(TARGET lib1::lib1_shared APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  set_target_properties(lib1::lib1_shared PROPERTIES
    IMPORTED_LOCATION_RELEASE &quot;${_IMPORT_PREFIX}/lib/liblib1_shared.dylib&quot;
    IMPORTED_SONAME_RELEASE &quot;@rpath/liblib1_shared.dylib&quot;
    )
  
  list(APPEND _IMPORT_CHECK_TARGETS lib1::lib1_shared )
  list(APPEND _IMPORT_CHECK_FILES_FOR_lib1::lib1_shared &quot;${_IMPORT_PREFIX}/lib/liblib1_shared.dylib&quot; )
  
  # Commands beyond this point should not need to know the version.
  set(CMAKE_IMPORT_FILE_VERSION)
  </code></pre>