Create proper pkg-config file for libprojectM_playlist.

Generalized the generator code as a macro. Still a huge mess.
This commit is contained in:
Kai Blaschke
2023-01-24 19:13:07 +01:00
parent 2287172cbb
commit ebafd69dfb
4 changed files with 71 additions and 42 deletions

View File

@ -0,0 +1,50 @@
macro(GENERATE_PKG_CONFIG_FILES target package_name)
if(UNIX)
macro(set_pkg_config_path varname path)
if(IS_ABSOLUTE "${path}")
set(${varname} "${path}")
else()
set(${varname} "\${prefix}/${path}")
endif()
endmacro()
set(PKGCONFIG_PACKAGE_NAME "${package_name}")
set(PKGCONFIG_PREFIX "${CMAKE_INSTALL_PREFIX}")
set_pkg_config_path(PKGCONFIG_LIB_DIR "${PROJECTM_LIB_DIR}")
set_pkg_config_path(PKGCONFIG_INCLUDE_DIR "${PROJECTM_INCLUDE_DIR}")
set_pkg_config_path(PKGCONFIG_DATADIR_PATH "${PROJECTM_DATADIR_PATH}")
# Get exported target defines
get_target_property(_exported_defines ${target} INTERFACE_COMPILE_DEFINITIONS)
if(_exported_defines)
foreach(_define ${_exported_defines})
set(PKGCONFIG_FLAGS "${PKGCONFIG_FLAGS} -D${_define}")
endforeach()
endif()
# Using different package name for debug and release, as pkg-config doesn't support
# multi-config packages such as CMake provides. It's a mess.
set(PKGCONFIG_PROJECTM_LIBRARY "${target}")
set(PKGCONFIG_PACKAGE_REQUIREMENTS "${PKGCONFIG_PACKAGE_REQUIREMENTS_ALL} ${PKGCONFIG_PACKAGE_REQUIREMENTS_RELEASE}")
configure_file(${CMAKE_SOURCE_DIR}/cmake/pkgconfig-file.in "${CMAKE_CURRENT_BINARY_DIR}/${package_name}.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${package_name}.pc"
CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
DESTINATION "${PROJECTM_LIB_DIR}/pkgconfig"
COMPONENT Devel
)
set(PKGCONFIG_PROJECTM_LIBRARY "${target}${CMAKE_DEBUG_POSTFIX}")
set(PKGCONFIG_PACKAGE_REQUIREMENTS "${PKGCONFIG_PACKAGE_REQUIREMENTS_ALL} ${PKGCONFIG_PACKAGE_REQUIREMENTS_DEBUG}")
configure_file(${CMAKE_SOURCE_DIR}/cmake/pkgconfig-file.in "${CMAKE_CURRENT_BINARY_DIR}/${package_name}-debug.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${package_name}-debug.pc"
CONFIGURATIONS Debug
DESTINATION "${PROJECTM_LIB_DIR}/pkgconfig"
COMPONENT Devel
)
unset(_output_name)
unset(_exported_defines)
endif()
endmacro()

View File

@ -5,9 +5,9 @@ includedir=@PKGCONFIG_INCLUDE_DIR@
pkgdatadir=@PKGCONFIG_DATADIR_PATH@
sysconfdir=@PKGCONFIG_DATADIR_PATH@
Name: libprojectM
Name: @PKGCONFIG_PACKAGE_NAME@
Version: @PROJECT_VERSION@
Description: projectM Music Visualizer
Requires: opengl
Description: @PKGCONFIG_PACKAGE_DESCRIPTION@
Requires: @PKGCONFIG_PACKAGE_REQUIREMENTS@
Libs: -L${libdir} -l:@PKGCONFIG_PROJECTM_LIBRARY@ @PKGCONFIG_LIBS@
Cflags: -I${includedir} @PKGCONFIG_FLAGS@

View File

@ -256,49 +256,16 @@ install(EXPORT libprojectMTargets
# pkg-config export, only supported on UNIX systems.
if(UNIX)
macro(set_pkg_config_path varname path)
if(IS_ABSOLUTE "${path}")
set(${varname} "${path}")
else()
set(${varname} "\${prefix}/${path}")
endif()
endmacro()
set(PKGCONFIG_PREFIX "${CMAKE_INSTALL_PREFIX}")
set_pkg_config_path(PKGCONFIG_LIB_DIR "${PROJECTM_LIB_DIR}")
set_pkg_config_path(PKGCONFIG_INCLUDE_DIR "${PROJECTM_INCLUDE_DIR}")
set_pkg_config_path(PKGCONFIG_DATADIR_PATH "${PROJECTM_DATADIR_PATH}")
set(PKGCONFIG_FLAGS "")
set(PKGCONFIG_LIBS "")
# Get exported target defines
get_target_property(_exported_defines projectM INTERFACE_COMPILE_DEFINITIONS)
if(_exported_defines)
foreach(_define ${_exported_defines})
set(PKGCONFIG_FLAGS "${PKGCONFIG_FLAGS} -D${_define}")
endforeach()
endif()
include(GeneratePkgConfigFiles)
if(ENABLE_LLVM)
set(PKGCONFIG_LIBS "${PKGCONFIG_LIBS} -L${LLVM_LIB_DIR} ${LLVM_LIBRARIES}")
endif()
# Using different package name for debug and release, as pkg-config doesn't support
# multi-config packages such as CMake provides.
set(PKGCONFIG_PROJECTM_LIBRARY "projectM")
configure_file(libprojectM.pc.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/libprojectM.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libprojectM.pc"
CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
DESTINATION "${PROJECTM_LIB_DIR}/pkgconfig"
COMPONENT Devel
)
set(PKGCONFIG_PACKAGE_NAME "libprojectM")
set(PKGCONFIG_PACKAGE_DESCRIPTION "projectM Music Visualizer")
set(PKGCONFIG_PACKAGE_REQUIREMENTS_ALL "opengl")
generate_pkg_config_files(projectM libprojectM)
set(PKGCONFIG_PROJECTM_LIBRARY "projectM${CMAKE_DEBUG_POSTFIX}")
configure_file(libprojectM.pc.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/libprojectMd.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libprojectMd.pc"
CONFIGURATIONS Debug
DESTINATION "${PROJECTM_LIB_DIR}/pkgconfig"
COMPONENT Devel
)
endif()

View File

@ -141,3 +141,15 @@ install(EXPORT libprojectMPlaylist
DESTINATION "${PROJECTM_LIB_DIR}/cmake/libprojectMPlaylist"
COMPONENT Devel
)
# pkg-config export, only supported on UNIX systems.
if(UNIX)
include(GeneratePkgConfigFiles)
set(PKGCONFIG_PACKAGE_NAME "libprojectM-playlist")
set(PKGCONFIG_PACKAGE_DESCRIPTION "projectM Playlist Library")
set(PKGCONFIG_PACKAGE_REQUIREMENTS_RELEASE "libprojectM")
set(PKGCONFIG_PACKAGE_REQUIREMENTS_DEBUG "libprojectM-debug")
generate_pkg_config_files(projectM_playlist libprojectM-playlist)
endif()