diff --git a/CMakeLists.txt b/CMakeLists.txt index 15b550876..cddc278cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -847,25 +847,25 @@ if(OCOS_ENABLE_AZURE) message(STATUS "Found CURL package") set(libcurl_target CURL::libcurl) else() - # curl is coming from triton but as that's an external project it isn't built yet and we have to add - # paths and library names instead of cmake targets. message(STATUS "Using CURL build from triton client. Once built it should be in ${triton_THIRD_PARTY_DIR}/curl") - target_include_directories(ocos_operators PUBLIC ${triton_THIRD_PARTY_DIR}/curl/include) - - # Install is to 'lib' except on CentOS (which is used for the manylinux build of the python wheel). - # Side note: we have to patch the triton client CMakeLists.txt to only use 'lib64' for 64-bit builds otherwise - # the build of the 32-bit python wheel fails with CURL not being found due to the invalid library - # directory name. - target_link_directories(ocos_operators PUBLIC ${triton_THIRD_PARTY_DIR}/curl/lib) - target_link_directories(ocos_operators PUBLIC ${triton_THIRD_PARTY_DIR}/curl/lib64) - - if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set(libcurl_target "curl-d") - else() - set(libcurl_target "curl") + + # Paths to Triton-built curl + set(TRITON_CURL_INCLUDE_DIR ${triton_THIRD_PARTY_DIR}/curl/build/include) + set(TRITON_CURL_LIBRARY ${triton_THIRD_PARTY_DIR}/curl/build/lib/libcurl.a) + + if(NOT EXISTS ${TRITON_CURL_LIBRARY}) + message(WARNING "Triton libcurl not found yet at ${TRITON_CURL_LIBRARY}. This may be expected if Triton hasn't built yet.") endif() + + # Add include and link directories directly + target_include_directories(ocos_operators PUBLIC ${TRITON_CURL_INCLUDE_DIR}) + target_link_directories(ocos_operators PUBLIC ${triton_THIRD_PARTY_DIR}/curl/build/lib) + + # Instead of an imported target, link directly using full path + set(libcurl_target ${TRITON_CURL_LIBRARY}) endif() + # Finally, link libcurl (and others) target_link_libraries(ocos_operators PUBLIC httpclient_static ${libcurl_target} OpenSSL::Crypto OpenSSL::SSL ZLIB::ZLIB) endif() endif() diff --git a/cmake/externals/rapidjson_cmake.patch b/cmake/externals/rapidjson_cmake.patch new file mode 100644 index 000000000..70815667a --- /dev/null +++ b/cmake/externals/rapidjson_cmake.patch @@ -0,0 +1,10 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index ceda71b1..67692ba3 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,4 +1,4 @@ +-CMAKE_MINIMUM_REQUIRED(VERSION 2.8) ++CMAKE_MINIMUM_REQUIRED(VERSION 3.5) + if(POLICY CMP0025) + # detect Apple's Clang + cmake_policy(SET CMP0025 NEW) diff --git a/cmake/externals/triton.cmake b/cmake/externals/triton.cmake index b515b1d71..0143b73c1 100644 --- a/cmake/externals/triton.cmake +++ b/cmake/externals/triton.cmake @@ -86,25 +86,46 @@ else() # include path will be wrong so the build error is delayed/misleading and non-trivial to understand/resolve. set(RapidJSON_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_deps/rapidjson) set(RapidJSON_INSTALL_DIR ${RapidJSON_PREFIX}/install) + + set(triton_patch_exe patch) + + set(rapidjson_patch_file ${PROJECT_SOURCE_DIR}/cmake/externals/rapidjson_cmake.patch) + set(rapidjson_patch_command ${triton_patch_exe} --verbose -p1 -i ${rapidjson_patch_file}) + ExternalProject_Add(RapidJSON - PREFIX ${RapidJSON_PREFIX} - URL https://github.com/Tencent/rapidjson/archive/refs/tags/v1.1.0.zip - URL_HASH SHA1=0fe7b4f7b83df4b3d517f4a202f3a383af7a0818 - CMAKE_ARGS -DRAPIDJSON_BUILD_DOC=OFF - -DRAPIDJSON_BUILD_EXAMPLES=OFF - -DRAPIDJSON_BUILD_TESTS=OFF - -DRAPIDJSON_HAS_STDSTRING=ON - -DRAPIDJSON_USE_MEMBERSMAP=ON - -DCMAKE_INSTALL_PREFIX=${RapidJSON_INSTALL_DIR} - ) + PREFIX ${RapidJSON_PREFIX} + URL https://github.com/Tencent/rapidjson/archive/refs/tags/v1.1.0.zip + URL_HASH SHA1=0fe7b4f7b83df4b3d517f4a202f3a383af7a0818 + PATCH_COMMAND ${rapidjson_patch_command} + CMAKE_ARGS -DRAPIDJSON_BUILD_DOC=OFF + -DRAPIDJSON_BUILD_EXAMPLES=OFF + -DRAPIDJSON_BUILD_TESTS=OFF + -DRAPIDJSON_HAS_STDSTRING=ON + -DRAPIDJSON_USE_MEMBERSMAP=ON + -DCMAKE_INSTALL_PREFIX=${RapidJSON_INSTALL_DIR} + ) ExternalProject_Get_Property(RapidJSON SOURCE_DIR BINARY_DIR) # message(STATUS "RapidJSON src=${SOURCE_DIR} binary=${BINARY_DIR}") # Set RapidJSON_ROOT_DIR for find_package. The required RapidJSONConfig.cmake file is generated in the binary dir set(RapidJSON_ROOT_DIR ${BINARY_DIR}) - set(triton_extra_cmake_args "") - set(triton_patch_exe patch) + set(triton_THIRD_PARTY_DIR ${BINARY_DIR}/third-party) + + # Set custom CURL paths manually because find_package(CURL) fails sometimes in CMake + set(triton_curl_include_dir ${triton_THIRD_PARTY_DIR}/curl/build/include) + set(triton_curl_library ${triton_THIRD_PARTY_DIR}/curl/build/lib/libcurl.a) + + set(triton_extra_cmake_args + -DTRITON_CURL_INCLUDE_DIRS=${triton_curl_include_dir} + -DTRITON_CURL_LIBRARY=${triton_curl_library} + ) + + # Debug info + message(STATUS "Using custom CURL include dir: ${triton_curl_include_dir}") + message(STATUS "Using custom CURL library path: ${triton_curl_library}") + message(STATUS "triton_extra_cmake_args: ${triton_extra_cmake_args}") + set(triton_dependencies RapidJSON) endif() #if (WIN32) @@ -140,9 +161,9 @@ ExternalProject_Add(triton ${triton_extra_cmake_args} INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step." PATCH_COMMAND ${triton_patch_command} + BUILD_BYPRODUCTS ${triton_curl_library} ) add_dependencies(triton ${triton_dependencies}) ExternalProject_Get_Property(triton SOURCE_DIR BINARY_DIR) -set(triton_THIRD_PARTY_DIR ${BINARY_DIR}/third-party) diff --git a/cmake/externals/triton_cmake.patch b/cmake/externals/triton_cmake.patch index e31a03d2c..6fafb49e0 100644 --- a/cmake/externals/triton_cmake.patch +++ b/cmake/externals/triton_cmake.patch @@ -2,7 +2,7 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b11178..7749fa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -115,10 +115,11 @@ if(TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER +@@ -115,10 +115,14 @@ if(TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER file(STRINGS /etc/os-release DISTRO REGEX "^NAME=") string(REGEX REPLACE "NAME=\"(.*)\"" "\\1" DISTRO "${DISTRO}") message(STATUS "Distro Name: ${DISTRO}") @@ -12,9 +12,41 @@ index 7b11178..7749fa9 100644 endif() endif() + message(STATUS "Triton client CURL_LIB_DIR=${CURL_LIB_DIR}") - ++ set(_cc_client_depends "") if(${TRITON_ENABLE_CC_HTTP}) + set(_cc_client_depends ${_cc_client_depends} curl) + endif() # TRITON_ENABLE_CC_HTTP + if(${TRITON_ENABLE_CC_GRPC} OR ${TRITON_ENABLE_PERF_ANALYZER}) + set(_cc_client_depends ${_cc_client_depends} grpc protobuf) + endif() # TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER + + if(NOT ${TRITON_ENABLE_PERF_ANALYZER} AND ${TRITON_ENABLE_PERF_ANALYZER_C_API}) + message(FATAL_ERROR "TRITON_ENABLE_PERF_ANALYZER_C_API=ON requires TRITON_ENABLE_PERF_ANALYZER=ON") + endif() # NOT TRITON_ENABLE_PERF_ANALYZER AND TRITON_ENABLE_PERF_ANALYZER_C_API + if(NOT ${TRITON_ENABLE_PERF_ANALYZER} AND ${TRITON_ENABLE_PERF_ANALYZER_TFS}) + message(FATAL_ERROR "TRITON_ENABLE_PERF_ANALYZER_TFS=ON requires TRITON_ENABLE_PERF_ANALYZER=ON") + endif() # NOT TRITON_ENABLE_PERF_ANALYZER AND TRITON_ENABLE_PERF_ANALYZER_TFS + if(NOT ${TRITON_ENABLE_PERF_ANALYZER} AND ${TRITON_ENABLE_PERF_ANALYZER_TS}) + message(FATAL_ERROR "TRITON_ENABLE_PERF_ANALYZER_TS=ON requires TRITON_ENABLE_PERF_ANALYZER=ON") + endif() # NOT TRITON_ENABLE_PERF_ANALYZER AND TRITON_ENABLE_PERF_ANALYZER_TS + + ExternalProject_Add(cc-clients + PREFIX cc-clients + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/c++" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/cc-clients" + CMAKE_CACHE_ARGS + ${_CMAKE_ARGS_OPENSSL_ROOT_DIR} + ${_CMAKE_ARGS_CMAKE_TOOLCHAIN_FILE} + ${_CMAKE_ARGS_VCPKG_TARGET_TRIPLET} ++ -DCMAKE_PREFIX_PATH:PATH=${TRITON_THIRD_PARTY_INSTALL_PREFIX}/curl/${CURL_LIB_DIR} + -DCURL_DIR:PATH=${TRITON_THIRD_PARTY_INSTALL_PREFIX}/curl/${CURL_LIB_DIR}/cmake/CURL + -DProtobuf_DIR:PATH=${_FINDPACKAGE_PROTOBUF_CONFIG_DIR} + -DgRPC_DIR:PATH=${TRITON_THIRD_PARTY_INSTALL_PREFIX}/grpc/lib/cmake/grpc + -Dabsl_DIR:PATH=${TRITON_THIRD_PARTY_INSTALL_PREFIX}/absl/lib/cmake/absl + -Dc-ares_DIR:PATH=${TRITON_THIRD_PARTY_INSTALL_PREFIX}/c-ares/lib/cmake/c-ares + -DGTEST_ROOT:PATH=${TRITON_THIRD_PARTY_INSTALL_PREFIX}/googletest + -DTRITON_COMMON_REPO_TAG:STRING=${TRITON_COMMON_REPO_TAG} diff --git a/src/c++/library/CMakeLists.txt b/src/c++/library/CMakeLists.txt index bdaae25..0e599f2 100644 --- a/src/c++/library/CMakeLists.txt @@ -46,3 +78,8 @@ index bdaae25..0e599f2 100644 ) set_target_properties( +@@ -468,0 +469,4 @@ ++project(TritonClient) ++ ++# Fix missing CURL::libcurl by ensuring CURL is found ++find_package(CURL REQUIRED)