CMAKE: how to include and link alternative libraries?
<p>My project need four libraries including <code>MPI</code>, <code>BOOST</code>, <code>VTK</code> and <code>SQLITE3</code>. Since <code>BOOST</code> and <code>SQLITE3</code> are too old, I installed new version of the two libraries and the old version are not uninstalled:</p>

<pre><code>BOOST    # alternative BOOST
  |___include
  |___lib
  |
SQLITE   # alternative SQLITE
  |___bin
  |___include
  |___lib
  |___share
  |
Mypoject
  |___src
  |    |___CMakeLists
  |    |___.cpp and .h file
  |
  |___CMakeLists
</code></pre>

<p>And I used <code>FindSQLite3.cmake</code> to find the alternative SQLite3:</p>

<pre><code># Look for the header file.
FIND_PATH(SQLITE3_INCLUDE_DIR sqlite3.h /export/home/hh/hh/sqlite/include)

# Look for the library.
FIND_LIBRARY(SQLITE3_LIBRARY sqlite3 /export/home/hh/hh/sqlite/lib)

# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR)

# Copy the results to the output variables.
IF(SQLITE3_FOUND)
    SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY})
    SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR})
ELSE(SQLITE3_FOUND)
    SET(SQLITE3_LIBRARIES)
    SET(SQLITE3_INCLUDE_DIRS)
ENDIF(SQLITE3_FOUND)

MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES)
</code></pre>

<p>I am trying to link alternative libraries by following lines:</p>

<pre><code># CMake version
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)

SET(VERSION 0.1)
SET(SOVERSION 1)

# searching ENV{PATH} to find mpicc and
# store the path of mpicc to MPI_INTEL_C
FIND_PATH(MPI_INTEL_C mpicc $ENV{PATH})

# searching ENV{PATH} to find mpicxx and
# store the path of mpicc to MPI_INTEL_CXX
FIND_PATH(MPI_INTEL_CXX mpicxx $ENV{PATH})

IF(MPI_INTEL_C AND MPI_INTEL_CXX)
    MESSAGE(STATUS "Intel MPI compiler is used.")

    # set C++ complier as mpicxx, and set C complier as mpicc   
    SET(CMAKE_CXX_COMPILER mpicxx)
    SET(CMAKE_C_COMPILER mpicc)
ENDIF(MPI_INTEL_C AND MPI_INTEL_CXX)

find_package(VTK REQUIRED NO_MODULE)
IF(VTK_FOUND)
    MESSAGE(STATUS "VTK IS USED")
    include(${VTK_USE_FILE})
ELSE()
    MESSAGE("VTK IS NOT FOUND")
ENDIF(VTK_FOUND)

list(APPEND CMAKE_MODULE_PATH "/export/home/hh/hh/iRoot-make/cmake")


FIND_PACKAGE(SQLite3 REQUIRED)
MESSAGE(STATUS "${SQLITE3_INCLUDE_DIRS}")
MESSAGE(STATUS "${SQLITE3_LIBRARY}")

# try to link boost--error
INCLUDE_DIRECTORIES(/export/home/hh/hh/boost/include)
LINK_DIRECTORIES(/export/home/hh/hh/boost/lib)

find_package(MPI REQUIRED)
IF(MPI_FOUND)
    MESSAGE(STATUS "MPI IS USED")
    INCLUDE_DIRECTORIES(${MPI_INCLUDE_PATH})
ELSE()
    MESSAGE("MPI IS NOT FOUND")
ENDIF(MPI_FOUND)

aux_source_directory(. DIR_SRCS)
ADD_EXECUTABLE(test ${DIR_SRCS})

#TARGET_LINK_LIBRARIES(iRoot)

# set location of binary generated by the program, 
# here PROJECT_BINARY_DIR = DIR OF build
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

# set location of lib generated by the program
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

install(TARGETS test DESTINATION bin)
</code></pre>

<p>CMake could not find the alternative <code>SQLite3</code>, and could find the old version:</p>

<pre><code>-- /usr/include
-- /usr/lib64/libsqlite3.so
</code></pre>

<p>but the new version is located at:</p>

<pre><code>/export/home/hh/hh/sqlite/include
/export/home/hh/hh/sqlite/lib/libsqlite3.so
</code></pre>

<p>I am very new to <code>CMAKE</code>, please help me, thank you in advance!</p>