CmakeLists.txt: Fixed package config generation

This commit is contained in:
gabime 2019-10-04 21:49:20 +03:00
parent 5c02fc47b9
commit cf2bf488a2
2 changed files with 16 additions and 8 deletions

View File

@ -87,8 +87,6 @@ set(SPDLOG_SRCS
src/file_sinks.cpp
src/async.cpp)
set(SPDLOG_CFLAGS "${PROJECT_NAME}")
if (SPDLOG_BUILD_SHARED)
if(WIN32)
message(FATAL_ERROR "spdlog shared lib is not yet supported under windows")
@ -129,14 +127,13 @@ if(SPDLOG_FMT_EXTERNAL)
if (NOT TARGET fmt::fmt)
find_package(fmt REQUIRED)
endif ()
set(SPDLOG_CFLAGS "${SPDLOG_CFLAGS} -DSPDLOG_FMT_EXTERNAL")
target_compile_definitions(spdlog PUBLIC SPDLOG_FMT_EXTERNAL)
target_link_libraries(spdlog PUBLIC fmt::fmt)
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FMT_EXTERNAL)
target_link_libraries(spdlog_header_only INTERFACE fmt::fmt)
set(PKG_CONFIG_REQUIRES fmt) # add dependecy to pkg-config
endif()
if(SPDLOG_WCHAR_SUPPORT)
@ -204,11 +201,17 @@ if (SPDLOG_INSTALL)
endif()
#---------------------------------------------------------------------------------------
# Package and version files
# Install pkg-config file
#---------------------------------------------------------------------------------------
get_target_property(PKG_CONFIG_DEFINES spdlog INTERFACE_COMPILE_DEFINITIONS)
string(REPLACE ";" " -D" PKG_CONFIG_DEFINES "${PKG_CONFIG_DEFINES}")
string(PREPEND PKG_CONFIG_DEFINES "-D")
configure_file("cmake/${PROJECT_NAME}.pc.in" "${pkg_config}" @ONLY)
install(FILES "${pkg_config}" DESTINATION "${pkgconfig_install_dir}")
#---------------------------------------------------------------------------------------
# Install CMake config files
#---------------------------------------------------------------------------------------
install(EXPORT spdlog
DESTINATION ${export_dest_dir}
NAMESPACE spdlog::
@ -216,6 +219,7 @@ if (SPDLOG_INSTALL)
include(CMakePackageConfigHelpers)
configure_file("${project_config_in}" "${project_config_out}" @ONLY)
write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion)
install(FILES
"${project_config_out}"
@ -227,3 +231,4 @@ if (SPDLOG_INSTALL)
include(cmake/spdlogCPack.cmake)
endif ()

View File

@ -7,5 +7,8 @@ Name: lib@PROJECT_NAME@
Description: Fast C++ logging library.
URL: https://github.com/gabime/@PROJECT_NAME@
Version: @SPDLOG_VERSION@
CFlags: -I${includedir}/@SPDLOG_CFLAGS@
Libs: -L${libdir}/@PROJECT_NAME@ -l@PROJECT_NAME@
CFlags: -I${includedir} @PKG_CONFIG_DEFINES@
Libs: -L${libdir} -lspdlog
Libs.private: -lpthread
Requires: @PKG_CONFIG_REQUIRES@