Skip to content

Commit

Permalink
Add pc files upon installation (#214) (#222)
Browse files Browse the repository at this point in the history
* Add pc files upon installation

* Avoid hardcoded paths
  • Loading branch information
cguimaraes authored Jul 26, 2023
1 parent b9ccf63 commit 65d9552
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
31 changes: 29 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#
cmake_minimum_required(VERSION 3.8)

project(libzenohpico VERSION 0.10.0.0 LANGUAGES C)
project(zenohpico VERSION 0.10.0.0 LANGUAGES C)

include(CMakePackageConfigHelpers)

option(BUILD_SHARED_LIBS "Build shared libraries if ON, otherwise build static libraries" ON)
option(ZENOH_DEBUG "Use this to set the ZENOH_DEBUG variable." 0)
Expand Down Expand Up @@ -217,6 +219,31 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh-pico
COMPONENT Headers
)

set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/zenohpico")
# Generate <Package>Config.cmake
configure_package_config_file(
"PackageConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/zenohpicoConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKEDIR}")

# Generate <Package>Version.cmake
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/zenohpicoConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/zenohpicoConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/zenohpicoConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
CONFIGURATIONS ${configurations}
COMPONENT dev)

if(UNIX)
configure_file("${CMAKE_SOURCE_DIR}/zenohpico.pc.in" "${CMAKE_SOURCE_DIR}/zenohpico.pc" @ONLY)
install(FILES "${CMAKE_SOURCE_DIR}/zenohpico.pc" CONFIGURATIONS Release RelWithDebInfo DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()

if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
Expand Down Expand Up @@ -363,4 +390,4 @@ if(PACKAGING)
include(CPack)
endif()

endif()
endif()
28 changes: 28 additions & 0 deletions PackageConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright (c) 2023 ZettaScale Technology.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# ZettaScale Zenoh team, <[email protected]>
#

@PACKAGE_INIT@

add_library(__zenohpico_static STATIC IMPORTED GLOBAL)
add_library(zenohpico::static ALIAS __zenohpico_static)
set_property(TARGET __zenohpico_static PROPERTY IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/@STATICLIB@")

add_library(__zenohpico_lib SHARED IMPORTED GLOBAL)
add_library(zenohpico::lib ALIAS __zenohpico_lib)
set_target_properties(__zenohpico_lib PROPERTIES IMPORTED_NO_SONAME TRUE)
set_property(TARGET __zenohpico_lib PROPERTY IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/@DYLIB@")
if(NOT ("@IMPLIB@" STREQUAL ""))
set_property(TARGET __zenohpico_lib PROPERTY IMPORTED_IMPLIB "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/@IMPLIB@")
endif()
target_include_directories(__zenohpico_lib INTERFACE "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@")
8 changes: 8 additions & 0 deletions zenohpico.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
prefix=@CMAKE_INSTALL_PREFIX@

Name: @PROJECT_NAME@
Description: @CMAKE_PROJECT_DESCRIPTION@
URL: @CMAKE_PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Cflags: -I${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Libs: -L${prefix}/@CMAKE_INSTALL_LIBDIR@ -lzenohpico@LIBNAME_POSTFIX@

0 comments on commit 65d9552

Please sign in to comment.