CMakeLists.txt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. ${_common_path}/sampling.h
  17. ${_common_path}/sampling.cpp
  18. )
  19. # WARNING: because build-info.h is auto-generated, it will only
  20. # be available after the user has built the llama.cpp sources.
  21. #
  22. configure_file(${_common_path}/../build-info.h
  23. ${CMAKE_CURRENT_BINARY_DIR}/build-info.h
  24. COPYONLY)
  25. target_include_directories(common PUBLIC ${LLAMA_INCLUDE_DIR}
  26. ${CMAKE_CURRENT_BINARY_DIR})
  27. # If the common project was part of "main-cmake-pkg" the transient
  28. # defines would automatically be attached. Because the common func-
  29. # tionality is separate, but dependent upon the defines, it must be
  30. # explicitly extracted from the "llama" target.
  31. #
  32. get_target_property(_llama_transient_defines llama
  33. INTERFACE_COMPILE_DEFINITIONS)
  34. target_compile_definitions(common PRIVATE "${_llama_transient_defines}")
  35. add_executable(${TARGET} ${CMAKE_CURRENT_LIST_DIR}/../main/main.cpp)
  36. target_include_directories(${TARGET} PRIVATE ${_common_path})
  37. install(TARGETS ${TARGET} RUNTIME)
  38. target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
  39. target_compile_features(${TARGET} PRIVATE cxx_std_11)