181 lines
6.6 KiB
CMake
181 lines
6.6 KiB
CMake
set(TOM_GAME_TARGET IMX6U-Game)
|
|
set(TOM_ATLAS_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/generated/tom_atlas.h")
|
|
set_source_files_properties(${TOM_ATLAS_HEADER} PROPERTIES GENERATED TRUE)
|
|
|
|
set(TOM_GAME_ENABLE_TFLITE_C_API_DEFAULT OFF)
|
|
if(CMAKE_CROSSCOMPILING AND TARGET_IMX)
|
|
set(TOM_GAME_ENABLE_TFLITE_C_API_DEFAULT ON)
|
|
endif()
|
|
|
|
if(NOT DEFINED CACHE{TOM_GAME_ENABLE_TFLITE_C_API})
|
|
set(TOM_GAME_ENABLE_TFLITE_C_API
|
|
${TOM_GAME_ENABLE_TFLITE_C_API_DEFAULT}
|
|
CACHE BOOL
|
|
"Enable tiny KWS through TensorFlow Lite C API"
|
|
)
|
|
endif()
|
|
|
|
set(TOM_GAME_TFLITE_INCLUDE_DIR "" CACHE PATH "TensorFlow Lite C API include directory")
|
|
set(TOM_GAME_TFLITE_LIBRARY
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/runtime/lib/tensorflow/lite/c/libtensorflowlite_c.so"
|
|
CACHE FILEPATH
|
|
"TensorFlow Lite C API library"
|
|
)
|
|
|
|
if(TOM_GAME_ENABLE_TFLITE_C_API AND NOT TOM_GAME_TFLITE_INCLUDE_DIR)
|
|
set(TOM_GAME_TFLITE_INCLUDE_CANDIDATES
|
|
"$ENV{TOM_GAME_TENSORFLOW_ROOT}"
|
|
"$ENV{TENSORFLOW_ROOT}"
|
|
"$ENV{TF_SRC}"
|
|
"$ENV{HOME}/tensorflow-master/tensorflow-master"
|
|
"$ENV{HOME}/tensorflow-master"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/tensorflow"
|
|
"${PROJECT_SOURCE_DIR}/tensorflow"
|
|
)
|
|
|
|
foreach(TOM_GAME_TFLITE_INCLUDE_CANDIDATE IN LISTS TOM_GAME_TFLITE_INCLUDE_CANDIDATES)
|
|
if(TOM_GAME_TFLITE_INCLUDE_CANDIDATE AND
|
|
EXISTS "${TOM_GAME_TFLITE_INCLUDE_CANDIDATE}/tensorflow/lite/c/c_api.h")
|
|
set(TOM_GAME_TFLITE_INCLUDE_DIR
|
|
"${TOM_GAME_TFLITE_INCLUDE_CANDIDATE}"
|
|
CACHE PATH
|
|
"TensorFlow Lite C API include directory"
|
|
FORCE
|
|
)
|
|
break()
|
|
endif()
|
|
endforeach()
|
|
endif()
|
|
|
|
add_executable(${TOM_GAME_TARGET}
|
|
Main.cpp
|
|
src/app/TomGameApp.cpp
|
|
src/audio/VoiceEffect.cpp
|
|
src/audio/VoicePlayer.cpp
|
|
src/audio/VoiceRecorder.cpp
|
|
src/recognition/KeywordRecognizer.cpp
|
|
src/recognition/TinyKwsRecognizer.cpp
|
|
src/recognition/PythonKeywordRecognizer.cpp
|
|
${TOM_ATLAS_HEADER}
|
|
)
|
|
|
|
target_include_directories(${TOM_GAME_TARGET} PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/app
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/audio
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/recognition
|
|
${CMAKE_CURRENT_SOURCE_DIR}/generated
|
|
)
|
|
|
|
imx6u_configure_app_target(${TOM_GAME_TARGET})
|
|
|
|
if(TOM_GAME_ENABLE_TFLITE_C_API)
|
|
if(NOT TOM_GAME_TFLITE_INCLUDE_DIR OR
|
|
NOT EXISTS "${TOM_GAME_TFLITE_INCLUDE_DIR}/tensorflow/lite/c/c_api.h")
|
|
message(FATAL_ERROR
|
|
"TOM_GAME_ENABLE_TFLITE_C_API is enabled, but TensorFlow Lite C API headers were not found. "
|
|
"Set TOM_GAME_TFLITE_INCLUDE_DIR to the TensorFlow source root, for example "
|
|
"-DTOM_GAME_TFLITE_INCLUDE_DIR=/home/xushengyi/tensorflow-master/tensorflow-master"
|
|
)
|
|
endif()
|
|
|
|
if(NOT TOM_GAME_TFLITE_LIBRARY OR NOT EXISTS "${TOM_GAME_TFLITE_LIBRARY}")
|
|
message(FATAL_ERROR
|
|
"TOM_GAME_ENABLE_TFLITE_C_API is enabled, but libtensorflowlite_c.so was not found. "
|
|
"Set TOM_GAME_TFLITE_LIBRARY to the ARMhf TensorFlow Lite C API shared library."
|
|
)
|
|
endif()
|
|
|
|
message(STATUS "TomGame tiny KWS enabled with TensorFlow Lite C API")
|
|
message(STATUS "TensorFlow Lite include root: ${TOM_GAME_TFLITE_INCLUDE_DIR}")
|
|
message(STATUS "TensorFlow Lite C library: ${TOM_GAME_TFLITE_LIBRARY}")
|
|
|
|
target_compile_definitions(${TOM_GAME_TARGET} PRIVATE TOM_GAME_ENABLE_TFLITE_C_API)
|
|
target_include_directories(${TOM_GAME_TARGET} PRIVATE ${TOM_GAME_TFLITE_INCLUDE_DIR})
|
|
target_link_libraries(${TOM_GAME_TARGET} PRIVATE ${TOM_GAME_TFLITE_LIBRARY})
|
|
|
|
add_custom_command(TARGET ${TOM_GAME_TARGET} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
"${TOM_GAME_TFLITE_LIBRARY}"
|
|
"$<TARGET_FILE_DIR:${TOM_GAME_TARGET}>"
|
|
COMMENT "Copying TensorFlow Lite C API runtime next to Tom game binary"
|
|
VERBATIM
|
|
)
|
|
endif()
|
|
|
|
if(CMAKE_CROSSCOMPILING AND NOT EXISTS "${TOM_ATLAS_HEADER}")
|
|
message(FATAL_ERROR
|
|
"Tom atlas header is missing. Run GenerateTomAtlasHeader in a host build before cross compiling."
|
|
)
|
|
endif()
|
|
|
|
if(NOT TARGET_IMX)
|
|
set(TOM_ATLAS_TOOL_SOURCES
|
|
tools/asset_pipeline/SpriteAssetTool.cpp
|
|
)
|
|
|
|
if(WIN32)
|
|
add_executable(TomAtlasTool EXCLUDE_FROM_ALL ${TOM_ATLAS_TOOL_SOURCES})
|
|
target_include_directories(TomAtlasTool PRIVATE
|
|
${PROJECT_SOURCE_DIR}/libs/Win/SDL2/include
|
|
${PROJECT_SOURCE_DIR}/libs/Win/SDL_image/include
|
|
)
|
|
target_link_directories(TomAtlasTool PRIVATE
|
|
${SDL2_LIB_DIR}
|
|
${SDL2_IMAGE_LIB_DIR}
|
|
)
|
|
target_link_libraries(TomAtlasTool PRIVATE SDL2main SDL2 SDL2_image)
|
|
|
|
add_custom_command(TARGET TomAtlasTool POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
"${SDL2_DLL}"
|
|
"$<TARGET_FILE_DIR:TomAtlasTool>"
|
|
)
|
|
add_custom_command(TARGET TomAtlasTool POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
"${SDL2_IMAGE_DLL}"
|
|
"$<TARGET_FILE_DIR:TomAtlasTool>"
|
|
)
|
|
elseif(SDL2_image_FOUND)
|
|
add_executable(TomAtlasTool EXCLUDE_FROM_ALL ${TOM_ATLAS_TOOL_SOURCES})
|
|
target_include_directories(TomAtlasTool PRIVATE
|
|
${SDL2_image_INCLUDE_DIRS}
|
|
${SDL2_IMAGE_INCLUDE_DIRS}
|
|
)
|
|
target_link_libraries(TomAtlasTool PRIVATE SDL2::SDL2)
|
|
|
|
if(TARGET SDL2_image::SDL2_image)
|
|
target_link_libraries(TomAtlasTool PRIVATE SDL2_image::SDL2_image)
|
|
else()
|
|
target_link_libraries(TomAtlasTool PRIVATE
|
|
${SDL2_image_LIBRARIES}
|
|
${SDL2_IMAGE_LIBRARIES}
|
|
)
|
|
endif()
|
|
else()
|
|
message(STATUS "TomAtlasTool disabled: SDL2_image was not found")
|
|
endif()
|
|
|
|
if(TARGET TomAtlasTool)
|
|
if(NOT CMAKE_CROSSCOMPILING)
|
|
add_custom_target(GenerateTomAtlasHeader
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory
|
|
"src/Apps/Game/generated"
|
|
COMMAND $<TARGET_FILE:TomAtlasTool>
|
|
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
|
|
DEPENDS TomAtlasTool
|
|
COMMENT "Generating Tom atlas header from PNG assets"
|
|
VERBATIM
|
|
)
|
|
|
|
add_dependencies(${TOM_GAME_TARGET} GenerateTomAtlasHeader)
|
|
else()
|
|
add_custom_target(GenerateTomAtlasHeader
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
"GenerateTomAtlasHeader is host-only. Run it in build-win or build-linux before cross compiling."
|
|
VERBATIM
|
|
)
|
|
endif()
|
|
endif()
|
|
endif()
|