-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support building static libraries #21
Open
csukuangfj
wants to merge
6
commits into
rhasspy:master
Choose a base branch
from
csukuangfj:fix-cmake
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6595b2e
support building static libraries
csukuangfj f685d6b
Remove soversion
csukuangfj 290533e
Fix for iOS
csukuangfj 23dcd9e
Fix linker warnings
csukuangfj 42253dd
Enable soname optionally
csukuangfj 6383e46
Fix cmake warnings
csukuangfj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,27 +17,34 @@ if(MSVC) | |
|
||
elseif(NOT APPLE) | ||
# Linux flags | ||
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'") | ||
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra ") | ||
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra") | ||
endif() | ||
|
||
option(BUILD_SHARED_LIBS "Whether to build shared libraries" ON) | ||
option(BUILD_PIPER_PHONMIZE_EXE "Whether to build piper_phonemize_exe" ON) | ||
option(BUILD_PIPER_PHONMIZE_TESTS "Whether to build tests" ON) | ||
option(ENABLE_PIPER_PHONMIZE_SONAME "Whether to enable soname" ON) | ||
|
||
add_library( | ||
piper_phonemize SHARED | ||
piper_phonemize | ||
src/phonemize.cpp | ||
src/phoneme_ids.cpp | ||
src/tashkeel.cpp | ||
src/shared.cpp | ||
) | ||
|
||
set_target_properties(piper_phonemize PROPERTIES | ||
if(ENABLE_PIPER_PHONMIZE_SONAME) | ||
set_target_properties(piper_phonemize PROPERTIES | ||
VERSION ${PROJECT_VERSION} | ||
SOVERSION ${PROJECT_VERSION_MAJOR} | ||
) | ||
) | ||
endif() | ||
|
||
# ---- onnxruntime --- | ||
|
||
# Look for onnxruntime files in <root>/lib | ||
if(NOT DEFINED ONNXRUNTIME_DIR) | ||
if(NOT DEFINED ONNXRUNTIME_DIR AND NOT DEFINED ENV{SHERPA_ONNXRUNTIME_LIB_DIR}) | ||
if(NOT DEFINED ONNXRUNTIME_VERSION) | ||
set(ONNXRUNTIME_VERSION "1.14.1") | ||
endif() | ||
|
@@ -107,7 +114,7 @@ if(NOT DEFINED ESPEAK_NG_DIR) | |
URL "https://github.com/rhasspy/espeak-ng/archive/refs/heads/master.zip" | ||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${ESPEAK_NG_DIR} | ||
CMAKE_ARGS -DUSE_ASYNC:BOOL=OFF | ||
CMAKE_ARGS -DBUILD_SHARED_LIBS:BOOL=ON | ||
CMAKE_ARGS -DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS} | ||
CMAKE_ARGS -DUSE_MBROLA:BOOL=OFF | ||
CMAKE_ARGS -DUSE_LIBSONIC:BOOL=OFF | ||
CMAKE_ARGS -DUSE_LIBPCAUDIO:BOOL=OFF | ||
|
@@ -130,73 +137,107 @@ target_include_directories( | |
${ONNXRUNTIME_DIR}/include | ||
) | ||
|
||
target_link_directories( | ||
piper_phonemize PUBLIC | ||
${ESPEAK_NG_DIR}/lib | ||
${ONNXRUNTIME_DIR}/lib | ||
) | ||
if(DEFINED ENV{SHERPA_ONNXRUNTIME_INCLUDE_DIR}) | ||
target_include_directories( | ||
piper_phonemize PUBLIC | ||
$ENV{SHERPA_ONNXRUNTIME_INCLUDE_DIR} | ||
) | ||
endif() | ||
|
||
if(EXISTS ${ESPEAK_NG_DIR}/lib) | ||
target_link_directories( | ||
piper_phonemize PUBLIC | ||
${ESPEAK_NG_DIR}/lib | ||
) | ||
endif() | ||
|
||
if(EXISTS ${ONNXRUNTIME_DIR}/lib) | ||
target_link_directories( | ||
piper_phonemize PUBLIC | ||
${ONNXRUNTIME_DIR}/lib | ||
) | ||
endif() | ||
|
||
if(DEFINED ENV{SHERPA_ONNXRUNTIME_LIB_DIR}) | ||
target_link_directories( | ||
piper_phonemize PUBLIC | ||
$ENV{SHERPA_ONNXRUNTIME_LIB_DIR} | ||
) | ||
endif() | ||
|
||
target_link_libraries( | ||
piper_phonemize | ||
espeak-ng | ||
onnxruntime | ||
) | ||
|
||
target_compile_features(piper_phonemize PUBLIC cxx_std_17) | ||
|
||
# ---- Declare executable ---- | ||
|
||
add_executable(piper_phonemize_exe src/main.cpp src/phoneme_ids.cpp) | ||
|
||
if(NOT WIN32) | ||
set_property(TARGET piper_phonemize_exe PROPERTY OUTPUT_NAME piper_phonemize) | ||
if(NOT BUILD_SHARED_LIBS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is to fix the following link errors:
|
||
target_link_libraries(piper_phonemize ucd) | ||
endif() | ||
|
||
target_compile_features(piper_phonemize_exe PUBLIC cxx_std_17) | ||
target_compile_features(piper_phonemize PUBLIC cxx_std_17) | ||
|
||
target_include_directories( | ||
piper_phonemize_exe PUBLIC | ||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>" | ||
${ESPEAK_NG_DIR}/include | ||
) | ||
if(BUILD_PIPER_PHONMIZE_EXE) | ||
# ---- Declare executable ---- | ||
|
||
target_link_directories( | ||
piper_phonemize_exe PUBLIC | ||
${ESPEAK_NG_DIR}/lib | ||
) | ||
add_executable(piper_phonemize_exe src/main.cpp src/phoneme_ids.cpp) | ||
|
||
target_link_libraries(piper_phonemize_exe PUBLIC | ||
piper_phonemize | ||
espeak-ng | ||
) | ||
if(NOT WIN32) | ||
set_property(TARGET piper_phonemize_exe PROPERTY OUTPUT_NAME piper_phonemize) | ||
endif() | ||
|
||
# ---- Declare test ---- | ||
target_compile_features(piper_phonemize_exe PUBLIC cxx_std_17) | ||
|
||
include(CTest) | ||
enable_testing() | ||
add_executable(test_piper_phonemize src/test.cpp src/phoneme_ids.cpp) | ||
add_test( | ||
NAME test_piper_phonemize | ||
COMMAND test_piper_phonemize "${ESPEAK_NG_DIR}/share/espeak-ng-data" "${CMAKE_SOURCE_DIR}/etc/libtashkeel_model.ort" | ||
) | ||
target_include_directories( | ||
piper_phonemize_exe PUBLIC | ||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>" | ||
${ESPEAK_NG_DIR}/include | ||
) | ||
|
||
target_compile_features(test_piper_phonemize PUBLIC cxx_std_17) | ||
if(EXISTS ${ESPEAK_NG_DIR}/lib) | ||
target_link_directories( | ||
piper_phonemize_exe PUBLIC | ||
${ESPEAK_NG_DIR}/lib | ||
) | ||
endif() | ||
|
||
target_include_directories( | ||
test_piper_phonemize PUBLIC | ||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>" | ||
${ESPEAK_NG_DIR}/include | ||
) | ||
target_link_libraries(piper_phonemize_exe PUBLIC | ||
piper_phonemize | ||
espeak-ng | ||
) | ||
endif() | ||
|
||
target_link_directories( | ||
test_piper_phonemize PUBLIC | ||
${ESPEAK_NG_DIR}/lib | ||
) | ||
if(BUILD_PIPER_PHONMIZE_TESTS) | ||
# ---- Declare test ---- | ||
|
||
include(CTest) | ||
enable_testing() | ||
add_executable(test_piper_phonemize src/test.cpp src/phoneme_ids.cpp) | ||
add_test( | ||
NAME test_piper_phonemize | ||
COMMAND test_piper_phonemize "${ESPEAK_NG_DIR}/share/espeak-ng-data" "${CMAKE_SOURCE_DIR}/etc/libtashkeel_model.ort" | ||
) | ||
|
||
target_compile_features(test_piper_phonemize PUBLIC cxx_std_17) | ||
|
||
target_include_directories( | ||
test_piper_phonemize PUBLIC | ||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>" | ||
${ESPEAK_NG_DIR}/include | ||
) | ||
|
||
if(EXISTS ${ESPEAK_NG_DIR}/lib) | ||
target_link_directories( | ||
test_piper_phonemize PUBLIC | ||
${ESPEAK_NG_DIR}/lib | ||
) | ||
endif() | ||
|
||
target_link_libraries(test_piper_phonemize PUBLIC | ||
piper_phonemize | ||
espeak-ng | ||
) | ||
target_link_libraries(test_piper_phonemize PUBLIC | ||
piper_phonemize | ||
espeak-ng | ||
) | ||
endif() | ||
|
||
# ---- Declare install targets ---- | ||
|
||
|
@@ -213,9 +254,11 @@ install( | |
PATTERN "*.h" | ||
PATTERN "*.hpp") | ||
|
||
install( | ||
TARGETS piper_phonemize_exe | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
if(BUILD_PIPER_PHONMIZE_EXE) | ||
install( | ||
TARGETS piper_phonemize_exe | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
endif() | ||
|
||
install( | ||
FILES ${CMAKE_SOURCE_DIR}/etc/libtashkeel_model.ort | ||
|
@@ -226,10 +269,14 @@ install( | |
DIRECTORY ${ESPEAK_NG_DIR}/ | ||
DESTINATION ${CMAKE_INSTALL_PREFIX}) | ||
|
||
install( | ||
DIRECTORY ${ONNXRUNTIME_DIR}/include/ | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
if(EXISTS ${ONNXRUNTIME_DIR}/include) | ||
install( | ||
DIRECTORY ${ONNXRUNTIME_DIR}/include/ | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
endif() | ||
|
||
install( | ||
DIRECTORY ${ONNXRUNTIME_DIR}/lib/ | ||
DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
if(EXISTS ${ONNXRUNTIME_DIR}/lib) | ||
install( | ||
DIRECTORY ${ONNXRUNTIME_DIR}/lib/ | ||
DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
endif() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
piper-phonemize is used as a subproject in sherpa-onnx and it is always compiled from source along with sherpa-onnx.
We don't need to manage the version of piper-phonemize via soname.
In addition, setting soname will produce two more symlink files. If I use
cp /path/to/install/lib/lib*.so* /some/dest/dir
, it will dereference the symlink files and copy the real file, which means there are two more copies of the lib.I don't see the need to keep the soname. I cannot think of a use case where we only update the version of
piper-phonemize without updating the main project where piper-phonemize is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other people have requested this, so I'd like to keep it. We could make it an option, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will create an option, defaulting to ON.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.