From 3ebad06bd4ef95530b10ea47c0b26f9c43aeceba Mon Sep 17 00:00:00 2001 From: James Price Date: Wed, 11 May 2016 22:22:20 +0100 Subject: [PATCH] [SYCL] Fix detection of CL/sycl.hpp for C++14 versions --- CMakeLists.txt | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34847ba..8d10c40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) project(gpu-stream) include(CheckIncludeFileCXX) +include(CheckCXXCompilerFlag) set(gpu-stream_VERSION_MAJOR 2) set(gpu-stream_VERSION_MINOR 0) @@ -110,22 +111,31 @@ endif () #------------------------------------------------------------------------------- # SYCL #------------------------------------------------------------------------------- -set(CMAKE_REQUIRED_FLAGS "-std=c++11") +if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR + "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + # Use C++14 if available, otherwise drop back to C++11 + check_cxx_compiler_flag("-std=c++14" CXX14) + if (CXX14) + set(CMAKE_REQUIRED_FLAGS "-std=c++14") + else() + set(CMAKE_REQUIRED_FLAGS "-std=c++11") + endif() +endif() + check_include_file_cxx("CL/sycl.hpp" HAS_SYCL) if (HAS_SYCL) + add_executable(gpu-stream-sycl main.cpp SYCLStream.cpp) + target_compile_definitions(gpu-stream-sycl PUBLIC SYCL) + find_program(COMPUTECPP "compute++") if (COMPUTECPP) message(STATUS "Using ComputeCpp for SYCL compilation") add_custom_target(SYCLStream.sycl COMMAND ${COMPUTECPP} ${CMAKE_CURRENT_SOURCE_DIR}/SYCLStream.cpp -sycl -no-serial-memop -O2 -emit-llvm -c) - add_executable(gpu-stream-sycl main.cpp SYCLStream.cpp) add_dependencies(gpu-stream-sycl SYCLStream.sycl) - target_compile_definitions(gpu-stream-sycl PUBLIC SYCL) target_compile_options(gpu-stream-sycl PUBLIC -include SYCLStream.sycl) target_link_libraries(gpu-stream-sycl SYCL OpenCL) else() message(STATUS "Using header-only SYCL implementation") - add_executable(gpu-stream-sycl main.cpp SYCLStream.cpp) - target_compile_definitions(gpu-stream-sycl PUBLIC SYCL) set_property(TARGET gpu-stream-sycl PROPERTY CXX_STANDARD 14) endif(COMPUTECPP) else ()