diff --git a/CMakeLists.txt b/CMakeLists.txt index b6981a92..47f5e5c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,7 +125,10 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) endif() include(GNUInstallDirs) include(CMakePackageConfigHelpers) -set(INSTALL_TARGETS ${TREELITE_TARGETS} objtreelite rapidjson mdspan) +set(INSTALL_TARGETS ${TREELITE_TARGETS} objtreelite rapidjson) +if(NOT mdspan_FOUND) # Found mdspan via FetchContent + list(APPEND INSTALL_TARGETS mdspan) +endif() if(NOT nlohmann_json_FOUND) # Fetched nlohmann/json via FetchContent list(APPEND INSTALL_TARGETS nlohmann_json) endif() diff --git a/cmake/ExternalLibs.cmake b/cmake/ExternalLibs.cmake index 4b4a4083..a4c39e30 100644 --- a/cmake/ExternalLibs.cmake +++ b/cmake/ExternalLibs.cmake @@ -41,21 +41,24 @@ if(NOT nlohmann_json_FOUND) endif() # mdspan (header-only library) -message(STATUS "Fetching mdspan...") -set(MDSPAN_CXX_STANDARD 17 CACHE STRING "") -FetchContent_Declare( - mdspan - GIT_REPOSITORY https://github.com/kokkos/mdspan.git - GIT_TAG mdspan-0.6.0 -) -FetchContent_GetProperties(mdspan) -if(NOT mdspan_POPULATED) - FetchContent_Populate(mdspan) - add_subdirectory(${mdspan_SOURCE_DIR} ${mdspan_BINARY_DIR} EXCLUDE_FROM_ALL) - message(STATUS "mdspan was downloaded at ${mdspan_SOURCE_DIR}.") -endif() -if(MSVC) # workaround for MSVC 19.x: https://github.com/kokkos/mdspan/issues/276 - target_compile_options(mdspan INTERFACE "/permissive-") +find_package(mdspan 0.6.0) +if(NOT mdspan_FOUND) + message(STATUS "Fetching mdspan...") + set(MDSPAN_CXX_STANDARD 17 CACHE STRING "") + FetchContent_Declare( + mdspan + GIT_REPOSITORY https://github.com/kokkos/mdspan.git + GIT_TAG mdspan-0.6.0 + ) + FetchContent_GetProperties(mdspan) + if(NOT mdspan_POPULATED) + FetchContent_Populate(mdspan) + add_subdirectory(${mdspan_SOURCE_DIR} ${mdspan_BINARY_DIR} EXCLUDE_FROM_ALL) + message(STATUS "mdspan was downloaded at ${mdspan_SOURCE_DIR}.") + endif() + if(MSVC) # workaround for MSVC 19.x: https://github.com/kokkos/mdspan/issues/276 + target_compile_options(mdspan INTERFACE "/permissive-") + endif() endif() # Google C++ tests