From e288eaf2ec5a76abfff5553fe0fe3f7b9c7d49f8 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Sat, 26 Sep 2020 13:41:42 -0400 Subject: [PATCH] cmake/install: add THRUST_ENABLE_INSTALL_RULES option cmake/install: mv ThrustAddSubdir handling to after project() We want to add the option to install in this case, which requires the paths set by project() thrust: separate out determination of whether Thrust is top-level project This determines whether an install target will be provided. If Thrust is built as top-level project, the install target will be provided by default, as before. If Thrust is built as a sub-project, the install target will, by default, not be provided, again maintaining existing behavior. So what's new here is that via this option a downstream project can enable install of thrust if it is used via `add_subdirectory`. Update CONTRIBUTING.md with new CMake option docs. --- CMakeLists.txt | 28 ++++++++++++++++++++-------- CONTRIBUTING.md | 6 ++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11e6711dd..bceaf3c7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,3 @@ -# Support adding Thrust to a parent project via add_subdirectory. -# See examples/cmake/add_subdir/CMakeLists.txt for details. -if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") - include(cmake/ThrustAddSubdir.cmake) - return() -endif() - # 3.15 is the minimum. # 3.17 for nvc++/Feta # 3.18 for C++17 + CUDA @@ -18,12 +11,31 @@ endif() project(Thrust NONE) +# Determine whether Thrust is the top-level project or included into +# another project via add_subdirectory() +if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") + set(THRUST_TOPLEVEL_PROJECT ON) +else() + set(THRUST_TOPLEVEL_PROJECT OFF) +endif() + +option(THRUST_ENABLE_INSTALL_RULES "Enable installation of Thrust" ${THRUST_TOPLEVEL_PROJECT}) +if (THRUST_ENABLE_INSTALL_RULES) + include(cmake/ThrustInstallRules.cmake) +endif() + +# Support adding Thrust to a parent project via add_subdirectory. +# See examples/cmake/add_subdir/CMakeLists.txt for details. +if (NOT THRUST_TOPLEVEL_PROJECT) + include(cmake/ThrustAddSubdir.cmake) + return() +endif() + include(cmake/AppendOptionIfAvailable.cmake) include(cmake/ThrustBuildCompilerTargets.cmake) include(cmake/ThrustBuildTargetList.cmake) include(cmake/ThrustMultiConfig.cmake) -include(cmake/ThrustInstallRules.cmake) include(cmake/ThrustUtilities.cmake) option(THRUST_ENABLE_HEADER_TESTING "Test that all public headers compile." "ON") diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a1c178470..488976614 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -336,6 +336,8 @@ The CMake options are divided into these categories: - `THRUST_ENABLE_EXAMPLE_FILECHECK={ON, OFF}` - Enable validation of example outputs using the LLVM FileCheck utility. Default is `OFF`. +- `THRUST_ENABLE_INSTALL_RULES={ON, OFF}` + - If true, installation rules will be generated for thrust. Default is `ON`. ## Single Config CMake Options @@ -391,6 +393,10 @@ The CMake options are divided into these categories: simultaneously. - CUB configurations will be generated for each C++ dialect targeted by the current Thrust build. +- `THRUST_INSTALL_CUB_HEADERS={ON, OFF}` + - If enabled, the CUB project's headers will be installed through Thrust's + installation rules. Default is `ON`. + - This option depends on `THRUST_ENABLE_INSTALL_RULES`. - `THRUST_ENABLE_COMPUTE_XX={ON, OFF}` - Controls the targeted CUDA architecture(s) - Multiple options may be selected when using NVCC as the CUDA compiler.