@@ -6,38 +6,46 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
66set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
77
88option (AGENT_CPP_BUILD_TESTS "Build agent.cpp tests" OFF )
9+ option (AGENT_CPP_BUNDLED_LLAMA "Bundle llama.cpp (vs. find installed)" ON )
910
1011set (LLAMA_CPP_DIR "" CACHE PATH "Path to existing llama.cpp directory (leave empty to use submodule)" )
1112
12- if (LLAMA_CPP_DIR)
13- if (NOT EXISTS "${LLAMA_CPP_DIR} /CMakeLists.txt" )
14- message (FATAL_ERROR "LLAMA_CPP_DIR is set to '${LLAMA_CPP_DIR} ' but no CMakeLists.txt found there." )
13+ if (AGENT_CPP_BUNDLED_LLAMA)
14+ # Use bundled llama.cpp (submodule or custom path)
15+ if (LLAMA_CPP_DIR)
16+ if (NOT EXISTS "${LLAMA_CPP_DIR} /CMakeLists.txt" )
17+ message (FATAL_ERROR "LLAMA_CPP_DIR is set to '${LLAMA_CPP_DIR} ' but no CMakeLists.txt found there." )
18+ endif ()
19+ set (LLAMA_SOURCE_DIR "${LLAMA_CPP_DIR} " )
20+ message (STATUS "Using custom llama.cpp from: ${LLAMA_SOURCE_DIR } " )
21+ else ()
22+ set (LLAMA_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR } /llama.cpp" )
23+ if (NOT EXISTS "${LLAMA_SOURCE_DIR } /CMakeLists.txt" )
24+ message (FATAL_ERROR
25+ "llama.cpp submodule not found at ${LLAMA_SOURCE_DIR } \n "
26+ "Please initialize submodules with:\n "
27+ " git submodule update --init --recursive\n "
28+ "Or provide a custom path with -DLLAMA_CPP_DIR=/path/to/llama.cpp"
29+ )
30+ endif ()
31+ message (STATUS "Using llama.cpp submodule from: ${LLAMA_SOURCE_DIR } " )
1532 endif ()
16- set (LLAMA_SOURCE_DIR "${LLAMA_CPP_DIR} " )
17- message (STATUS "Using custom llama.cpp from: ${LLAMA_SOURCE_DIR } " )
18- else ()
19- set (LLAMA_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR } /llama.cpp" )
20- if (NOT EXISTS "${LLAMA_SOURCE_DIR } /CMakeLists.txt" )
21- message (FATAL_ERROR
22- "llama.cpp submodule not found at ${LLAMA_SOURCE_DIR } \n "
23- "Please initialize submodules with:\n "
24- " git submodule update --init --recursive\n "
25- "Or provide a custom path with -DLLAMA_CPP_DIR=/path/to/llama.cpp"
26- )
27- endif ()
28- message (STATUS "Using llama.cpp submodule from: ${LLAMA_SOURCE_DIR } " )
29- endif ()
3033
31- set (LLAMA_BUILD_TESTS OFF CACHE BOOL "" FORCE )
32- set (LLAMA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
33- set (LLAMA_BUILD_SERVER OFF CACHE BOOL "" FORCE )
34- set (LLAMA_BUILD_TOOLS OFF CACHE BOOL "" FORCE )
35- set (LLAMA_BUILD_COMMON ON CACHE BOOL "" FORCE )
36- set (LLAMA_CURL OFF CACHE BOOL "" FORCE )
37- set (LLAMA_HTTPLIB OFF CACHE BOOL "" FORCE )
38- set (LLAMA_LLGUIDANCE OFF CACHE BOOL "" FORCE )
34+ set (LLAMA_BUILD_TESTS OFF CACHE BOOL "" FORCE )
35+ set (LLAMA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
36+ set (LLAMA_BUILD_SERVER OFF CACHE BOOL "" FORCE )
37+ set (LLAMA_BUILD_TOOLS OFF CACHE BOOL "" FORCE )
38+ set (LLAMA_BUILD_COMMON ON CACHE BOOL "" FORCE )
39+ set (LLAMA_CURL OFF CACHE BOOL "" FORCE )
40+ set (LLAMA_HTTPLIB OFF CACHE BOOL "" FORCE )
41+ set (LLAMA_LLGUIDANCE OFF CACHE BOOL "" FORCE )
3942
40- add_subdirectory (${LLAMA_SOURCE_DIR } ${CMAKE_BINARY_DIR } /llama.cpp )
43+ add_subdirectory (${LLAMA_SOURCE_DIR } ${CMAKE_BINARY_DIR } /llama.cpp )
44+ else ()
45+ # Use system-installed llama.cpp
46+ find_package (llama REQUIRED )
47+ message (STATUS "Using system-installed llama.cpp" )
48+ endif ()
4149
4250add_library (model STATIC src/model.cpp )
4351target_include_directories (model
@@ -94,12 +102,53 @@ option(AGENT_CPP_INSTALL "Generate install target" OFF)
94102
95103if (AGENT_CPP_INSTALL)
96104 include (GNUInstallDirs )
105+ include (CMakePackageConfigHelpers )
97106
107+ # Install public headers
98108 install (FILES
99109 src/agent.h
100110 src/model.h
101111 src/tool.h
102112 src/callbacks.h
103113 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /agent-cpp
104114 )
115+
116+ # Install libraries with export set
117+ install (TARGETS agent model
118+ EXPORT agent-cpp-targets
119+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
120+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
121+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
122+ INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
123+ )
124+
125+ # Generate and install the export targets file
126+ install (EXPORT agent-cpp-targets
127+ FILE agent-cpp-targets .cmake
128+ NAMESPACE agent-cpp::
129+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/agent-cpp
130+ )
131+
132+ # Generate the version file for find_package version checking
133+ write_basic_package_version_file (
134+ "${CMAKE_CURRENT_BINARY_DIR } /agent-cpp-config-version.cmake"
135+ VERSION ${PROJECT_VERSION }
136+ COMPATIBILITY SameMajorVersion
137+ )
138+
139+ # Generate the config file from template
140+ configure_package_config_file (
141+ "${CMAKE_CURRENT_SOURCE_DIR } /cmake/agent-cpp-config.cmake.in"
142+ "${CMAKE_CURRENT_BINARY_DIR } /agent-cpp-config.cmake"
143+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/agent-cpp
144+ )
145+
146+ # Install the CMake config files
147+ install (FILES
148+ "${CMAKE_CURRENT_BINARY_DIR } /agent-cpp-config.cmake"
149+ "${CMAKE_CURRENT_BINARY_DIR } /agent-cpp-config-version.cmake"
150+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/agent-cpp
151+ )
152+
153+ message (STATUS "Install target enabled. Install with: cmake --install build --prefix /your/path" )
105154endif ()
0 commit comments