Skip to content

Commit 7d2584c

Browse files
bashbaugkepatil
authored andcommitted
Create directory tree, fix warnings, cmake improvements (#58)
* fix make test * include CTest and wrap tests with BUILD_TESTING * move loader files to their own directory * create specific directories for Windows and Linux * cmake improvements * fix path to map file for linux build * add definition for CL_TARGET_OPENCL_VERSION * fix warnings * don't use target_link_options for cmake compatibility * remove SHARED from a few cmake files
1 parent 7433f2a commit 7d2584c

22 files changed

Lines changed: 53 additions & 31 deletions

CMakeLists.txt

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
cmake_minimum_required (VERSION 2.6)
1+
cmake_minimum_required (VERSION 2.8.11)
22

33
project (OPENCL_ICD_LOADER)
4+
find_package (Threads REQUIRED)
45

56
# The option below allows building the ICD Loader library as a shared library
67
# (ON, default) or a static library (OFF).
@@ -32,27 +33,31 @@ project (OPENCL_ICD_LOADER)
3233
# advance. Use it with discretion.
3334
option (BUILD_SHARED_LIBS "Build shared libs" ON)
3435

35-
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
36-
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
37-
38-
set (OPENCL_ICD_LOADER_SOURCES icd.c icd_dispatch.c)
36+
set (OPENCL_ICD_LOADER_SOURCES
37+
loader/icd.c
38+
loader/icd_dispatch.c)
3939

4040
if (WIN32)
41-
list (APPEND OPENCL_ICD_LOADER_SOURCES icd_windows.c icd_windows_hkr.c OpenCL.def OpenCL.rc)
42-
include_directories ($ENV{DXSDK_DIR}/Include)
41+
list (APPEND OPENCL_ICD_LOADER_SOURCES
42+
loader/windows/icd_windows.c
43+
loader/windows/icd_windows_hkr.c
44+
loader/windows/OpenCL.def
45+
loader/windows/OpenCL.rc)
46+
# Only add the DXSDK include directory if the environment variable is
47+
# defined. Since the DXSDK has merged into the Windows SDK, this is
48+
# only required in rare cases.
49+
if (DEFINED ENV{DXSDK_DIR})
50+
include_directories ($ENV{DXSDK_DIR}/Include)
51+
endif ()
4352
else ()
44-
list (APPEND OPENCL_ICD_LOADER_SOURCES icd_linux.c icd_exports.map)
45-
endif ()
46-
47-
# Change this to point to a directory containing OpenCL header directory "CL"
48-
# OR copy OpenCL headers to ./inc/CL/
49-
if (NOT DEFINED OPENCL_INCLUDE_DIRS)
50-
set (OPENCL_INCLUDE_DIRS ./inc)
53+
list (APPEND OPENCL_ICD_LOADER_SOURCES
54+
loader/linux/icd_linux.c
55+
loader/linux/icd_exports.map)
5156
endif ()
5257

53-
include_directories (${OPENCL_INCLUDE_DIRS})
58+
set (OPENCL_ICD_LOADER_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/inc CACHE PATH "Path to OpenCL Headers")
5459

55-
add_library (OpenCL SHARED ${OPENCL_ICD_LOADER_SOURCES})
60+
add_library (OpenCL ${OPENCL_ICD_LOADER_SOURCES})
5661
set_target_properties (OpenCL PROPERTIES VERSION "1.2" SOVERSION "1")
5762

5863
if (WIN32)
@@ -69,13 +74,25 @@ if (WIN32)
6974
endif()
7075
else()
7176
if (APPLE)
72-
set_target_properties (OpenCL PROPERTIES LINK_FLAGS "-pthread")
77+
target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
7378
else ()
74-
set_target_properties (OpenCL PROPERTIES LINK_FLAGS "-pthread -Wl,--version-script -Wl,${PROJECT_SOURCE_DIR}/icd_exports.map")
79+
set_target_properties (OpenCL PROPERTIES LINK_FLAGS "-Wl,--version-script -Wl,${CMAKE_CURRENT_SOURCE_DIR}/loader/linux/icd_exports.map")
80+
target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
7581
endif ()
7682
endif ()
7783

84+
include_directories (${OPENCL_ICD_LOADER_HEADERS_DIR})
85+
add_definitions (-DCL_TARGET_OPENCL_VERSION=220)
86+
87+
target_include_directories (OpenCL PRIVATE loader)
7888
target_link_libraries (OpenCL ${CMAKE_DL_LIBS})
7989

80-
enable_testing()
81-
add_subdirectory (test)
90+
include (CTest)
91+
if (BUILD_TESTING)
92+
add_subdirectory (test)
93+
endif()
94+
95+
install (TARGETS OpenCL
96+
RUNTIME DESTINATION bin
97+
ARCHIVE DESTINATION lib
98+
LIBRARY DESTINATION lib)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)