Removed uneeded lines in Cmakelists.txt file. (#141)
[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 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).
11 #
12 # Khronos OpenCL Working Group strongly recommends building and using the ICD
13 # loader as a shared library due to the following benefits:
14 #
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
17 #    the application.
18 #
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.
23 #
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.
28 #
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.
31 #
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)
38
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)
43
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)
49
50 set (OPENCL_ICD_LOADER_SOURCES
51     loader/icd.c
52     loader/icd.h
53     loader/icd_dispatch.c
54     loader/icd_dispatch.h
55     loader/icd_dispatch_generated.c
56     loader/icd_envvars.h
57     loader/icd_platform.h)
58
59 if (WIN32)
60     list (APPEND OPENCL_ICD_LOADER_SOURCES 
61         loader/windows/adapter.h
62         loader/windows/icd_windows.c
63         loader/windows/icd_windows.h
64         loader/windows/icd_windows_dxgk.c
65         loader/windows/icd_windows_dxgk.h
66         loader/windows/icd_windows_envvars.c
67         loader/windows/icd_windows_hkr.c
68         loader/windows/icd_windows_hkr.h
69         loader/windows/icd_windows_apppackage.cpp
70         loader/windows/icd_windows_apppackage.h
71         loader/windows/OpenCL.def
72         loader/windows/OpenCL.rc)
73     # Only add the DXSDK include directory if the environment variable is
74     # defined.  Since the DXSDK has merged into the Windows SDK, this is
75     # only required in rare cases.
76     if (DEFINED ENV{DXSDK_DIR} AND NOT (MINGW OR MSYS OR CYGWIN))
77         include_directories ($ENV{DXSDK_DIR}/Include)
78     endif ()
79 else ()
80     list (APPEND OPENCL_ICD_LOADER_SOURCES
81         loader/linux/icd_linux.c
82         loader/linux/icd_linux_envvars.c
83         loader/linux/icd_exports.map)
84 endif ()
85
86 set (OPENCL_ICD_LOADER_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/inc CACHE PATH "Path to OpenCL Headers")
87
88 add_library (OpenCL ${OPENCL_ICD_LOADER_SOURCES})
89 set_target_properties (OpenCL PROPERTIES VERSION "1.2" SOVERSION "1")
90 target_include_directories(OpenCL SYSTEM PUBLIC ${OPENCL_ICD_LOADER_HEADERS_DIR})
91 target_include_directories(OpenCL PRIVATE include)
92
93
94 if (WIN32)
95     target_link_libraries (OpenCL cfgmgr32.lib runtimeobject.lib)
96
97     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)
98     if (OPENCL_ICD_LOADER_DISABLE_OPENCLON12)
99         target_compile_definitions(OpenCL PRIVATE OPENCL_ICD_LOADER_DISABLE_OPENCLON12)
100     endif()
101
102     if(NOT USE_DYNAMIC_VCXX_RUNTIME)
103         string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
104         string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
105         string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
106         string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
107         string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
108         string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
109         string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
110         string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
111     endif()
112 else()
113     if (APPLE)
114         target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
115     else ()
116         set_target_properties (OpenCL PROPERTIES LINK_FLAGS "-Wl,--version-script -Wl,${CMAKE_CURRENT_SOURCE_DIR}/loader/linux/icd_exports.map")
117         if (OPENCL_ICD_LOADER_PIC)
118             set_target_properties(OpenCL PROPERTIES POSITION_INDEPENDENT_CODE ON)
119         endif ()
120         target_link_libraries (OpenCL ${CMAKE_THREAD_LIBS_INIT})
121     endif ()
122 endif ()
123
124 include_directories (${OPENCL_ICD_LOADER_HEADERS_DIR})
125 add_definitions (-DCL_TARGET_OPENCL_VERSION=300)
126
127 if (ENABLE_OPENCL_LAYERS)
128     add_definitions (-DCL_ENABLE_LAYERS)
129 endif ()
130
131 target_include_directories (OpenCL PRIVATE ${CMAKE_CURRENT_BINARY_DIR} loader)
132 target_link_libraries (OpenCL ${CMAKE_DL_LIBS})
133
134 option (OPENCL_ICD_LOADER_BUILD_TESTING "Enable support for OpenCL ICD Loader testing." OFF)
135
136 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR OPENCL_ICD_LOADER_BUILD_TESTING)
137     include(CTest)
138 endif()
139 if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR OPENCL_ICD_LOADER_BUILD_TESTING) AND BUILD_TESTING)
140     add_subdirectory (test)
141 endif()
142
143 install (TARGETS OpenCL
144     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
145     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
146     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})