CMakeLists.txt 2.8 KB

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