CMakeLists.txt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. cmake_minimum_required(VERSION 3.12)
  2. project("main-cmake-pkg" C CXX)
  3. set(TARGET main-cmake-pkg)
  4. find_package(Llama 0.0.1 REQUIRED)
  5. # Bake common functionality in with target. Because applications
  6. # using the relocatable Llama package should be outside of the
  7. # source tree, main-cmake-pkg pretends the dependencies are built-in.
  8. set(_common_path "${CMAKE_CURRENT_LIST_DIR}/../../common")
  9. add_library(common OBJECT
  10. ${_common_path}/common.h
  11. ${_common_path}/common.cpp
  12. ${_common_path}/console.h
  13. ${_common_path}/console.cpp
  14. ${_common_path}/grammar-parser.h
  15. ${_common_path}/grammar-parser.cpp
  16. )
  17. # WARNING: because build-info.h is auto-generated, it will only
  18. # be available after the user has built the llama.cpp sources.
  19. #
  20. configure_file(${_common_path}/../build-info.h
  21. ${CMAKE_CURRENT_BINARY_DIR}/build-info.h
  22. COPYONLY)
  23. target_include_directories(common PUBLIC ${LLAMA_INCLUDE_DIR}
  24. ${CMAKE_CURRENT_BINARY_DIR})
  25. # If the common project was part of "main-cmake-pkg" the transient
  26. # defines would automatically be attached. Because the common func-
  27. # tionality is separate, but dependent upon the defines, it must be
  28. # explicitly extracted from the "llama" target.
  29. #
  30. get_target_property(_llama_transient_defines llama
  31. INTERFACE_COMPILE_DEFINITIONS)
  32. target_compile_definitions(common PRIVATE "${_llama_transient_defines}")
  33. add_executable(${TARGET} ${CMAKE_CURRENT_LIST_DIR}/../main/main.cpp)
  34. target_include_directories(${TARGET} PRIVATE ${_common_path})
  35. install(TARGETS ${TARGET} RUNTIME)
  36. target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
  37. target_compile_features(${TARGET} PRIVATE cxx_std_11)