1 cmake_minimum_required (VERSION 2.8.11)
3 project (OPENCL_ICD_LOADER)
4 include (GNUInstallDirs)
5 find_package (Threads REQUIRED)
7 # The option below allows building the ICD Loader library as a shared library
8 # (ON, default) or a static library (OFF).
10 # Khronos OpenCL Working Group strongly recommends building and using the ICD
11 # loader as a shared library due to the following benefits:
13 # 1. The shared library can be updated independent of the application. This
14 # allows releasing new fixes and features in the ICD loader without updating
17 # In rare cases when there are backward-incompatible changes to the ICD
18 # loader (due to platform requirements, for instance), using a shared
19 # library allows updating the library to make the transition seamless to
20 # installed applications.
22 # 2. On platforms that require the ICD mechanism there are multiple vendors
23 # shipping their OpenCL implementations. The vendor installers collaborate
24 # to make sure that the installed ICD shared library version is suitable for
25 # working with all vendor implementations installed on the system.
27 # If applications statically link to ICD Loader then that version of the ICD
28 # loader may not work with one or more installed vendor implementations.
30 # Using the OpenCL ICD loader as a static library is NOT recommended for
31 # end-user installations in general. However in some controlled environments it
32 # may be useful to simplify the build and distribution of the application. E.g.
33 # in test farms, or in cases where the end-user system configs are known in
34 # advance. Use it with discretion.
35 option (BUILD_SHARED_LIBS "Build shared libs" ON)
37 include(CheckFunctionExists)
38 check_function_exists(secure_getenv HAVE_SECURE_GETENV)
39 check_function_exists(__secure_getenv HAVE___SECURE_GETENV)
40 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/loader/icd_cmake_config.h.in
41 ${CMAKE_CURRENT_BINARY_DIR}/icd_cmake_config.h)
43 set (OPENCL_ICD_LOADER_SOURCES
49 loader/icd_platform.h)
52 list (APPEND OPENCL_ICD_LOADER_SOURCES
53 loader/windows/icd_windows.c
54 loader/windows/icd_windows.h
55 loader/windows/icd_windows_dxgk.c
56 loader/windows/icd_windows_dxgk.h
57 loader/windows/icd_windows_envvars.c
58 loader/windows/icd_windows_hkr.c
59 loader/windows/icd_windows_hkr.h
60 loader/windows/OpenCL.def
61 loader/windows/OpenCL.rc)
62 # Only add the DXSDK include directory if the environment variable is
63 # defined. Since the DXSDK has merged into the Windows SDK, this is
64 # only required in rare cases.
65 if (DEFINED ENV{DXSDK_DIR} AND NOT (MINGW OR MSYS OR CYGWIN))
66 include_directories ($ENV{DXSDK_DIR}/Include)
69 list (APPEND OPENCL_ICD_LOADER_SOURCES
70 loader/linux/icd_linux.c
71 loader/linux/icd_linux_envvars.c
72 loader/linux/icd_exports.map)
75 set (OPENCL_ICD_LOADER_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/inc CACHE PATH "Path to OpenCL Headers")
77 add_library (OpenCL ${OPENCL_ICD_LOADER_SOURCES})
78 set_target_properties (OpenCL PROPERTIES VERSION "1.2" SOVERSION "1")
81 target_link_libraries (OpenCL cfgmgr32.lib)
83 option (OPENCL_ICD_LOADER_REQUIRE_WDK "Build with D3DKMT support, which requires the Windows WDK." ON)
84 if (OPENCL_ICD_LOADER_REQUIRE_WDK)
85 if(DEFINED ENV{WDKContentRoot})
86 file(GLOB D3DKMT_HEADER "$ENV{WDKContentRoot}/Include/*/km/d3dkmthk.h")
88 file(GLOB D3DKMT_HEADER "$ENV{HOMEDRIVE}/Program Files */Windows Kits/10/Include/*/km/d3dkmthk.h")
92 list(GET D3DKMT_HEADER -1 LATEST_D3DKMT_HEADER)
93 get_filename_component(WDK_DIRECTORY ${LATEST_D3DKMT_HEADER} DIRECTORY)
94 get_filename_component(WDK_DIRECTORY ${WDK_DIRECTORY} DIRECTORY)
95 message(STATUS "Found the Windows WDK in: ${WDK_DIRECTORY}")
96 target_compile_definitions(OpenCL PRIVATE OPENCL_ICD_LOADER_REQUIRE_WDK)
97 target_include_directories(OpenCL PRIVATE ${WDK_DIRECTORY}/um)
98 target_include_directories(OpenCL PRIVATE ${WDK_DIRECTORY}/km)
99 target_include_directories(OpenCL PRIVATE ${WDK_DIRECTORY}/shared)
101 message(FATAL_ERROR "The Windows WDK was not found. Consider disabling OPENCL_ICD_LOADER_REQUIRE_WDK. Aborting.")
105 if(NOT USE_DYNAMIC_VCXX_RUNTIME)
106 string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
107 string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
108 string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
109 string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
110 string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
111 string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
112 string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
113 string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
117 target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
119 set_target_properties (OpenCL PROPERTIES LINK_FLAGS "-Wl,--version-script -Wl,${CMAKE_CURRENT_SOURCE_DIR}/loader/linux/icd_exports.map")
120 target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
124 include_directories (${OPENCL_ICD_LOADER_HEADERS_DIR})
125 add_definitions (-DCL_TARGET_OPENCL_VERSION=220)
127 target_include_directories (OpenCL PRIVATE ${CMAKE_CURRENT_BINARY_DIR} loader)
128 target_link_libraries (OpenCL ${CMAKE_DL_LIBS})
132 add_subdirectory (test)
135 install (TARGETS OpenCL
136 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
137 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
138 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})