Skip to content

Commit f7d1fd7

Browse files
committed
Use library dependency in CMake
1 parent 35f2d3e commit f7d1fd7

File tree

7 files changed

+49
-152
lines changed

7 files changed

+49
-152
lines changed

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ endif()
4848

4949
add_subdirectory(libsyclinterface)
5050

51-
file(GLOB _dpctl_capi_headers dpctl/apis/include/*.h*)
52-
install(FILES ${_dpctl_capi_headers}
53-
DESTINATION dpctl/include
51+
add_library(DpctlCAPI INTERFACE)
52+
target_include_directories(DpctlCAPI INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/dpctl/apis/include)
53+
target_link_libraries(DpctlCAPI INTERFACE DPCTLSyclInterface)
54+
55+
install(DIRECTORY
56+
${CMAKE_CURRENT_SOURCE_DIR}/dpctl/apis/include/
57+
DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/include
58+
FILES_MATCHING REGEX "\\.h(pp)?$"
5459
)
5560

5661
# Define CMAKE_INSTALL_xxx: LIBDIR, INCLUDEDIR

dpctl/CMakeLists.txt

Lines changed: 19 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -74,64 +74,6 @@ endif()
7474

7575
# at build time create include/ directory and copy header files over
7676
set(DPCTL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
77-
add_custom_target(_build_time_create_dpctl_include ALL
78-
COMMAND ${CMAKE_COMMAND} -E make_directory ${DPCTL_INCLUDE_DIR}
79-
COMMAND ${CMAKE_COMMAND} -E make_directory ${DPCTL_INCLUDE_DIR}/syclinterface
80-
COMMAND ${CMAKE_COMMAND} -E make_directory ${DPCTL_INCLUDE_DIR}/syclinterface/Support
81-
COMMAND ${CMAKE_COMMAND} -E make_directory ${DPCTL_INCLUDE_DIR}/syclinterface/Config
82-
DEPENDS DPCTLSyclInterface
83-
)
84-
85-
set(_copied_header_files)
86-
file(GLOB _syclinterface_h ${CMAKE_SOURCE_DIR}/libsyclinterface/include/*.h*)
87-
foreach(hf ${_syclinterface_h})
88-
get_filename_component(_header_name ${hf} NAME)
89-
set(_target_header_file ${DPCTL_INCLUDE_DIR}/syclinterface/${_header_name})
90-
list(APPEND _copied_header_files ${_target_header_file})
91-
add_custom_command(OUTPUT ${_target_header_file}
92-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${hf} ${_target_header_file}
93-
DEPENDS ${hf} _build_time_create_dpctl_include
94-
VERBATIM
95-
)
96-
endforeach()
97-
98-
file(GLOB _syclinterface_Support_h ${CMAKE_SOURCE_DIR}/libsyclinterface/include/Support/*.h)
99-
foreach(hf ${_syclinterface_Support_h})
100-
get_filename_component(_header_name ${hf} NAME)
101-
set(_target_header_file ${DPCTL_INCLUDE_DIR}/syclinterface/Support/${_header_name})
102-
list(APPEND _copied_header_files ${_target_header_file})
103-
add_custom_command(OUTPUT ${_target_header_file}
104-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${hf} ${_target_header_file}
105-
DEPENDS ${hf} _build_time_create_dpctl_include
106-
)
107-
endforeach()
108-
109-
file(GLOB _syclinterface_Config_h ${CMAKE_SOURCE_DIR}/libsyclinterface/include/Config/*.h)
110-
foreach(hf ${_syclinterface_Config_h})
111-
get_filename_component(_header_name ${hf} NAME)
112-
set(_target_header_file ${DPCTL_INCLUDE_DIR}/syclinterface/Config/${_header_name})
113-
list(APPEND _copied_header_files ${_target_header_file})
114-
add_custom_command(OUTPUT ${_target_header_file}
115-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${hf} ${_target_header_file}
116-
DEPENDS ${hf} _build_time_create_dpctl_include
117-
)
118-
endforeach()
119-
120-
file(GLOB _apis_h ${CMAKE_CURRENT_SOURCE_DIR}/apis/include/*)
121-
foreach(hf ${_apis_h})
122-
get_filename_component(_header_name ${hf} NAME)
123-
set(_target_header_file ${DPCTL_INCLUDE_DIR}/${_header_name})
124-
list(APPEND _copied_header_files ${_target_header_file})
125-
add_custom_command(OUTPUT ${_target_header_file}
126-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${hf} ${_target_header_file}
127-
DEPENDS ${hf} _build_time_create_dpctl_include
128-
)
129-
endforeach()
130-
131-
add_custom_target(
132-
_build_time_create_dpctl_include_copy ALL
133-
DEPENDS ${_copied_header_files}
134-
)
13577

13678
set(CMAKE_INSTALL_RPATH "$ORIGIN")
13779

@@ -140,7 +82,6 @@ function(build_dpctl_ext _trgt _src _dest)
14082
cmake_parse_arguments(BUILD_DPCTL_EXT "${options}" "" "" ${ARGN})
14183
add_cython_target(${_trgt} ${_src} CXX OUTPUT_VAR _generated_src)
14284
set(_cythonize_trgt "${_trgt}_cythonize_pyx")
143-
add_custom_target(${_cythonize_trgt} DEPENDS ${_src})
14485
Python_add_library(${_trgt} MODULE WITH_SOABI ${_generated_src})
14586
if (BUILD_DPCTL_EXT_SYCL)
14687
add_sycl_to_target(TARGET ${_trgt} SOURCES ${_generated_src})
@@ -158,8 +99,7 @@ function(build_dpctl_ext _trgt _src _dest)
15899
)
159100
endif()
160101
endif()
161-
target_include_directories(${_trgt} PRIVATE ${NumPy_INCLUDE_DIR} ${DPCTL_INCLUDE_DIR})
162-
add_dependencies(${_trgt} _build_time_create_dpctl_include_copy ${_cythonize_trgt})
102+
target_link_libraries(${_trgt} PRIVATE Python::NumPy)
163103
if (DPCTL_GENERATE_COVERAGE)
164104
target_compile_definitions(${_trgt} PRIVATE CYTHON_TRACE=1 CYTHON_TRACE_NOGIL=1)
165105
# target_compile_options(${_trgt} PRIVATE -fno-sycl-use-footer)
@@ -171,42 +111,31 @@ function(build_dpctl_ext _trgt _src _dest)
171111
get_filename_component(_generated_src_dir ${_generated_src} DIRECTORY)
172112
set(_generated_public_h "${_generated_src_dir}/${_name_wle}.h")
173113
set(_generated_api_h "${_generated_src_dir}/${_name_wle}_api.h")
174-
set(_copy_trgt "${_trgt}_copy_capi_include")
175-
add_custom_target(
176-
${_copy_trgt} ALL
177-
COMMAND ${CMAKE_COMMAND}
178-
-DSOURCE_FILE=${_generated_public_h}
179-
-DDEST=${CMAKE_CURRENT_SOURCE_DIR}
180-
-P ${CMAKE_SOURCE_DIR}/dpctl/cmake/copy_existing.cmake
181-
COMMAND ${CMAKE_COMMAND}
182-
-DSOURCE_FILE=${_generated_api_h}
183-
-DDEST=${CMAKE_CURRENT_SOURCE_DIR}
184-
-P ${CMAKE_SOURCE_DIR}/dpctl/cmake/copy_existing.cmake
185-
DEPENDS ${_trgt}
186-
VERBATIM
187-
COMMENT "Copying Cython-generated headers to dpctl"
188-
)
189-
if (DPCTL_GENERATE_COVERAGE)
190-
set(_copy_cxx_trgt "${_trgt}_copy_cxx")
191-
add_custom_target(
192-
${_copy_cxx_trgt} ALL
193-
COMMAND ${CMAKE_COMMAND}
194-
-DSOURCE_FILE=${_generated_src}
195-
-DDEST=${CMAKE_CURRENT_SOURCE_DIR}
196-
-P ${CMAKE_SOURCE_DIR}/dpctl/cmake/copy_existing.cmake
197-
DEPENDS ${_trgt}
198-
VERBATIM
199-
COMMENT "Copying Cython-generated source to dpctl"
200-
)
201-
endif()
202-
install(TARGETS ${_trgt} LIBRARY DESTINATION ${_dest})
114+
115+
# TODO: create separate folder inside build folder that contains only
116+
# headers related to this target and appropriate folder structure to
117+
# eliminate shadow dependencies
118+
get_filename_component(_generated_src_dir_dir ${_generated_src_dir} DIRECTORY)
119+
target_include_directories(${_trgt} INTERFACE ${_generated_src_dir_dir})
120+
121+
install(TARGETS ${_trgt}
122+
LIBRARY DESTINATION ${_dest})
123+
install(FILES
124+
${_generated_api_h}
125+
DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/include/${_dest}
126+
OPTIONAL)
127+
install(FILES
128+
${_generated_public_h}
129+
DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/include/${_dest}
130+
OPTIONAL)
203131
endfunction()
204132

205133
file(GLOB _cython_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.pyx)
206134
list(REMOVE_ITEM _cython_sources ${CMAKE_CURRENT_SOURCE_DIR}/_sycl_queue.pyx)
207135
foreach(_cy_file ${_cython_sources})
208136
get_filename_component(_trgt ${_cy_file} NAME_WLE)
209137
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl")
138+
target_link_libraries(DpctlCAPI INTERFACE ${_trgt})
210139
endforeach()
211140

212141
set(_cy_file ${CMAKE_CURRENT_SOURCE_DIR}/_sycl_queue.pyx)

dpctl/memory/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ file(GLOB _cython_sources *.pyx)
33
foreach(_cy_file ${_cython_sources})
44
get_filename_component(_trgt ${_cy_file} NAME_WLE)
55
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/memory")
6+
target_link_libraries(DpctlCAPI INTERFACE ${_trgt})
67
endforeach()

dpctl/program/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ file(GLOB _cython_sources *.pyx)
33
foreach(_cy_file ${_cython_sources})
44
get_filename_component(_trgt ${_cy_file} NAME_WLE)
55
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/program")
6+
target_link_libraries(DpctlCAPI INTERFACE ${_trgt})
67
endforeach()

dpctl/tensor/CMakeLists.txt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@ foreach(_cy_file ${_cython_sources})
33
get_filename_component(_trgt ${_cy_file} NAME_WLE)
44
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/tensor")
55
target_include_directories(${_trgt} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
6+
target_link_libraries(DpctlCAPI INTERFACE ${_trgt})
67
endforeach()
78

9+
# TODO: do we need to write this dependencies explicitly? Does it even work this
10+
# way?
811
add_custom_target(_usmarray_deps SOURCES
912
${CMAKE_CURRENT_SOURCE_DIR}/_slicing.pxi
1013
${CMAKE_CURRENT_SOURCE_DIR}/_types.pxi
1114
${CMAKE_CURRENT_SOURCE_DIR}/_stride_utils.pxi
1215
)
1316
add_dependencies(_usmarray _usmarray_deps)
1417

15-
add_custom_target(_dpctl4pybind11_deps
16-
DEPENDS
17-
_usmarray_copy_capi_include
18-
_memory_copy_capi_include
19-
_sycl_device_copy_capi_include
20-
_sycl_queue_copy_capi_include
21-
_sycl_context_copy_capi_include
22-
_sycl_event_copy_capi_include
23-
)
24-
2518
if(WIN32)
2619
if (${CMAKE_VERSION} VERSION_LESS "3.23")
2720
# this is a work-around for target_link_options inserting option after -link option, cause
@@ -242,7 +235,6 @@ foreach(python_module_name ${_py_trgts})
242235
target_link_options(${python_module_name} PRIVATE -fsycl-device-code-split=per_kernel)
243236
target_include_directories(${python_module_name}
244237
PRIVATE
245-
${CMAKE_CURRENT_SOURCE_DIR}/../include
246238
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/include
247239
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/
248240
)
@@ -270,6 +262,8 @@ foreach(python_module_name ${_py_trgts})
270262
-fsycl-targets=${_dpctl_sycl_targets}
271263
)
272264
endif()
273-
add_dependencies(${python_module_name} _dpctl4pybind11_deps)
265+
# TODO: update source so they refernece individual libraries instead of
266+
# dpctl4pybind11.hpp. It will allow to simplify dependency tree
267+
target_link_libraries(${python_module_name} PRIVATE DpctlCAPI)
274268
install(TARGETS ${python_module_name} DESTINATION "dpctl/tensor")
275269
endforeach()

dpctl/utils/CMakeLists.txt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ foreach(_cy_file ${_cython_sources})
55
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/utils")
66
endforeach()
77

8-
add_custom_target(_dpctl4pybind11_header_ready
9-
DEPENDS
10-
_usmarray_copy_capi_include
11-
_memory_copy_capi_include
12-
_sycl_device_copy_capi_include
13-
_sycl_queue_copy_capi_include
14-
_sycl_context_copy_capi_include
15-
_sycl_event_copy_capi_include
16-
)
17-
188
set(python_module_name _device_queries)
199
set(_module_src ${CMAKE_CURRENT_SOURCE_DIR}/src/device_queries.cpp)
2010
pybind11_add_module(${python_module_name} MODULE
@@ -44,9 +34,5 @@ if(_dpctl_sycl_targets)
4434
-fsycl-targets=${_dpctl_sycl_targets}
4535
)
4636
endif()
47-
target_include_directories(${python_module_name}
48-
PRIVATE
49-
${CMAKE_CURRENT_SOURCE_DIR}/../include
50-
)
51-
add_dependencies(${python_module_name} _dpctl4pybind11_header_ready)
37+
target_link_libraries(${python_module_name} PRIVATE DpctlCAPI)
5238
install(TARGETS ${python_module_name} DESTINATION "dpctl/utils")

libsyclinterface/CMakeLists.txt

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ message(STATUS "LIB_ZE: ${LIBZE_LOADER_FILENAME}")
9595
message(STATUS "LIB_CL: ${LIBCL_LOADER_FILENAME}")
9696

9797
configure_file(
98-
${CMAKE_CURRENT_SOURCE_DIR}/include/Config/dpctl_config.h.in
99-
${CMAKE_CURRENT_SOURCE_DIR}/include/Config/dpctl_config.h
98+
${CMAKE_CURRENT_SOURCE_DIR}/include/syclinterface/Config/dpctl_config.h.in
99+
${CMAKE_CURRENT_SOURCE_DIR}/include/syclinterface/Config/dpctl_config.h
100100
)
101101

102102
# Set the C++ standard to C++17
@@ -226,11 +226,12 @@ if(DPCTL_GENERATE_COVERAGE)
226226
endif()
227227

228228
target_include_directories(DPCTLSyclInterface
229-
PUBLIC
230-
${CMAKE_CURRENT_SOURCE_DIR}/include/
231-
${CMAKE_CURRENT_SOURCE_DIR}/include/Support
232-
${CMAKE_CURRENT_SOURCE_DIR}/include/Config
229+
# PUBLIC
233230
PRIVATE
231+
${CMAKE_CURRENT_SOURCE_DIR}/include/syclinterface
232+
${CMAKE_CURRENT_SOURCE_DIR}/include/syclinterface/Support
233+
${CMAKE_CURRENT_SOURCE_DIR}/include/syclinterface/Config
234+
# PRIVATE
234235
${CMAKE_CURRENT_SOURCE_DIR}/helper/include/
235236
${SYCL_INCLUDE_DIR}
236237
)
@@ -267,25 +268,10 @@ if(DPCTL_ENABLE_L0_PROGRAM_CREATION)
267268
)
268269
endif()
269270

270-
# Install all headers
271-
272-
file(GLOB MAIN_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
273-
file(GLOB SUPPORT_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/Support/*.h")
274-
file(GLOB CONFIG_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/Config/*.h")
275-
276-
set_target_properties(DPCTLSyclInterface
277-
PROPERTIES PUBLIC_HEADER
278-
"${MAIN_HEADERS}"
271+
target_include_directories(DPCTLSyclInterface INTERFACE
272+
${CMAKE_CURRENT_SOURCE_DIR}/include
279273
)
280274

281-
if (SKBUILD)
282-
set(_lib_destination dpctl)
283-
set(_include_destination dpctl/include/syclinterface)
284-
else()
285-
set(_lib_destination ${CMAKE_INSTALL_PREFIX}/lib)
286-
set(_include_destination ${CMAKE_INSTALL_PREFIX}/include)
287-
endif()
288-
289275
install(TARGETS
290276
DPCTLSyclInterface
291277
LIBRARY
@@ -294,16 +280,11 @@ install(TARGETS
294280
DESTINATION ${_lib_destination}
295281
RUNTIME
296282
DESTINATION ${_lib_destination}
297-
PUBLIC_HEADER
298-
DESTINATION ${_include_destination}
299283
)
300-
install(
301-
FILES ${SUPPORT_HEADERS}
302-
DESTINATION ${_include_destination}/Support
303-
)
304-
install(
305-
FILES ${CONFIG_HEADERS}
306-
DESTINATION ${_include_destination}/Config
284+
install(DIRECTORY
285+
${CMAKE_CURRENT_SOURCE_DIR}/include/
286+
DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/include
287+
FILES_MATCHING REGEX "\\.h(pp)?$"
307288
)
308289

309290
# Add sub-directory to build the dpctl C API test cases

0 commit comments

Comments
 (0)