Use QueryAdapter APIs as per MS directives
[platform/upstream/OpenCL-ICD-Loader.git] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.8.11)
2
3 project (OPENCL_ICD_LOADER)
4 find_package (Threads REQUIRED)
5
6 # The option below allows building the ICD Loader library as a shared library
7 # (ON, default) or a static library (OFF).
8 #
9 # Khronos OpenCL Working Group strongly recommends building and using the ICD
10 # loader as a shared library due to the following benefits:
11 #
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
14 #    the application.
15 #
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.
20 #
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.
25 #
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.
28 #
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)
35
36 set (OPENCL_ICD_LOADER_SOURCES
37     loader/icd.c
38     loader/icd_dispatch.c)
39
40 if (WIN32)
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)
53     endif ()
54 else ()
55     list (APPEND OPENCL_ICD_LOADER_SOURCES
56         loader/linux/icd_linux.c
57         loader/linux/icd_exports.map)
58 endif ()
59
60 set (OPENCL_ICD_LOADER_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/inc CACHE PATH "Path to OpenCL Headers")
61
62 add_library (OpenCL ${OPENCL_ICD_LOADER_SOURCES})
63 set_target_properties (OpenCL PROPERTIES VERSION "1.2" SOVERSION "1")
64
65 if (WIN32)
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}")
76     endif()
77 else()
78     if (APPLE)
79         target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
80     else ()
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})
83     endif ()
84 endif ()
85
86 include_directories (${OPENCL_ICD_LOADER_HEADERS_DIR})
87 add_definitions (-DCL_TARGET_OPENCL_VERSION=220)
88
89 target_include_directories (OpenCL PRIVATE loader)
90 target_link_libraries (OpenCL ${CMAKE_DL_LIBS})
91
92 include (CTest)
93 if (BUILD_TESTING)
94     add_subdirectory (test)
95 endif()
96
97 install (TARGETS OpenCL
98     RUNTIME DESTINATION bin
99     ARCHIVE DESTINATION lib
100     LIBRARY DESTINATION lib)