-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
131 lines (115 loc) · 3.32 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
cmake_minimum_required (VERSION 3.16)
file(READ "version" VERSION_OUTPUT)
string(STRIP ${VERSION_OUTPUT} PACKAGE_VERSION)
project(opencl-language-server
DESCRIPTION "OpenCL Language Server"
VERSION ${PACKAGE_VERSION}
LANGUAGES CXX
)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
set(LINUX FALSE)
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
set(ENABLE_TESTING_DEFAULT OFF)
option(ENABLE_TESTING "Include unittest related targtes"
${ENABLE_TESTING_DEFAULT}
)
if(MSVC)
add_compile_options(/WX /W4 /EHsc)
else()
add_compile_options(-Wall -Wextra -Wpedantic -Wimplicit-fallthrough -Werror)
if(LINUX)
# Prebuilt Clang and LLVM static libraries are position-dependent
add_link_options(-no-pie)
endif()
endif()
message(STATUS "Build Configuration")
message(STATUS "Enable testing:" ${ENABLE_TESTING})
message(STATUS "CMake Generator:" ${CMAKE_GENERATOR})
message(STATUS "C++ Flags:" ${CMAKE_CXX_FLAGS})
message(STATUS "List of compile features:" ${CMAKE_CXX_COMPILE_FEATURES})
message(STATUS "Toolchain file:" ${CMAKE_TOOLCHAIN_FILE})
if(APPLE)
find_package(OpenCL REQUIRED)
else()
find_package(OpenCLICDLoader REQUIRED)
endif()
find_package(OpenCLHeadersCpp REQUIRED)
find_package(spdlog REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(CLI11 REQUIRED)
find_package(uriparser REQUIRED)
# libclang is not currently used, uncomment when needed (#17, #24)
# add_subdirectory(libclang)
if(ENABLE_TESTING)
find_package(GTest REQUIRED)
include(GoogleTest)
enable_testing()
add_subdirectory(tests)
endif()
set(headers
clinfo.hpp
device.hpp
diagnostics.hpp
jsonrpc.hpp
log.hpp
lsp.hpp
utils.hpp
)
set(sources
clinfo.cpp
diagnostics.cpp
jsonrpc.cpp
log.cpp
lsp.cpp
main.cpp
utils.cpp
)
if(APPLE)
set(headers ${headers} oslogger.hpp)
endif()
list(TRANSFORM headers PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/include/")
list(TRANSFORM sources PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/src/")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/version.hpp.in version.hpp)
source_group("include" FILES ${headers})
source_group("src" FILES ${sources})
set(conan_libs nlohmann_json::nlohmann_json spdlog::spdlog OpenCL::HeadersCpp CLI11::CLI11 uriparser::uriparser)
if(LINUX)
set(conan_libs ${conan_libs} stdc++fs OpenCL::OpenCL)
elseif(APPLE)
set(conan_libs ${conan_libs} ${OpenCL_LIBRARIES})
elseif(WIN32)
set(conan_libs ${conan_libs} OpenCL::OpenCL)
endif()
add_executable (${PROJECT_NAME} ${sources} ${headers})
target_compile_definitions(${PROJECT_NAME} PRIVATE
OPENCL_LS_VERSION="${PACKAGE_VERSION}"
CL_HPP_ENABLE_EXCEPTIONS
CL_HPP_CL_1_2_DEFAULT_BUILD
)
if(APPLE)
target_compile_definitions(${PROJECT_NAME} PRIVATE
CL_HPP_MINIMUM_OPENCL_VERSION=120
CL_HPP_TARGET_OPENCL_VERSION=120
)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE
CL_HPP_MINIMUM_OPENCL_VERSION=110
CL_HPP_TARGET_OPENCL_VERSION=300
)
endif()
target_link_libraries(${PROJECT_NAME} ${conan_libs}
# libclang-imported
)
target_include_directories(${PROJECT_NAME} PRIVATE
"${PROJECT_SOURCE_DIR}/include"
${CMAKE_CURRENT_BINARY_DIR}
)
if(APPLE)
target_include_directories(${PROJECT_NAME} PRIVATE "${OpenCL_INCLUDE_DIRS}")
endif()