1 cmake_minimum_required (VERSION 2.8.11)
3 project (OPENCL_ICD_LOADER)
4 find_package (Threads REQUIRED)
6 # The option below allows building the ICD Loader library as a shared library
7 # (ON, default) or a static library (OFF).
9 # Khronos OpenCL Working Group strongly recommends building and using the ICD
10 # loader as a shared library due to the following benefits:
12 # 1. The shared library can be updated independent of the application. This
13 # allows releasing new fixes and features in the ICD loader without updating
16 # In rare cases when there are backward-incompatible changes to the ICD
17 # loader (due to platform requirements, for instance), using a shared
18 # library allows updating the library to make the transition seamless to
19 # installed applications.
21 # 2. On platforms that require the ICD mechanism there are multiple vendors
22 # shipping their OpenCL implementations. The vendor installers collaborate
23 # to make sure that the installed ICD shared library version is suitable for
24 # working with all vendor implementations installed on the system.
26 # If applications statically link to ICD Loader then that version of the ICD
27 # loader may not work with one or more installed vendor implementations.
29 # Using the OpenCL ICD loader as a static library is NOT recommended for
30 # end-user installations in general. However in some controlled environments it
31 # may be useful to simplify the build and distribution of the application. E.g.
32 # in test farms, or in cases where the end-user system configs are known in
33 # advance. Use it with discretion.
34 option (BUILD_SHARED_LIBS "Build shared libs" ON)
36 set (OPENCL_ICD_LOADER_SOURCES
38 loader/icd_dispatch.c)
41 list (APPEND OPENCL_ICD_LOADER_SOURCES
42 loader/windows/icd_windows.c
43 loader/windows/icd_windows_hkr.c
44 loader/windows/icd_windows_dxgk.c
45 loader/windows/OpenCL.def
46 loader/windows/OpenCL.rc)
47 # Only add the DXSDK include directory if the environment variable is
48 # defined. Since the DXSDK has merged into the Windows SDK, this is
49 # only required in rare cases.
50 if (DEFINED ENV{DXSDK_DIR})
51 include_directories ($ENV{DXSDK_DIR}/Include)
52 include_directories ($ENV{WDK}/km)
55 list (APPEND OPENCL_ICD_LOADER_SOURCES
56 loader/linux/icd_linux.c
57 loader/linux/icd_exports.map)
60 set (OPENCL_ICD_LOADER_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/inc CACHE PATH "Path to OpenCL Headers")
62 add_library (OpenCL ${OPENCL_ICD_LOADER_SOURCES})
63 set_target_properties (OpenCL PROPERTIES VERSION "1.2" SOVERSION "1")
66 target_link_libraries (OpenCL cfgmgr32.lib)
67 if(NOT USE_DYNAMIC_VCXX_RUNTIME)
68 string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
69 string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
70 string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
71 string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
72 string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
73 string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
74 string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
75 string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
79 target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
81 set_target_properties (OpenCL PROPERTIES LINK_FLAGS "-Wl,--version-script -Wl,${CMAKE_CURRENT_SOURCE_DIR}/loader/linux/icd_exports.map")
82 target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
86 include_directories (${OPENCL_ICD_LOADER_HEADERS_DIR})
87 add_definitions (-DCL_TARGET_OPENCL_VERSION=220)
89 target_include_directories (OpenCL PRIVATE loader)
90 target_link_libraries (OpenCL ${CMAKE_DL_LIBS})
94 add_subdirectory (test)
97 install (TARGETS OpenCL
98 RUNTIME DESTINATION bin
99 ARCHIVE DESTINATION lib
100 LIBRARY DESTINATION lib)