|
| 1 | +cmake_minimum_required(VERSION 3.26) |
| 2 | + |
| 3 | +project(workTaskflowExample |
| 4 | + LANGUAGES CXX |
| 5 | +) |
| 6 | + |
| 7 | +include(CMakePackageConfigHelpers) |
| 8 | +include(FetchContent) |
| 9 | +include(GNUInstallDirs) |
| 10 | + |
| 11 | +set(CMAKE_CXX_STANDARD 17) |
| 12 | +set(CMAKE_CXX_STANDARD_REQUIRED True) |
| 13 | + |
| 14 | +# Fetch and install Taskflow unless the user has already supplied that |
| 15 | +# dependency and it can be found via a call to find_package. This would |
| 16 | +# typically happen if the user made Taskflow's config file package visible |
| 17 | +# to cmake, e.g. by setting Taskflow_DIR to the directory where Taskflow's |
| 18 | +# config files are installed. |
| 19 | +# |
| 20 | +# Note that by default FetchContent doesn't provide any diagnostic output, |
| 21 | +# but users can specify FETCHCONTENT_QUIET=OFF when running cmake to get |
| 22 | +# more information. |
| 23 | +FetchContent_Declare( |
| 24 | + Taskflow |
| 25 | + GIT_REPOSITORY https://github.com/taskflow/taskflow.git |
| 26 | + GIT_TAG 2dfa50a567d48b8439807f5da8a041ba64d4fb63 # v3.10.0 |
| 27 | + FIND_PACKAGE_ARGS CONFIG |
| 28 | +) |
| 29 | + |
| 30 | +# Disable tests and examples since we don't need them and they can |
| 31 | +# be slow-ish to build. |
| 32 | +set(TF_BUILD_EXAMPLES OFF CACHE INTERNAL BOOL) |
| 33 | +set(TF_BUILD_TESTS OFF CACHE INTERNAL BOOL) |
| 34 | + |
| 35 | +FetchContent_MakeAvailable(Taskflow) |
| 36 | + |
| 37 | +# Make sure that Taskflow_DIR is set to the location of the _installed_ |
| 38 | +# Taskflow package config file used to build this library. We'll use this |
| 39 | +# below when setting up our package config file. |
| 40 | +# |
| 41 | +# If we found an externally-supplied Taskflow package above, Taskflow_FOUND |
| 42 | +# will be set and Taskflow_DIR will already be set to the location we want. |
| 43 | +# |
| 44 | +# If we built Taskflow ourselves, Taskflow_FOUND will not be set and |
| 45 | +# Taskflow_DIR will be set to some internal build location. We want to |
| 46 | +# reset that to the location where Taskflow will be installed. |
| 47 | +if (NOT Taskflow_FOUND) |
| 48 | + set(Taskflow_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/Taskflow") |
| 49 | +endif() |
| 50 | + |
| 51 | +# Set up library target. |
| 52 | +add_library(workTaskflowExample SHARED) |
| 53 | + |
| 54 | +target_link_libraries( |
| 55 | + workTaskflowExample |
| 56 | + PUBLIC |
| 57 | + Taskflow::Taskflow |
| 58 | +) |
| 59 | + |
| 60 | +target_sources( |
| 61 | + workTaskflowExample |
| 62 | + PRIVATE |
| 63 | + detachedTask.cpp |
| 64 | + dispatcher.cpp |
| 65 | + PUBLIC |
| 66 | + FILE_SET HEADERS |
| 67 | + FILES |
| 68 | + api.h |
| 69 | + detachedTask.h |
| 70 | + dispatcher.h |
| 71 | + executorStack.h |
| 72 | + impl.h |
| 73 | + loops.h |
| 74 | + reduce.h |
| 75 | + sort.h |
| 76 | + threadLimits.h |
| 77 | + withScopedParallelism.h |
| 78 | +) |
| 79 | + |
| 80 | +target_include_directories( |
| 81 | + workTaskflowExample |
| 82 | + PUBLIC |
| 83 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..> |
| 84 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 85 | +) |
| 86 | + |
| 87 | +target_compile_definitions( |
| 88 | + workTaskflowExample |
| 89 | + PRIVATE |
| 90 | + "WORK_TASKFLOW_EXAMPLE_EXPORT" |
| 91 | +) |
| 92 | + |
| 93 | +# Install artifacts and set up package config file |
| 94 | +install( |
| 95 | + TARGETS workTaskflowExample |
| 96 | + EXPORT workTaskflowExampleTargets |
| 97 | + FILE_SET HEADERS |
| 98 | + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/workTaskflowExample" |
| 99 | +) |
| 100 | + |
| 101 | +install( |
| 102 | + EXPORT workTaskflowExampleTargets |
| 103 | + FILE workTaskflowExampleTargets.cmake |
| 104 | + NAMESPACE workTaskflowExample:: |
| 105 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/workTaskflowExample" |
| 106 | +) |
| 107 | + |
| 108 | +configure_package_config_file( |
| 109 | + workTaskflowExampleConfig.cmake.in |
| 110 | + "${CMAKE_CURRENT_BINARY_DIR}/workTaskflowExampleConfig.cmake" |
| 111 | + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/workTaskflowExample" |
| 112 | + PATH_VARS Taskflow_DIR |
| 113 | +) |
| 114 | + |
| 115 | +install( |
| 116 | + FILES "${CMAKE_CURRENT_BINARY_DIR}/workTaskflowExampleConfig.cmake" |
| 117 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/workTaskflowExample" |
| 118 | +) |
0 commit comments