Skip to content

Commit

Permalink
[LinearSolver.Direct] Fix metis dependency (sofa-framework#4450)
Browse files Browse the repository at this point in the history
* Link dynamically with embedded metis to comply conda-forge rules

* export all symbols (for MSVC)

* Use external 5.1.0 metis or fallback to embedded code linked dynamically

* fix comments in metis cmake module

* ADD find or fetch mechanism

* Remove embeded metis and put linkage to private

* Fix metis dependency but still not the best fix

* test

* Put back public linkage

* Revert "Put back public linkage"

This reverts commit 71baa47.

* Clean

* cleaning sofa-framework#2

* Use SOFA_ALLOW_FETCH_DEPENDENCIES cmake option for metis

* Add missing CImg to list of fetchable dependencies in doc

* Update applications/plugins/SofaMatrix/CMakeLists.txt

Co-authored-by: Frederick Roy <[email protected]>

---------

Co-authored-by: Frederick Roy <[email protected]>
Co-authored-by: Paul Baksic <[email protected]>
Co-authored-by: bakpaul <[email protected]>
Co-authored-by: Paul Baksic <[email protected]>
Co-authored-by: Frederick Roy <[email protected]>
  • Loading branch information
6 people authored Feb 27, 2024
1 parent e71453d commit 6fab76a
Show file tree
Hide file tree
Showing 102 changed files with 140 additions and 39,800 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ option(SOFA_BUILD_RELEASE_PACKAGE "Run package specific configure" OFF)
# Option to allow some dependencies such as cxxopts to be fetched by cmake if
# the package is not found
option(SOFA_ALLOW_FETCH_DEPENDENCIES "Allow compatible dependencies to be fetched if the package is not found by cmake.
List of dependencies that can be fetched: cxxopts, gtest" ON)
List of dependencies that can be fetched: cxxopts, gtest, metis, CImg" ON)

# Option to accelerate the compilation
# see https://cmake.org/cmake/help/v3.16/command/target_precompile_headers.html
Expand Down
20 changes: 14 additions & 6 deletions Sofa/Component/LinearSolver/Direct/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,19 @@ set(SOURCE_FILES
${SOFACOMPONENTLINEARSOLVERDIRECT_SOURCE_DIR}/TypedMatrixLinearSystem[BTDMatrix].cpp
)

sofa_find_package(metis QUIET) # Unix users can have an installed version of metis
if(NOT metis_FOUND)
message(STATUS "${PROJECT_NAME}: using built-in metis library")
option(METIS-GKLIB_GKRAND "enable GKRAND support" ON) #GKRAND support allows the portability of random number generation across different architectures
add_subdirectory(extlibs/metis-5.1.0)
find_package(metis 5.1.0 EXACT QUIET)
if(NOT metis_FOUND AND SOFA_ALLOW_FETCH_DEPENDENCIES)
message("Sofa.Component.LinearSolver.Direct: DEPENDENCY metis NOT FOUND. SOFA_ALLOW_FETCH_DEPENDENCIES is ON, fetching metis...")
include(FetchContent)
FetchContent_Declare(metis
GIT_REPOSITORY https://github.com/sofa-framework/METIS
GIT_TAG v5.1.0-ModernInstall
)
FetchContent_MakeAvailable(metis)
elseif (NOT metis_FOUND)
message(FATAL_ERROR "Sofa.Component.LinearSolver.Direct: DEPENDENCY metis NOT FOUND. SOFA_ALLOW_FETCH_DEPENDENCIES is OFF and thus cannot be fetched. Install metis (version=5.1.0), or enable SOFA_ALLOW_FETCH_DEPENDENCIES to fix this issue.")
endif()

sofa_set_01(SOFA_COMPONENT_LINEARSOLVER_DIRECT_HAVE_METIS VALUE TRUE)

# make sure you have threads for AsyncSparseLDLSolver
Expand All @@ -75,8 +82,9 @@ sofa_find_package(Sofa.Component.LinearSolver.Iterative REQUIRED) # Only for Mat
sofa_find_package(Sofa.Component.LinearSolver.Ordering REQUIRED)

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${WRAPPER_FILES})

target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Simulation.Core Sofa.Component.LinearSolver.Iterative Sofa.Component.LinearSolver.Ordering)
target_link_libraries(${PROJECT_NAME} PUBLIC metis)
target_link_libraries(${PROJECT_NAME} PRIVATE metis)
target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads)

sofa_create_package_with_targets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ find_package(Threads QUIET REQUIRED)

set(SOFA_COMPONENT_LINEARSOLVER_DIRECT_HAVE_METIS @SOFA_COMPONENT_LINEARSOLVER_DIRECT_HAVE_METIS@)

if(SOFA_COMPONENT_LINEARSOLVER_DIRECT_HAVE_METIS)
find_package(Metis QUIET REQUIRED HINTS "${CMAKE_CURRENT_LIST_DIR}/..")
endif()

if(NOT TARGET @PROJECT_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
endif()
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6fab76a

Please sign in to comment.