Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.

Commit 0fed859

Browse files
authored
[CMake] ARG prefix for cmake_parse_arguments (#278)
Instead of using `SDK_BUILD_IR`, `SDK_ADD_SYCL`, or `SDK_ADD_SAMPLE` just use `ARG` since local variables are created anyway. This should reduce the verbosity a bit.
1 parent 0eb0d88 commit 0fed859

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

cmake/Modules/FindComputeCpp.cmake

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -318,33 +318,33 @@ function(__build_ir)
318318
COUNTER
319319
)
320320
set(multi_value_args)
321-
cmake_parse_arguments(SDK_BUILD_IR
321+
cmake_parse_arguments(ARG
322322
"${options}"
323323
"${one_value_args}"
324324
"${multi_value_args}"
325325
${ARGN}
326326
)
327-
get_filename_component(sourceFileName ${SDK_BUILD_IR_SOURCE} NAME)
327+
get_filename_component(sourceFileName ${ARG_SOURCE} NAME)
328328

329329
# Set the path to the integration header.
330330
# The .sycl filename must depend on the target so that different targets
331331
# using the same source file will be generated with a different rule.
332-
set(baseSyclName ${CMAKE_CURRENT_BINARY_DIR}/${SDK_BUILD_IR_TARGET}_${sourceFileName})
332+
set(baseSyclName ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}_${sourceFileName})
333333
set(outputSyclFile ${baseSyclName}.sycl)
334334
get_sycl_target_extension(targetExtension)
335335
set(outputDeviceFile ${baseSyclName}.${targetExtension})
336336
set(depFileName ${baseSyclName}.sycl.d)
337337

338-
set(include_directories "$<TARGET_PROPERTY:${SDK_BUILD_IR_TARGET},INCLUDE_DIRECTORIES>")
339-
set(compile_definitions "$<TARGET_PROPERTY:${SDK_BUILD_IR_TARGET},COMPILE_DEFINITIONS>")
338+
set(include_directories "$<TARGET_PROPERTY:${ARG_TARGET},INCLUDE_DIRECTORIES>")
339+
set(compile_definitions "$<TARGET_PROPERTY:${ARG_TARGET},COMPILE_DEFINITIONS>")
340340
set(generated_include_directories
341341
$<$<BOOL:${include_directories}>:-I\"$<JOIN:${include_directories},\"\t-I\">\">)
342342
set(generated_compile_definitions
343343
$<$<BOOL:${compile_definitions}>:-D$<JOIN:${compile_definitions},\t-D>>)
344344

345345
# Obtain language standard of the file
346346
set(device_compiler_cxx_standard)
347-
get_target_property(targetCxxStandard ${SDK_BUILD_IR_TARGET} CXX_STANDARD)
347+
get_target_property(targetCxxStandard ${ARG_TARGET} CXX_STANDARD)
348348
if (targetCxxStandard MATCHES 17)
349349
set(device_compiler_cxx_standard "-std=c++1z")
350350
elseif (targetCxxStandard MATCHES 14)
@@ -358,7 +358,7 @@ function(__build_ir)
358358
endif()
359359

360360
get_property(source_compile_flags
361-
SOURCE ${SDK_BUILD_IR_SOURCE}
361+
SOURCE ${ARG_SOURCE}
362362
PROPERTY COMPUTECPP_SOURCE_FLAGS
363363
)
364364
separate_arguments(source_compile_flags)
@@ -372,8 +372,8 @@ function(__build_ir)
372372
${computecpp_source_flags}
373373
)
374374

375-
set(ir_dependencies ${SDK_BUILD_IR_SOURCE})
376-
get_target_property(target_libraries ${SDK_BUILD_IR_TARGET} LINK_LIBRARIES)
375+
set(ir_dependencies ${ARG_SOURCE})
376+
get_target_property(target_libraries ${ARG_TARGET} LINK_LIBRARIES)
377377
if(target_libraries)
378378
foreach(library ${target_libraries})
379379
if(TARGET ${library})
@@ -400,51 +400,51 @@ function(__build_ir)
400400
${generated_compile_definitions}
401401
-sycl-ih ${outputSyclFile}
402402
-o ${outputDeviceFile}
403-
-c ${SDK_BUILD_IR_SOURCE}
403+
-c ${ARG_SOURCE}
404404
${generate_depfile}
405405
DEPENDS ${ir_dependencies}
406-
IMPLICIT_DEPENDS CXX ${SDK_BUILD_IR_SOURCE}
406+
IMPLICIT_DEPENDS CXX ${ARG_SOURCE}
407407
${enable_depfile}
408408
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
409409
COMMENT "Building ComputeCpp integration header file ${outputSyclFile}")
410410

411411
# Name: (user-defined name)_(source file)_(counter)_ih
412412
set(headerTargetName
413-
${SDK_BUILD_IR_TARGET}_${sourceFileName}_${SDK_BUILD_IR_COUNTER}_ih)
413+
${ARG_TARGET}_${sourceFileName}_${ARG_COUNTER}_ih)
414414

415415
if(NOT MSVC)
416416
# Add a custom target for the generated integration header
417417
add_custom_target(${headerTargetName} DEPENDS ${outputDeviceFile} ${outputSyclFile})
418-
add_dependencies(${SDK_BUILD_IR_TARGET} ${headerTargetName})
418+
add_dependencies(${ARG_TARGET} ${headerTargetName})
419419
endif()
420420

421421
# This property can be set on a per-target basis to indicate that the
422422
# integration header should appear after the main source listing
423-
get_target_property(includeAfter ${SDK_ADD_SYCL_TARGET} COMPUTECPP_INCLUDE_AFTER)
423+
get_target_property(includeAfter ${ARG_TARGET} COMPUTECPP_INCLUDE_AFTER)
424424

425425
if(includeAfter)
426426
# Change the source file to the integration header - e.g.
427427
# g++ -c source_file_name.cpp.sycl
428-
get_target_property(current_sources ${SDK_BUILD_IR_TARGET} SOURCES)
428+
get_target_property(current_sources ${ARG_TARGET} SOURCES)
429429
# Remove absolute path to source file
430-
list(REMOVE_ITEM current_sources ${SDK_BUILD_IR_SOURCE})
430+
list(REMOVE_ITEM current_sources ${ARG_SOURCE})
431431
# Remove relative path to source file
432432
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" ""
433-
rel_source_file ${SDK_BUILD_IR_SOURCE}
433+
rel_source_file ${ARG_SOURCE}
434434
)
435435
list(REMOVE_ITEM current_sources ${rel_source_file})
436436
# Add SYCL header to source list
437437
list(APPEND current_sources ${outputSyclFile})
438-
set_property(TARGET ${SDK_BUILD_IR_TARGET}
438+
set_property(TARGET ${ARG_TARGET}
439439
PROPERTY SOURCES ${current_sources})
440440
# CMake/gcc don't know what language a .sycl file is, so tell them
441441
set_property(SOURCE ${outputSyclFile} PROPERTY LANGUAGE CXX)
442-
set(includedFile ${SDK_BUILD_IR_SOURCE})
442+
set(includedFile ${ARG_SOURCE})
443443
set(cppFile ${outputSyclFile})
444444
else()
445445
set_property(SOURCE ${outputSyclFile} PROPERTY HEADER_FILE_ONLY ON)
446446
set(includedFile ${outputSyclFile})
447-
set(cppFile ${SDK_BUILD_IR_SOURCE})
447+
set(cppFile ${ARG_SOURCE})
448448
endif()
449449

450450
# Force inclusion of the integration header for the host compiler
@@ -455,11 +455,11 @@ function(__build_ir)
455455
if(includeAfter)
456456
# Allow the source file to be edited using Visual Studio.
457457
# It will be added as a header file so it won't be compiled.
458-
set_property(SOURCE ${SDK_BUILD_IR_SOURCE} PROPERTY HEADER_FILE_ONLY true)
458+
set_property(SOURCE ${ARG_SOURCE} PROPERTY HEADER_FILE_ONLY true)
459459
endif()
460460

461461
# Add both source and the sycl files to the VS solution.
462-
target_sources(${SDK_BUILD_IR_TARGET} PUBLIC ${SDK_BUILD_IR_SOURCE} ${outputSyclFile})
462+
target_sources(${ARG_TARGET} PUBLIC ${ARG_SOURCE} ${outputSyclFile})
463463

464464
set(forceIncludeFlags "/FI${includedFile} /TP")
465465
else()
@@ -491,17 +491,17 @@ function(add_sycl_to_target)
491491
set(multi_value_args
492492
SOURCES
493493
)
494-
cmake_parse_arguments(SDK_ADD_SYCL
494+
cmake_parse_arguments(ARG
495495
"${options}"
496496
"${one_value_args}"
497497
"${multi_value_args}"
498498
${ARGN}
499499
)
500-
if ("${SDK_ADD_SYCL_SOURCES}" STREQUAL "")
500+
if ("${ARG_SOURCES}" STREQUAL "")
501501
message(WARNING "No source files provided to add_sycl_to_target. "
502502
"SYCL integration headers may not be generated.")
503503
endif()
504-
set_target_properties(${SDK_ADD_SYCL_TARGET} PROPERTIES LINKER_LANGUAGE CXX)
504+
set_target_properties(${ARG_TARGET} PROPERTIES LINKER_LANGUAGE CXX)
505505

506506
# If the CXX compiler is set to compute++ enable the driver.
507507
get_filename_component(cmakeCxxCompilerFileName "${CMAKE_CXX_COMPILER}" NAME)
@@ -511,19 +511,19 @@ function(add_sycl_to_target)
511511
revert the CXX compiler to your default host compiler.")
512512
endif()
513513

514-
get_target_property(includeAfter ${SDK_ADD_SYCL_TARGET} COMPUTECPP_INCLUDE_AFTER)
514+
get_target_property(includeAfter ${ARG_TARGET} COMPUTECPP_INCLUDE_AFTER)
515515
if(includeAfter)
516516
list(APPEND COMPUTECPP_USER_FLAGS -fsycl-ih-last)
517517
endif()
518518
list(INSERT COMPUTECPP_DEVICE_COMPILER_FLAGS 0 -sycl-driver)
519519
# Prepend COMPUTECPP_DEVICE_COMPILER_FLAGS and append COMPUTECPP_USER_FLAGS
520520
foreach(prop COMPILE_OPTIONS INTERFACE_COMPILE_OPTIONS)
521-
get_target_property(target_compile_options ${SDK_ADD_SYCL_TARGET} ${prop})
521+
get_target_property(target_compile_options ${ARG_TARGET} ${prop})
522522
if(NOT target_compile_options)
523523
set(target_compile_options "")
524524
endif()
525525
set_property(
526-
TARGET ${SDK_ADD_SYCL_TARGET}
526+
TARGET ${ARG_TARGET}
527527
PROPERTY ${prop}
528528
${COMPUTECPP_DEVICE_COMPILER_FLAGS}
529529
${target_compile_options}
@@ -534,23 +534,23 @@ function(add_sycl_to_target)
534534
set(fileCounter 0)
535535
list(INSERT COMPUTECPP_DEVICE_COMPILER_FLAGS 0 -sycl)
536536
# Add custom target to run compute++ and generate the integration header
537-
foreach(sourceFile ${SDK_ADD_SYCL_SOURCES})
537+
foreach(sourceFile ${ARG_SOURCES})
538538
if(NOT IS_ABSOLUTE ${sourceFile})
539539
set(sourceFile "${CMAKE_CURRENT_SOURCE_DIR}/${sourceFile}")
540540
endif()
541541
__build_ir(
542-
TARGET ${SDK_ADD_SYCL_TARGET}
542+
TARGET ${ARG_TARGET}
543543
SOURCE ${sourceFile}
544544
COUNTER ${fileCounter}
545545
)
546546
MATH(EXPR fileCounter "${fileCounter} + 1")
547547
endforeach()
548548
endif()
549549

550-
set_property(TARGET ${SDK_ADD_SYCL_TARGET}
550+
set_property(TARGET ${ARG_TARGET}
551551
APPEND PROPERTY LINK_LIBRARIES ComputeCpp::ComputeCpp)
552-
set_property(TARGET ${SDK_ADD_SYCL_TARGET}
552+
set_property(TARGET ${ARG_TARGET}
553553
APPEND PROPERTY INTERFACE_LINK_LIBRARIES ComputeCpp::ComputeCpp)
554-
target_compile_definitions(${SDK_ADD_SYCL_TARGET} INTERFACE
554+
target_compile_definitions(${ARG_TARGET} INTERFACE
555555
SYCL_LANGUAGE_VERSION=${SYCL_LANGUAGE_VERSION})
556556
endfunction(add_sycl_to_target)

samples/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ function(add_sample)
99
set(options NO_TEST)
1010
set(one_value_args TARGET)
1111
set(multi_value_args SOURCES)
12-
cmake_parse_arguments(SDK_ADD_SAMPLE
12+
cmake_parse_arguments(ARG
1313
"${options}"
1414
"${one_value_args}"
1515
"${multi_value_args}"
1616
${ARGN}
1717
)
18-
add_executable(${SDK_ADD_SAMPLE_TARGET} ${SDK_ADD_SAMPLE_SOURCES})
19-
add_sycl_to_target(TARGET ${SDK_ADD_SAMPLE_TARGET}
20-
SOURCES ${SDK_ADD_SAMPLE_SOURCES})
21-
if(NOT SDK_ADD_SAMPLE_NO_TEST)
22-
add_test(NAME ${SDK_ADD_SAMPLE_TARGET} COMMAND ${SDK_ADD_SAMPLE_TARGET})
18+
add_executable(${ARG_TARGET} ${ARG_SOURCES})
19+
add_sycl_to_target(TARGET ${ARG_TARGET}
20+
SOURCES ${ARG_SOURCES})
21+
if(NOT ARG_NO_TEST)
22+
add_test(NAME ${ARG_TARGET} COMMAND ${ARG_TARGET})
2323
endif()
24-
install(TARGETS ${SDK_ADD_SAMPLE_TARGET} RUNTIME DESTINATION bin)
24+
install(TARGETS ${ARG_TARGET} RUNTIME DESTINATION bin)
2525
endfunction(add_sample)
2626

2727
add_sample(TARGET accessors SOURCES accessors.cpp)

0 commit comments

Comments
 (0)