11cmake_minimum_required (VERSION 3.10 FATAL_ERROR)
2- project ("dpCtl - A lightweight SYCL wrapper for Python " )
2+ project ("dpCtl C API - A C wrapper for a subset of SYCL " )
33
4- # The function checks is DPCPP_ROOT is valid and points to a dpcpp installation
5- function (check_for_dpcpp)
6- string (COMPARE EQUAL "${DPCPP_ROOT} " "" no_dpcpp_root)
7- if (${no_dpcpp_root} )
8- message (FATAL_ERROR "Set the DPCPP_ROOT argument providing the path to \
9- a dpcpp installation." )
10- endif ()
11-
12- if (WIN32 )
13- set (dpcpp_cmd "${DPCPP_ROOT} /bin/dpcpp" )
14- set (dpcpp_arg "--version" )
15- elseif (UNIX )
16- set (dpcpp_cmd "${DPCPP_ROOT} /bin/dpcpp" )
17- set (dpcpp_arg "--version" )
18- else ()
19- message (FATAL_ERROR "Unsupported system." )
20- endif ()
4+ # Option to turn on support for creating Level Zero interoperability programs
5+ # from a SPIR-V binary file.
6+ option (DPCTL_ENABLE_LO_PROGRAM_CREATION
7+ "Enable Level Zero Program creation from SPIR-V"
8+ OFF
9+ )
10+ # Option to generate code coverage report using llvm-cov and lcov.
11+ option (DPCTL_GENERATE_COVERAGE
12+ "Build dpctl C API with coverage instrumentation instrumentation"
13+ OFF
14+ )
15+ # Option to output html coverage report at a specific location.
16+ option (DPCTL_COVERAGE_REPORT_OUTPUT_DIR
17+ "Save the generated lcov html report to the specified location"
18+ OFF
19+ )
20+ # Option to build the Gtests for dpctl C API
21+ option (DPCTL_BUILD_CAPI_TESTS
22+ "Build dpctl C API google tests"
23+ OFF
24+ )
2125
22- # Check if dpcpp is available
23- execute_process (
24- COMMAND ${dpcpp_cmd} ${dpcpp_arg}
25- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
26- RESULT_VARIABLE dpcpp_result
27- OUTPUT_VARIABLE dpcpp_ver
28- )
26+ # Load our CMake modules to search for DPCPP and Level Zero
27+ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR} /cmake/modules/" )
28+ find_package (DPCPP REQUIRED)
2929
30- if (${dpcpp_result} MATCHES "0" )
31- string (REPLACE "\n " ";" DPCPP_VERSION_LIST "${dpcpp_ver} " )
32- list (GET DPCPP_VERSION_LIST 0 dpcpp_ver_line)
33- foreach (X ${DPCPP_VERSION_LIST} )
34- message (STATUS "dpcpp ver[${dpcpp_result} ]: ${X} " )
35- endforeach ()
36- else ()
37- message (FATAL_ERROR "DPCPP needed to build dpctl_sycl_interface" )
38- endif ()
39- endfunction ()
30+ if (DPCTL_ENABLE_LO_PROGRAM_CREATION)
31+ set (DPCTL_ENABLE_LO_PROGRAM_CREATION 1)
32+ find_package (LevelZero REQUIRED)
33+ endif ()
4034
41- # Check for dpcpp in the specified DPCPP_ROOT
42- check_for_dpcpp( )
35+ configure_file ( ${CMAKE_SOURCE_DIR} / include /Config/dpctl_config.h.in
36+ ${CMAKE_SOURCE_DIR} / include /Config/dpctl_config.h )
4337
4438if (WIN32 )
4539 set (CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT} /bin/dpcpp" )
@@ -54,6 +48,9 @@ if(WIN32)
5448 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG" )
5549 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -Qstd=c++17" )
5650elseif (UNIX )
51+ set (CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT} /bin/dpcpp" )
52+ set (CMAKE_C_COMPILER:PATH "${DPCPP_ROOT} /bin/clang" )
53+ set (CMAKE_LINKER:PATH "${DPCPP_ROOT} /bin/lld" )
5754 set (SDL_FLAGS "-fstack-protector -fstack-protector-all -fpic -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fno-strict-overflow -fno-delete-null-pointer-checks" )
5855 set (WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto" )
5956 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS} " )
@@ -80,30 +77,29 @@ add_library(
8077 helper/source /dpctl_utils_helper.cpp
8178)
8279
83- # Install DPCTLSyclInterface
84- target_include_directories (
85- DPCTLSyclInterface
86- PRIVATE
87- ${CMAKE_SOURCE_DIR} /include /
88- ${CMAKE_SOURCE_DIR} /helper/include /
80+ target_include_directories (DPCTLSyclInterface
81+ PRIVATE
82+ ${CMAKE_SOURCE_DIR} /include /
83+ ${CMAKE_SOURCE_DIR} /helper/include /
84+ ${DPCPP_SYCL_INCLUDE_DIR}
85+ )
86+ target_link_libraries (DPCTLSyclInterface
87+ PRIVATE ${DPCPP_SYCL_LIBRARY}
88+ PRIVATE ${DPCPP_OPENCL_LIBRARY}
8989)
9090
91- if (WIN32 )
92- message (
93- STATUS
94- "SYCL_INCLUDE_DIR: "
95- ${DPCPP_ROOT} /include /sycl
96- )
97- target_include_directories (
98- DPCTLSyclInterface
99- PUBLIC
100- ${DPCPP_ROOT} /include /sycl
101- )
102- target_link_libraries (
103- DPCTLSyclInterface
104- PRIVATE ${DPCPP_ROOT} /lib/sycl.lib
105- PRIVATE ${DPCPP_ROOT} /lib/OpenCL.lib
106- )
91+ if (DPCTL_ENABLE_LO_PROGRAM_CREATION)
92+ if (UNIX )
93+ target_include_directories (DPCTLSyclInterface
94+ PRIVATE
95+ ${LEVEL_ZERO_INCLUDE_DIR}
96+ )
97+ else ()
98+ message (WARNING
99+ "DPCTL support Level Zero program creation not supported "
100+ "on this system."
101+ )
102+ endif ()
107103endif ()
108104
109105install (
@@ -114,34 +110,46 @@ install(
114110)
115111
116112# Install all headers
117- file (GLOB HEADERS "${CMAKE_SOURCE_DIR} /include/*.h* " )
113+ file (GLOB HEADERS "${CMAKE_SOURCE_DIR} /include/*.h" )
118114foreach (HEADER ${HEADERS} )
119115 install (FILES "${HEADER} " DESTINATION include )
120116endforeach ()
121117
122118# Install all headers in include/Support
123- file (GLOB HEADERS "${CMAKE_SOURCE_DIR} /include/Support/*.h* " )
119+ file (GLOB HEADERS "${CMAKE_SOURCE_DIR} /include/Support/*.h" )
124120foreach (HEADER ${HEADERS} )
125121 install (FILES "${HEADER} " DESTINATION include /Support)
126122endforeach ()
127123
128- # Install all headers in helper/ include
129- file (GLOB HEADERS "${CMAKE_SOURCE_DIR} /helper/ include/*.h* " )
124+ # Install all headers in include/Config
125+ file (GLOB HEADERS "${CMAKE_SOURCE_DIR} /include/Config/ *.h" )
130126foreach (HEADER ${HEADERS} )
131- install (FILES "${HEADER} " DESTINATION helper/ include )
127+ install (FILES "${HEADER} " DESTINATION include /Config )
132128endforeach ()
133129
134- option (
135- BUILD_CAPI_TESTS
136- "Build dpctl C API google tests"
137- OFF
138- )
130+ # Enable code coverage related settings
131+ if (DPCTL_GENERATE_COVERAGE)
132+ # check if llvm-cov and lcov are available
133+ find_package (Lcov REQUIRED)
134+ # These flags are set inside FindDPCPP
135+ if (NOT (${LLVM_COV_FOUND} AND ${LLVM_PROFDATA_FOUND} ))
136+ message (FATAL_ERROR
137+ "llvm-cov and llvm-profdata are needed to generate coverage."
138+ )
139+ endif ()
140+ # Turn on DPCTL_BUILD_CAPI_TESTS as building tests is needed to generate
141+ # coverage reports
142+ set (DPCTL_BUILD_CAPI_TESTS "ON" )
143+ if (DPCTL_COVERAGE_REPORT_OUTPUT_DIR)
144+ set (COVERAGE_OUTPUT_DIR ${DPCTL_COVERAGE_REPORT_OUTPUT_DIR} )
145+ message (STATUS "Coverage reports to be saved at ${COVERAGE_OUTPUT_DIR} " )
146+ else ()
147+ set (COVERAGE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} )
148+ message (STATUS "Coverage reports to be saved at ${COVERAGE_OUTPUT_DIR} " )
149+ endif ()
150+ endif ()
139151
140- # Enable to build the dpCtl backend test cases
141- if (BUILD_CAPI_TESTS )
152+ # Add sub-directory to build the dpCtl C API test cases
153+ if (DPCTL_BUILD_CAPI_TESTS )
142154 add_subdirectory (tests)
143155endif ()
144-
145-
146- # Todo : Add build rules for doxygen
147- # maybe refer https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/
0 commit comments