File: FindFmt.cmake

package info (click to toggle)
ccache 4.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,192 kB
  • sloc: cpp: 47,336; asm: 28,570; sh: 8,709; ansic: 5,357; python: 685; perl: 68; makefile: 23
file content (39 lines) | stat: -rw-r--r-- 1,536 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
mark_as_advanced(FMT_INCLUDE_DIR FMT_LIBRARY)

if(DEPS STREQUAL "DOWNLOAD" OR DEP_FMT STREQUAL "BUNDLED")
  message(STATUS "Using bundled Fmt as requested")
else()
  find_path(FMT_INCLUDE_DIR NAMES fmt/base.h fmt/core.h)
  find_library(FMT_LIBRARY fmt)
  if(FMT_INCLUDE_DIR AND FMT_LIBRARY)
    if(EXISTS "${FMT_INCLUDE_DIR}/fmt/base.h")
      set(_fmt_h base.h)
    else()
      set(_fmt_h core.h)
    endif()
    file(READ "${FMT_INCLUDE_DIR}/fmt/${_fmt_h}" _fmt_h_content)
    string(REGEX MATCH "#define FMT_VERSION ([0-9]+)" _ "${_fmt_h_content}")
    if("${CMAKE_MATCH_0}" STREQUAL "")
      message(FATAL_ERROR "FMT_VERSION not found")
      return()
    endif()
    math(EXPR _fmt_major "${CMAKE_MATCH_1} / 10000")
    math(EXPR _fmt_minor "${CMAKE_MATCH_1} / 100 % 100")
    math(EXPR _fmt_patch "${CMAKE_MATCH_1} % 100")
    set(_fmt_version_string "${_fmt_major}.${_fmt_minor}.${_fmt_patch}")
    if(NOT "${CMAKE_MATCH_0}" STREQUAL "" AND "${_fmt_version_string}" VERSION_GREATER_EQUAL "${Fmt_FIND_VERSION}")
      message(STATUS "Using system Fmt (${FMT_LIBRARY})")
      add_library(dep_fmt UNKNOWN IMPORTED)
      set_target_properties(
        dep_fmt
        PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${FMT_INCLUDE_DIR}"
        IMPORTED_LOCATION "${FMT_LIBRARY}"
      )
      register_dependency(Fmt "SYSTEM (${FMT_LIBRARY})" "${_fmt_version_string}")
    endif()
  endif()
  if(NOT TARGET dep_fmt)
    message(STATUS "Using bundled Fmt since Fmt>=${Fmt_FIND_VERSION} was not found locally")
  endif()
endif()