Skip to content

Commit

Permalink
#102: add support for external fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
cwschilly committed Sep 4, 2024
1 parent bb91fb3 commit 3004ea3
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 30 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ option(VT_TV_PYTHON_BINDINGS_ENABLED "Build vt-tv with Python bindings" OFF)
option(VT_TV_OPENMP_ENABLED "Build vt-tv with openMP support" ON)
option(VT_TV_TESTS_ENABLED "Build vt-tv with unit tests" ON)
option(VT_TV_COVERAGE_ENABLED "Build vt-tv with coverage" OFF)
option(VT_TV_EXTERNAL_FMT "Build vt-tv with an external fmt library" ON)

if(VT_TV_EXTERNAL_FMT)
set(FMT_INCLUDE_NAME fmt)
else()
set(FMT_INCLUDE_NAME fmt-vt-tv)
endif()

add_definitions(-DINCLUDE_FMT_CORE=<${FMT_INCLUDE_NAME}/core.h>)
add_definitions(-DINCLUDE_FMT_FORMAT=<${FMT_INCLUDE_NAME}/format.h>)
add_definitions(-DINCLUDE_FMT_OSTREAM=<${FMT_INCLUDE_NAME}/ostream.h>)

# add -fPIC to all targets (if building with nanobind)
if(VT_TV_PYTHON_BINDINGS_ENABLED)
Expand Down
2 changes: 1 addition & 1 deletion apps/vt-tv_standalone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include <vt-tv/render/render.h>
#include <vt-tv/utility/parse_render.h>

#include <fmt-vt/format.h>
#include INCLUDE_FMT_FORMAT
#include <CLI/CLI11.hpp>

int main(int argc, char** argv) {
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/tv.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

#include <string>

#include <fmt-vt/format.h>
#include INCLUDE_FMT_FORMAT
#include "vt-tv/render/render.h"
#include "vt-tv/api/types.h"
#include "vt-tv/api/info.h"
Expand Down
19 changes: 16 additions & 3 deletions cmake/load_packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ if (NOT TARGET nlohmann_json)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/json)
endif()

# fmt always included in the build
if (NOT TARGET fmt)
# use included fmt or external one
if(VT_TV_EXTERNAL_FMT)
# user should provide 'fmt_DIR' or 'fmt_ROOT' to CMake (unless fmt is installed in system libs)
if(fmt_ROOT)
message(STATUS "VT_TV_EXTERNAL_FMT=ON. Using fmt located at ${fmt_ROOT}")
elseif(fmt_DIR)
message(STATUS "VT_TV_EXTERNAL_FMT=ON. Using fmt located at ${fmt_DIR}")
else()
message(STATUS "VT_TV_EXTERNAL_FMT=ON but neither fmt_DIR nor fmt_ROOT is provided!")
endif()
find_package(fmt 7.1.0 REQUIRED)
set(FMT_LIBRARY fmt)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/fmt)
else()
if (NOT TARGET fmt)
set(FMT_LIBRARY fmt)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/fmt)
endif()
endif()

if (NOT TARGET brotli)
Expand Down
5 changes: 5 additions & 0 deletions cmake/vtTVConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
include(${SELF_DIR}/vtTVTargets.cmake)

include(CMakeFindDependencyMacro)

if (@VT_TV_EXTERNAL_FMT@)
set (fmt_DIR @fmt_DIR@)
find_dependency(fmt REQUIRED HINTS @fmt_DIR@)
endif()
2 changes: 2 additions & 0 deletions lib/CLI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
add_library(CLI INTERFACE)
target_include_directories(CLI INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/CLI)

set_target_properties(CLI PROPERTIES OUTPUT_NAME CLI-vt-tv)

install(
DIRECTORY CLI
DESTINATION include
Expand Down
1 change: 1 addition & 0 deletions lib/brotli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ foreach(lib IN LISTS BROTLI_SHARED_LIBS)
endforeach()

foreach(lib IN LISTS BROTLI_SHARED_LIBS BROTLI_STATIC_LIBS)
set_target_properties (${lib} PROPERTIES OUTPUT_NAME ${lib}-vt-tv)
target_include_directories(
${lib}
INTERFACE
Expand Down
6 changes: 3 additions & 3 deletions lib/fmt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(FMT CXX)
function(add_headers VAR)
set(headers ${${VAR}})
foreach (header ${ARGN})
set(headers ${headers} include/fmt-vt/${header})
set(headers ${headers} include/fmt-vt-tv/${header})
endforeach()
set(${VAR} ${headers} PARENT_SCOPE)
endfunction()
Expand All @@ -14,7 +14,7 @@ set(FMT_SOURCES src/format.cc)

add_library(fmt ${FMT_SOURCES} ${FMT_HEADERS})
add_library(fmt::fmt ALIAS fmt)
set_target_properties(fmt PROPERTIES OUTPUT_NAME fmt-vt)
set_target_properties(fmt PROPERTIES OUTPUT_NAME fmt-vt-tv)

target_include_directories(fmt SYSTEM PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
Expand All @@ -26,7 +26,7 @@ set_target_properties(fmt PROPERTIES
DEBUG_POSTFIX "${FMT_DEBUG_POSTFIX}")

install(
DIRECTORY include/fmt-vt
DIRECTORY include/fmt-vt-tv
DESTINATION include
CONFIGURATIONS ${build_type_list}
FILES_MATCHING PATTERN "*"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/fmt/src/format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// For the license information refer to format.h.

#include "fmt-vt/format-inl.h"
#include "fmt-vt-tv/format-inl.h"

FMT_BEGIN_NAMESPACE
namespace detail {
Expand Down
2 changes: 2 additions & 0 deletions lib/json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ target_include_directories(
$<INSTALL_INTERFACE:include>
)

set_target_properties(${NLOHMANN_JSON_TARGET_NAME} PROPERTIES OUTPUT_NAME ${NLOHMANN_JSON_TARGET_NAME}-vt-tv)

## add debug view definition file for msvc (natvis)
if (MSVC)
set(NLOHMANN_ADD_NATVIS TRUE)
Expand Down
1 change: 1 addition & 0 deletions lib/yaml-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ if (NOT DEFINED CMAKE_DEBUG_POSTFIX)
endif()

set_target_properties(yaml-cpp PROPERTIES
OUTPUT_NAME yaml-cpp-vt-tv
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
PROJECT_LABEL "yaml-cpp ${yaml-cpp-label-postfix}"
Expand Down
35 changes: 21 additions & 14 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,15 @@ target_link_libraries(
${VT_TV_LIBRARY} PUBLIC ${JSON_LIBRARY}
)

target_link_libraries(
${VT_TV_LIBRARY} PUBLIC ${FMT_LIBRARY}
)
if(${VT_TV_EXTERNAL_FMT})
target_link_libraries(
${VT_TV_LIBRARY} PUBLIC fmt::fmt
)
else()
target_link_libraries(
${VT_TV_LIBRARY} PUBLIC ${FMT_LIBRARY}
)
endif()

target_link_libraries(
${VT_TV_LIBRARY} PUBLIC ${BROTLI_LIBRARY}
Expand Down Expand Up @@ -125,17 +131,18 @@ install(
COMPONENT runtime
)

install(TARGETS ${FMT_LIBRARY} EXPORT ${VT_TV_LIBRARY})
install(TARGETS ${JSON_LIBRARY} EXPORT ${VT_TV_LIBRARY})
install(TARGETS ${BROTLI_LIBRARY} EXPORT ${VT_TV_LIBRARY})
install(TARGETS ${YAML_LIBRARY} EXPORT ${VT_TV_LIBRARY})
set(LIBRARIES_TO_INSTALL ${JSON_LIBRARY} ${BROTLI_LIBRARY} ${YAML_LIBRARY})

if(NOT VT_TV_EXTERNAL_FMT)
list(APPEND LIBRARIES_TO_INSTALL ${FMT_LIBRARY})
endif()

foreach(LIBRARY ${LIBRARIES_TO_INSTALL})
install(TARGETS ${LIBRARY} EXPORT ${VT_TV_LIBRARY})
endforeach()

export(
TARGETS ${VT_TV_LIBRARY}
${FMT_LIBRARY}
${JSON_LIBRARY}
${BROTLI_LIBRARY}
${YAML_LIBRARY}
FILE "vtTVTargets.cmake"
NAMESPACE vt::lib::
TARGETS ${VT_TV_LIBRARY} ${LIBRARIES_TO_INSTALL}
FILE "vtTVTargets.cmake"
NAMESPACE vt::lib::
)
2 changes: 1 addition & 1 deletion src/vt-tv/api/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include "vt-tv/api/rank.h"
#include "vt-tv/api/object_info.h"

#include <fmt-vt/format.h>
#include INCLUDE_FMT_FORMAT

#include <unordered_map>
#include <cassert>
Expand Down
2 changes: 1 addition & 1 deletion src/vt-tv/api/object_communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include <utility>

#include "vt-tv/api/types.h"
#include <fmt-vt/format.h>
#include INCLUDE_FMT_FORMAT

namespace vt::tv {

Expand Down
2 changes: 1 addition & 1 deletion src/vt-tv/render/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
#include "vt-tv/api/rank.h"
#include "vt-tv/api/info.h"

#include <fmt-vt/format.h>
#include INCLUDE_FMT_FORMAT
#include <ostream>
#include <cmath>
#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion src/vt-tv/utility/decompressor.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

#include <cassert>

#include <fmt-vt/format.h>
#include INCLUDE_FMT_FORMAT

namespace vt::tv::utility {

Expand Down
4 changes: 2 additions & 2 deletions src/vt-tv/utility/json_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
#include "vt-tv/utility/qoi_serializer.h"

#include <nlohmann/json.hpp>
#include <fmt-vt/core.h>
#include <fmt-vt/format.h>
#include INCLUDE_FMT_CORE
#include INCLUDE_FMT_FORMAT

#include <fstream>

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#include <regex>
#include <tuple>

#include <fmt-vt/format.h>
#include INCLUDE_FMT_FORMAT

#include <gtest/gtest.h>
#include <gmock/gmock.h>
Expand Down

0 comments on commit 3004ea3

Please sign in to comment.