Skip to content

Commit

Permalink
Create pkg-config files (#19)
Browse files Browse the repository at this point in the history
* Try export package

* Add and install pkg config file

* Find pkg config executable
  • Loading branch information
domire8 authored Nov 25, 2022
1 parent f6edb64 commit acba2e8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
33 changes: 28 additions & 5 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(network_interfaces VERSION 1.1.0)

set (NETWORK_INTERFACES_VERSION 1.1.0)
project(network_interfaces VERSION ${NETWORK_INTERFACES_VERSION})

option(BUILD_TESTING "Build tests." OFF)

Expand All @@ -23,12 +25,22 @@ else()
find_package(GTest QUIET)
endif()

macro(add_project_dependency)
find_package(${ARGV})
if(PKG_EXTERNAL_DEPS)
set(PKG_EXTERNAL_DEPS "${PKG_EXTERNAL_DEPS}, ${ARGV0} >= ${ARGV1}")
else()
set(PKG_EXTERNAL_DEPS "${ARGV0} >= ${ARGV1}")
endif()
endmacro()

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(FindPkgConfig)

find_package(control_libraries 6.0.0 REQUIRED COMPONENTS state_representation)
find_package(clproto 6.0.0 REQUIRED)
find_package(cppzmq 4.7.1 REQUIRED)
add_project_dependency(control_libraries 6.0.0 REQUIRED COMPONENTS state_representation)
add_project_dependency(clproto 6.0.0 REQUIRED)
add_project_dependency(cppzmq 4.7.1 REQUIRED)

include_directories(include)

Expand Down Expand Up @@ -60,7 +72,7 @@ write_basic_package_version_file(
)

# create config file
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/network_interfaces-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
Expand All @@ -71,3 +83,14 @@ install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

if(${PKG_CONFIG_FOUND})
set(PKG_NAME ${PROJECT_NAME})
set(PKG_DESC "Network Interfaces")
set(pkg_conf_file "network_interfaces.pc")
configure_file("${pkg_conf_file}.in" "${CMAKE_BINARY_DIR}/${pkg_conf_file}" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/${pkg_conf_file}"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ COMPONENT pkgconfig)
else()
message(WARNING "Could not find pkg-config executable, skipping generation of pkg-config files.")
endif()
File renamed without changes.
9 changes: 9 additions & 0 deletions cpp/network_interfaces.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@

Name: @PKG_NAME@
Description: @PKG_DESC@
Version: @NETWORK_INTERFACES_VERSION@
Requires: @PKG_EXTERNAL_DEPS@
Cflags: -I${includedir}

0 comments on commit acba2e8

Please sign in to comment.