3 # Finds the Fmt library
5 # This will define the following variables::
7 # FMT_FOUND - system has Fmt
8 # FMT_INCLUDE_DIRS - the Fmt include directory
9 # FMT_LIBRARIES - the Fmt libraries
11 # and the following imported targets::
13 # fmt::fmt - The Fmt library
15 define_property(TARGET PROPERTY LIB_BUILD
16 BRIEF_DOCS "This target will be compiling the library"
17 FULL_DOCS "This target will be compiling the library")
21 # If target exists, no need to rerun find
22 # Allows a module that may be a dependency for multiple libraries to just be executed
23 # once to populate all required variables/targets
24 if((NOT TARGET fmt::fmt OR Fmt_FIND_REQUIRED) AND NOT TARGET fmt)
26 # Build if ENABLE_INTERNAL_FMT, or if required version in find_package call is greater
27 # than already found FMT_VERSION from a previous find_package call
28 if(ENABLE_INTERNAL_FMT OR (Fmt_FIND_REQUIRED AND FMT_VERSION VERSION_LESS Fmt_FIND_VERSION))
30 include(cmake/scripts/common/ModuleHelpers.cmake)
36 # Check for existing FMT. If version >= FMT-VERSION file version, dont build
37 find_package(FMT CONFIG QUIET)
40 if(FMT_VERSION VERSION_LESS ${Fmt_FIND_VERSION})
47 if(${FORCE_BUILD} OR FMT_VERSION VERSION_LESS ${${MODULE}_VER})
49 # Set FORCE_BUILD to enable fmt::fmt property that build will occur
53 set(EXTRA_ARGS "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
56 set(FMT_VERSION ${${MODULE}_VER})
57 # fmt debug uses postfix d for all platforms
58 set(FMT_DEBUG_POSTFIX d)
60 if(WIN32 OR WINDOWS_STORE)
61 set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-windows-pdb-symbol-gen.patch")
62 generate_patchcommand("${patches}")
65 set(CMAKE_ARGS -DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}
66 -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
74 # Populate paths for find_package_handle_standard_args
75 find_path(FMT_INCLUDE_DIR NAMES fmt/format.h)
76 find_library(FMT_LIBRARY_RELEASE NAMES fmt)
77 find_library(FMT_LIBRARY_DEBUG NAMES fmtd)
80 find_package(FMT 6.1.2 CONFIG REQUIRED QUIET)
83 pkg_check_modules(PC_FMT libfmt QUIET)
84 if(PC_FMT_VERSION AND NOT FMT_VERSION)
85 set(FMT_VERSION ${PC_FMT_VERSION})
89 find_path(FMT_INCLUDE_DIR NAMES fmt/format.h
90 PATHS ${PC_FMT_INCLUDEDIR})
92 find_library(FMT_LIBRARY_RELEASE NAMES fmt
93 PATHS ${PC_FMT_LIBDIR})
94 find_library(FMT_LIBRARY_DEBUG NAMES fmtd
95 PATHS ${PC_FMT_LIBDIR})
99 include(SelectLibraryConfigurations)
100 select_library_configurations(FMT)
102 include(FindPackageHandleStandardArgs)
103 find_package_handle_standard_args(Fmt
104 REQUIRED_VARS FMT_LIBRARY FMT_INCLUDE_DIR
105 VERSION_VAR FMT_VERSION)
108 set(FMT_LIBRARIES ${FMT_LIBRARY})
109 set(FMT_INCLUDE_DIRS ${FMT_INCLUDE_DIR})
111 # Reorder this to allow handling of FMT_FORCE_BUILD and not duplicate in property
112 if(NOT TARGET fmt::fmt)
113 set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP fmt::fmt)
116 if(NOT TARGET fmt::fmt OR FORCE_BUILD)
117 if(NOT TARGET fmt::fmt)
118 add_library(fmt::fmt UNKNOWN IMPORTED)
121 if(FMT_LIBRARY_RELEASE)
122 set_target_properties(fmt::fmt PROPERTIES
123 IMPORTED_CONFIGURATIONS RELEASE
124 IMPORTED_LOCATION "${FMT_LIBRARY_RELEASE}")
126 if(FMT_LIBRARY_DEBUG)
127 set_target_properties(fmt::fmt PROPERTIES
128 IMPORTED_CONFIGURATIONS DEBUG
129 IMPORTED_LOCATION "${FMT_LIBRARY_DEBUG}")
131 set_target_properties(fmt::fmt PROPERTIES
132 INTERFACE_INCLUDE_DIRECTORIES "${FMT_INCLUDE_DIR}")
134 # If a force build is done, let any calling packages know they may want to rebuild
136 set_target_properties(fmt::fmt PROPERTIES LIB_BUILD ON)
140 add_dependencies(fmt::fmt fmt)
143 if(FMT_FIND_REQUIRED)
144 message(FATAL_ERROR "Fmt lib not found. Maybe use -DENABLE_INTERNAL_FMT=ON")
148 mark_as_advanced(FMT_INCLUDE_DIR FMT_LIBRARY)