Skip to content

Commit 342af81

Browse files
authored
Make spdlog and fmt mutually exclusive and support -Werror=missing-braces (KomputeProject#419)
* Update bin2h.cmake to avoid -Werror=missing-braces Signed-off-by: zachferguson <[email protected]> Signed-off-by: Zachary Ferguson <[email protected]> * Use the fmt inside spdlog if using spdlog Signed-off-by: zachferguson <[email protected]> Signed-off-by: Zachary Ferguson <[email protected]> * Fix python build by linking fmt when KOMPUTE_OPT_LOG_LEVEL_DISABLED Signed-off-by: Zachary Ferguson <[email protected]> --------- Signed-off-by: zachferguson <[email protected]> Signed-off-by: Zachary Ferguson <[email protected]>
1 parent 12cbbc6 commit 342af81

File tree

6 files changed

+42
-19
lines changed

6 files changed

+42
-19
lines changed

CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ else()
171171
endif()
172172

173173
# Spdlog
174-
if(KOMPUTE_OPT_USE_SPDLOG)
174+
if(NOT KOMPUTE_OPT_LOG_LEVEL_DISABLED AND KOMPUTE_OPT_USE_SPDLOG)
175175
add_compile_definitions(KOMPUTE_OPT_USE_SPDLOG=1)
176176

177177
if(KOMPUTE_OPT_USE_BUILT_IN_SPDLOG)
@@ -185,17 +185,17 @@ if(KOMPUTE_OPT_USE_SPDLOG)
185185
else()
186186
find_package(spdlog REQUIRED)
187187
endif()
188-
endif()
189-
190-
# fmt
191-
if(KOMPUTE_OPT_USE_BUILT_IN_FMT)
192-
set(FMT_INSTALL ${KOMPUTE_OPT_INSTALL})
193-
FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git
194-
GIT_TAG 11.0.0
195-
GIT_SHALLOW 1) # Source: https://github.com/fmtlib/fmt/releases
196-
FetchContent_MakeAvailable(fmt)
197188
else()
198-
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()
199199
endif()
200200

201201
# GoogleTest

cmake/bin2h.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ function(BIN2H)
9595
set(namespaceStart "namespace ${HEADER_NAMESPACE} {")
9696
set(namespaceEnd "} // namespace ${HEADER_NAMESPACE}")
9797
set(arrayIncludes "#pragma once\n#include <array>\n#include <cstdint>")
98-
set(arrayDefinition "const std::array<uint32_t, ${arraySize}> ${BIN2H_VARIABLE_NAME} = { ${arrayValues} };")
98+
set(arrayDefinition "const std::array<uint32_t, ${arraySize}> ${BIN2H_VARIABLE_NAME} = { { ${arrayValues} } };")
9999

100100
set(declarations "${arrayIncludes}\n\n${namespaceStart}\n${arrayDefinition}\n${namespaceEnd}\n\n")
101101
if(BIN2H_APPEND)
102102
file(APPEND ${BIN2H_HEADER_FILE} "${declarations}")
103103
else()
104104
file(WRITE ${BIN2H_HEADER_FILE} "${declarations}")
105105
endif()
106-
endfunction()
106+
endfunction()

src/CMakeLists.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,22 @@ if(KOMPUTE_OPT_ANDROID_BUILD)
6767
target_link_libraries(kompute PUBLIC vulkanAndroid
6868
android
6969
kp_logger
70-
kp_shader
71-
fmt::fmt)
70+
kp_shader)
7271
else()
7372
target_link_libraries(kompute PUBLIC Vulkan::Vulkan
7473
kp_logger
75-
kp_shader
76-
fmt::fmt)
74+
kp_shader)
75+
endif()
76+
77+
# If OPT_LOG_LEVEL is disabled, kp_logger wont link against fmt::fmt, but we
78+
# still need it for non-logging utilities. Therefore, explicitly link fmt::fmt
79+
# to kompute target.
80+
if(KOMPUTE_OPT_LOG_LEVEL_DISABLED)
81+
if(KOMPUTE_OPT_USE_SPDLOG)
82+
message(FATAL_ERROR "KOMPUTE_OPT_LOG_LEVEL_DISABLED is incompatible with KOMPUTE_OPT_USE_SPDLOG. To continue set either one option to 'OFF'.")
83+
else()
84+
target_link_libraries(kompute PUBLIC fmt::fmt)
85+
endif()
7786
endif()
7887

7988
if(KOMPUTE_OPT_BUILD_PYTHON)
@@ -94,7 +103,7 @@ add_subdirectory(shaders)
94103
add_subdirectory(include)
95104

96105
if(KOMPUTE_OPT_INSTALL)
97-
if (KOMPUTE_OPT_USE_BUILT_IN_FMT)
106+
if (NOT KOMPUTE_OPT_USE_SPDLOG AND KOMPUTE_OPT_USE_BUILT_IN_FMT)
98107
# We can't export fmt::fmt because it's alias target, so we unwrap the alias and install it.
99108
get_target_property(fmt_aliased_target fmt::fmt ALIASED_TARGET)
100109
install(TARGETS ${fmt_aliased_target}

src/Manager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
#include "kompute/Manager.hpp"
44
#include "kompute/logger/Logger.hpp"
5+
#if KOMPUTE_OPT_USE_SPDLOG
6+
#include <spdlog/fmt/fmt.h>
7+
#include <spdlog/fmt/ranges.h>
8+
#else
59
#include <fmt/core.h>
610
#include <fmt/ranges.h>
11+
#endif
712
#include <iterator>
813
#include <set>
914
#include <sstream>

src/Memory.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
#include "kompute/Memory.hpp"
44
#include "kompute/Image.hpp"
55
#include "kompute/Tensor.hpp"
6+
#if KOMPUTE_OPT_USE_SPDLOG
7+
#include <spdlog/fmt/fmt.h>
8+
#else
69
#include <fmt/core.h>
10+
#endif
711

812
namespace kp {
913

src/include/kompute/Algorithm.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
#include "kompute/Core.hpp"
55

6-
#include "fmt/format.h"
6+
#if KOMPUTE_OPT_USE_SPDLOG
7+
#include <spdlog/fmt/fmt.h>
8+
#else
9+
#include <fmt/format.h>
10+
#endif
11+
712
#include "kompute/Tensor.hpp"
813
#include "logger/Logger.hpp"
914

0 commit comments

Comments
 (0)