Skip to content

Commit a82eda0

Browse files
committed
CMake updates, add CUB (tests, etc) as optional build feature.
- Add option THRUST_INCLUDE_CUB_CMAKE that enables CUB build targets and test entries from Thrust builds. Default is off. - Remove out of date compiler checks, since a more up-to-date check is implemented at build time. - Rename ThrustCUDAConfig.cmake -> ThrustCudaConfig.cmake for consistency. - Remove CheckCXX*.cmake files since these are included in cmake 3.15. - Sanitize variable names in AppendOptionIfAvailable. - GCC wasn't detecting -Werror, this fixes it. - Add `thrust.all` metatarget that just builds thrust when CUB is enabled. - Add utility CMake script that sorts and prints per-target build times from `.ninja_log`. - Add all project files to custom target for IDE detection.
1 parent d11aee4 commit a82eda0

File tree

13 files changed

+160
-241
lines changed

13 files changed

+160
-241
lines changed

CMakeLists.txt

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ endif ()
2222
# Disable compiler extensions:
2323
set(CMAKE_CXX_EXTENSIONS OFF)
2424

25-
# Where to put the things we build:
26-
set(THRUST_LIBRARY_OUTPUT_DIR "${Thrust_BINARY_DIR}/lib")
27-
set(THRUST_EXECUTABLE_OUTPUT_DIR "${Thrust_BINARY_DIR}/bin")
25+
# Where to put build outputs. Use CMAKE_BINARY_DIR so they'll show up in the
26+
# top-level project's dir when building Thrust via add_subdirectory.
27+
set(THRUST_LIBRARY_OUTPUT_DIR "${CMAKE_BINARY_DIR}/lib")
28+
set(THRUST_EXECUTABLE_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin")
2829

2930
# Temporary hacks to make Feta work; this requires you to define
3031
# `CMAKE_CUDA_COMPILER_ID=Feta` and `CMAKE_CUDA_COMPILER_FORCED`.
@@ -62,7 +63,8 @@ enable_language(CXX)
6263
# pass `-ccbin ${CMAKE_CUDA_HOST_COMPILER}` to Feta, which it doesn't
6364
# understand.
6465
if (NOT "Feta" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
65-
if (NOT "${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "")
66+
if (NOT ("${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "" OR
67+
"${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "${CMAKE_CXX_COMPILER}"))
6668
unset(CMAKE_CUDA_HOST_COMPILER CACHE)
6769
message(FATAL_ERROR "Thrust tests and examples require the C++ compiler"
6870
" and the CUDA host compiler to be the same; to set this compiler, please"
@@ -82,24 +84,13 @@ message(STATUS "TBB system found? ${THRUST_TBB_FOUND}")
8284
message(STATUS "OMP system found? ${THRUST_OMP_FOUND}")
8385

8486
if (THRUST_CUDA_FOUND)
85-
include(cmake/ThrustCUDAConfig.cmake)
87+
include(cmake/ThrustCudaConfig.cmake)
8688
endif()
8789

88-
if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
89-
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.00)
90-
message(FATAL_ERROR "This version of MSVC no longer supported.")
91-
endif ()
92-
endif ()
93-
94-
if ("GNU" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
95-
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
96-
message(FATAL_ERROR "This version of GCC no longer supported.")
97-
endif ()
98-
endif ()
99-
10090
option(THRUST_ENABLE_HEADER_TESTING "Test that all public headers compile." "ON")
10191
option(THRUST_ENABLE_TESTING "Build Thrust testing suite." "ON")
10292
option(THRUST_ENABLE_EXAMPLES "Build Thrust examples." "ON")
93+
option(THRUST_INCLUDE_CUB_CMAKE "Build CUB tests and examples. (Requires CUDA)." "OFF")
10394

10495
if (THRUST_ENABLE_HEADER_TESTING)
10596
include(cmake/ThrustHeaderTesting.cmake)
@@ -118,3 +109,8 @@ endif()
118109
if (THRUST_ENABLE_EXAMPLES)
119110
add_subdirectory(examples)
120111
endif()
112+
113+
if (THRUST_INCLUDE_CUB_CMAKE AND THRUST_CUDA_FOUND)
114+
set(CUB_IN_THRUST ON)
115+
add_subdirectory(dependencies/cub)
116+
endif()

cmake/AppendOptionIfAvailable.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include(CheckCXXCompilerFlag)
33

44
macro (APPEND_OPTION_IF_AVAILABLE _FLAG _LIST)
55

6-
set(_VAR "CXX_FLAG_${_FLAG}")
6+
string(MAKE_C_IDENTIFIER "CXX_FLAG_${_FLAG}" _VAR)
77
check_cxx_compiler_flag(${_FLAG} ${_VAR})
88

99
if (${${_VAR}})

cmake/CheckCXXCompilerFlag.cmake

Lines changed: 0 additions & 64 deletions
This file was deleted.

cmake/CheckCXXSourceCompiles.cmake

Lines changed: 0 additions & 135 deletions
This file was deleted.

cmake/PrintNinjaBuildTimes.cmake

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
## This CMake script parses a .ninja_log file (LOGFILE) and prints a list of
2+
## build/link times, sorted longest first.
3+
##
4+
## cmake -DLOGFILE=<.ninja_log file> \
5+
## -P PrintNinjaBuildTimes.cmake
6+
##
7+
## If LOGFILE is omitted, the current directory's .ninja_log file is used.
8+
################################################################################
9+
10+
cmake_minimum_required(VERSION 3.15)
11+
12+
# Prepend the string with "0" until the string length equals the specified width
13+
function(pad_string_with_zeros string_var width)
14+
set(local_string "${${string_var}}")
15+
string(LENGTH "${local_string}" size)
16+
while(size LESS width)
17+
string(PREPEND local_string "0")
18+
string(LENGTH "${local_string}" size)
19+
endwhile()
20+
set(${string_var} "${local_string}" PARENT_SCOPE)
21+
endfunction()
22+
23+
################################################################################
24+
25+
if (NOT LOGFILE)
26+
set(LOGFILE ".ninja_log")
27+
endif()
28+
29+
# Check if logfile exists
30+
if (NOT EXISTS "${LOGFILE}")
31+
message(FATAL_ERROR "LOGFILE does not exist ('${LOGFILE}').")
32+
endif()
33+
34+
# Read the logfile and generate a map / keylist
35+
set(keys)
36+
file(STRINGS "${LOGFILE}" lines)
37+
foreach(line ${lines})
38+
39+
# Parse each build time
40+
string(REGEX MATCH
41+
"^([0-9]+)\t([0-9]+)\t[0-9]+\t([^\t]+)+\t[0-9a-fA-F]+$" _DUMMY "${line}")
42+
43+
if (CMAKE_MATCH_COUNT EQUAL 3)
44+
set(start_ms ${CMAKE_MATCH_1})
45+
set(end_ms ${CMAKE_MATCH_2})
46+
set(command "${CMAKE_MATCH_3}")
47+
math(EXPR runtime_ms "${end_ms} - ${start_ms}")
48+
49+
# Compute human readable time
50+
math(EXPR days "${runtime_ms} / (1000 * 60 * 60 * 24)")
51+
math(EXPR runtime_ms "${runtime_ms} - (${days} * 1000 * 60 * 60 * 24)")
52+
math(EXPR hours "${runtime_ms} / (1000 * 60 * 60)")
53+
math(EXPR runtime_ms "${runtime_ms} - (${hours} * 1000 * 60 * 60)")
54+
math(EXPR minutes "${runtime_ms} / (1000 * 60)")
55+
math(EXPR runtime_ms "${runtime_ms} - (${minutes} * 1000 * 60)")
56+
math(EXPR seconds "${runtime_ms} / 1000")
57+
math(EXPR milliseconds "${runtime_ms} - (${seconds} * 1000)")
58+
59+
# Format time components
60+
pad_string_with_zeros(days 3)
61+
pad_string_with_zeros(hours 2)
62+
pad_string_with_zeros(minutes 2)
63+
pad_string_with_zeros(seconds 2)
64+
pad_string_with_zeros(milliseconds 3)
65+
66+
# Construct table entry
67+
# Later values in the file for the same command overwrite earlier entries
68+
string(MAKE_C_IDENTIFIER "${command}" key)
69+
set(ENTRY_${key}
70+
"${days}d ${hours}h ${minutes}m ${seconds}s ${milliseconds}ms | ${command}"
71+
)
72+
73+
# Record the key:
74+
list(APPEND keys "${key}")
75+
endif()
76+
endforeach()
77+
78+
list(REMOVE_DUPLICATES keys)
79+
80+
# Build the entry list:
81+
set(entries)
82+
foreach(key ${keys})
83+
list(APPEND entries "${ENTRY_${key}}")
84+
endforeach()
85+
86+
if (NOT entries)
87+
message(FATAL_ERROR "LOGFILE contained no build entries ('${LOGFILE}').")
88+
endif()
89+
90+
# Sort in descending order:
91+
list(SORT entries)
92+
list(REVERSE entries)
93+
94+
# Dump table:
95+
message(STATUS "-----------------------+----------------------------")
96+
message(STATUS "Time | Command ")
97+
message(STATUS "-----------------------+----------------------------")
98+
99+
foreach(entry ${entries})
100+
message(STATUS ${entry})
101+
endforeach()

0 commit comments

Comments
 (0)