44# SPDX-License-Identifier: MIT
55#
66
7- project (ocloc )
7+ project (ocloc_lib )
88
9- set (CLOC_SRCS_LIB
9+ set (CLOC_LIB_SRCS_LIB
1010 ${NEO_CORE_DIRECTORY} /device_binary_format/ar/ar.h
1111 ${NEO_CORE_DIRECTORY} /device_binary_format/ar/ar_decoder.h
1212 ${NEO_CORE_DIRECTORY} /device_binary_format/ar/ar_decoder.cpp
@@ -30,6 +30,10 @@ set(CLOC_SRCS_LIB
3030 ${NEO_SOURCE_DIR} /offline_compiler/decoder/helper.h
3131 ${NEO_SOURCE_DIR} /offline_compiler/decoder/iga_wrapper.h
3232 ${NEO_SOURCE_DIR} /offline_compiler/decoder/translate_platform_base.h
33+ ${NEO_SOURCE_DIR} /offline_compiler/ocloc_api.cpp
34+ ${NEO_SOURCE_DIR} /offline_compiler/ocloc_api.h
35+ ${NEO_SOURCE_DIR} /offline_compiler/ocloc_arg_helper.h
36+ ${NEO_SOURCE_DIR} /offline_compiler/ocloc_arg_helper.cpp
3337 ${NEO_SOURCE_DIR} /offline_compiler/ocloc_fatbinary.cpp
3438 ${NEO_SOURCE_DIR} /offline_compiler/ocloc_fatbinary.h
3539 ${NEO_SOURCE_DIR} /offline_compiler/offline_compiler_helper.cpp
@@ -47,24 +51,24 @@ set(CLOC_SRCS_LIB
4751)
4852
4953if (${IGA_HEADERS_AVAILABLE} )
50- set (CLOC_SRCS_LIB ${CLOC_SRCS_LIB }
54+ set (CLOC_LIB_SRCS_LIB ${CLOC_LIB_SRCS_LIB }
5155 ${NEO_SOURCE_DIR} /offline_compiler/decoder/iga_wrapper.cpp
5256 ${NEO_SOURCE_DIR} /offline_compiler/decoder${BRANCH_DIR_SUFFIX} /translate_platform.cpp
5357 )
5458else ()
55- set (CLOC_SRCS_LIB ${CLOC_SRCS_LIB }
59+ set (CLOC_LIB_SRCS_LIB ${CLOC_LIB_SRCS_LIB }
5660 ${NEO_SOURCE_DIR} /offline_compiler/decoder/iga_stubs.cpp
5761 )
5862endif ()
5963
6064if (WIN32 )
61- list (APPEND CLOC_SRCS_LIB
65+ list (APPEND CLOC_LIB_SRCS_LIB
6266 ${NEO_CORE_DIRECTORY} /os_interface/windows/os_library_win.cpp
6367 ${NEO_CORE_DIRECTORY} /os_interface/windows/os_library_win.h
6468 ${NEO_SOURCE_DIR} /opencl/source /dll/windows/options_windows.cpp
6569 )
6670else ()
67- list (APPEND CLOC_SRCS_LIB
71+ list (APPEND CLOC_LIB_SRCS_LIB
6872 ${NEO_CORE_DIRECTORY} /os_interface/linux/os_library_linux.cpp
6973 ${NEO_CORE_DIRECTORY} /os_interface/linux/os_library_linux.h
7074 ${NEO_SOURCE_DIR} /opencl/source /dll/linux/options_linux.cpp
@@ -73,7 +77,7 @@ endif()
7377
7478string (REPLACE ";" "," ALL_SUPPORTED_PRODUCT_FAMILIES "${ALL_SUPPORTED_PRODUCT_FAMILY} " )
7579
76- set (CLOC_LIB_FLAGS_DEFINITIONS
80+ set (CLOC_LIB_LIB_FLAGS_DEFINITIONS
7781 -DCIF_HEADERS_ONLY_BUILD
7882 -DALL_SUPPORTED_PRODUCT_FAMILIES=${ALL_SUPPORTED_PRODUCT_FAMILIES}
7983)
@@ -83,43 +87,34 @@ set(RUNTIME_GENX_CPP_FILES
8387)
8488
8589macro (macro_for_each_platform)
86- list (APPEND CLOC_SRCS_LIB ${NEO_SOURCE_DIR} /opencl/source /${GEN_TYPE_LOWER} /hw_info_${PLATFORM_IT_LOWER} .inl)
90+ list (APPEND CLOC_LIB_SRCS_LIB ${NEO_SOURCE_DIR} /opencl/source /${GEN_TYPE_LOWER} /hw_info_${PLATFORM_IT_LOWER} .inl)
8791endmacro ()
8892
8993macro (macro_for_each_gen)
9094 foreach (SRC_IT ${RUNTIME_GENX_CPP_FILES} )
9195 set (SRC_FILE ${NEO_SOURCE_DIR} /opencl/source /${GEN_TYPE_LOWER} /${SRC_IT} )
9296 if (EXISTS ${SRC_FILE} _${GEN_TYPE_LOWER} .cpp)
93- list (APPEND CLOC_SRCS_LIB ${SRC_FILE} _${GEN_TYPE_LOWER} .cpp)
97+ list (APPEND CLOC_LIB_SRCS_LIB ${SRC_FILE} _${GEN_TYPE_LOWER} .cpp)
9498 endif ()
9599 endforeach ()
96100 apply_macro_for_each_platform()
97101
98- list (APPEND CLOC_SRCS_LIB ${NEO_CORE_DIRECTORY} /${GEN_TYPE_LOWER} /enable_${GEN_TYPE_LOWER} .cpp)
102+ list (APPEND CLOC_LIB_SRCS_LIB ${NEO_CORE_DIRECTORY} /${GEN_TYPE_LOWER} /enable_${GEN_TYPE_LOWER} .cpp)
99103endmacro ()
100104
101105apply_macro_for_each_gen("SUPPORTED" )
102106
103- set (CLOC_SRCS
104- ${CLOC_SRCS_LIB}
105- ${CMAKE_CURRENT_SOURCE_DIR} /main.cpp
107+ set (CLOC_LIB_SRCS
108+ ${CLOC_LIB_SRCS_LIB}
106109 ${CMAKE_CURRENT_SOURCE_DIR} /CMakeLists.txt
107110)
108- add_executable (ocloc ${CLOC_SRCS} )
109-
110- if (UNIX )
111- install (FILES $<TARGET_FILE:ocloc>
112- DESTINATION ${CMAKE_INSTALL_BINDIR}
113- PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
114- COMPONENT ocloc)
115- set_property (GLOBAL APPEND PROPERTY NEO_COMPONENTS_LIST "ocloc" )
116- endif ()
111+ add_library (ocloc_lib SHARED ${CLOC_LIB_SRCS} )
117112
118113add_subdirectories()
119114
120- create_project_source_tree(ocloc )
115+ create_project_source_tree(ocloc_lib )
121116
122- set (CLOC_INCLUDES
117+ set (CLOC_LIB_INCLUDES
123118 ${ENGINE_NODE_DIR}
124119 ${IGC_OCL_ADAPTOR_DIR}
125120 ${CIF_BASE_DIR}
@@ -128,22 +123,75 @@ set(CLOC_INCLUDES
128123 ${NEO__IGC_INCLUDE_DIR}
129124)
130125
131- target_include_directories (ocloc BEFORE PRIVATE ${CLOC_INCLUDES } )
132- target_include_directories (ocloc BEFORE PRIVATE ${IGA_INCLUDE_DIR} )
126+ target_include_directories (ocloc_lib BEFORE PRIVATE ${CLOC_LIB_INCLUDES } )
127+ target_include_directories (ocloc_lib BEFORE PRIVATE ${IGA_INCLUDE_DIR} )
133128
134- target_compile_definitions (ocloc PUBLIC ${CLOC_LIB_FLAGS_DEFINITIONS } ${SUPPORTED_GEN_FLAGS_DEFINITONS} DEFAULT_PLATFORM=${DEFAULT_SUPPORTED_PLATFORM}
129+ target_compile_definitions (ocloc_lib PUBLIC ${CLOC_LIB_LIB_FLAGS_DEFINITIONS } ${SUPPORTED_GEN_FLAGS_DEFINITONS} DEFAULT_PLATFORM=${DEFAULT_SUPPORTED_PLATFORM}
135130 IGA_LIBRARY_NAME=${CMAKE_SHARED_LIBRARY_PREFIX}${IGA_LIBRARY_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX} )
136- target_compile_definitions (ocloc PRIVATE ${NEO__IGC_COMPILE_DEFINITIONS} )
131+ target_compile_definitions (ocloc_lib PRIVATE ${NEO__IGC_COMPILE_DEFINITIONS} )
137132
138133if (MSVC )
139- target_link_libraries (ocloc dbghelp)
134+ target_link_libraries (ocloc_lib dbghelp)
135+ endif ()
136+
137+ if (UNIX )
138+ target_link_libraries (ocloc_lib dl pthread)
139+ endif ()
140+
141+ set (CLOC_LIB_SRCS_LIB ${CLOC_LIB_SRCS_LIB} PARENT_SCOPE)
142+
143+ set (CLOC_SRCS
144+ ${NEO_CORE_DIRECTORY} /os_interface/os_library.h
145+ ${NEO_SOURCE_DIR} /offline_compiler/ocloc_wrapper.h
146+ ${NEO_SOURCE_DIR} /offline_compiler/ocloc_wrapper.cpp
147+ ${NEO_SOURCE_DIR} /offline_compiler/utilities/get_path.h
148+ )
149+ if (WIN32 )
150+ list (APPEND CLOC_SRCS
151+ ${NEO_CORE_DIRECTORY} /os_interface/windows/os_library_win.cpp
152+ ${NEO_CORE_DIRECTORY} /os_interface/windows/os_library_win.h
153+ ${NEO_SOURCE_DIR} /offline_compiler/utilities/windows/get_path.cpp
154+
155+ )
156+ else ()
157+ list (APPEND CLOC_SRCS
158+ ${NEO_CORE_DIRECTORY} /os_interface/linux/os_library_linux.cpp
159+ ${NEO_CORE_DIRECTORY} /os_interface/linux/os_library_linux.h
160+ ${NEO_SOURCE_DIR} /offline_compiler/utilities/linux/get_path.cpp
161+ )
162+ endif ()
163+
164+ add_executable (ocloc ${CLOC_SRCS} ${NEO_SOURCE_DIR} /offline_compiler/main.cpp)
165+ add_dependencies (ocloc ocloc_lib)
166+ target_link_libraries (ocloc ocloc_lib)
167+
168+ set (OCLOC_LIB_NAME "ocloc" )
169+ if (CMAKE_SIZEOF_VOID_P EQUAL 4)
170+ set (OCLOC_BITNESS_SUFFIX 32)
171+ elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
172+ set (OCLOC_BITNESS_SUFFIX 64)
140173endif ()
141174
142175if (UNIX )
143- target_link_libraries (ocloc dl pthread)
176+ install (FILES $<TARGET_FILE:ocloc_lib>
177+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /intel-opencl
178+ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
179+ install (FILES $<TARGET_FILE:ocloc>
180+ DESTINATION ${CMAKE_INSTALL_BINDIR}
181+ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
182+ COMPONENT ocloc)
183+ set_property (GLOBAL APPEND PROPERTY NEO_COMPONENTS_LIST "ocloc" )
184+ set_target_properties (ocloc_lib PROPERTIES OUTPUT_NAME ${OCLOC_LIB_NAME} )
185+ add_definitions (-DOCLOC_LIB_NAME="lib${OCLOC_LIB_NAME} .so" )
186+ else ()
187+ set_target_properties (ocloc_lib PROPERTIES OUTPUT_NAME "${OCLOC_LIB_NAME}${OCLOC_BITNESS_SUFFIX} " )
188+ add_definitions (-DOCLOC_LIB_NAME="${OCLOC_LIB_NAME}${OCLOC_BITNESS_SUFFIX} .dll" )
144189endif ()
145190
191+ create_project_source_tree(ocloc)
146192set_target_properties (ocloc PROPERTIES FOLDER "offline_compiler" )
193+ set_target_properties (ocloc_lib PROPERTIES FOLDER "offline_compiler" )
194+
147195
148196add_custom_target (copy_compiler_files DEPENDS ${NEO__IGC_TARGETS} )
149197set_target_properties (copy_compiler_files PROPERTIES FOLDER "opencl runtime" )
@@ -153,10 +201,11 @@ if(WIN32)
153201 add_custom_command (
154202 TARGET copy_compiler_files
155203 PRE_BUILD
204+ COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:ocloc_lib>
205+ COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${TARGET_tmp} > $<TARGET_FILE_DIR:ocloc_lib>
156206 COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:ocloc>
157207 COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${TARGET_tmp} > $<TARGET_FILE_DIR:ocloc>
158208 )
159209 endforeach ()
160210endif ()
161211
162- set (CLOC_SRCS_LIB ${CLOC_SRCS_LIB} PARENT_SCOPE)
0 commit comments