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 # This option enables support for OpenCL 3.0 Provisional in the ICD loader. It
38 # is currently off by default while the specification is provisional, as it may
40 option (ENABLE_OPENCL30_PROVISIONAL "Enable 3.0 provisional entry points" OFF)
42 include(CheckFunctionExists)
43 check_function_exists(secure_getenv HAVE_SECURE_GETENV)
44 check_function_exists(__secure_getenv HAVE___SECURE_GETENV)
45 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/loader/icd_cmake_config.h.in
46 ${CMAKE_CURRENT_BINARY_DIR}/icd_cmake_config.h)
48 set (OPENCL_ICD_LOADER_SOURCES
54 loader/icd_platform.h)
57 # By default don't include OpenCL 3.0 symbol definitions (i.e. comment them
58 # out), but include them for OpenCL 3.0 builds. Once the symbols are no
59 # longer provisional then they may be included unconditionally.
60 set(ENABLE_OPENCL30_SYMBOLS ";")
61 if (ENABLE_OPENCL30_PROVISIONAL)
62 set(ENABLE_OPENCL30_SYMBOLS "")
65 ${CMAKE_CURRENT_SOURCE_DIR}/loader/windows/OpenCL.def.in
66 ${CMAKE_CURRENT_BINARY_DIR}/loader/windows/OpenCL.def)
68 list (APPEND OPENCL_ICD_LOADER_SOURCES
69 loader/windows/adapter.h
70 loader/windows/icd_windows.c
71 loader/windows/icd_windows.h
72 loader/windows/icd_windows_dxgk.c
73 loader/windows/icd_windows_dxgk.h
74 loader/windows/icd_windows_envvars.c
75 loader/windows/icd_windows_hkr.c
76 loader/windows/icd_windows_hkr.h
77 loader/windows/icd_windows_apppackage.cpp
78 loader/windows/icd_windows_apppackage.h
79 ${CMAKE_CURRENT_BINARY_DIR}/loader/windows/OpenCL.def
80 loader/windows/OpenCL.rc)
81 # Only add the DXSDK include directory if the environment variable is
82 # defined. Since the DXSDK has merged into the Windows SDK, this is
83 # only required in rare cases.
84 if (DEFINED ENV{DXSDK_DIR} AND NOT (MINGW OR MSYS OR CYGWIN))
85 include_directories ($ENV{DXSDK_DIR}/Include)
88 # By default don't include OpenCL 3.0 symbol definitions (i.e. comment them
89 # out), but include them for OpenCL 3.0 builds. Once the symbols are no
90 # longer provisional then they may be included unconditionally.
91 set(ENABLE_OPENCL30_SYMBOLS_START "/*")
92 set(ENABLE_OPENCL30_SYMBOLS_END "*/")
93 if (ENABLE_OPENCL30_PROVISIONAL)
94 set(ENABLE_OPENCL30_SYMBOLS_START "")
95 set(ENABLE_OPENCL30_SYMBOLS_END "")
98 ${CMAKE_CURRENT_SOURCE_DIR}/loader/linux/icd_exports.map.in
99 ${CMAKE_CURRENT_BINARY_DIR}/loader/linux/icd_exports.map)
101 list (APPEND OPENCL_ICD_LOADER_SOURCES
102 loader/linux/icd_linux.c
103 loader/linux/icd_linux_envvars.c
104 ${CMAKE_CURRENT_BINARY_DIR}/loader/linux/icd_exports.map)
107 set (OPENCL_ICD_LOADER_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/inc CACHE PATH "Path to OpenCL Headers")
109 add_library (OpenCL ${OPENCL_ICD_LOADER_SOURCES})
110 set_target_properties (OpenCL PROPERTIES VERSION "1.2" SOVERSION "1")
113 target_link_libraries (OpenCL cfgmgr32.lib runtimeobject.lib)
115 option (OPENCL_ICD_LOADER_DISABLE_OPENCLON12 "Disable support for OpenCLOn12. Support for OpenCLOn12 should only be disabled when building an import lib to link with, and must be enabled when building an ICD loader for distribution!" OFF)
116 if (OPENCL_ICD_LOADER_DISABLE_OPENCLON12)
117 target_compile_definitions(OpenCL PRIVATE OPENCL_ICD_LOADER_DISABLE_OPENCLON12)
120 if(NOT USE_DYNAMIC_VCXX_RUNTIME)
121 string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
122 string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
123 string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
124 string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
125 string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
126 string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
127 string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
128 string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
132 target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
134 set_target_properties (OpenCL PROPERTIES LINK_FLAGS "-Wl,--version-script -Wl,${CMAKE_CURRENT_BINARY_DIR}/loader/linux/icd_exports.map")
135 target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
139 include_directories (${OPENCL_ICD_LOADER_HEADERS_DIR})
140 if (ENABLE_OPENCL30_PROVISIONAL)
141 add_definitions (-DCL_TARGET_OPENCL_VERSION=300)
143 add_definitions (-DCL_TARGET_OPENCL_VERSION=220)
146 target_include_directories (OpenCL PRIVATE ${CMAKE_CURRENT_BINARY_DIR} loader)
147 target_link_libraries (OpenCL ${CMAKE_DL_LIBS})
151 add_subdirectory (test)
154 install (TARGETS OpenCL
155 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
156 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
157 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})