Skip to content

Commit 942ad02

Browse files
domin1441div0
authored andcommitted
build: Remove Findfmt.cmake (AcademySoftwareFoundation#4069)
fmt provides cmake config files since at least version 7.0.0, which is the minimum version supported. Fixed some variable names, so the provided config can be used. The previous variable names were missing, if the library was installed in a custom location, like in case of manual build or provided by conan. --------- Signed-off-by: Dominik Wójt <[email protected]> Signed-off-by: Peter Kovář <[email protected]>
1 parent ffc1345 commit 942ad02

File tree

5 files changed

+43
-52
lines changed

5 files changed

+43
-52
lines changed

src/cmake/externalpackages.cmake

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ macro (find_or_download_fmt)
338338
# If an external copy wasn't found and we requested that missing
339339
# packages be built, or we we are forcing a local copy to be built, then
340340
# download and build it.
341-
if ((BUILD_MISSING_FMT AND NOT FMT_FOUND) OR BUILD_FMT_FORCE)
341+
if ((BUILD_MISSING_FMT AND NOT fmt_FOUND) OR BUILD_FMT_FORCE)
342342
message (STATUS "Downloading local fmtlib/fmt")
343343
set (FMT_INSTALL_DIR "${PROJECT_SOURCE_DIR}/ext/fmt")
344344
set (FMT_GIT_REPOSITORY "https://github.com/fmtlib/fmt")
@@ -356,16 +356,23 @@ macro (find_or_download_fmt)
356356
endif ()
357357
set (FMT_INCLUDE_DIR "${FMT_INSTALL_DIR}/include")
358358
set (OIIO_USING_FMT_LOCAL TRUE)
359+
file (STRINGS "${FMT_INCLUDE_DIR}/fmt/core.h" TMP REGEX "^#define FMT_VERSION .*$")
360+
string (REGEX MATCHALL "[0-9]+" FMT_VERSION_NUMERIC ${TMP})
361+
math(EXPR FMT_VERSION_PATCH "${FMT_VERSION_NUMERIC} % 100")
362+
math(EXPR FMT_VERSION_MINOR "(${FMT_VERSION_NUMERIC} / 100) % 100")
363+
math(EXPR FMT_VERSION_MAJOR "${FMT_VERSION_NUMERIC} / 10000")
364+
set (fmt_VERSION "${FMT_VERSION_MAJOR}.${FMT_VERSION_MINOR}.${FMT_VERSION_PATCH}")
359365
else ()
366+
get_target_property(FMT_INCLUDE_DIR fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES)
360367
set (OIIO_USING_FMT_LOCAL FALSE)
368+
checked_find_package (fmt REQUIRED
369+
VERSION_MIN 7.0)
361370
endif ()
362-
checked_find_package (fmt REQUIRED
363-
VERSION_MIN 7.0)
364371
endmacro()
365372

366373
find_or_download_fmt()
367374

368-
if (FMT_VERSION VERSION_EQUAL 90100
375+
if (fmt_VERSION VERSION_EQUAL 9.1.0
369376
AND GCC_VERSION VERSION_GREATER 0.0 AND NOT GCC_VERSION VERSION_GREATER 7.2)
370377
message (WARNING "${ColorRed}fmt 9.1 is known to not work with gcc <= 7.2${ColorReset}")
371378
endif ()

src/cmake/modules/Findfmt.cmake

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/include/CMakeLists.txt

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,28 @@ install (FILES ${detail_headers}
6565
COMPONENT developer)
6666

6767
if (INTERNALIZE_FMT OR OIIO_USING_FMT_LOCAL)
68-
set (fmt_headers
69-
${FMT_INCLUDES}/fmt/core.h
70-
${FMT_INCLUDES}/fmt/format-inl.h
71-
${FMT_INCLUDES}/fmt/format.h
72-
${FMT_INCLUDES}/fmt/ostream.h
73-
${FMT_INCLUDES}/fmt/printf.h )
74-
if (fmt_VERSION VERSION_GREATER_EQUAL 90000)
75-
list (APPEND fmt_headers ${FMT_INCLUDES}/fmt/std.h)
68+
set (fmt_headers_base_names core.h format-inl.h format.h ostream.h printf.h)
69+
if (fmt_VERSION VERSION_GREATER_EQUAL 9)
70+
list (APPEND fmt_headers_base_names std.h)
7671
endif ()
77-
file (COPY ${fmt_headers}
78-
DESTINATION ${CMAKE_BINARY_DIR}/include/OpenImageIO/detail/fmt)
72+
set (fmt_internal_directory ${CMAKE_BINARY_DIR}/include/OpenImageIO/detail/fmt)
73+
list (TRANSFORM fmt_headers_base_names
74+
PREPEND ${FMT_INCLUDE_DIR}/fmt/
75+
OUTPUT_VARIABLE fmt_headers)
76+
list (TRANSFORM fmt_headers_base_names
77+
PREPEND ${fmt_internal_directory}/
78+
OUTPUT_VARIABLE fmt_headers_internal)
79+
add_custom_command (OUTPUT ${fmt_internal_directory}
80+
COMMAND
81+
${CMAKE_COMMAND} -E make_directory
82+
${fmt_internal_directory})
83+
add_custom_command (OUTPUT ${fmt_headers_internal}
84+
DEPENDS ${fmt_headers} ${fmt_internal_directory}
85+
COMMAND
86+
${CMAKE_COMMAND} -E copy
87+
${fmt_headers}
88+
${fmt_internal_directory})
89+
add_custom_target (fmt_internal_target DEPENDS ${fmt_headers_internal})
7990
else ()
8091
set (fmt_headers
8192
${CMAKE_BINARY_DIR}/include/OpenImageIO/detail/fmt/format.h
@@ -85,7 +96,7 @@ else ()
8596
file (WRITE "${CMAKE_BINARY_DIR}/include/OpenImageIO/detail/fmt/${f}"
8697
"#include <fmt/${f}>")
8798
endforeach ()
88-
if (fmt_VERSION VERSION_GREATER_EQUAL 90000)
99+
if (fmt_VERSION VERSION_GREATER_EQUAL 9)
89100
list (APPEND fmt_headers ${CMAKE_BINARY_DIR}/include/OpenImageIO/detail/fmt/std.h)
90101
file (WRITE "${CMAKE_BINARY_DIR}/include/OpenImageIO/detail/fmt/std.h"
91102
"#include <fmt/std.h>")

src/libOpenImageIO/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,12 @@ if (MINGW)
169169
target_link_libraries (OpenImageIO PRIVATE ws2_32)
170170
endif()
171171

172-
172+
if (INTERNALIZE_FMT OR OIIO_USING_FMT_LOCAL)
173+
add_dependencies(OpenImageIO_Util fmt_internal_target)
174+
else ()
175+
target_link_libraries (OpenImageIO_Util
176+
PUBLIC fmt::fmt-header-only)
177+
endif ()
173178

174179
file (GLOB iba_sources "imagebufalgo_*.cpp")
175180
if (MSVC)

src/libutil/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ target_link_libraries (OpenImageIO_Util
2727
${CMAKE_DL_LIBS}
2828
)
2929

30-
if (NOT OIIO_USING_FMT_LOCAL)
31-
target_include_directories (OpenImageIO_Util
32-
PUBLIC ${FMT_INCLUDES} )
30+
if (INTERNALIZE_FMT OR OIIO_USING_FMT_LOCAL)
31+
add_dependencies(OpenImageIO_Util fmt_internal_target)
32+
else ()
3333
target_link_libraries (OpenImageIO_Util
34-
PUBLIC $<TARGET_NAME_IF_EXISTS:fmt::fmt> )
34+
PUBLIC fmt::fmt-header-only)
3535
endif ()
3636

3737
if (WIN32)

0 commit comments

Comments
 (0)