Skip to content

Commit 399f19e

Browse files
committed
refactored platform specific defines into icd_platform.h
1 parent 663c28e commit 399f19e

6 files changed

Lines changed: 53 additions & 21 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/loader/icd_cmake_config.h.in
4141

4242
set (OPENCL_ICD_LOADER_SOURCES
4343
loader/icd.c
44-
loader/icd_dispatch.c)
44+
loader/icd.h
45+
loader/icd_dispatch.c
46+
loader/icd_dispatch.h
47+
loader/icd_envvars.h
48+
loader/icd_platform.h)
4549

4650
if (WIN32)
4751
list (APPEND OPENCL_ICD_LOADER_SOURCES
4852
loader/windows/icd_windows.c
53+
loader/windows/icd_windows_dxgk.c
54+
loader/windows/icd_windows_dxgk.h
4955
loader/windows/icd_windows_envvars.c
5056
loader/windows/icd_windows_hkr.c
51-
loader/windows/icd_windows_dxgk.c
57+
loader/windows/icd_windows_hkr.h
5258
loader/windows/OpenCL.def
5359
loader/windows/OpenCL.rc)
5460
# Only add the DXSDK include directory if the environment variable is

loader/icd.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,6 @@ void khrIcdVendorAdd(const char *libraryName)
189189
}
190190
}
191191

192-
#if defined(__linux__) || defined(__APPLE__)
193-
#define PATH_SEPARATOR ':'
194-
#elif defined(_WIN32)
195-
#define PATH_SEPARATOR ';'
196-
#endif
197-
198192
// Get next file or dirname given a string list or registry key path.
199193
// Note: the input string may be modified!
200194
static char *loader_get_next_path(char *path) {

loader/icd.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef _ICD_H_
2020
#define _ICD_H_
2121

22+
#include "icd_platform.h"
23+
2224
#ifndef CL_USE_DEPRECATED_OPENCL_1_0_APIS
2325
#define CL_USE_DEPRECATED_OPENCL_1_0_APIS
2426
#endif
@@ -34,10 +36,6 @@
3436
#include <CL/cl.h>
3537
#include <CL/cl_ext.h>
3638

37-
#ifdef _WIN32
38-
#include <tchar.h>
39-
#endif
40-
4139
/*
4240
* type definitions
4341
*/

loader/icd_platform.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2016-2019 The Khronos Group Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* OpenCL is a trademark of Apple Inc. used under license by Khronos.
17+
*/
18+
19+
#ifndef _ICD_PLATFORM_H_
20+
#define _ICD_PLATFORM_H_
21+
22+
#if defined(__linux__) || defined(__APPLE__)
23+
24+
#define PATH_SEPARATOR ':'
25+
#define DIRECTORY_SYMBOL '/'
26+
#ifdef __ANDROID__
27+
#define ICD_VENDOR_PATH "/system/vendor/Khronos/OpenCL/vendors/";
28+
#else
29+
#define ICD_VENDOR_PATH "/etc/OpenCL/vendors/";
30+
#endif // ANDROID
31+
32+
#elif defined(_WIN32)
33+
34+
#define PATH_SEPARATOR ';'
35+
#define DIRECTORY_SYMBOL '\\'
36+
37+
#endif
38+
39+
#endif

loader/linux/icd_linux.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ void khrIcdOsVendorsEnumerate(void)
4040
{
4141
DIR *dir = NULL;
4242
struct dirent *dirEntry = NULL;
43-
char* vendorPath =
44-
#ifdef __ANDROID__
45-
"/system/vendor/Khronos/OpenCL/vendors/";
46-
#else
47-
"/etc/OpenCL/vendors/";
48-
#endif // ANDROID
43+
char* vendorPath = ICD_VENDOR_PATH;
4944
char* envPath = NULL;
5045

5146
khrIcdVendorsEnumerateEnv();

loader/windows/icd_windows.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ BOOL CALLBACK khrIcdOsVendorsEnumerate(PINIT_ONCE InitOnce, PVOID Parameter, PVO
6969
{
7070
char cszLibraryName[1024] = {0};
7171
DWORD dwLibraryNameSize = sizeof(cszLibraryName);
72-
DWORD dwLibraryNameType = 0;
72+
DWORD dwLibraryNameType = 0;
7373
DWORD dwValue = 0;
7474
DWORD dwValueSize = sizeof(dwValue);
7575

@@ -85,15 +85,15 @@ BOOL CALLBACK khrIcdOsVendorsEnumerate(PINIT_ONCE InitOnce, PVOID Parameter, PVO
8585
(LPBYTE)&dwValue,
8686
&dwValueSize);
8787
// if RegEnumKeyEx fails, we are done with the enumeration
88-
if (ERROR_SUCCESS != result)
88+
if (ERROR_SUCCESS != result)
8989
{
9090
KHR_ICD_TRACE("Failed to read value %d, done reading key.\n", dwIndex);
9191
break;
9292
}
9393
KHR_ICD_TRACE("Value %s found...\n", cszLibraryName);
9494

9595
// Require that the value be a DWORD and equal zero
96-
if (REG_DWORD != dwLibraryNameType)
96+
if (REG_DWORD != dwLibraryNameType)
9797
{
9898
KHR_ICD_TRACE("Value not a DWORD, skipping\n");
9999
continue;

0 commit comments

Comments
 (0)