CMakeLists.txt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # common
  2. find_package(Threads REQUIRED)
  3. llama_add_compile_flags()
  4. # Build info header
  5. #
  6. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../.git")
  7. set(GIT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../.git")
  8. # Is git submodule
  9. if(NOT IS_DIRECTORY "${GIT_DIR}")
  10. file(READ ${GIT_DIR} REAL_GIT_DIR_LINK)
  11. string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" REAL_GIT_DIR ${REAL_GIT_DIR_LINK})
  12. string(FIND "${REAL_GIT_DIR}" "/" SLASH_POS)
  13. if (SLASH_POS EQUAL 0)
  14. set(GIT_DIR "${REAL_GIT_DIR}")
  15. else()
  16. set(GIT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${REAL_GIT_DIR}")
  17. endif()
  18. endif()
  19. if(EXISTS "${GIT_DIR}/index")
  20. set(GIT_INDEX "${GIT_DIR}/index")
  21. else()
  22. message(WARNING "Git index not found in git repository.")
  23. set(GIT_INDEX "")
  24. endif()
  25. else()
  26. message(WARNING "Git repository not found; to enable automatic generation of build info, make sure Git is installed and the project is a Git repository.")
  27. set(GIT_INDEX "")
  28. endif()
  29. # Add a custom command to rebuild build-info.cpp when .git/index changes
  30. add_custom_command(
  31. OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/build-info.cpp"
  32. COMMENT "Generating build details from Git"
  33. COMMAND ${CMAKE_COMMAND} -DMSVC=${MSVC} -DCMAKE_C_COMPILER_VERSION=${CMAKE_C_COMPILER_VERSION}
  34. -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID} -DCMAKE_VS_PLATFORM_NAME=${CMAKE_VS_PLATFORM_NAME}
  35. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/build-info-gen-cpp.cmake"
  36. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.."
  37. DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build-info.cpp.in" ${GIT_INDEX}
  38. VERBATIM
  39. )
  40. set(TARGET build_info)
  41. add_library(${TARGET} OBJECT build-info.cpp)
  42. if (BUILD_SHARED_LIBS)
  43. set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON)
  44. endif()
  45. set(TARGET common)
  46. add_library(${TARGET} STATIC
  47. arg.cpp
  48. arg.h
  49. base64.hpp
  50. chat.cpp
  51. chat.hpp
  52. chat-template.hpp
  53. common.cpp
  54. common.h
  55. console.cpp
  56. console.h
  57. json-schema-to-grammar.cpp
  58. json.hpp
  59. log.cpp
  60. log.h
  61. minja.hpp
  62. ngram-cache.cpp
  63. ngram-cache.h
  64. sampling.cpp
  65. sampling.h
  66. speculative.cpp
  67. speculative.h
  68. )
  69. if (BUILD_SHARED_LIBS)
  70. set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON)
  71. endif()
  72. set(LLAMA_COMMON_EXTRA_LIBS build_info)
  73. # Use curl to download model url
  74. if (LLAMA_CURL)
  75. find_package(CURL REQUIRED)
  76. target_compile_definitions(${TARGET} PUBLIC LLAMA_USE_CURL)
  77. include_directories(${CURL_INCLUDE_DIRS})
  78. find_library(CURL_LIBRARY curl REQUIRED)
  79. set(LLAMA_COMMON_EXTRA_LIBS ${LLAMA_COMMON_EXTRA_LIBS} ${CURL_LIBRARY})
  80. endif ()
  81. target_include_directories(${TARGET} PUBLIC .)
  82. target_compile_features (${TARGET} PUBLIC cxx_std_17)
  83. target_link_libraries (${TARGET} PRIVATE ${LLAMA_COMMON_EXTRA_LIBS} PUBLIC llama Threads::Threads)