Skip to content

Commit

Permalink
driver: Fix pkg-config dependency list generation (#61)
Browse files Browse the repository at this point in the history
Tested on Linux. pkg-config is also generated on macOS, but this is
untested for now. The main use case is for Linux anyway.
  • Loading branch information
PeterCxy authored Mar 23, 2024
1 parent 94be1bc commit edeb2be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
24 changes: 21 additions & 3 deletions driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ option(LPAC_WITH_HTTP_CURL "Build HTTP Curl interface" ON)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} DIR_INTERFACE_SRCS)
if(LPAC_DYNAMIC_DRIVERS)
add_library(euicc-drivers SHARED ${DIR_INTERFACE_SRCS})
list(APPEND LIBEUICC_DRIVERS_REQUIRES "libeuicc = ${PROJECT_VERSION}")
else()
add_library(euicc-drivers STATIC ${DIR_INTERFACE_SRCS})
endif()
Expand All @@ -26,9 +27,16 @@ if(LPAC_WITH_APDU_PCSC)
target_link_libraries(euicc-drivers winscard)
elseif(APPLE)
target_link_libraries(euicc-drivers "-framework PCSC")
if(LPAC_DYNAMIC_DRIVERS)
# for pkg-config
set(LIBEUICC_DRIVERS_EXTRA_CFLAGS "-framework PCSC")
endif()
else()
find_package(PCSCLite)
target_link_libraries(euicc-drivers PCSCLite::PCSCLite)
if(LPAC_DYNAMIC_DRIVERS)
list(APPEND LIBEUICC_DRIVERS_REQUIRES "libpcsclite")
endif()
endif()
endif()

Expand All @@ -44,6 +52,10 @@ if(LPAC_WITH_APDU_GBINDER)
pkg_check_modules(GBINDER REQUIRED IMPORTED_TARGET libgbinder)
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
target_link_libraries(euicc-drivers PkgConfig::GBINDER PkgConfig::GLIB)
if(LPAC_DYNAMIC_DRIVERS)
list(APPEND LIBEUICC_DRIVERS_REQUIRES "libgbinder")
list(APPEND LIBEUICC_DRIVERS_REQUIRES "glib-2.0")
endif()
endif()

if(LPAC_WITH_HTTP_CURL)
Expand All @@ -54,6 +66,9 @@ if(LPAC_WITH_HTTP_CURL)
else()
find_package(curl)
target_link_libraries(euicc-drivers curl)
if(LPAC_DYNAMIC_DRIVERS)
list(APPEND LIBEUICC_DRIVERS_REQUIRES "libcurl")
endif()
endif()
endif()

Expand All @@ -66,9 +81,12 @@ if(LPAC_DYNAMIC_DRIVERS)
endif()
endforeach()
set_target_properties(euicc-drivers PROPERTIES PUBLIC_HEADER "${ALL_HEADERS}")
# Install a pkg-config file
configure_file(libeuicc-drivers.pc.in libeuicc-drivers.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libeuicc-drivers.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# Install a pkg-config file (mainly for Linux; macOS is untested; Win32 is not supported)
if(UNIX)
list(JOIN LIBEUICC_DRIVERS_REQUIRES ", " LIBEUICC_DRIVERS_REQUIRES)
configure_file(libeuicc-drivers.pc.in libeuicc-drivers.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libeuicc-drivers.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
set_target_properties(euicc-drivers PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})
install(TARGETS euicc-drivers LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/euicc)
Expand Down
4 changes: 2 additions & 2 deletions driver/libeuicc-drivers.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ includedir="${prefix}/include"
Name: libeuicc-drivers
Description: An "official" collection of drivers (backends) and their loader for use with libeuicc
Version: @PROJECT_VERSION@
Requires: libeuicc = @PROJECT_VERSION@
Cflags: -I${includedir}
Requires: @LIBEUICC_DRIVERS_REQUIRES@
Cflags: -I${includedir} @LIBEUICC_DRIVERS_EXTRA_CFLAGS@
Libs: -L${libdir} -leuicc-drivers

0 comments on commit edeb2be

Please sign in to comment.