Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Update install rules to install cmake into lib directory #1323

Merged
merged 2 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 18 additions & 93 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ else()
set(THRUST_TOPLEVEL_PROJECT OFF)
endif()

# This must be done before any languages are enabled:
if (THRUST_TOPLEVEL_PROJECT)
include(cmake/ThrustCompilerHacks.cmake)
endif()

# This must appear after our Compiler Hacks or else CMake will delete the cache
# and reconfigure from scratch.
# This must also appear before the installation rules, as it is required by the
# GNUInstallDirs CMake module.
enable_language(CXX)

# Optionally include installation rules for non-top-level builds:
option(THRUST_ENABLE_INSTALL_RULES "Enable installation of Thrust" ${THRUST_TOPLEVEL_PROJECT})
if (THRUST_ENABLE_INSTALL_RULES)
include(cmake/ThrustInstallRules.cmake)
Expand All @@ -31,13 +43,6 @@ if (NOT THRUST_TOPLEVEL_PROJECT)
return()
endif()

include(cmake/AppendOptionIfAvailable.cmake)

include(cmake/ThrustBuildCompilerTargets.cmake)
include(cmake/ThrustBuildTargetList.cmake)
include(cmake/ThrustMultiConfig.cmake)
include(cmake/ThrustUtilities.cmake)

option(THRUST_ENABLE_HEADER_TESTING "Test that all public headers compile." "ON")
option(THRUST_ENABLE_TESTING "Build Thrust testing suite." "ON")
option(THRUST_ENABLE_EXAMPLES "Build Thrust examples." "ON")
Expand All @@ -53,6 +58,12 @@ if (NOT (THRUST_ENABLE_HEADER_TESTING OR
return()
endif()

include(cmake/AppendOptionIfAvailable.cmake)
include(cmake/ThrustBuildCompilerTargets.cmake)
include(cmake/ThrustBuildTargetList.cmake)
include(cmake/ThrustMultiConfig.cmake)
include(cmake/ThrustUtilities.cmake)

# Add cache string options for CMAKE_BUILD_TYPE and default to RelWithDebInfo.
if ("" STREQUAL "${CMAKE_BUILD_TYPE}")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build." FORCE)
Expand All @@ -71,92 +82,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(THRUST_LIBRARY_OUTPUT_DIR "${CMAKE_BINARY_DIR}/lib")
set(THRUST_EXECUTABLE_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin")

# Temporary hacks to make Feta work; this requires you to define
# `CMAKE_CUDA_COMPILER_ID=Feta` and `CMAKE_CUDA_COMPILER_FORCED`.
if ("Feta" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
# If using Feta, don't set CXX compiler
if (NOT "${CMAKE_CXX_COMPILER}" STREQUAL "")
unset(CMAKE_CXX_COMPILER CACHE)
message(FATAL_ERROR "You are using Feta as your CUDA C++ compiler, but have"
" specified a different ISO C++ compiler; Feta acts as both, so please"
" unset the CMAKE_CXX_COMPILER variable.")
endif ()

# We don't set CMAKE_CUDA_HOST_COMPILER for Feta; if we do, CMake tries to
# pass `-ccbin ${CMAKE_CUDA_HOST_COMPILER}` to Feta, which it doesn't
# understand.
if (NOT "${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "")
unset(CMAKE_CUDA_HOST_COMPILER CACHE)
message(FATAL_ERROR "You are using Feta as your CUDA C++ compiler, but have"
" specified a different host ISO C++ compiler; Feta acts as both, so"
" please unset the CMAKE_CUDA_HOST_COMPILER variable.")
endif ()

set(CMAKE_CXX_COMPILER "${CMAKE_CUDA_COMPILER}")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -stdpar")
set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${CMAKE_CUDA_COMPILER}")
set(CMAKE_CUDA_LINK_EXECUTABLE
"<CMAKE_CUDA_HOST_LINK_LAUNCHER> ${CMAKE_CUDA_FLAGS} <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
endif ()

# This must appear after any changes to CMAKE_CXX_COMPILER or else CMake will
# delete the cache and reconfigure from scratch.
enable_language(CXX)

# We don't set CMAKE_CUDA_HOST_COMPILER for Feta; if we do, CMake tries to
# pass `-ccbin ${CMAKE_CUDA_HOST_COMPILER}` to Feta, which it doesn't
# understand.
if (NOT "Feta" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
if (NOT ("${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "" OR
"${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "${CMAKE_CXX_COMPILER}"))
unset(CMAKE_CUDA_HOST_COMPILER CACHE)
message(FATAL_ERROR "Thrust tests and examples require the C++ compiler"
" and the CUDA host compiler to be the same; to set this compiler, please"
" use the CMAKE_CXX_COMPILER variable, not the CMAKE_CUDA_HOST_COMPILER"
" variable.")
endif ()
set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}")
endif ()

# Temporary hacks to make Feta work; this requires you to define
# `CMAKE_CUDA_COMPILER_ID=Feta` and `CMAKE_CUDA_COMPILER_FORCED`.
if ("Feta" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
# Need 3.17 for the properties used below.
cmake_minimum_required(VERSION 3.17)

set(CMAKE_CUDA_STANDARD_DEFAULT 03)

set(CMAKE_CUDA03_STANDARD_COMPILE_OPTION "-std=c++03")
set(CMAKE_CUDA03_EXTENSION_COMPILE_OPTION "-std=c++03")
set(CMAKE_CUDA03_STANDARD__HAS_FULL_SUPPORT TRUE)
set_property(GLOBAL PROPERTY CMAKE_CUDA03_KNOWN_FEATURES)

set(CMAKE_CUDA11_STANDARD_COMPILE_OPTION "-std=c++11")
set(CMAKE_CUDA11_EXTENSION_COMPILE_OPTION "-std=c++11")
set(CMAKE_CUDA11_STANDARD__HAS_FULL_SUPPORT TRUE)
set_property(GLOBAL PROPERTY CMAKE_CUDA11_KNOWN_FEATURES)

set(CMAKE_CUDA14_STANDARD_COMPILE_OPTION "-std=c++14")
set(CMAKE_CUDA14_EXTENSION_COMPILE_OPTION "-std=c++14")
set(CMAKE_CUDA14_STANDARD__HAS_FULL_SUPPORT TRUE)
set_property(GLOBAL PROPERTY CMAKE_CUDA14_KNOWN_FEATURES)

set(CMAKE_CUDA17_STANDARD_COMPILE_OPTION "-std=c++17")
set(CMAKE_CUDA17_EXTENSION_COMPILE_OPTION "-std=c++17")
set(CMAKE_CUDA17_STANDARD__HAS_FULL_SUPPORT TRUE)
set_property(GLOBAL PROPERTY CMAKE_CUDA17_KNOWN_FEATURES)

cmake_record_cuda_compile_features()

set(CMAKE_CUDA_COMPILE_FEATURES
${CMAKE_CUDA03_COMPILE_FEATURES}
${CMAKE_CUDA11_COMPILE_FEATURES}
${CMAKE_CUDA14_COMPILE_FEATURES}
${CMAKE_CUDA17_COMPILE_FEATURES}
${CMAKE_CUDA20_COMPILE_FEATURES}
)
endif ()

thrust_configure_multiconfig()
thrust_build_target_list()

Expand Down
91 changes: 91 additions & 0 deletions cmake/ThrustCompilerHacks.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Set up compiler paths and apply temporary hacks to support NVC++ (Feta).
# This file must be included before enabling any languages.

# Temporary hacks to make Feta work; this requires you to define
# `CMAKE_CUDA_COMPILER_ID=Feta` and `CMAKE_CUDA_COMPILER_FORCED`.
if ("Feta" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
# If using Feta, don't set CXX compiler
if (NOT "${CMAKE_CXX_COMPILER}" STREQUAL "")
unset(CMAKE_CXX_COMPILER CACHE)
message(FATAL_ERROR "You are using Feta as your CUDA C++ compiler, but have"
" specified a different ISO C++ compiler; Feta acts as both, so please"
" unset the CMAKE_CXX_COMPILER variable."
)
endif()

# We don't set CMAKE_CUDA_HOST_COMPILER for Feta; if we do, CMake tries to
# pass `-ccbin ${CMAKE_CUDA_HOST_COMPILER}` to Feta, which it doesn't
# understand.
if (NOT "${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "")
unset(CMAKE_CUDA_HOST_COMPILER CACHE)
message(FATAL_ERROR "You are using Feta as your CUDA C++ compiler, but have"
" specified a different host ISO C++ compiler; Feta acts as both, so"
" please unset the CMAKE_CUDA_HOST_COMPILER variable."
)
endif()

set(CMAKE_CXX_COMPILER "${CMAKE_CUDA_COMPILER}")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -stdpar")
set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${CMAKE_CUDA_COMPILER}")
set(CMAKE_CUDA_LINK_EXECUTABLE
"<CMAKE_CUDA_HOST_LINK_LAUNCHER> ${CMAKE_CUDA_FLAGS} <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
endif ()

# We don't set CMAKE_CUDA_HOST_COMPILER for Feta; if we do, CMake tries to
# pass `-ccbin ${CMAKE_CUDA_HOST_COMPILER}` to Feta, which it doesn't
# understand.
if ((NOT "Feta" STREQUAL "${CMAKE_CUDA_COMPILER_ID}"))
if (NOT ("${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "" OR
"${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "${CMAKE_CXX_COMPILER}"))
set(tmp "${CMAKE_CUDA_HOST_COMPILER}")
unset(CMAKE_CUDA_HOST_COMPILER CACHE)
message(FATAL_ERROR
"For convenience, Thrust's test harness uses CMAKE_CXX_COMPILER for the "
"CUDA host compiler. Refusing to overwrite specified "
"CMAKE_CUDA_HOST_COMPILER -- please reconfigure without setting this "
"variable. Currently:\n"
"CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}\n"
"CMAKE_CUDA_HOST_COMPILER=${tmp}"
)
endif ()
set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}")
endif ()

# Temporary hacks to make Feta work; this requires you to define
# `CMAKE_CUDA_COMPILER_ID=Feta` and `CMAKE_CUDA_COMPILER_FORCED`.
if ("Feta" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
# Need 3.17 for the properties used below.
cmake_minimum_required(VERSION 3.17)

set(CMAKE_CUDA_STANDARD_DEFAULT 03)

set(CMAKE_CUDA03_STANDARD_COMPILE_OPTION "-std=c++03")
set(CMAKE_CUDA03_EXTENSION_COMPILE_OPTION "-std=c++03")
set(CMAKE_CUDA03_STANDARD__HAS_FULL_SUPPORT TRUE)
set_property(GLOBAL PROPERTY CMAKE_CUDA03_KNOWN_FEATURES)

set(CMAKE_CUDA11_STANDARD_COMPILE_OPTION "-std=c++11")
set(CMAKE_CUDA11_EXTENSION_COMPILE_OPTION "-std=c++11")
set(CMAKE_CUDA11_STANDARD__HAS_FULL_SUPPORT TRUE)
set_property(GLOBAL PROPERTY CMAKE_CUDA11_KNOWN_FEATURES)

set(CMAKE_CUDA14_STANDARD_COMPILE_OPTION "-std=c++14")
set(CMAKE_CUDA14_EXTENSION_COMPILE_OPTION "-std=c++14")
set(CMAKE_CUDA14_STANDARD__HAS_FULL_SUPPORT TRUE)
set_property(GLOBAL PROPERTY CMAKE_CUDA14_KNOWN_FEATURES)

set(CMAKE_CUDA17_STANDARD_COMPILE_OPTION "-std=c++17")
set(CMAKE_CUDA17_EXTENSION_COMPILE_OPTION "-std=c++17")
set(CMAKE_CUDA17_STANDARD__HAS_FULL_SUPPORT TRUE)
set_property(GLOBAL PROPERTY CMAKE_CUDA17_KNOWN_FEATURES)

cmake_record_cuda_compile_features()

set(CMAKE_CUDA_COMPILE_FEATURES
${CMAKE_CUDA03_COMPILE_FEATURES}
${CMAKE_CUDA11_COMPILE_FEATURES}
${CMAKE_CUDA14_COMPILE_FEATURES}
${CMAKE_CUDA17_COMPILE_FEATURES}
${CMAKE_CUDA20_COMPILE_FEATURES}
)
endif ()
14 changes: 11 additions & 3 deletions cmake/ThrustInstallRules.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Bring in CMAKE_INSTALL_LIBDIR
include(GNUInstallDirs)

# Thrust is a header library; no need to build anything before installing:
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE)

Expand All @@ -6,8 +9,10 @@ install(DIRECTORY "${Thrust_SOURCE_DIR}/thrust"
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.inl"
PATTERN "*.cmake"
PATTERN "*.md"
)

install(DIRECTORY "${Thrust_SOURCE_DIR}/thrust/cmake/"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/thrust"
)

# Depending on how Thrust is configured, CUB's CMake scripts may or may not be
Expand All @@ -20,6 +25,9 @@ if (THRUST_INSTALL_CUB_HEADERS)
TYPE INCLUDE
FILES_MATCHING
PATTERN "*.cuh"
PATTERN "*.cmake"
)

install(DIRECTORY "${Thrust_SOURCE_DIR}/dependencies/cub/cub/cmake/"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cub"
)
endif()
1 change: 1 addition & 0 deletions testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ foreach(thrust_target IN LISTS THRUST_TARGETS)
endforeach()

# Add specialized tests:
add_subdirectory(cmake)
add_subdirectory(cpp)
add_subdirectory(cuda)
add_subdirectory(omp)
Expand Down
17 changes: 17 additions & 0 deletions testing/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
thrust_update_system_found_flags()

if (THRUST_CPP_FOUND AND THRUST_CUDA_FOUND)
# Test that we can use `find_package` on an installed Thrust:
add_test(
NAME thrust.test.cmake.test_install
COMMAND "${CMAKE_COMMAND}"
--log-level=VERBOSE
-G "${CMAKE_GENERATOR}"
-S "${CMAKE_CURRENT_SOURCE_DIR}/test_install"
-B "${CMAKE_CURRENT_BINARY_DIR}/test_install"
-D "THRUST_BINARY_DIR=${Thrust_BINARY_DIR}"
-D "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
-D "CMAKE_CUDA_COMPILER=${CMAKE_CUDA_COMPILER}"
-D "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
)
endif()
Loading