title: How to fix "Could not find a package configuration file ..." error in CMake?
body: <p>I have been working on a project which uses <a href="https://github.com/Slamtec/rplidar_sdk" rel="noreferrer">rplidar_sdk</a> and in the beginning, I was facing <a href="https://stackoverflow.com/q/64978368/10358768">this</a> problem:</p>
  <blockquote>
  <p>How can I link locally installed SDK's static library in my C++ project?</p>
  <p>Basically, the SDK generates the library in its local directory, and in its <code>Makefile</code>, it does not have <code>install</code> rules. I mean I can run <code>make</code> but after that, if I run <code>sudo make install</code> then it gives <code>make: *** No rule to make target 'install'.  Stop.</code> error.</p>
  </blockquote>
  <p>So, with the help of <a href="https://stackoverflow.com/a/64978601/10358768">this</a> &amp; <a href="https://stackoverflow.com/a/65044763/10358768">this</a> answer, I was able to build my local project. So far so good.</p>
  <p>However, the main problem is that I have to hard-code the RPLidar SDK path in <code>CMakeLists.txt</code> of my repo. Now, whenever someone else in my team starts working on that repo (which is quite obvious) then he/she has to update the <code>CMakeLists.txt</code> first. This is not a good idea/practice!</p>
  <p>To fix this, I updated the <a href="https://github.com/Slamtec/rplidar_sdk/blob/master/sdk/Makefile" rel="noreferrer"><code>Makefile</code></a> of RPLidar SDK as follow:</p>
  <pre><code>.
  .
  .
  
  RPLIDAR_RELEASE_LIB := $(HOME_TREE)/output/Linux/Release/librplidar_sdk.a
  
  install: $(RPLIDAR_RELEASE_LIB)
      install -d $(DESTDIR)/usr/local/lib/rplidar/Release/
      install -m 644 $(RPLIDAR_RELEASE_LIB) $(DESTDIR)/usr/local/lib/rplidar/Release/
  
  
  RPLIDAR_DEBUG_LIB := $(HOME_TREE)/output/Linux/Debug/librplidar_sdk.a
  
  install: $(RPLIDAR_DEBUG_LIB)
      install -d $(DESTDIR)/usr/local/lib/rplidar/Debug/
      install -m 644 $(RPLIDAR_DEBUG_LIB) $(DESTDIR)/usr/local/lib/rplidar/Debug/
  
  
  RPLIDAR_HEADERS := $(HOME_TREE)/sdk/include
  
  install: $(RPLIDAR_HEADERS)
      install -d $(DESTDIR)/usr/local/include/rplidar/
      cp -r $(RPLIDAR_HEADERS)/* $(DESTDIR)/usr/local/include/rplidar/
  
  RPLIDAR_HEADERS_HAL := $(HOME_TREE)/sdk/src/hal
  
  install: $(RPLIDAR_HEADERS_HAL)
      install -d $(DESTDIR)/usr/local/include/rplidar/
      cp -r $(RPLIDAR_HEADERS_HAL) $(DESTDIR)/usr/local/include/rplidar/
  </code></pre>
  <p>Due to this update, now, I can run <code>sudo make install</code> which basically copies the header files of RPLidar SDK from the local directory to <code>/usr/local/rplidar/</code> directory. It also copies the lib file to <code>/usr/local/lib/rplidar/&lt;Debug&gt; or &lt;Release&gt;/</code> directory.</p>
  <p>Now, in my local project, I updated the <code>CMakeLists.txt</code> to as follow:</p>
  <pre><code>cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
  
  project(&lt;project_name&gt;)
  
  set(CMAKE_CXX_STANDARD 17)
  set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
  SET(CMAKE_CXX_FLAGS -pthread)
  
  include_directories(include)
  add_executable(${PROJECT_NAME} src/main.cpp src/another_src_file.cpp)
  
  find_package(rplidar REQUIRED)
  include_directories(${rplidar_INCLUDE_DIRS})
  link_directories(${rplidar_LIBRARY_DIRS})
  target_link_libraries(${PROJECT_NAME} ${rplidar_LIBRARY})
  </code></pre>
  <p>However, upon running <code>cmake ..</code> command, I'm getting this error:</p>
  <pre><code>.
  .
  .
  CMake Error at CMakeLists.txt:12 (find_package):
    By not providing &quot;Findrplidar.cmake&quot; in CMAKE_MODULE_PATH this project has
    asked CMake to find a package configuration file provided by &quot;rplidar&quot;, but
    CMake did not find one.
  
    Could not find a package configuration file provided by &quot;rplidar&quot; with any
    of the following names:
  
      rplidarConfig.cmake
      rplidar-config.cmake
  
    Add the installation prefix of &quot;rplidar&quot; to CMAKE_PREFIX_PATH or set
    &quot;rplidar_DIR&quot; to a directory containing one of the above files.  If
    &quot;rplidar&quot; provides a separate development package or SDK, be sure it has
    been installed.
  
  
  -- Configuring incomplete, errors occurred!
  
  </code></pre>
  <p>As far as I know, RPLidar SDK does not have <code>rplidarConfig.cmake</code> or <code>rplidar-config.cmake</code> file.</p>
  <p>How can I fix this error?</p>