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

Remove Findfmt.cmake #4069

Merged
merged 8 commits into from
Jan 5, 2024
Merged
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
15 changes: 11 additions & 4 deletions src/cmake/externalpackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ macro (find_or_download_fmt)
# If an external copy wasn't found and we requested that missing
# packages be built, or we we are forcing a local copy to be built, then
# download and build it.
if ((BUILD_MISSING_FMT AND NOT FMT_FOUND) OR BUILD_FMT_FORCE)
if ((BUILD_MISSING_FMT AND NOT fmt_FOUND) OR BUILD_FMT_FORCE)
message (STATUS "Downloading local fmtlib/fmt")
set (FMT_INSTALL_DIR "${PROJECT_SOURCE_DIR}/ext/fmt")
set (FMT_GIT_REPOSITORY "https://github.com/fmtlib/fmt")
Expand All @@ -350,16 +350,23 @@ macro (find_or_download_fmt)
endif ()
set (FMT_INCLUDE_DIR "${FMT_INSTALL_DIR}/include")
set (OIIO_USING_FMT_LOCAL TRUE)
file (STRINGS "${FMT_INCLUDE_DIR}/fmt/core.h" TMP REGEX "^#define FMT_VERSION .*$")
string (REGEX MATCHALL "[0-9]+" FMT_VERSION_NUMERIC ${TMP})
math(EXPR FMT_VERSION_PATCH "${FMT_VERSION_NUMERIC} % 100")
math(EXPR FMT_VERSION_MINOR "(${FMT_VERSION_NUMERIC} / 100) % 100")
math(EXPR FMT_VERSION_MAJOR "${FMT_VERSION_NUMERIC} / 10000")
set (fmt_VERSION "${FMT_VERSION_MAJOR}.${FMT_VERSION_MINOR}.${FMT_VERSION_PATCH}")
else ()
get_target_property(FMT_INCLUDE_DIR fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES)
set (OIIO_USING_FMT_LOCAL FALSE)
checked_find_package (fmt REQUIRED
VERSION_MIN 7.0)
endif ()
checked_find_package (fmt REQUIRED
VERSION_MIN 7.0)
endmacro()

find_or_download_fmt()

if (FMT_VERSION VERSION_EQUAL 90100
if (fmt_VERSION VERSION_EQUAL 9.1.0
AND GCC_VERSION VERSION_GREATER 0.0 AND NOT GCC_VERSION VERSION_GREATER 7.2)
message (WARNING "${ColorRed}fmt 9.1 is known to not work with gcc <= 7.2${ColorReset}")
endif ()
32 changes: 0 additions & 32 deletions src/cmake/modules/Findfmt.cmake

This file was deleted.

33 changes: 22 additions & 11 deletions src/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,28 @@ install (FILES ${detail_headers}
COMPONENT developer)

if (INTERNALIZE_FMT OR OIIO_USING_FMT_LOCAL)
set (fmt_headers
${FMT_INCLUDES}/fmt/core.h
${FMT_INCLUDES}/fmt/format-inl.h
${FMT_INCLUDES}/fmt/format.h
${FMT_INCLUDES}/fmt/ostream.h
${FMT_INCLUDES}/fmt/printf.h )
if (fmt_VERSION VERSION_GREATER_EQUAL 90000)
list (APPEND fmt_headers ${FMT_INCLUDES}/fmt/std.h)
set (fmt_headers_base_names core.h format-inl.h format.h ostream.h printf.h)
if (fmt_VERSION VERSION_GREATER_EQUAL 9)
list (APPEND fmt_headers_base_names std.h)
endif ()
file (COPY ${fmt_headers}
DESTINATION ${CMAKE_BINARY_DIR}/include/OpenImageIO/detail/fmt)
set (fmt_internal_directory ${CMAKE_BINARY_DIR}/include/OpenImageIO/detail/fmt)
list (TRANSFORM fmt_headers_base_names
PREPEND ${FMT_INCLUDE_DIR}/fmt/
OUTPUT_VARIABLE fmt_headers)
list (TRANSFORM fmt_headers_base_names
PREPEND ${fmt_internal_directory}/
OUTPUT_VARIABLE fmt_headers_internal)
add_custom_command (OUTPUT ${fmt_internal_directory}
COMMAND
${CMAKE_COMMAND} -E make_directory
${fmt_internal_directory})
add_custom_command (OUTPUT ${fmt_headers_internal}
DEPENDS ${fmt_headers} ${fmt_internal_directory}
COMMAND
${CMAKE_COMMAND} -E copy
${fmt_headers}
${fmt_internal_directory})
add_custom_target (fmt_internal_target DEPENDS ${fmt_headers_internal})
else ()
set (fmt_headers
${CMAKE_BINARY_DIR}/include/OpenImageIO/detail/fmt/format.h
Expand All @@ -85,7 +96,7 @@ else ()
file (WRITE "${CMAKE_BINARY_DIR}/include/OpenImageIO/detail/fmt/${f}"
"#include <fmt/${f}>")
endforeach ()
if (fmt_VERSION VERSION_GREATER_EQUAL 90000)
if (fmt_VERSION VERSION_GREATER_EQUAL 9)
list (APPEND fmt_headers ${CMAKE_BINARY_DIR}/include/OpenImageIO/detail/fmt/std.h)
file (WRITE "${CMAKE_BINARY_DIR}/include/OpenImageIO/detail/fmt/std.h"
"#include <fmt/std.h>")
Expand Down
7 changes: 6 additions & 1 deletion src/libOpenImageIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ if (MINGW)
target_link_libraries (OpenImageIO PRIVATE ws2_32)
endif()


if (INTERNALIZE_FMT OR OIIO_USING_FMT_LOCAL)
add_dependencies(OpenImageIO_Util fmt_internal_target)
else ()
target_link_libraries (OpenImageIO_Util
PUBLIC fmt::fmt-header-only)
endif ()

file (GLOB iba_sources "imagebufalgo_*.cpp")
if (MSVC)
Expand Down
8 changes: 4 additions & 4 deletions src/libutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ target_link_libraries (OpenImageIO_Util
${CMAKE_DL_LIBS}
)

if (NOT OIIO_USING_FMT_LOCAL)
target_include_directories (OpenImageIO_Util
PUBLIC ${FMT_INCLUDES} )
if (INTERNALIZE_FMT OR OIIO_USING_FMT_LOCAL)
add_dependencies(OpenImageIO_Util fmt_internal_target)
else ()
target_link_libraries (OpenImageIO_Util
PUBLIC $<TARGET_NAME_IF_EXISTS:fmt::fmt> )
PUBLIC fmt::fmt-header-only)
endif ()

if (WIN32)
Expand Down
Loading