Skip to content

Commit

Permalink
Try again
Browse files Browse the repository at this point in the history
  • Loading branch information
skottmckay committed Sep 16, 2024
1 parent 788e129 commit edf5056
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 76 deletions.
59 changes: 59 additions & 0 deletions cmake/external/helper_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,65 @@ function(set_folder_for_subdir_targets srcDir folderName)
endforeach()
endfunction()

# Add a new library and it's dependencies to an existing list.
# The new library and any dependencies it has that are not already in the list will be prepended to the existing list.
# output_var will be set to the combined list.
#
# e.g. libA is new, and depends on libB and libC. libB is already in extended_list.
# add_dependencies_to_external_lib(libA output_var "${existing_dependencies}") # need to quote existing list values
# before: existing_dependencies = [libB]
# after: output_var = [libA, libC, libB]
function(add_dependencies_to_external_libs new_lib output_var)
set(existing_deps ${ARGN})
set(new_deps)

function(get_dependencies input_target)
get_target_property(alias ${input_target} ALIASED_TARGET)
if(TARGET ${alias})
set(input_target ${alias})
endif()

# if this already exists we don't need to recurse any more
if(${input_target} IN_LIST existing_deps OR ${input_target} IN_LIST new_deps)
return()
endif()

list(APPEND new_deps ${input_target})

get_target_property(link_libraries ${input_target} LINK_LIBRARIES)
foreach(dependency IN LISTS link_libraries)
if(TARGET ${dependency})
get_dependencies(${dependency})
endif()
endforeach()

# Add if needed. As this is to primarily update the items to link against, interface libraries shouldn't be relevant
# get_target_property(link_libraries ${input_target} INTERFACE_LINK_LIBRARIES)
# foreach(dependency IN LISTS link_libraries)
# if(TARGET ${dependency})
# get_dependencies(${dependency})
# endif()
# endforeach()

set(new_deps ${new_deps} PARENT_SCOPE)
endfunction()

message(STATUS "### Getting dependencies for ${new_lib}")
get_dependencies(${new_lib})

set(combined_deps)
foreach(dependency IN LISTS new_deps)
get_target_property(type ${dependency} TYPE)
if(${type} STREQUAL "STATIC_LIBRARY" OR ${type} STREQUAL "OBJECT_LIBRARY")
list(APPEND combined_deps ${dependency})
endif()
endforeach()

list(APPEND combined_deps ${existing_deps})
message(STATUS "Combined: ${combined_deps}")
set(${output_var} ${combined_deps} PARENT_SCOPE)
endfunction()

# This file was copied from cmake source with modifications:
# 1. Add the EXCLUDE_FROM_ALL keyword when this function calls add_subdirectory. It will also resolve the
# 'make install' issue.
Expand Down
97 changes: 21 additions & 76 deletions cmake/external/onnxruntime_external_deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ if (onnxruntime_USE_MIMALLOC)
onnxruntime_fetchcontent_makeavailable(mimalloc)
endif()

set(onnxruntime_EXTERNAL_LIBRARIES ${onnxruntime_EXTERNAL_LIBRARIES_XNNPACK} ${WIL_TARGET} nlohmann_json::nlohmann_json
onnx onnx_proto ${PROTOBUF_LIB} re2::re2 Boost::mp11 safeint_interface
flatbuffers::flatbuffers ${GSL_TARGET} ${ABSEIL_LIBS} date::date
${ONNXRUNTIME_CLOG_TARGET_NAME})

# The source code of onnx_proto is generated, we must build this lib first before starting to compile the other source code that uses ONNX protobuf types.
# The other libs do not have the problem. All the sources are already there. We can compile them in any order.
set(onnxruntime_EXTERNAL_DEPENDENCIES onnx_proto flatbuffers::flatbuffers)
Expand Down Expand Up @@ -675,91 +680,31 @@ if (onnxruntime_USE_WEBGPU)
set(DAWN_ENABLE_VULKAN OFF CACHE BOOL "" FORCE)
endif()

if (ANDROID)
endif()

onnxruntime_fetchcontent_makeavailable(dawn)
endif()

message(STATUS "Finished fetching external dependencies")

set(onnxruntime_LINK_DIRS )

if (onnxruntime_USE_CUDA)
find_package(CUDAToolkit REQUIRED)

if(onnxruntime_CUDNN_HOME)
file(TO_CMAKE_PATH ${onnxruntime_CUDNN_HOME} onnxruntime_CUDNN_HOME)
set(CUDNN_PATH ${onnxruntime_CUDNN_HOME})
endif()
include(cuDNN)
# Add with dependencies in reverse order as new values are added at the front in each call
add_dependencies_to_external_libs(dawn::dawn_proc onnxruntime_EXTERNAL_LIBRARIES "${onnxruntime_EXTERNAL_LIBRARIES}")
add_dependencies_to_external_libs(dawn::native onnxruntime_EXTERNAL_LIBRARIES "${onnxruntime_EXTERNAL_LIBRARIES}")
endif()

set(onnxruntime_LINK_DIRS)
if(onnxruntime_USE_SNPE)
include(external/find_snpe.cmake)
include(external/find_snpe.cmake)
list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${SNPE_NN_LIBS})
endif()

# add dependencies to the list of external libraries and populate onnxruntime_EXTERNAL_LIBRARIES with the result
function(add_dependencies_to_external_libs output_var)
set (external_libs ${ARGN})
set(extended_deps)

function(get_dependencies input_target)
message(STATUS "get_dependencies: ${input_target}")
get_target_property(alias ${input_target} ALIASED_TARGET)
if(TARGET ${alias})
set(input_target ${alias})
endif()

if(${input_target} IN_LIST all_dependencies)
return()
endif()

list(APPEND all_dependencies ${input_target})

get_target_property(link_libraries ${input_target} LINK_LIBRARIES)
foreach(dependency IN LISTS link_libraries)
if(TARGET ${dependency})
get_dependencies(${dependency})
endif()
endforeach()

# get_target_property(link_libraries ${input_target} INTERFACE_LINK_LIBRARIES)
# foreach(dependency IN LISTS link_libraries)
# if(TARGET ${dependency})
# get_dependencies(${dependency})
# endif()
# endforeach()

set(all_dependencies ${all_dependencies} PARENT_SCOPE)
endfunction()

foreach(external_lib IN LISTS external_libs)
message(STATUS "### Getting dependencies for : ${external_lib}")
get_dependencies(${external_lib})
endforeach()

foreach(dependency IN LISTS all_dependencies)
get_target_property(type ${dependency} TYPE)
if((${type} STREQUAL "STATIC_LIBRARY" OR ${type} STREQUAL "OBJECT_LIBRARY") AND
NOT ${dependency} IN_LIST external_libs_extended)
list(APPEND extended_deps ${dependency})
endif()
endforeach()

set(${output_var} ${extended_deps} PARENT_SCOPE)
endfunction()
if (onnxruntime_USE_CUDA)
find_package(CUDAToolkit REQUIRED)

# Create list of external libraries potentially added in this file.
set(_external_libraries ${onnxruntime_EXTERNAL_LIBRARIES_XNNPACK} ${SNPE_NN_LIBS} ${WIL_TARGET}
dawn::dawn_native dawn::dawn_proc nlohmann_json::nlohmann_json
onnx onnx_proto ${PROTOBUF_LIB} re2::re2 Boost::mp11 safeint_interface
flatbuffers::flatbuffers ${GSL_TARGET} ${ABSEIL_LIBS} date::date
${ONNXRUNTIME_CLOG_TARGET_NAME})
if(onnxruntime_CUDNN_HOME)
file(TO_CMAKE_PATH ${onnxruntime_CUDNN_HOME} onnxruntime_CUDNN_HOME)
set(CUDNN_PATH ${onnxruntime_CUDNN_HOME})
endif()

# add the dependencies as well. this is need in some places where we have to process the full list of libraries
# e.g. iOS pre-linking.
add_dependencies_to_external_libs(onnxruntime_EXTERNAL_LIBRARIES "${_external_libraries}")
include(cuDNN)
endif()

FILE(TO_NATIVE_PATH ${CMAKE_BINARY_DIR} ORT_BINARY_DIR)
FILE(TO_NATIVE_PATH ${PROJECT_SOURCE_DIR} ORT_SOURCE_DIR)

message(STATUS "Finished fetching external dependencies")

0 comments on commit edf5056

Please sign in to comment.