Skip to content

Commit 411113b

Browse files
authored
build(ExternalLibs/mdspan): prefer find_package over fetchcontent (#653)
Closes #652
1 parent 86778be commit 411113b

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
125125
endif()
126126
include(GNUInstallDirs)
127127
include(CMakePackageConfigHelpers)
128-
set(INSTALL_TARGETS ${TREELITE_TARGETS} objtreelite rapidjson mdspan)
128+
set(INSTALL_TARGETS ${TREELITE_TARGETS} objtreelite rapidjson)
129+
if(NOT mdspan_FOUND) # Found mdspan via FetchContent
130+
list(APPEND INSTALL_TARGETS mdspan)
131+
endif()
129132
if(NOT nlohmann_json_FOUND) # Fetched nlohmann/json via FetchContent
130133
list(APPEND INSTALL_TARGETS nlohmann_json)
131134
endif()

cmake/ExternalLibs.cmake

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,24 @@ if(NOT nlohmann_json_FOUND)
4141
endif()
4242

4343
# mdspan (header-only library)
44-
message(STATUS "Fetching mdspan...")
45-
set(MDSPAN_CXX_STANDARD 17 CACHE STRING "")
46-
FetchContent_Declare(
47-
mdspan
48-
GIT_REPOSITORY https://github.com/kokkos/mdspan.git
49-
GIT_TAG mdspan-0.6.0
50-
)
51-
FetchContent_GetProperties(mdspan)
52-
if(NOT mdspan_POPULATED)
53-
FetchContent_Populate(mdspan)
54-
add_subdirectory(${mdspan_SOURCE_DIR} ${mdspan_BINARY_DIR} EXCLUDE_FROM_ALL)
55-
message(STATUS "mdspan was downloaded at ${mdspan_SOURCE_DIR}.")
56-
endif()
57-
if(MSVC) # workaround for MSVC 19.x: https://github.com/kokkos/mdspan/issues/276
58-
target_compile_options(mdspan INTERFACE "/permissive-")
44+
find_package(mdspan 0.6.0)
45+
if(NOT mdspan_FOUND)
46+
message(STATUS "Fetching mdspan...")
47+
set(MDSPAN_CXX_STANDARD 17 CACHE STRING "")
48+
FetchContent_Declare(
49+
mdspan
50+
GIT_REPOSITORY https://github.com/kokkos/mdspan.git
51+
GIT_TAG mdspan-0.6.0
52+
)
53+
FetchContent_GetProperties(mdspan)
54+
if(NOT mdspan_POPULATED)
55+
FetchContent_Populate(mdspan)
56+
add_subdirectory(${mdspan_SOURCE_DIR} ${mdspan_BINARY_DIR} EXCLUDE_FROM_ALL)
57+
message(STATUS "mdspan was downloaded at ${mdspan_SOURCE_DIR}.")
58+
endif()
59+
if(MSVC) # workaround for MSVC 19.x: https://github.com/kokkos/mdspan/issues/276
60+
target_compile_options(mdspan INTERFACE "/permissive-")
61+
endif()
5962
endif()
6063

6164
# Google C++ tests

0 commit comments

Comments
 (0)