cmusphinx / pocketsphinx

A small speech recognizer
Other
3.87k stars 713 forks source link

FetchContent #380

Open TheMariday opened 6 months ago

TheMariday commented 6 months ago

Hi hi! Long time sphinx-fan, first time bug-raiser

Just wanted to report something I found whilst trying to include this library in my latest project using fetch content.

This could very well be a me issue, however in programs/CMakeLists.txt, I needed to add the following around the check dependency:

  if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
    add_dependencies(check ${PROGRAM})
  endif()

I have managed to get pocketsphinx standalone to work with the following CMake, however I do have to provide the -hmm, -lm and -dict args as I assume I've broken the default configs including this in the project without installing it?

Thank you and I hope at least this can help others!

My CMakeLists.txt:

FetchContent_Declare(
  pocketsphinx
  GIT_REPOSITORY https://github.com/themariday/pocketsphinx.git
)

FetchContent_MakeAvailable(pocketsphinx)

include_directories(${pocketsphinx_SOURCE_DIR}/src)
include_directories(${pocketsphinx_SOURCE_DIR}/include)
include_directories(${pocketsphinx_SOURCE_DIR}/src/util)

include_directories(${pocketsphinx_BINARY_DIR})
include_directories(${pocketsphinx_BINARY_DIR}/include)
dhdaines commented 6 months ago

Ah, thanks! I'm still a bit bewildered by CMake, that should be the right fix for the check target, I assume the problem was it was trying to build all the tests when it shouldn't?

For the rest... I'm not familiar with FetchContent, probably the issue is that the default directory isn't getting set properly. Can you point me to a full minimal example of what you're trying to do?

TheMariday commented 6 months ago

Firstly yes, I think that was the issue. All other check dependencies seem to be wrapped in that CMAKE_PROJECT_NAME checking codeblock. See my fork used above here https://github.com/cmusphinx/pocketsphinx/commit/d618334dfe689889a00dd3be4fc1f45d96a47e8c

Secondly, I got up early this morning to put together an example cmake but could I get include_directories to include directories? Could I bugger. Worked last night.

I'll try and get an example to you in the next day or so.

dhdaines commented 3 months ago

Let me know if you find the time to put together an example - I think the fix you propose is correct, though it would be good to test it.

TheMariday commented 2 months ago

Here's an example of building a pocketsphinx example program using fetchcontent: https://github.com/TheMariday/pocketsphinx_fetch_content_example

P.S. I've modified simple.c at line 58 to cast the returned malloc address from void to short pointer otherwise -fpermissive complains

this points to a fork of pocketsphinx here: https://github.com/themariday/pocketsphinx.git

I've made 2 changes that both do the same thing:

I've added a project name check around doxygen, program and examples in the main CMakeLists so that these aren't built using fetch content.

If you do want to build these using fetch content, it will still fail due to 'check' missing a project name check in programs/CMakeLists.txt which I have also added.

Hope this is what you were looking for and as always thank you!

dhdaines commented 1 month ago

Oh! Thank you! I turned off GitHub notifications so it took me a while to see this. Will look at it ASAP.