Support pkg-config (#253)

This commit is contained in:
Fangjun Kuang
2023-08-10 11:22:36 +08:00
committed by GitHub
parent a04221a1ce
commit 865fd1e017
7 changed files with 167 additions and 5 deletions

View File

@@ -2,10 +2,11 @@ function(download_cargs)
include(FetchContent)
set(cargs_URL "https://github.com/likle/cargs/archive/refs/tags/v1.0.3.tar.gz")
set(cargs_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/cargs-1.0.3.tar.gz")
set(cargs_HASH "SHA256=ddba25bd35e9c6c75bc706c126001b8ce8e084d40ef37050e6aa6963e836eb8b")
# If you don't have access to the Internet,
# please pre-download asio
# please pre-download cargs
set(possible_file_locations
$ENV{HOME}/Downloads/cargs-1.0.3.tar.gz
${PROJECT_SOURCE_DIR}/cargs-1.0.3.tar.gz
@@ -19,11 +20,18 @@ function(download_cargs)
set(cargs_URL "${f}")
file(TO_CMAKE_PATH "${cargs_URL}" cargs_URL)
message(STATUS "Found local downloaded cargs: ${cargs_URL}")
set(cargs_URL2)
break()
endif()
endforeach()
FetchContent_Declare(cargs URL ${cargs_URL} URL_HASH ${cargs_HASH})
FetchContent_Declare(cargs
URL
${cargs_URL}
${cargs_URL2}
URL_HASH
${cargs_HASH}
)
FetchContent_GetProperties(cargs)
if(NOT cargs_POPULATED)
@@ -32,6 +40,11 @@ function(download_cargs)
endif()
message(STATUS "cargs is downloaded to ${cargs_SOURCE_DIR}")
add_subdirectory(${cargs_SOURCE_DIR} ${cargs_BINARY_DIR} EXCLUDE_FROM_ALL)
install(TARGETS cargs DESTINATION lib)
install(FILES ${cargs_SOURCE_DIR}/include/cargs.h
DESTINATION include
)
endfunction()
download_cargs()

View File

@@ -57,6 +57,9 @@ function(download_portaudio)
if(BUILD_SHARED_LIBS)
set_target_properties(portaudio PROPERTIES OUTPUT_NAME "sherpa-onnx-portaudio")
if(NOT WIN32)
target_compile_options(portaudio PRIVATE "-Wno-deprecated-declarations")
endif()
if(SHERPA_ONNX_ENABLE_PYTHON AND WIN32)
install(TARGETS portaudio DESTINATION ..)
@@ -65,6 +68,9 @@ function(download_portaudio)
endif()
else()
set_target_properties(portaudio_static PROPERTIES OUTPUT_NAME "sherpa-onnx-portaudio_static")
if(NOT WIN32)
target_compile_options(portaudio_static PRIVATE "-Wno-deprecated-declarations")
endif()
if(SHERPA_ONNX_ENABLE_PYTHON AND WIN32)
install(TARGETS portaudio_static DESTINATION ..)
else()

16
cmake/sherpa-onnx.pc.in Normal file
View File

@@ -0,0 +1,16 @@
prefix="@CMAKE_INSTALL_PREFIX@"
exec_prefix="${prefix}"
includedir="${prefix}/include"
libdir="${exec_prefix}/lib"
Name: sherpa-onnx
Description: pkg-config for sherpa-onnx
URL: https://github.com/k2-fsa/sherpa-onnx
Version: @SHERPA_ONNX_VERSION@
Cflags: -I"${includedir}"
# Note: -lcargs is required only for the following file
# https://github.com/k2-fsa/sherpa-onnx/blob/master/c-api-examples/decode-file-c-api.c
# We add it here so that users don't need to specify -lcargs when compiling decode-file-c-api.c
Libs: -L"${libdir}" -lsherpa-onnx-c-api -lsherpa-onnx-core -lonnxruntime -lkaldi-native-fbank-core -lcargs -Wl,-rpath,${libdir} @SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS@