Skip to content

Commit

Permalink
thrust from find_package
Browse files Browse the repository at this point in the history
  • Loading branch information
schuhmaj committed Jul 5, 2022
1 parent 4f770af commit f8e0d94
Showing 1 changed file with 60 additions and 54 deletions.
114 changes: 60 additions & 54 deletions cmake/thrust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,67 @@ include(FetchContent)

message(STATUS "Setting up thrust")

message(STATUS "Using thrust from git repository")
# Fetches the version 1.16.0 of the official NVIDIA Thrust repository
FetchContent_Declare(thrust
GIT_REPOSITORY https://github.com/NVIDIA/thrust.git
GIT_TAG 1.16.0
)

FetchContent_GetProperties(thrust)
if(NOT thrust_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(thrust)

# Set custom variables, policies, etc.
# Disable stuff not needed
set(THRUST_ENABLE_HEADER_TESTING "OFF")
set(THRUST_ENABLE_TESTING "OFF")
set(THRUST_ENABLE_EXAMPLES "OFF")

# Set standard CPP Dialect to 17 (default of thrust would be 14)
set(THRUST_CPP_DIALECT 17)


if(EXISTS ${thrust_SOURCE_DIR}/thrust/cmake/thrust-config-version.cmake)
message(STATUS "Found problem causing thrust file (1)")
file(READ ${thrust_SOURCE_DIR}/thrust/cmake/thrust-config-version.cmake THRUST_CONFIG_VERSION_FILE)
string(REPLACE
"file(READ \"\${_THRUST_VERSION_INCLUDE_DIR}/thrust/version.h\" THRUST_VERSION_HEADER)"
"file(READ \"${thrust_SOURCE_DIR}/thrust/version.h\" THRUST_VERSION_HEADER)"
THRUST_CONFIG_VERSION_FILE "${THRUST_CONFIG_VERSION_FILE}")

file(WRITE ${thrust_SOURCE_DIR}/thrust/cmake/thrust-config-version.cmake
"${THRUST_CONFIG_VERSION_FILE}"
)
message(STATUS "Modified the the problem causing file (1)")
else()
message(STATUS "Problem causing thrust file (1) not found!")
endif()
# Set custom variables, policies, etc.
# Disable stuff not needed
set(THRUST_ENABLE_HEADER_TESTING "OFF")
set(THRUST_ENABLE_TESTING "OFF")
set(THRUST_ENABLE_EXAMPLES "OFF")

if(EXISTS ${thrust_SOURCE_DIR}/thrust/cmake/thrust-config.cmake)
message(STATUS "Found problem causing thrust file (2)")
file(READ ${thrust_SOURCE_DIR}/thrust/cmake/thrust-config.cmake THRUST_CONFIG_FILE)
string(REPLACE
"target_include_directories(_Thrust_Thrust INTERFACE \"\${_THRUST_INCLUDE_DIR}\")"
"target_include_directories(_Thrust_Thrust INTERFACE \"${thrust_SOURCE_DIR}\")"
THRUST_CONFIG_FILE "${THRUST_CONFIG_FILE}")

file(WRITE ${thrust_SOURCE_DIR}/thrust/cmake/thrust-config.cmake
"${THRUST_CONFIG_FILE}"
)
message(STATUS "Modified the the problem causing file (2)")
else()
message(STATUS "Problem causing thrust file (2) not found!")
endif()
# Set standard CPP Dialect to 17 (default of thrust would be 14)
set(THRUST_CPP_DIALECT 17)

find_package(thrust 1.16.0 QUIET)

if (${thrust_FOUND})

message(STATUS "Using local thrust installation")

else()
message(STATUS "Using thrust from git repository")
# Fetches the version 1.16.0 of the official NVIDIA Thrust repository
FetchContent_Declare(thrust
GIT_REPOSITORY https://github.com/NVIDIA/thrust.git
GIT_TAG 1.16.0
)

# Bring the populated content into the build
add_subdirectory(${thrust_SOURCE_DIR} ${thrust_BINARY_DIR})
FetchContent_GetProperties(thrust)
if(NOT thrust_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(thrust)

if(EXISTS ${thrust_SOURCE_DIR}/thrust/cmake/thrust-config-version.cmake)
message(STATUS "Found problem causing thrust file (1)")
file(READ ${thrust_SOURCE_DIR}/thrust/cmake/thrust-config-version.cmake THRUST_CONFIG_VERSION_FILE)
string(REPLACE
"file(READ \"\${_THRUST_VERSION_INCLUDE_DIR}/thrust/version.h\" THRUST_VERSION_HEADER)"
"file(READ \"${thrust_SOURCE_DIR}/thrust/version.h\" THRUST_VERSION_HEADER)"
THRUST_CONFIG_VERSION_FILE "${THRUST_CONFIG_VERSION_FILE}")

file(WRITE ${thrust_SOURCE_DIR}/thrust/cmake/thrust-config-version.cmake
"${THRUST_CONFIG_VERSION_FILE}"
)
message(STATUS "Modified the the problem causing file (1)")
else()
message(STATUS "Problem causing thrust file (1) not found!")
endif()

if(EXISTS ${thrust_SOURCE_DIR}/thrust/cmake/thrust-config.cmake)
message(STATUS "Found problem causing thrust file (2)")
file(READ ${thrust_SOURCE_DIR}/thrust/cmake/thrust-config.cmake THRUST_CONFIG_FILE)
string(REPLACE
"target_include_directories(_Thrust_Thrust INTERFACE \"\${_THRUST_INCLUDE_DIR}\")"
"target_include_directories(_Thrust_Thrust INTERFACE \"${thrust_SOURCE_DIR}\")"
THRUST_CONFIG_FILE "${THRUST_CONFIG_FILE}")

file(WRITE ${thrust_SOURCE_DIR}/thrust/cmake/thrust-config.cmake
"${THRUST_CONFIG_FILE}"
)
message(STATUS "Modified the the problem causing file (2)")
else()
message(STATUS "Problem causing thrust file (2) not found!")
endif()

# Bring the populated content into the build
add_subdirectory(${thrust_SOURCE_DIR} ${thrust_BINARY_DIR})
endif()
endif()

0 comments on commit f8e0d94

Please sign in to comment.