Skip to content

Commit 43413c0

Browse files
authored
Update to a more modern CMake using target properties (#558)
This makes a few changes moving to a more modern style. It adds our CMake module path to the CMake module path, it declares an empty target, adding source files to it instead of accumulating in variables. Also switched to add compiler definitions to the target, and avoid repetition for definitions used in C++ and CUDA.
1 parent d9c849b commit 43413c0

2 files changed

Lines changed: 27 additions & 35 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
cmake_minimum_required(VERSION 3.26.4 FATAL_ERROR)
1818

1919
cmake_path(SET CUPYNUMERIC_CMAKE_DIR NORMALIZE "${CMAKE_CURRENT_LIST_DIR}/cmake")
20+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
2021

2122
set(CMAKE_CXX_STANDARD 17 CACHE STRING "" FORCE)
2223
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE STRING "" FORCE)

cupynumeric_cpp.cmake

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ option(Legion_BOUNDS_CHECKS "Build cuPyNumeric with bounds checks (expensive)" O
7272
# make sense to build cuPyNumeric's CUDA bindings if legate wasn't built
7373
# with CUDA support).
7474
###
75-
include(cmake/thirdparty/get_legate.cmake)
75+
include(thirdparty/get_legate)
7676

7777
# Use of DEFINED is deliberate. CMAKE_CUDA_ARCHITECTURES may be OFF which we want to leave
7878
# in place. Legion_CUDA_ARCH is defined by Legate.
@@ -81,7 +81,7 @@ if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
8181
endif()
8282

8383
if(Legion_USE_CUDA)
84-
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/cuda_arch_helpers.cmake)
84+
include(Modules/cuda_arch_helpers)
8585
# Needs to run before `rapids_cuda_init_architectures`
8686
set_cuda_arch_from_names()
8787
# Needs to run before `enable_language(CUDA)`
@@ -105,28 +105,28 @@ if(Legion_USE_CUDA)
105105
INSTALL_EXPORT_SET cupynumeric-exports
106106
)
107107

108-
include(cmake/thirdparty/get_nccl.cmake)
109-
include(cmake/thirdparty/get_cutensor.cmake)
108+
include(thirdparty/get_nccl)
109+
include(thirdparty/get_cutensor)
110110
endif()
111111

112-
include(cmake/thirdparty/get_openblas.cmake)
112+
include(thirdparty/get_openblas)
113113

114-
include(cmake/thirdparty/get_tblis.cmake)
114+
include(thirdparty/get_tblis)
115115

116116
##############################################################################
117117
# - cuPyNumeric ----------------------------------------------------------------
118118

119-
set(cupynumeric_SOURCES "")
120-
set(cupynumeric_CXX_DEFS "")
121-
set(cupynumeric_CUDA_DEFS "")
119+
add_library(cupynumeric)
120+
add_library(cupynumeric::cupynumeric ALIAS cupynumeric)
121+
122122
set(cupynumeric_CXX_OPTIONS "")
123123
set(cupynumeric_CUDA_OPTIONS "")
124124

125-
include(cmake/Modules/set_cpu_arch_flags.cmake)
125+
include(Modules/set_cpu_arch_flags)
126126
set_cpu_arch_flags(cupynumeric_CXX_OPTIONS)
127127

128128
# Add `src/cupynumeric.mk` sources
129-
list(APPEND cupynumeric_SOURCES
129+
target_sources(cupynumeric PRIVATE
130130
src/cupynumeric/ternary/where.cc
131131
src/cupynumeric/scan/scan_global.cc
132132
src/cupynumeric/scan/scan_local.cc
@@ -193,7 +193,7 @@ list(APPEND cupynumeric_SOURCES
193193
)
194194

195195
if(Legion_USE_OpenMP)
196-
list(APPEND cupynumeric_SOURCES
196+
target_sources(cupynumeric PRIVATE
197197
src/cupynumeric/ternary/where_omp.cc
198198
src/cupynumeric/scan/scan_global_omp.cc
199199
src/cupynumeric/scan/scan_local_omp.cc
@@ -245,7 +245,7 @@ if(Legion_USE_OpenMP)
245245
endif()
246246

247247
if(Legion_USE_CUDA)
248-
list(APPEND cupynumeric_SOURCES
248+
target_sources(cupynumeric PRIVATE
249249
src/cupynumeric/ternary/where.cu
250250
src/cupynumeric/scan/scan_global.cu
251251
src/cupynumeric/scan/scan_local.cu
@@ -302,20 +302,20 @@ if(Legion_USE_CUDA)
302302
endif()
303303

304304
# Add `src/cupynumeric/sort/sort.mk` sources
305-
list(APPEND cupynumeric_SOURCES
305+
target_sources(cupynumeric PRIVATE
306306
src/cupynumeric/sort/sort.cc
307307
src/cupynumeric/sort/searchsorted.cc
308308
)
309309

310310
if(Legion_USE_OpenMP)
311-
list(APPEND cupynumeric_SOURCES
311+
target_sources(cupynumeric PRIVATE
312312
src/cupynumeric/sort/sort_omp.cc
313313
src/cupynumeric/sort/searchsorted_omp.cc
314314
)
315315
endif()
316316

317317
if(Legion_USE_CUDA)
318-
list(APPEND cupynumeric_SOURCES
318+
target_sources(cupynumeric PRIVATE
319319
src/cupynumeric/sort/sort.cu
320320
src/cupynumeric/sort/searchsorted.cu
321321
src/cupynumeric/sort/cub_sort_bool.cu
@@ -349,37 +349,35 @@ endif()
349349

350350
# Add `src/cupynumeric/random/random.mk` sources
351351
if(Legion_USE_CUDA)
352-
list(APPEND cupynumeric_SOURCES
352+
target_sources(cupynumeric PRIVATE
353353
src/cupynumeric/random/bitgenerator.cu
354354
src/cupynumeric/random/randutil/generator_device.cu
355355
src/cupynumeric/random/randutil/generator_device_straightforward.cu
356356
src/cupynumeric/random/randutil/generator_device_advanced.cu
357-
)
357+
)
358358
endif()
359359

360360
# add sources for cusolverMp
361361
if(Legion_USE_CUDA AND CUSOLVERMP_DIR)
362-
list(APPEND cupynumeric_SOURCES
362+
target_sources(cupynumeric PRIVATE
363363
src/cupynumeric/matrix/mp_potrf.cu
364364
src/cupynumeric/matrix/mp_solve.cu
365365
)
366366
endif()
367367

368-
list(APPEND cupynumeric_SOURCES
368+
target_sources(cupynumeric PRIVATE
369369
# This must always be the last file!
370370
# It guarantees we do our registration callback
371371
# only after all task variants are recorded
372372
src/cupynumeric/cupynumeric.cc
373373
)
374374

375375
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
376-
list(APPEND cupynumeric_CXX_DEFS DEBUG_CUPYNUMERIC)
377-
list(APPEND cupynumeric_CUDA_DEFS DEBUG_CUPYNUMERIC)
376+
target_compile_definitions(cupynumeric PUBLIC "$<$<COMPILE_LANGUAGE:CXX,CUDA>:DEBUG_CUPYNUMERIC>")
378377
endif()
379378

380379
if(Legion_BOUNDS_CHECKS)
381-
list(APPEND cupynumeric_CXX_DEFS BOUNDS_CHECKS)
382-
list(APPEND cupynumeric_CUDA_DEFS BOUNDS_CHECKS)
380+
target_compile_definitions(cupynumeric PUBLIC "$<$<COMPILE_LANGUAGE:CXX,CUDA>:BOUNDS_CHECKS>")
383381
endif()
384382

385383
list(APPEND cupynumeric_CUDA_OPTIONS -Xfatbin=-compress-all)
@@ -388,9 +386,6 @@ list(APPEND cupynumeric_CUDA_OPTIONS --expt-relaxed-constexpr)
388386
list(APPEND cupynumeric_CXX_OPTIONS -Wno-deprecated-declarations)
389387
list(APPEND cupynumeric_CUDA_OPTIONS -Wno-deprecated-declarations)
390388

391-
add_library(cupynumeric ${cupynumeric_SOURCES})
392-
add_library(cupynumeric::cupynumeric ALIAS cupynumeric)
393-
394389
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
395390
set(platform_rpath_origin "\$ORIGIN")
396391
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
@@ -409,7 +404,7 @@ set_target_properties(cupynumeric
409404
LIBRARY_OUTPUT_DIRECTORY lib)
410405

411406
target_link_libraries(cupynumeric
412-
PUBLIC legate::legate
407+
PUBLIC legate::legate
413408
$<TARGET_NAME_IF_EXISTS:NCCL::NCCL>
414409
PRIVATE BLAS::BLAS
415410
tblis::tblis
@@ -422,14 +417,14 @@ target_link_libraries(cupynumeric
422417
$<TARGET_NAME_IF_EXISTS:cutensor::cutensor>)
423418

424419
if(NOT Legion_USE_CUDA AND cupynumeric_cuRAND_INCLUDE_DIR)
425-
list(APPEND cupynumeric_CXX_DEFS CUPYNUMERIC_CURAND_FOR_CPU_BUILD)
420+
target_compile_definitions(cupynumeric
421+
PUBLIC "$<$<COMPILE_LANGUAGE:CXX>:CUPYNUMERIC_CURAND_FOR_CPU_BUILD>")
426422
target_include_directories(cupynumeric PRIVATE ${cupynumeric_cuRAND_INCLUDE_DIR})
427423
endif()
428424

429425
if(Legion_USE_CUDA AND CUSOLVERMP_DIR)
430426
message(VERBOSE "cupynumeric: CUSOLVERMP_DIR ${CUSOLVERMP_DIR}")
431-
list(APPEND cupynumeric_CXX_DEFS CUPYNUMERIC_USE_CUSOLVERMP)
432-
list(APPEND cupynumeric_CUDA_DEFS CUPYNUMERIC_USE_CUSOLVERMP)
427+
target_compile_definitions(cupynumeric PUBLIC "$<$<COMPILE_LANGUAGE:CXX,CUDA>:CUPYNUMERIC_USE_CUSOLVERMP>")
433428
target_include_directories(cupynumeric PRIVATE ${CUSOLVERMP_DIR}/include)
434429
target_link_libraries(cupynumeric PRIVATE ${CUSOLVERMP_DIR}/lib/libcusolverMp.so)
435430
endif()
@@ -438,10 +433,6 @@ target_compile_options(cupynumeric
438433
PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${cupynumeric_CXX_OPTIONS}>"
439434
"$<$<COMPILE_LANGUAGE:CUDA>:${cupynumeric_CUDA_OPTIONS}>")
440435

441-
target_compile_definitions(cupynumeric
442-
PUBLIC "$<$<COMPILE_LANGUAGE:CXX>:${cupynumeric_CXX_DEFS}>"
443-
"$<$<COMPILE_LANGUAGE:CUDA>:${cupynumeric_CUDA_DEFS}>")
444-
445436
target_include_directories(cupynumeric
446437
PUBLIC
447438
$<BUILD_INTERFACE:${cupynumeric_SOURCE_DIR}/src>

0 commit comments

Comments
 (0)