title: How to make cmake find a shared library in a subfolder
body: <p>I'm trying to learn how to make a shared library. And the following seems to work (please comment if you have some feedback to this method, I basically have no idea what I'm doing).</p>
  
  <p>In my library project, I've put the header files into a folder named "include", and the source files into "src".</p>
  
  <p>My library's CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.4.0)
  
  project(mycustomlib)
  
  # Find source files
  file(GLOB SOURCES src/*.cpp)
  
  # Include header files
  include_directories(include)
  
  # Create shared library
  add_library(${PROJECT_NAME} SHARED ${SOURCES})
  
  # Install library
  install(TARGETS ${PROJECT_NAME} DESTINATION lib)
  
  # Install library headers
  file(GLOB HEADERS include/*.h)
  install(FILES ${HEADERS} DESTINATION include)
  </code></pre>
  
  <p>My application's CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.4.0)
  
  project(myprogram)
  
  # Find source files
  file(GLOB SOURCES src/*.cpp)
  
  # Create executable
  add_executable(${PROJECT_NAME} ${SOURCES})
  
  # Find and link library
  find_library(MYCUSTOMLIB mycustomlib)
  target_link_libraries(${PROJECT_NAME} ${MYCUSTOMLIB})
  </code></pre>
  
  <p>And this is <strong>working</strong>. The problem is that I want to put both the headers and the library into subfolders (specifically: <code>/usr/local/include/mycustomlib/</code> for the headers, and <code>/usr/local/lib/mycustomlib/</code> for the library).</p>
  
  <p>So this is my attempt:</p>
  
  <p>My library's new CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.4.0)
  
  project(mycustomlib)
  
  # Find source files
  file(GLOB SOURCES src/*.cpp)
  
  # Include header files
  include_directories(include)
  
  # Create shared library
  add_library(${PROJECT_NAME} SHARED ${SOURCES})
  
  # Install library
  install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME})
  
  # Install library headers
  file(GLOB HEADERS include/*.h)
  install(FILES ${HEADERS} DESTINATION include/${PROJECT_NAME})
  </code></pre>
  
  <p>My application's new CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.4.0)
  
  project(myprogram)
  
  # Find source files
  file(GLOB SOURCES src/*.cpp)
  
  # Create executable
  add_executable(${PROJECT_NAME} ${SOURCES})
  
  # Find and link library
  find_library(MYCUSTOMLIB mycustomlib/mycustomlib)
  target_link_libraries(${PROJECT_NAME} ${MYCUSTOMLIB})
  </code></pre>
  
  <p>And this is <strong>not</strong> working. Now, I'm forced to specify the .so file of the library like this:</p>
  
  <p><code>find_library(MYCUSTOMLIB mycustomlib/libmycustomlib.so)</code></p>
  
  <p>How come?</p>