Skip to content

Commit ad823a0

Browse files
committed
[SYCL] Simplified CMakeLists.txt file
Use a function to call common code in source/CMakeLists.txt and plugins/opencl/CMakeLists.txt. This change allows extension of other plugins to be easier and maintaining the options at a single location. Signed-off-by: Garima Gupta <garima.gupta@intel.com>
1 parent 67c035f commit ad823a0

File tree

3 files changed

+35
-47
lines changed

3 files changed

+35
-47
lines changed

sycl/CMakeLists.txt

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,40 @@ if (MSVC)
143143
list(APPEND SYCL_RT_LIBS sycld)
144144
endif()
145145

146+
# This function allows building multiple libraries with the same options.
147+
# Currently used by sycl and plugins library.
148+
function( add_libcxxsupport_gccworkaround LIB_NAME)
149+
if (SYCL_USE_LIBCXX)
150+
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR
151+
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
152+
target_compile_options(${LIB_NAME} PRIVATE -nostdinc++)
153+
if ((NOT (DEFINED SYCL_LIBCXX_INCLUDE_PATH)) OR (NOT (DEFINED SYCL_LIBCXX_LIBRARY_PATH)))
154+
message(FATAL_ERROR "When building with libc++ SYCL_LIBCXX_INCLUDE_PATHS and"
155+
"SYCL_LIBCXX_LIBRARY_PATH should be set")
156+
endif()
157+
target_include_directories(${LIB_NAME} PRIVATE "${SYCL_LIBCXX_INCLUDE_PATH}")
158+
target_link_libraries(${LIB_NAME} PRIVATE "-L${SYCL_LIBCXX_LIBRARY_PATH}" -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc)
159+
else()
160+
message(FATAL_ERROR "Build with libc++ is not yet supported for this compiler")
161+
endif()
162+
else()
163+
164+
# Workaround for bug in GCC version 5 and higher.
165+
# More information https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899
166+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
167+
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
168+
target_link_libraries(${LIB_NAME} PRIVATE gcc_s gcc)
169+
endif()
170+
171+
endif()
172+
endfunction(add_libcxxsupport_gccworkaround)
173+
146174
# SYCL runtime library
147-
add_subdirectory(source)
175+
add_subdirectory( source )
148176

149177
# SYCL toolchain builds all components: compiler, libraries, headers, etc.
150178
add_custom_target( sycl-toolchain
151179
DEPENDS ${SYCL_RT_LIBS}
152-
pi_opencl
153180
clang
154181
clang-offload-wrapper
155182
clang-offload-bundler
@@ -173,7 +200,10 @@ option(SYCL_INCLUDE_TESTS
173200
"Generate build targets for the SYCL unit tests."
174201
${LLVM_INCLUDE_TESTS})
175202

203+
204+
# Plugin Library
176205
add_subdirectory( plugins )
206+
177207
add_subdirectory(tools)
178208

179209
if(SYCL_INCLUDE_TESTS)

sycl/plugins/opencl/CMakeLists.txt

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ add_dependencies(pi_opencl
1919
ocl-headers
2020
)
2121

22-
add_dependencies(sycl pi_opencl)
22+
add_dependencies(sycl-toolchain pi_opencl)
2323

2424
set_target_properties(pi_opencl PROPERTIES LINKER_LANGUAGE CXX)
2525

@@ -32,29 +32,7 @@ target_link_libraries( pi_opencl
3232
PRIVATE ${OpenCL_LIBRARIES}
3333
)
3434

35-
if (SYCL_USE_LIBCXX)
36-
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR
37-
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
38-
target_compile_options(pi_opencl PRIVATE -nostdinc++)
39-
if ((NOT (DEFINED SYCL_LIBCXX_INCLUDE_PATH)) OR (NOT (DEFINED SYCL_LIBCXX_LIBRARY_PATH)))
40-
message(FATAL_ERROR "When building with libc++ SYCL_LIBCXX_INCLUDE_PATHS and"
41-
"SYCL_LIBCXX_LIBRARY_PATH should be set")
42-
endif()
43-
target_include_directories(pi_opencl PRIVATE "${SYCL_LIBCXX_INCLUDE_PATH}")
44-
target_link_libraries(pi_opencl PRIVATE "-L${SYCL_LIBCXX_LIBRARY_PATH}" -nodefaultlibs -lc++ -lc)
45-
else()
46-
message(FATAL_ERROR "Build with libc++ is not yet supported for this compiler")
47-
endif()
48-
else()
49-
50-
# Workaround for bug in GCC version 5 and higher.
51-
# More information https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899
52-
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
53-
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
54-
target_link_libraries(pi_opencl PRIVATE gcc_s gcc)
55-
endif()
56-
57-
endif()
35+
add_libcxxsupport_gccworkaround(pi_opencl)
5836

5937
install(TARGETS pi_opencl
6038
LIBRARY DESTINATION "lib" COMPONENT pi_opencl

sycl/source/CMakeLists.txt

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,9 @@ function(add_sycl_rt_library LIB_NAME)
2626
PRIVATE ${OpenCL_LIBRARIES}
2727
PRIVATE ${CMAKE_DL_LIBS}
2828
)
29-
if (SYCL_USE_LIBCXX)
30-
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR
31-
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
32-
target_compile_options(${LIB_NAME} PRIVATE -nostdinc++)
33-
if ((NOT (DEFINED SYCL_LIBCXX_INCLUDE_PATH)) OR (NOT (DEFINED SYCL_LIBCXX_LIBRARY_PATH)))
34-
message(FATAL_ERROR "When building with libc++ SYCL_LIBCXX_INCLUDE_PATHS and"
35-
"SYCL_LIBCXX_LIBRARY_PATH should be set")
36-
endif()
37-
target_include_directories(${LIB_NAME} PRIVATE "${SYCL_LIBCXX_INCLUDE_PATH}")
38-
target_link_libraries(${LIB_NAME} PRIVATE "-L${SYCL_LIBCXX_LIBRARY_PATH}" -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc)
39-
else()
40-
message(FATAL_ERROR "Build with libc++ is not yet supported for this compiler")
41-
endif()
42-
else()
4329

44-
# Workaround for bug in GCC version 5 and higher.
45-
# More information https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899
46-
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
47-
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
48-
target_link_libraries(${LIB_NAME} PRIVATE gcc_s gcc)
49-
endif()
30+
add_libcxxsupport_gccworkaround(${LIB_NAME})
5031

51-
endif()
5232
endfunction(add_sycl_rt_library)
5333

5434
set(SYCL_SOURCES

0 commit comments

Comments
 (0)