Skip to content

Commit d55a27a

Browse files
committed
refactored platform specific defines into icd_platform.h
1 parent 73eaf1d commit d55a27a

6 files changed

Lines changed: 51 additions & 20 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ 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
4953
loader/windows/icd_windows_envvars.c
5054
loader/windows/icd_windows_hkr.c
55+
loader/windows/icd_windows_hkr.h
5156
loader/windows/OpenCL.def
5257
loader/windows/OpenCL.rc)
5358
# 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
@@ -64,7 +64,7 @@ BOOL CALLBACK khrIcdOsVendorsEnumerate(PINIT_ONCE InitOnce, PVOID Parameter, PVO
6464
{
6565
char cszLibraryName[1024] = {0};
6666
DWORD dwLibraryNameSize = sizeof(cszLibraryName);
67-
DWORD dwLibraryNameType = 0;
67+
DWORD dwLibraryNameType = 0;
6868
DWORD dwValue = 0;
6969
DWORD dwValueSize = sizeof(dwValue);
7070

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

9090
// Require that the value be a DWORD and equal zero
91-
if (REG_DWORD != dwLibraryNameType)
91+
if (REG_DWORD != dwLibraryNameType)
9292
{
9393
KHR_ICD_TRACE("Value not a DWORD, skipping\n");
9494
continue;

0 commit comments

Comments
 (0)