@@ -88,6 +88,7 @@ message(STATUS "=======================================================")
8888
8989# Enable or disable targets
9090kompute_option (KOMPUTE_OPT_BUILD_TESTS "Enable if you want to build tests." OFF )
91+ kompute_option (KOMPUTE_OPT_ENABLE_BENCHMARK "Enable if you want to build and enable benchmark." OFF )
9192kompute_option (KOMPUTE_OPT_CODE_COVERAGE "Enable if you want code coverage." OFF )
9293kompute_option (KOMPUTE_OPT_BUILD_DOCS "Enable if you want to build documentation." OFF )
9394kompute_option (KOMPUTE_OPT_INSTALL "Enable if you want to enable installation." ${kompute_opt_install_default_val} )
@@ -123,13 +124,20 @@ include(cmake/vulkan_shader_compiler.cmake)
123124include (cmake/check_vulkan_version.cmake )
124125include (FetchContent )
125126
127+ # Set -fPIC so that ../lib/kp.cpython-310-x86_64-linux-gnu.so links correctly
128+ if (KOMPUTE_OPT_BUILD_PYTHON)
129+ set (CMAKE_POSITION_INDEPENDENT_CODE ON )
130+ endif ()
131+
126132# Vulkan Header
127133# We don't import Vulkan library if Android build as it is built dynamically
128134# Otherwise it is expected that the Vulkan SDK and dependencies are installed
129135# Has to happen AFTER using the build-in Vulkan headers to prevent multiple targets with the name Vulkan::Headers
130136if (KOMPUTE_OPT_ANDROID_BUILD)
131137 add_library (vulkanAndroid INTERFACE )
132- set (VULKAN_INCLUDE_DIR ${ANDROID_NDK} /sources/third_party/vulkan/src/include)
138+ if (NOT DEFINED VULKAN_INCLUDE_DIR)
139+ message (FATAL_ERROR "VULKAN_INCLUDE_DIR is not set. Please set it to the Vulkan SDK include directory." )
140+ endif ()
133141 target_sources (vulkanAndroid INTERFACE ${VULKAN_INCLUDE_DIR} /vulkan/vulkan.hpp )
134142 target_include_directories (vulkanAndroid INTERFACE ${VULKAN_INCLUDE_DIR} )
135143
@@ -138,7 +146,8 @@ if(KOMPUTE_OPT_ANDROID_BUILD)
138146else ()
139147 if (KOMPUTE_OPT_USE_BUILT_IN_VULKAN_HEADER)
140148 FetchContent_Declare (vulkan_header GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers.git
141- GIT_TAG ${KOMPUTE_OPT_BUILT_IN_VULKAN_HEADER_TAG} ) # Source: https://github.com/KhronosGroup/Vulkan-Headers/tags
149+ GIT_TAG ${KOMPUTE_OPT_BUILT_IN_VULKAN_HEADER_TAG}
150+ GIT_SHALLOW 1) # Source: https://github.com/KhronosGroup/Vulkan-Headers/tags
142151 FetchContent_MakeAvailable (vulkan_header)
143152
144153 if (NOT KOMPUTE_OPT_DISABLE_VULKAN_VERSION_CHECK)
@@ -162,38 +171,38 @@ else()
162171endif ()
163172
164173# Spdlog
165- if (KOMPUTE_OPT_USE_SPDLOG)
174+ if (NOT KOMPUTE_OPT_LOG_LEVEL_DISABLED AND KOMPUTE_OPT_USE_SPDLOG)
166175 add_compile_definitions (KOMPUTE_OPT_USE_SPDLOG=1 )
167176
168- if (NOT KOMPUTE_OPT_LOG_LEVEL_DISABLED)
169- if (KOMPUTE_OPT_USE_BUILT_IN_SPDLOG)
170- set (SPDLOG_INSTALL ${KOMPUTE_OPT_INSTALL} )
171- set (SPDLOG_BUILD_SHARED ${BUILD_SHARED_LIBS } )
177+ if (KOMPUTE_OPT_USE_BUILT_IN_SPDLOG)
178+ set (SPDLOG_INSTALL ${KOMPUTE_OPT_INSTALL} )
179+ set (SPDLOG_BUILD_SHARED ${BUILD_SHARED_LIBS } )
172180
173- FetchContent_Declare (spdlog GIT_REPOSITORY https://github.com/gabime/spdlog.git
174- GIT_TAG v1.10.0) # Source: https://github.com/gabime/spdlog/releases
175- FetchContent_MakeAvailable (spdlog)
176- else ( )
177- find_package ( spdlog REQUIRED )
178- endif ( )
181+ FetchContent_Declare (spdlog GIT_REPOSITORY https://github.com/gabime/spdlog.git
182+ GIT_TAG v1.10.0
183+ GIT_SHALLOW 1) # Source: https://github.com/gabime/spdlog/releases
184+ FetchContent_MakeAvailable (spdlog )
185+ else ( )
186+ find_package ( spdlog REQUIRED )
179187 endif ()
180- endif ()
181-
182- # fmt
183- if (KOMPUTE_OPT_USE_BUILT_IN_FMT)
184- set (FMT_INSTALL ${KOMPUTE_OPT_INSTALL} )
185- FetchContent_Declare (fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git
186- GIT_TAG 10.1.1) # Source: https://github.com/fmtlib/fmt/releases
187- FetchContent_MakeAvailable (fmt)
188188else ()
189- find_package (fmt REQUIRED )
189+ # fmt
190+ if (KOMPUTE_OPT_USE_BUILT_IN_FMT)
191+ set (FMT_INSTALL ${KOMPUTE_OPT_INSTALL} )
192+ FetchContent_Declare (fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git
193+ GIT_TAG 11.0.0
194+ GIT_SHALLOW 1) # Source: https://github.com/fmtlib/fmt/releases
195+ FetchContent_MakeAvailable (fmt)
196+ else ()
197+ find_package (fmt REQUIRED )
198+ endif ()
190199endif ()
191200
192201# GoogleTest
193- if (KOMPUTE_OPT_BUILD_TESTS)
202+ if (KOMPUTE_OPT_BUILD_TESTS OR KOMPUTE_OPT_ENABLE_BENCHMARK )
194203 if (KOMPUTE_OPT_USE_BUILT_IN_GOOGLE_TEST)
195204 FetchContent_Declare (googletest GIT_REPOSITORY https://github.com/google/googletest.git
196- GIT_TAG release-1.11 .0) # Source: https://github.com/google/googletest/releases
205+ GIT_TAG v1.17 .0) # Source: https://github.com/google/googletest/releases
197206
198207 # Use a shared C runtime in case we build shared
199208 set (gtest_force_shared_crt ON CACHE BOOL "" FORCE )
@@ -217,7 +226,8 @@ endif()
217226if (KOMPUTE_OPT_BUILD_PYTHON)
218227 if (KOMPUTE_OPT_USE_BUILT_IN_PYBIND11)
219228 FetchContent_Declare (pybind GIT_REPOSITORY https://github.com/pybind/pybind11.git
220- GIT_TAG v2.9.2) # Source: https://github.com/pybind/pybind11/releases
229+ GIT_TAG v3.0.0
230+ GIT_SHALLOW 1) # Source: https://github.com/pybind/pybind11/releases
221231 FetchContent_MakeAvailable (pybind)
222232 else ()
223233 find_package (pybind11 REQUIRED )
@@ -266,11 +276,18 @@ endfunction()
266276
267277add_subdirectory (src )
268278
269- if (KOMPUTE_OPT_BUILD_TESTS)
279+ if (KOMPUTE_OPT_BUILD_TESTS OR KOMPUTE_OPT_ENABLE_BENCHMARK )
270280 enable_testing ()
281+ endif ()
282+
283+ if (KOMPUTE_OPT_BUILD_TESTS)
271284 add_subdirectory (test )
272285endif ()
273286
287+ if (KOMPUTE_OPT_ENABLE_BENCHMARK)
288+ add_subdirectory (benchmark )
289+ endif ()
290+
274291if (KOMPUTE_OPT_CODE_COVERAGE)
275292 if (NOT UNIX )
276293 message (FATAL_ERROR "KOMPUTE_OPT_CODE_COVERAGE can only be enabled in unix based systems due to limitation on gcov." )
@@ -295,6 +312,13 @@ if(KOMPUTE_OPT_INSTALL)
295312 FILE komputeTargets.cmake
296313 NAMESPACE kompute::
297314 DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/kompute)
315+
316+ # Copy CMake files needed to `vulkan_compile_shader`
317+ install (FILES
318+ cmake/vulkan_shader_compiler.cmake
319+ cmake/bin_file_to_header.cmake
320+ cmake/bin2h.cmake
321+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/kompute)
298322endif ()
299323
300324
0 commit comments