Skip to content
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

#102: Add support for external fmt library #104

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ 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" OFF)
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)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
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
8 changes: 8 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function on_off() {
# > Build variables
# >> Path
VTK_DIR="${VTK_DIR:-$PARENT_DIR/vtk/build}"
fmt_DIR="${fmt_DIR:-''}"
fmt_ROOT="${fmt_ROOT:-''}"
CC="${CC:-$(which gcc || echo '')}"
CXX="${CXX:-$(which g++ || echo '')}"
GCOV="${GCOV:-gcov}"
Expand All @@ -41,6 +43,7 @@ VT_TV_CLEAN=$(on_off ${VT_TV_CLEAN:-ON})
VT_TV_PYTHON_BINDINGS_ENABLED=$(on_off ${VT_TV_PYTHON_BINDINGS_ENABLED:-OFF})
VT_TV_WERROR_ENABLED=$(on_off ${VT_TV_WERROR_ENABLED:-OFF})
VT_TV_XVFB_ENABLED=$(on_off ${VT_TV_XVFB_ENABLED:-OFF})
VT_TV_EXTERNAL_FMT=$(on_off ${VT_TV_EXTERNAL_FMT:-OFF})
# >> Run tests settings
VT_TV_RUN_TESTS=$(on_off ${VT_TV_RUN_TESTS:-OFF})
VT_TV_RUN_TESTS_FILTER=${VT_TV_RUN_TESTS_FILTER:-""}
Expand Down Expand Up @@ -154,6 +157,7 @@ echo CC=$CC
echo CXX=$CXX
echo GCOV=$GCOV
echo VTK_DIR=$VTK_DIR
echo VT_TV_EXTERNAL_FMT=$VT_TV_EXTERNAL_FMT

# Build
if [[ "${VT_TV_BUILD}" == "ON" ]]; then
Expand Down Expand Up @@ -186,6 +190,10 @@ if [[ "${VT_TV_BUILD}" == "ON" ]]; then
-DPython_EXECUTABLE="$(which python)" \
-DPython_INCLUDE_DIRS=$(python -c "import sysconfig; print(sysconfig.get_path('include'))") \
\
-DVT_TV_EXTERNAL_FMT=${VT_TV_EXTERNAL_FMT} \
-Dfmt_DIR=${fmt_DIR} \
-Dfmt_ROOT=${fmt_ROOT} \
\
"${VT_TV_DIR}"

time cmake --build . --parallel -j "${VT_TV_CMAKE_JOBS}"
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()
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.
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
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
3 changes: 2 additions & 1 deletion src/vt-tv/api/object_communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>

#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