Skip to content

Commit e7f0726

Browse files
authored
CMake target cleanup, formatting, linting (rapidsai#604)
Sets up framework for automating formatting + linting of CMake files via pre-commit, and fixes all known formatting + linting issues. Additionally, moves compiler / linker / etc. options to the RMM target instead of using CMake global options. Depends on: rapidsai/integration#156
1 parent 14e1446 commit e7f0726

18 files changed

+535
-374
lines changed

.pre-commit-config.yaml

+35-25
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
repos:
2-
- repo: https://github.com/timothycrosley/isort
3-
rev: 5.0.4
4-
hooks:
5-
- id: isort
6-
- repo: https://github.com/ambv/black
7-
rev: stable
8-
hooks:
9-
- id: black
10-
- repo: https://gitlab.com/pycqa/flake8
11-
rev: 3.8.1
12-
hooks:
13-
- id: flake8
14-
alias: flake8
15-
name: flake8
16-
args: ["--config=python/.flake8"]
17-
types: [python]
18-
- repo: https://gitlab.com/pycqa/flake8
19-
rev: 3.8.1
20-
hooks:
21-
- id: flake8
22-
alias: flake8-cython
23-
name: flake8-cython
24-
args: ["--config=python/.flake8.cython"]
25-
types: [cython]
2+
- repo: https://github.com/timothycrosley/isort
3+
rev: 5.0.7
4+
hooks:
5+
- id: isort
6+
- repo: https://github.com/ambv/black
7+
rev: 19.10b0
8+
hooks:
9+
- id: black
10+
- repo: https://gitlab.com/pycqa/flake8
11+
rev: 3.8.3
12+
hooks:
13+
- id: flake8
14+
alias: flake8
15+
name: flake8
16+
args: ["--config=python/.flake8"]
17+
types: [python]
18+
- id: flake8
19+
alias: flake8-cython
20+
name: flake8-cython
21+
args: ["--config=python/.flake8.cython"]
22+
types: [cython]
23+
- repo: https://github.com/cheshirekow/cmake-format-precommit
24+
rev: v0.6.11
25+
hooks:
26+
- id: cmake-format
27+
name: cmake-format
28+
args: ["--config-files", "cmake/config.json", "--in-place", "--"]
29+
types: [file] # override `types: [cmake]`
30+
files: \.(cmake(\.in)?)$|CMakeLists\.txt
31+
- id: cmake-lint
32+
args: ["--config-files", "cmake/config.json", "--"]
33+
types: [file] # override `types: [cmake]`
34+
files: \.(cmake(\.in)?)$|CMakeLists\.txt
35+
2636
default_language_version:
27-
python: python3
37+
python: python3

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
## Improvements
99

10+
- PR #604 CMake target cleanup, formatting, linting
1011
- PR #599 Make the arena memory resource work better with the producer/consumer mode
1112
- PR #612 Drop old Python `device_array*` API
1213
- PR #603 Always test both legacy and per-thread default stream

CMakeLists.txt

+66-102
Original file line numberDiff line numberDiff line change
@@ -1,166 +1,130 @@
1-
#=============================================================================
1+
# =============================================================================
22
# Copyright (c) 2018, NVIDIA CORPORATION.
33
#
4-
# Licensed under the Apache License, Version 2.0 (the "License");
5-
# you may not use this file except in compliance with the License.
6-
# You may obtain a copy of the License at
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
# in compliance with the License. You may obtain a copy of the License at
76
#
8-
# http://www.apache.org/licenses/LICENSE-2.0
7+
# http://www.apache.org/licenses/LICENSE-2.0
98
#
10-
# Unless required by applicable law or agreed to in writing, software
11-
# distributed under the License is distributed on an "AS IS" BASIS,
12-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
# See the License for the specific language governing permissions and
14-
# limitations under the License.
15-
#=============================================================================
16-
cmake_minimum_required(VERSION 3.17...3.18 FATAL_ERROR)
9+
# Unless required by applicable law or agreed to in writing, software distributed under the License
10+
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
# or implied. See the License for the specific language governing permissions and limitations under
12+
# the License.
13+
# =============================================================================
14+
cmake_minimum_required(VERSION 3.18...3.18 FATAL_ERROR)
1715

18-
project(RMM VERSION 0.17.0 LANGUAGES C CXX CUDA)
16+
project(
17+
RMM
18+
VERSION 0.17.0
19+
LANGUAGES CXX)
1920

20-
include(cmake/CPM.cmake)
21+
include(cmake/Modules/CPM.cmake)
22+
include(cmake/Modules/RMM_thirdparty.cmake)
2123

22-
###################################################################################################
23-
# - build type
24+
# build type
2425

2526
# Set a default build type if none was specified
2627
set(DEFAULT_BUILD_TYPE "Release")
2728

2829
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
29-
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' since none specified.")
30-
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE
31-
STRING "Choose the type of build." FORCE)
30+
message(STATUS "RMM: Setting build type to '${DEFAULT_BUILD_TYPE}' since none specified.")
31+
set(CMAKE_BUILD_TYPE
32+
"${DEFAULT_BUILD_TYPE}"
33+
CACHE STRING "Choose the type of build." FORCE)
3234
# Set the possible values of build type for cmake-gui
33-
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
34-
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
35+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel"
36+
"RelWithDebInfo")
3537
endif()
3638

37-
###################################################################################################
38-
# - compiler options
39-
40-
set(CMAKE_CXX_STANDARD 14)
41-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
42-
43-
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
44-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-error=deprecated-declarations")
45-
endif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
46-
47-
###################################################################################################
48-
# - build options
39+
# build options
4940

5041
option(BUILD_TESTS "Configure CMake to build tests" ON)
5142
option(BUILD_BENCHMARKS "Configure CMake to build (google) benchmarks" OFF)
5243

53-
option(DISABLE_DEPRECATION_WARNING "Disable warnings generated from deprecated declarations." OFF)
54-
if(DISABLE_DEPRECATION_WARNING)
55-
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler -Wno-deprecated-declarations")
56-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
57-
endif(DISABLE_DEPRECATION_WARNING)
58-
5944
# cudart can be statically linked or dynamically linked the python ecosystem wants dynamic linking
6045
option(CUDA_STATIC_RUNTIME "Statically link the CUDA runtime" OFF)
6146

62-
###################################################################################################
6347
# find packages we depend on
6448

6549
find_package(CUDAToolkit REQUIRED)
6650

67-
###################################################################################################
68-
# cmake modules
69-
70-
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
71-
72-
###################################################################################################
73-
# third-party dependencies
74-
75-
include(RMM_thirdparty)
76-
77-
###################################################################################################
7851
# library targets
7952

8053
add_library(rmm INTERFACE)
8154
add_library(rmm::rmm ALIAS rmm)
8255

83-
target_include_directories(rmm INTERFACE
84-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
85-
"$<INSTALL_INTERFACE:include>"
86-
)
56+
target_include_directories(rmm INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
57+
"$<INSTALL_INTERFACE:include>")
8758

8859
if(CUDA_STATIC_RUNTIME)
89-
message(STATUS "Enabling static linking of cudart")
60+
message(STATUS "RMM: Enabling static linking of cudart")
9061
target_link_libraries(rmm INTERFACE CUDA::cudart_static)
9162
else()
9263
target_link_libraries(rmm INTERFACE CUDA::cudart)
9364
endif(CUDA_STATIC_RUNTIME)
9465

95-
target_link_libraries(rmm INTERFACE rmm::Thrust spdlog::spdlog_header_only ${CMAKE_DL_LIBS})
66+
target_link_libraries(rmm INTERFACE rmm::Thrust)
67+
target_link_libraries(rmm INTERFACE spdlog::spdlog_header_only)
68+
target_compile_features(rmm INTERFACE cxx_std_14 cuda_std_14)
9669

97-
###################################################################################################
98-
# Set logging level. Must go before including gtests and benchmarks.
70+
# Set logging level. Must go before including gtests and benchmarks.
9971

100-
set(RMM_LOGGING_LEVEL "INFO" CACHE STRING "Choose the logging level.")
72+
set(RMM_LOGGING_LEVEL
73+
"INFO"
74+
CACHE STRING "Choose the logging level.")
10175
# Set the possible values of build type for cmake-gui
102-
set_property(CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS
103-
"TRACE" "DEBUG" "INFO" "WARN" "ERROR" "CRITICAL" "OFF")
104-
message(STATUS "RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'.")
76+
set_property(CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS "TRACE" "DEBUG" "INFO" "WARN" "ERROR"
77+
"CRITICAL" "OFF")
78+
message(STATUS "RMM: RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'")
10579

106-
###################################################################################################
107-
# add gtest
80+
# optionally build tests
10881

10982
if(BUILD_TESTS)
110-
include(CTest)
111-
add_subdirectory(tests)
83+
enable_testing()
84+
add_subdirectory(tests)
11285
endif(BUILD_TESTS)
11386

114-
###################################################################################################
11587
# add google benchmark
11688

11789
if(BUILD_BENCHMARKS)
11890
add_subdirectory(benchmarks)
11991
endif(BUILD_BENCHMARKS)
12092

121-
###################################################################################################
12293
# install targets
12394

12495
include(GNUInstallDirs)
12596
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/rmm)
12697

127-
install(TARGETS rmm
128-
EXPORT rmm-targets)
98+
install(TARGETS rmm EXPORT rmm-targets)
12999

130-
install(DIRECTORY include/rmm
131-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
100+
install(DIRECTORY include/rmm DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
132101

133102
include(CMakePackageConfigHelpers)
134-
configure_package_config_file(
135-
cmake/rmm-config.cmake.in
136-
${RMM_BINARY_DIR}/rmm-config.cmake
137-
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
138-
)
139-
140-
write_basic_package_version_file(
141-
${RMM_BINARY_DIR}/rmm-config-version.cmake
142-
COMPATIBILITY SameMinorVersion
143-
)
144-
145-
install(EXPORT rmm-targets
103+
configure_package_config_file(cmake/rmm-config.cmake.in ${RMM_BINARY_DIR}/rmm-config.cmake
104+
INSTALL_DESTINATION ${INSTALL_CONFIGDIR})
105+
106+
write_basic_package_version_file(${RMM_BINARY_DIR}/rmm-config-version.cmake
107+
COMPATIBILITY SameMinorVersion)
108+
109+
install(
110+
EXPORT rmm-targets
146111
FILE rmm-targets.cmake
147112
NAMESPACE rmm::
148-
DESTINATION ${INSTALL_CONFIGDIR}
149-
)
150-
151-
install(FILES
152-
${RMM_BINARY_DIR}/rmm-config.cmake
153-
${RMM_BINARY_DIR}/rmm-config-version.cmake
154-
${RMM_SOURCE_DIR}/cmake/install/FindThrust.cmake
155-
DESTINATION ${INSTALL_CONFIGDIR}
156-
)
157-
158-
###################################################################################################
159-
# make documentation
113+
DESTINATION ${INSTALL_CONFIGDIR})
114+
115+
install(FILES ${RMM_BINARY_DIR}/rmm-config.cmake ${RMM_BINARY_DIR}/rmm-config-version.cmake
116+
${RMM_SOURCE_DIR}/cmake/install/FindThrust.cmake DESTINATION ${INSTALL_CONFIGDIR})
160117

161-
add_custom_command(OUTPUT RMM_DOXYGEN
162-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen
163-
COMMAND doxygen Doxyfile
164-
VERBATIM)
118+
# make documentation
165119

166-
add_custom_target(rmm_doc DEPENDS RMM_DOXYGEN)
120+
add_custom_command(
121+
OUTPUT RMM_DOXYGEN
122+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen
123+
COMMAND doxygen Doxyfile
124+
VERBATIM
125+
COMMENT "Custom command for RMM doxygen docs")
126+
127+
add_custom_target(
128+
rmm_doc
129+
DEPENDS RMM_DOXYGEN
130+
COMMENT "Target for the custom command to build the RMM doxygen docs")

0 commit comments

Comments
 (0)