diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cfdec5e..bf504c79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,7 +169,7 @@ else() endif() # Spdlog -if(KOMPUTE_OPT_USE_SPDLOG) +if(NOT KOMPUTE_OPT_LOG_LEVEL_DISABLED AND KOMPUTE_OPT_USE_SPDLOG) add_compile_definitions(KOMPUTE_OPT_USE_SPDLOG=1) if(KOMPUTE_OPT_USE_BUILT_IN_SPDLOG) @@ -183,17 +183,17 @@ if(KOMPUTE_OPT_USE_SPDLOG) else() find_package(spdlog REQUIRED) endif() -endif() - -# fmt -if(KOMPUTE_OPT_USE_BUILT_IN_FMT) - set(FMT_INSTALL ${KOMPUTE_OPT_INSTALL}) - FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git - GIT_TAG 11.0.0 - GIT_SHALLOW 1) # Source: https://github.com/fmtlib/fmt/releases - FetchContent_MakeAvailable(fmt) else() - find_package(fmt REQUIRED) + # fmt + if(KOMPUTE_OPT_USE_BUILT_IN_FMT) + set(FMT_INSTALL ${KOMPUTE_OPT_INSTALL}) + FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG 11.0.0 + GIT_SHALLOW 1) # Source: https://github.com/fmtlib/fmt/releases + FetchContent_MakeAvailable(fmt) + else() + find_package(fmt REQUIRED) + endif() endif() # GoogleTest diff --git a/cmake/bin2h.cmake b/cmake/bin2h.cmake index 21ad56cb..d91c6b0b 100644 --- a/cmake/bin2h.cmake +++ b/cmake/bin2h.cmake @@ -95,7 +95,7 @@ function(BIN2H) set(namespaceStart "namespace ${HEADER_NAMESPACE} {") set(namespaceEnd "} // namespace ${HEADER_NAMESPACE}") set(arrayIncludes "#pragma once\n#include \n#include ") - set(arrayDefinition "const std::array ${BIN2H_VARIABLE_NAME} = { ${arrayValues} };") + set(arrayDefinition "const std::array ${BIN2H_VARIABLE_NAME} = { { ${arrayValues} } };") set(declarations "${arrayIncludes}\n\n${namespaceStart}\n${arrayDefinition}\n${namespaceEnd}\n\n") if(BIN2H_APPEND) @@ -103,4 +103,4 @@ function(BIN2H) else() file(WRITE ${BIN2H_HEADER_FILE} "${declarations}") endif() -endfunction() \ No newline at end of file +endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 36d01505..945db5c6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,13 +67,22 @@ if(KOMPUTE_OPT_ANDROID_BUILD) target_link_libraries(kompute PUBLIC vulkanAndroid android kp_logger - kp_shader - fmt::fmt) + kp_shader) else() target_link_libraries(kompute PUBLIC Vulkan::Vulkan kp_logger - kp_shader - fmt::fmt) + kp_shader) +endif() + +# If OPT_LOG_LEVEL is disabled, kp_logger wont link against fmt::fmt, but we +# still need it for non-logging utilities. Therefore, explicitly link fmt::fmt +# to kompute target. +if(KOMPUTE_OPT_LOG_LEVEL_DISABLED) + if(KOMPUTE_OPT_USE_SPDLOG) + message(FATAL_ERROR "KOMPUTE_OPT_LOG_LEVEL_DISABLED is incompatible with KOMPUTE_OPT_USE_SPDLOG. To continue set either one option to 'OFF'.") + else() + target_link_libraries(kompute PUBLIC fmt::fmt) + endif() endif() if(KOMPUTE_OPT_BUILD_PYTHON) @@ -94,7 +103,7 @@ add_subdirectory(shaders) add_subdirectory(include) if(KOMPUTE_OPT_INSTALL) - if (KOMPUTE_OPT_USE_BUILT_IN_FMT) + if (NOT KOMPUTE_OPT_USE_SPDLOG AND KOMPUTE_OPT_USE_BUILT_IN_FMT) # We can't export fmt::fmt because it's alias target, so we unwrap the alias and install it. get_target_property(fmt_aliased_target fmt::fmt ALIASED_TARGET) install(TARGETS ${fmt_aliased_target} diff --git a/src/Manager.cpp b/src/Manager.cpp index 635e995e..b74dc59c 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -2,8 +2,13 @@ #include "kompute/Manager.hpp" #include "kompute/logger/Logger.hpp" +#if KOMPUTE_OPT_USE_SPDLOG +#include +#include +#else #include #include +#endif #include #include #include diff --git a/src/Memory.cpp b/src/Memory.cpp index 4774c088..40bc1c88 100644 --- a/src/Memory.cpp +++ b/src/Memory.cpp @@ -3,7 +3,11 @@ #include "kompute/Memory.hpp" #include "kompute/Image.hpp" #include "kompute/Tensor.hpp" +#if KOMPUTE_OPT_USE_SPDLOG +#include +#else #include +#endif namespace kp { diff --git a/src/include/kompute/Algorithm.hpp b/src/include/kompute/Algorithm.hpp index beabcf2f..c459babf 100644 --- a/src/include/kompute/Algorithm.hpp +++ b/src/include/kompute/Algorithm.hpp @@ -3,7 +3,12 @@ #include "kompute/Core.hpp" -#include "fmt/format.h" +#if KOMPUTE_OPT_USE_SPDLOG +#include +#else +#include +#endif + #include "kompute/Tensor.hpp" #include "logger/Logger.hpp"