Skip to content

Make spdlog and fmt mutually exclusive and support -Werror=missing-braces #419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmake/bin2h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ function(BIN2H)
set(namespaceStart "namespace ${HEADER_NAMESPACE} {")
set(namespaceEnd "} // namespace ${HEADER_NAMESPACE}")
set(arrayIncludes "#pragma once\n#include <array>\n#include <cstdint>")
set(arrayDefinition "const std::array<uint32_t, ${arraySize}> ${BIN2H_VARIABLE_NAME} = { ${arrayValues} };")
set(arrayDefinition "const std::array<uint32_t, ${arraySize}> ${BIN2H_VARIABLE_NAME} = { { ${arrayValues} } };")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work for both spdlog and fmt?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is separate from the other changes to spdlog and fmt.


set(declarations "${arrayIncludes}\n\n${namespaceStart}\n${arrayDefinition}\n${namespaceEnd}\n\n")
if(BIN2H_APPEND)
file(APPEND ${BIN2H_HEADER_FILE} "${declarations}")
else()
file(WRITE ${BIN2H_HEADER_FILE} "${declarations}")
endif()
endfunction()
endfunction()
8 changes: 3 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this because it is linked as a public dependency in kp_logger in src/logger/CMakeLists.txt.

kp_shader)
endif()

if(KOMPUTE_OPT_BUILD_PYTHON)
Expand All @@ -94,7 +92,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the need for the extra guard check?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my response below. I had to make SPDLOG and FMT mutually exclusive to avoid duplicate symbol errors.

# 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}
Expand Down
5 changes: 5 additions & 0 deletions src/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

#include "kompute/Manager.hpp"
#include "kompute/logger/Logger.hpp"
#if KOMPUTE_OPT_USE_SPDLOG
#include <spdlog/fmt/fmt.h>
#include <spdlog/fmt/ranges.h>
#else
#include <fmt/core.h>
#include <fmt/ranges.h>
#endif
#include <iterator>
#include <set>
#include <sstream>
Expand Down
4 changes: 4 additions & 0 deletions src/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#include "kompute/Memory.hpp"
#include "kompute/Image.hpp"
#include "kompute/Tensor.hpp"
#if KOMPUTE_OPT_USE_SPDLOG
#include <spdlog/fmt/fmt.h>
#else
#include <fmt/core.h>
#endif

namespace kp {

Expand Down
7 changes: 6 additions & 1 deletion src/include/kompute/Algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

#include "kompute/Core.hpp"

#include "fmt/format.h"
#if KOMPUTE_OPT_USE_SPDLOG
#include <spdlog/fmt/fmt.h>
#else
#include <fmt/format.h>
#endif

#include "kompute/Tensor.hpp"
#include "logger/Logger.hpp"

Expand Down
Loading