Я создал статическую библиотеку с помощью CMake и устанавливаю публичные заголовки в / usr / local / include /.Библиотека и ее тесты хорошо компилируются сами по себе, но при использовании библиотеки в другом проекте я получаю сообщение об ошибке:
/usr/local/include/weftworks/common/network/tcp/acceptor.hpp:28:10: fatal error: utility.hpp: No such file or directory
#include "utility.hpp"
, где оба acceptor.hpp и utility.hpp являются публичными заголовками.
Thisэто связанная структура папок:
root/
├ cmake/
├ external/
├ library/
│ ├─ include/
│ │ ├─ network/
│ │ │ └─ tcp/
│ │ │ └─ acceptor.hpp
│ │ └─ utility.hpp
│ ├─ src/
│ └─ CMakeLists.txt
├ test/
└ CMakeLists.txt
. / library / CMakeLists.txt:
# ./library/CMakeLists.txt
# Required CMake version
cmake_minimum_required(VERSION 3.13)
include(GNUInstallDirs)
# Project details
project(
weftworks-common-library
VERSION 0.4.0
DESCRIPTION "Internal Weftworks Common Library project."
)
# Library target sources
list(APPEND WEFTWORKS_COMMON_LIBRARY_PRIVATE_SOURCES)
list(APPEND WEFTWORKS_COMMON_LIBRARY_PUBLIC_SOURCES)
list(APPEND WEFTWORKS_COMMON_LIBRARY_INTERFACE_SOURCES)
include(src/CMakeLists.txt)
# A static library target
add_library(weftworks-common-library STATIC)
# Required compiler features
target_compile_features(
weftworks-common-library
PUBLIC
cxx_auto_type
cxx_constexpr
cxx_defaulted_functions
cxx_deleted_functions
cxx_final
cxx_lambdas
cxx_noexcept
cxx_override
cxx_range_for
cxx_static_assert
cxx_std_17
cxx_strong_enums
cxx_trailing_return_types
cxx_uniform_initialization
cxx_variadic_macros
)
target_compile_options(
weftworks-common-library
PRIVATE
-Wall
-Wextra
-pedantic
)
target_include_directories(
weftworks-common-library
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)
target_link_libraries(
weftworks-common-library
PUBLIC
Boost::boost
Boost::system
Boost::program_options
spdlog::spdlog
Threads::Threads
)
target_sources(
weftworks-common-library
PUBLIC ${WEFTWORKS_COMMON_LIBRARY_PUBLIC_SOURCES}
INTERFACE ${WEFTWORKS_COMMON_LIBRARY_INTERFACE_SOURCES}
PRIVATE ${WEFTWORKS_COMMON_LIBRARY_PRIVATE_SOURCES}
)
# Create alias target
add_library(weftworks::common-library ALIAS weftworks-common-library)
# Install library target
install(
TARGETS weftworks-common-library
EXPORT weftworks-common-library-config
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
EXPORT weftworks-common-library-config
NAMESPACE weftworks::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/weftworks/common-library
)
# Install public headers
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/weftworks/common
)
Теперь я не знаю, что мне нужно сделать, чтобы сделать эту работу.Я хотел бы избежать использования «префикса библиотеки» в структуре проекта, то есть library/include/weftworks/common/
, чтобы упростить его.