skip testing except for icd loader project (#117)
[platform/upstream/OpenCL-ICD-Loader.git] / CMakeLists.txt
1 cmake_minimum_required (VERSION 3.1)
2
3 project (OpenCL-ICD-Loader VERSION 1.2)
4 include (GNUInstallDirs)
5 find_package (Threads REQUIRED)
6
7 # The option below allows building the ICD Loader library as a shared library
8 # (ON, default) or a static library (OFF).
9 #
10 # Khronos OpenCL Working Group strongly recommends building and using the ICD
11 # loader as a shared library due to the following benefits:
12 #
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
15 #    the application.
16 #
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.
21 #
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.
26 #
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.
29 #
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)
36
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
39 # change.
40 option (ENABLE_OPENCL30_PROVISIONAL "Enable 3.0 provisional entry points" OFF)
41
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)
47
48 set (OPENCL_ICD_LOADER_SOURCES
49     loader/icd.c
50     loader/icd.h
51     loader/icd_dispatch.c
52     loader/icd_dispatch.h
53     loader/icd_dispatch_generated.c
54     loader/icd_envvars.h
55     loader/icd_platform.h)
56
57 if (WIN32)
58     # By default don't include OpenCL 3.0 symbol definitions (i.e. comment them
59     # out), but include them for OpenCL 3.0 builds.  Once the symbols are no
60     # longer provisional then they may be included unconditionally.
61     set(ENABLE_OPENCL30_SYMBOLS ";")
62     if (ENABLE_OPENCL30_PROVISIONAL)
63       set(ENABLE_OPENCL30_SYMBOLS "")
64     endif ()
65     configure_file(
66         ${CMAKE_CURRENT_SOURCE_DIR}/loader/windows/OpenCL.def.in
67         ${CMAKE_CURRENT_BINARY_DIR}/loader/windows/OpenCL.def)
68
69     list (APPEND OPENCL_ICD_LOADER_SOURCES 
70         loader/windows/adapter.h
71         loader/windows/icd_windows.c
72         loader/windows/icd_windows.h
73         loader/windows/icd_windows_dxgk.c
74         loader/windows/icd_windows_dxgk.h
75         loader/windows/icd_windows_envvars.c
76         loader/windows/icd_windows_hkr.c
77         loader/windows/icd_windows_hkr.h
78         loader/windows/icd_windows_apppackage.cpp
79         loader/windows/icd_windows_apppackage.h
80         ${CMAKE_CURRENT_BINARY_DIR}/loader/windows/OpenCL.def
81         loader/windows/OpenCL.rc)
82     # Only add the DXSDK include directory if the environment variable is
83     # defined.  Since the DXSDK has merged into the Windows SDK, this is
84     # only required in rare cases.
85     if (DEFINED ENV{DXSDK_DIR} AND NOT (MINGW OR MSYS OR CYGWIN))
86         include_directories ($ENV{DXSDK_DIR}/Include)
87     endif ()
88 else ()
89     # By default don't include OpenCL 3.0 symbol definitions (i.e. comment them
90     # out), but include them for OpenCL 3.0 builds.  Once the symbols are no
91     # longer provisional then they may be included unconditionally.
92     set(ENABLE_OPENCL30_SYMBOLS_START "/*")
93     set(ENABLE_OPENCL30_SYMBOLS_END "*/")
94     if (ENABLE_OPENCL30_PROVISIONAL)
95       set(ENABLE_OPENCL30_SYMBOLS_START "")
96       set(ENABLE_OPENCL30_SYMBOLS_END "")
97     endif ()
98     configure_file(
99         ${CMAKE_CURRENT_SOURCE_DIR}/loader/linux/icd_exports.map.in
100         ${CMAKE_CURRENT_BINARY_DIR}/loader/linux/icd_exports.map)
101
102     list (APPEND OPENCL_ICD_LOADER_SOURCES
103         loader/linux/icd_linux.c
104         loader/linux/icd_linux_envvars.c
105         ${CMAKE_CURRENT_BINARY_DIR}/loader/linux/icd_exports.map)
106 endif ()
107
108 set (OPENCL_ICD_LOADER_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/inc CACHE PATH "Path to OpenCL Headers")
109
110 add_library (OpenCL ${OPENCL_ICD_LOADER_SOURCES})
111 set_target_properties (OpenCL PROPERTIES VERSION "1.2" SOVERSION "1")
112 target_include_directories(OpenCL SYSTEM PUBLIC ${OPENCL_ICD_LOADER_HEADERS_DIR})
113
114 if (WIN32)
115     target_link_libraries (OpenCL cfgmgr32.lib runtimeobject.lib)
116
117     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)
118     if (OPENCL_ICD_LOADER_DISABLE_OPENCLON12)
119         target_compile_definitions(OpenCL PRIVATE OPENCL_ICD_LOADER_DISABLE_OPENCLON12)
120     endif()
121
122     if(NOT USE_DYNAMIC_VCXX_RUNTIME)
123         string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
124         string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
125         string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
126         string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
127         string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
128         string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
129         string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
130         string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
131     endif()
132 else()
133     if (APPLE)
134         target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
135     else ()
136         set_target_properties (OpenCL PROPERTIES LINK_FLAGS "-Wl,--version-script -Wl,${CMAKE_CURRENT_BINARY_DIR}/loader/linux/icd_exports.map")
137         target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
138     endif ()
139 endif ()
140
141 include_directories (${OPENCL_ICD_LOADER_HEADERS_DIR})
142 if (ENABLE_OPENCL30_PROVISIONAL)
143   add_definitions (-DCL_TARGET_OPENCL_VERSION=300)
144 else()
145   add_definitions (-DCL_TARGET_OPENCL_VERSION=220)
146 endif()
147
148 target_include_directories (OpenCL PRIVATE ${CMAKE_CURRENT_BINARY_DIR} loader)
149 target_link_libraries (OpenCL ${CMAKE_DL_LIBS})
150
151 option (OPENCL_ICD_LOADER_BUILD_TESTING "Enable support for OpenCL ICD Loader testing." OFF)
152
153 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR OPENCL_ICD_LOADER_BUILD_TESTING)
154     include(CTest)
155 endif()
156 if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR OPENCL_ICD_LOADER_BUILD_TESTING) AND BUILD_TESTING)
157     add_subdirectory (test)
158 endif()
159
160 install (TARGETS OpenCL
161     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
162     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
163     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})