diff --git a/Sofa/framework/Helper/CMakeLists.txt b/Sofa/framework/Helper/CMakeLists.txt index a3f30be4a4e..fe63cb5c9de 100644 --- a/Sofa/framework/Helper/CMakeLists.txt +++ b/Sofa/framework/Helper/CMakeLists.txt @@ -10,6 +10,22 @@ sofa_find_package(STB REQUIRED) # DiffLib (header only) sofa_find_package(DiffLib REQUIRED) +# taskflow +sofa_find_package(Taskflow) +if(NOT Taskflow_FOUND AND SOFA_ALLOW_FETCH_DEPENDENCIES) + message("Sofa.Helper: DEPENDENCY Taskflow NOT FOUND. SOFA_ALLOW_FETCH_DEPENDENCIES is ON, fetching Taskflow...") + + sofa_fetch_dependency(Taskflow + GIT_REPOSITORY https://github.com/taskflow/taskflow.git + GIT_TAG v3.10.0 + DONT_BUILD + ) + + set(TASKFLOW_ROOT ${Taskflow_SOURCE_DIR}) + sofa_find_package(Taskflow REQUIRED) +elseif (NOT Taskflow_FOUND) + message(FATAL_ERROR "Sofa.Helper: DEPENDENCY Taskflow NOT FOUND. SOFA_ALLOW_FETCH_DEPENDENCIES is OFF and thus cannot be fetched. Install Taskflow, or enable SOFA_ALLOW_FETCH_DEPENDENCIES to fix this issue.") +endif() set(SRC_ROOT "src/sofa/helper") @@ -46,6 +62,7 @@ set(HEADER_FILES ${SRC_ROOT}/SortedPermutation.h ${SRC_ROOT}/StringUtils.h ${SRC_ROOT}/TagFactory.h + ${SRC_ROOT}/taskflow.h ${SRC_ROOT}/TriangleOctree.h ${SRC_ROOT}/Utils.h ${SRC_ROOT}/accessor.h @@ -257,6 +274,9 @@ target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$") +# taskflow (header only) +target_link_libraries(${PROJECT_NAME} PUBLIC Taskflow::Taskflow) + set(is_release "$") set(is_debug "$") set(is_relwithdebinfo "$") diff --git a/Sofa/framework/Helper/Sofa.HelperConfig.cmake.in b/Sofa/framework/Helper/Sofa.HelperConfig.cmake.in index 72532cdfcbb..3fc4ebc6b2a 100644 --- a/Sofa/framework/Helper/Sofa.HelperConfig.cmake.in +++ b/Sofa/framework/Helper/Sofa.HelperConfig.cmake.in @@ -9,6 +9,10 @@ sofa_find_package(Sofa.Topology QUIET REQUIRED) sofa_find_package(Eigen3 QUIET REQUIRED) +if(NOT TARGET Taskflow::Taskflow) + sofa_find_package(Taskflow QUIET REQUIRED) +endif() + if(NOT TARGET @PROJECT_NAME@) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") endif() diff --git a/Sofa/framework/Helper/src/sofa/helper/taskflow.h b/Sofa/framework/Helper/src/sofa/helper/taskflow.h new file mode 100644 index 00000000000..32a010d1e76 --- /dev/null +++ b/Sofa/framework/Helper/src/sofa/helper/taskflow.h @@ -0,0 +1,23 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include diff --git a/cmake/Modules/FindTaskflow.cmake b/cmake/Modules/FindTaskflow.cmake new file mode 100644 index 00000000000..0fdcd199f2d --- /dev/null +++ b/cmake/Modules/FindTaskflow.cmake @@ -0,0 +1,50 @@ +# Set Taskflow_FOUND to false initially +set(Taskflow_FOUND FALSE) + + +# Specify the Taskflow include directory and library +find_path(Taskflow_INCLUDE_DIR + NAMES taskflow/taskflow.hpp + HINTS "${TASKFLOW_ROOT}" +) + +# If both the include directory are found, set Taskflow_FOUND to true +if(Taskflow_INCLUDE_DIR) + set(Taskflow_FOUND TRUE) + + # Read the content of the taskflow.hpp file + file(READ "${Taskflow_INCLUDE_DIR}/taskflow/taskflow.hpp" file_contents) + + # Use a regular expression to extract the version number + string(REGEX MATCH "#define TF_VERSION [0-9]+" version_line "${file_contents}") + + # Extract the numeric part of the version + string(REGEX REPLACE "#define TF_VERSION " "" version_number "${version_line}") + + # Split the version number into major, minor, and patch components + # Taskflow uses a version format like 300900 for 3.9.0 + math(EXPR major_version "${version_number} / 100000") + math(EXPR minor_version "(${version_number} % 100000) / 100") + math(EXPR patch_version "${version_number} % 100") + + # Format the version as X.Y.Z + set(formatted_version "${major_version}.${minor_version}.${patch_version}") + + # Set the output variable + set(Taskflow_VERSION "${formatted_version}") + + if(NOT TARGET Taskflow::Taskflow) + add_library(Taskflow::Taskflow INTERFACE IMPORTED) + set_target_properties(Taskflow::Taskflow PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Taskflow_INCLUDE_DIR}") + endif () + + # Handle REQUIRED and QUIET options + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Taskflow + REQUIRED_VARS Taskflow_FOUND Taskflow_INCLUDE_DIR + VERSION_VAR Taskflow_VERSION + ) + + mark_as_advanced(Taskflow_INCLUDE_DIR) +endif()