CMakeLists.txt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
  2. project(sherpa-ncnn)
  3. # Please also change the following files:
  4. #
  5. # ./build-ios.sh
  6. # ./build-swift-macos.sh
  7. #
  8. set(SHERPA_NCNN_VERSION "1.3.2")
  9. # Disable warning about
  10. #
  11. # "The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
  12. # not set.
  13. if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
  14. cmake_policy(SET CMP0135 NEW)
  15. endif()
  16. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
  17. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
  18. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  19. set(CMAKE_SKIP_BUILD_RPATH FALSE)
  20. set(BUILD_RPATH_USE_ORIGIN TRUE)
  21. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  22. if(NOT APPLE)
  23. set(SHERPA_NCNN_RPATH_ORIGIN "$ORIGIN")
  24. else()
  25. set(CMAKE_MACOSX_RPATH ON)
  26. set(SHERPA_NCNN_RPATH_ORIGIN "@loader_path")
  27. endif()
  28. set(CMAKE_INSTALL_RPATH ${SHERPA_NCNN_RPATH_ORIGIN})
  29. set(CMAKE_BUILD_RPATH ${SHERPA_NCNN_RPATH_ORIGIN})
  30. option(BUILD_SHARED_LIBS "Whether to build shared libraries" OFF)
  31. option(SHERPA_NCNN_ENABLE_PYTHON "Whether to build Python" OFF)
  32. option(SHERPA_NCNN_ENABLE_PORTAUDIO "Whether to build with portaudio" ON)
  33. option(SHERPA_NCNN_ENABLE_JNI "Whether to build JNI internface" OFF)
  34. option(SHERPA_NCNN_ENABLE_BINARY "Whether to build the binary sherpa-ncnn" ON)
  35. option(SHERPA_NCNN_ENABLE_TEST "Whether to build tests" OFF)
  36. option(SHERPA_NCNN_ENABLE_C_API "Whether to build C API" ON)
  37. if(DEFINED ANDROID_ABI)
  38. message(STATUS "Set SHERPA_NCNN_ENABLE_JNI to ON for Android")
  39. set(SHERPA_NCNN_ENABLE_JNI ON CACHE BOOL "" FORCE)
  40. endif()
  41. message(STATUS "BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}")
  42. message(STATUS "SHERPA_NCNN_ENABLE_PYTHON ${SHERPA_NCNN_ENABLE_PYTHON}")
  43. message(STATUS "SHERPA_NCNN_ENABLE_PORTAUDIO ${SHERPA_NCNN_ENABLE_PORTAUDIO}")
  44. message(STATUS "SHERPA_NCNN_ENABLE_JNI ${SHERPA_NCNN_ENABLE_JNI}")
  45. message(STATUS "SHERPA_NCNN_ENABLE_BINARY ${SHERPA_NCNN_ENABLE_BINARY}")
  46. message(STATUS "SHERPA_NCNN_ENABLE_TEST ${SHERPA_NCNN_ENABLE_TEST}")
  47. message(STATUS "SHERPA_NCNN_ENABLE_C_API ${SHERPA_NCNN_ENABLE_C_API}")
  48. if(NOT CMAKE_BUILD_TYPE)
  49. message(STATUS "No CMAKE_BUILD_TYPE given, default to Release")
  50. set(CMAKE_BUILD_TYPE Release)
  51. endif()
  52. message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
  53. set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ version to be used.")
  54. set(CMAKE_CXX_EXTENSIONS OFF)
  55. include(CheckIncludeFileCXX)
  56. check_include_file_cxx(alsa/asoundlib.h SHERPA_NCNN_HAS_ALSA)
  57. if(SHERPA_NCNN_HAS_ALSA)
  58. add_definitions(-DSHERPA_NCNN_ENABLE_ALSA=1)
  59. endif()
  60. list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
  61. if(WIN32)
  62. add_definitions(-DNOMINMAX) # Otherwise, std::max() and std::min() won't work
  63. endif()
  64. if(WIN32)
  65. # disable various warnings for MSVC
  66. # 4244: 'return': conversion from 'unsigned __int64' to 'int', possible loss of data
  67. # 4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
  68. # 4305: 'argument': truncation from 'double' to 'const float'
  69. # 4334: '<<': result of 32-bit shift implicitly converted to 64 bits
  70. # 4800: 'int': forcing value to bool 'true' or 'false'
  71. # 4996: 'fopen': This function or variable may be unsafe
  72. set(disabled_warnings
  73. /wd4244
  74. /wd4267
  75. /wd4305
  76. /wd4334
  77. /wd4800
  78. /wd4996
  79. )
  80. message(STATUS "Disabled warnings: ${disabled_warnings}")
  81. foreach(w IN LISTS disabled_warnings)
  82. string(APPEND CMAKE_CXX_FLAGS " ${w} ")
  83. endforeach()
  84. endif()
  85. include(kaldi-native-fbank)
  86. include(ncnn)
  87. if(SHERPA_NCNN_ENABLE_PORTAUDIO)
  88. include(portaudio)
  89. endif()
  90. if(SHERPA_NCNN_ENABLE_PYTHON)
  91. include(pybind11)
  92. endif()
  93. add_subdirectory(sherpa-ncnn)
  94. if(SHERPA_NCNN_ENABLE_C_API AND SHERPA_NCNN_ENABLE_BINARY)
  95. add_subdirectory(c-api-examples)
  96. endif()