1 cmake_minimum_required (VERSION 3.1)
3 project (OpenCL-ICD-Loader VERSION 1.2)
4 include (GNUInstallDirs)
5 find_package (Threads REQUIRED)
7 set(CMAKE_C_STANDARD 99)
8 set(CMAKE_C_STANDARD_REQUIRED ON)
9 # The option below allows building the ICD Loader library as a shared library
10 # (ON, default) or a static library (OFF).
12 # Khronos OpenCL Working Group strongly recommends building and using the ICD
13 # loader as a shared library due to the following benefits:
15 # 1. The shared library can be updated independent of the application. This
16 # allows releasing new fixes and features in the ICD loader without updating
19 # In rare cases when there are backward-incompatible changes to the ICD
20 # loader (due to platform requirements, for instance), using a shared
21 # library allows updating the library to make the transition seamless to
22 # installed applications.
24 # 2. On platforms that require the ICD mechanism there are multiple vendors
25 # shipping their OpenCL implementations. The vendor installers collaborate
26 # to make sure that the installed ICD shared library version is suitable for
27 # working with all vendor implementations installed on the system.
29 # If applications statically link to ICD Loader then that version of the ICD
30 # loader may not work with one or more installed vendor implementations.
32 # Using the OpenCL ICD loader as a static library is NOT recommended for
33 # end-user installations in general. However in some controlled environments it
34 # may be useful to simplify the build and distribution of the application. E.g.
35 # in test farms, or in cases where the end-user system configs are known in
36 # advance. Use it with discretion.
37 option (BUILD_SHARED_LIBS "Build shared libs" ON)
39 # This option enables/disables support for OpenCL layers in the ICD loader.
40 # It is currently needed default while the specification is being formalized,
41 # and to study the performance impact.
42 option (ENABLE_OPENCL_LAYERS "Enable OpenCL Layers" ON)
44 include(CheckFunctionExists)
45 check_function_exists(secure_getenv HAVE_SECURE_GETENV)
46 check_function_exists(__secure_getenv HAVE___SECURE_GETENV)
47 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/loader/icd_cmake_config.h.in
48 ${CMAKE_CURRENT_BINARY_DIR}/icd_cmake_config.h)
50 set (OPENCL_ICD_LOADER_SOURCES
55 loader/icd_dispatch_generated.c
57 loader/icd_platform.h)
59 if (ENABLE_OPENCL_LAYERS)
60 list (APPEND OPENCL_ICD_LOADER_SOURCES
61 include/cl_icd_layer.h)
65 list (APPEND OPENCL_ICD_LOADER_SOURCES
66 loader/windows/adapter.h
67 loader/windows/icd_windows.c
68 loader/windows/icd_windows.h
69 loader/windows/icd_windows_dxgk.c
70 loader/windows/icd_windows_dxgk.h
71 loader/windows/icd_windows_envvars.c
72 loader/windows/icd_windows_hkr.c
73 loader/windows/icd_windows_hkr.h
74 loader/windows/icd_windows_apppackage.cpp
75 loader/windows/icd_windows_apppackage.h
76 loader/windows/OpenCL.def
77 loader/windows/OpenCL.rc)
78 # Only add the DXSDK include directory if the environment variable is
79 # defined. Since the DXSDK has merged into the Windows SDK, this is
80 # only required in rare cases.
81 if (DEFINED ENV{DXSDK_DIR} AND NOT (MINGW OR MSYS OR CYGWIN))
82 include_directories ($ENV{DXSDK_DIR}/Include)
85 list (APPEND OPENCL_ICD_LOADER_SOURCES
86 loader/linux/icd_linux.c
87 loader/linux/icd_linux_envvars.c
88 loader/linux/icd_exports.map)
91 set (OPENCL_ICD_LOADER_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/inc CACHE PATH "Path to OpenCL Headers")
93 add_library (OpenCL ${OPENCL_ICD_LOADER_SOURCES})
94 set_target_properties (OpenCL PROPERTIES VERSION "1.2" SOVERSION "1")
95 target_include_directories(OpenCL SYSTEM PUBLIC ${OPENCL_ICD_LOADER_HEADERS_DIR})
96 target_include_directories(OpenCL PRIVATE include)
100 target_link_libraries (OpenCL cfgmgr32.lib runtimeobject.lib)
102 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)
103 if (OPENCL_ICD_LOADER_DISABLE_OPENCLON12)
104 target_compile_definitions(OpenCL PRIVATE OPENCL_ICD_LOADER_DISABLE_OPENCLON12)
107 if(NOT USE_DYNAMIC_VCXX_RUNTIME)
108 string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
109 string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
110 string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
111 string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
112 string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
113 string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
114 string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
115 string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
119 target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
121 set_target_properties (OpenCL PROPERTIES LINK_FLAGS "-Wl,--version-script -Wl,${CMAKE_CURRENT_SOURCE_DIR}/loader/linux/icd_exports.map")
122 if (OPENCL_ICD_LOADER_PIC)
123 set_target_properties(OpenCL PROPERTIES POSITION_INDEPENDENT_CODE ON)
125 target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
129 include_directories (${OPENCL_ICD_LOADER_HEADERS_DIR})
130 add_definitions (-DCL_TARGET_OPENCL_VERSION=300)
132 if (ENABLE_OPENCL_LAYERS)
133 add_definitions (-DCL_ENABLE_LAYERS)
136 target_include_directories (OpenCL PRIVATE ${CMAKE_CURRENT_BINARY_DIR} loader)
137 target_link_libraries (OpenCL ${CMAKE_DL_LIBS})
139 option (OPENCL_ICD_LOADER_BUILD_TESTING "Enable support for OpenCL ICD Loader testing." OFF)
141 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR OPENCL_ICD_LOADER_BUILD_TESTING)
144 if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR OPENCL_ICD_LOADER_BUILD_TESTING) AND BUILD_TESTING)
145 add_subdirectory (test)
148 install (TARGETS OpenCL
149 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
150 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
151 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})