CMake: Как добавить подкаталог с библиотекой? - PullRequest
0 голосов
/ 20 февраля 2019

Я не могу заставить cmake искать библиотеку в подкаталоге /usr/local/lib/db5.

Для поиска библиотек я использую следующий скрипт:

link_directories(/usr/local/lib/db5 /usr/local/lib /usr/lib)

set (LIBRARIES
        c m util ssl pthread db)

foreach (LIBRARY ${LIBRARIES})
    find_library ("${LIBRARY}_FOUND" ${LIBRARY})
    message (STATUS "Check the ${LIBRARY} is installed: " ${${LIBRARY}_FOUND})
    if ( "${${LIBRARY}_FOUND}" STREQUAL "${LIBRARY}_FOUND-NOTFOUND" )
        message (STATUS "Adding library sources")
        add_subdirectory (../${LIBRARY} lib/${LIBRARY})
    endif ()
endforeach ()

Библиотекаопределенно присутствует в каталоге.

ogogon@:/usr/local/src/util# ls /usr/local/lib/db5
libdb_cxx-5.3.a     libdb_cxx-5.3.so.0.0.0  libdb_cxx.so        libdb_stl-5.3.so.0  libdb_stl.a     libdb-5.3.so        libdb-5.so
libdb_cxx-5.3.so    libdb_cxx-5.so      libdb_stl-5.3.a     libdb_stl-5.3.so.0.0.0  libdb_stl.so        libdb-5.3.so.0      libdb.a
libdb_cxx-5.3.so.0  libdb_cxx.a     libdb_stl-5.3.so    libdb_stl-5.so      libdb-5.3.a     libdb-5.3.so.0.0.0  libdb.so

Поиск в библиотеке не приводит к успеху.

ogogon@ot:/usr/local/src/util# ./configure 
-- The C compiler identification is Clang 6.0.0
-- The CXX compiler identification is Clang 6.0.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check the c is installed: /usr/lib/libc.so
-- Check the m is installed: /usr/lib/libm.so
-- Check the util is installed: /usr/lib/libutil.so
-- Check the ssl is installed: /usr/lib/libssl.so
-- Check the pthread is installed: /usr/lib/libpthread.so
-- Check the db is installed: db_FOUND-NOTFOUND
-- Adding library sources
CMake Error at CMakeLists.txt:27 (add_subdirectory):
  add_subdirectory given source "../db" which is not an existing directory.


-- Configuring incomplete, errors occurred!
See also "/usr/local/src/util/CMakeFiles/CMakeOutput.log".

Если я удаляю библиотеку db из списка - все идет хорошо.

ogogon@ot:/usr/local/src/util# ./configure 
-- The C compiler identification is Clang 6.0.0
-- The CXX compiler identification is Clang 6.0.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check the c is installed: /usr/lib/libc.so
-- Check the m is installed: /usr/lib/libm.so
-- Check the util is installed: /usr/lib/libutil.so
-- Check the ssl is installed: /usr/lib/libssl.so
-- Check the pthread is installed: /usr/lib/libpthread.so
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/src/util

Что я делаю не так?Как мне решить эту проблему?

1 Ответ

0 голосов
/ 22 февраля 2019

Теперь я решил эту проблему следующим образом:

set (LIBPATHS /usr/local/lib/db5 /usr/local/lib /usr/lib libs5)

set (LIBRARIES
        c m util db ssl pthread)

foreach (LIBRARY ${LIBRARIES})
    find_library ("${LIBRARY}_FOUND" ${LIBRARY} PATHS ${LIBPATHS})
    message (STATUS "Check the ${LIBRARY} is installed: " ${${LIBRARY}_FOUND})
    if ( "${${LIBRARY}_FOUND}" STREQUAL "${LIBRARY}_FOUND-NOTFOUND" )
        message (STATUS "Adding library sources")
        add_subdirectory (../${LIBRARY} lib/${LIBRARY})
    endif ()
endforeach ()

Но, если версия библиотеки Berkley DB изменится, пути придется скорректировать.Есть ли способ написать что-то вроде / usr / local / lib / db *?

...