Skip to content

Commit

Permalink
Allow folly to build on systems not having the config-fmt.cmake (face…
Browse files Browse the repository at this point in the history
…book#1328)

Summary:
As written in the documentation, {fmt} should be built alongside folly. This is not possible in my case. My usecase is to provide some kind of small distribution of shared libraries that can be installed on any systems. Hence I really need to have libfmt treated as a normal shared lib.

Moreover, libfmt can be consumed on our side as a normal library outside on cmake. We do not provide the cmake config file which are strongly dependent on the system on which libfmt is installed.

My proposal is to first look for the fmt-config.cmake as it is now but in case of cmake support is not provided by system, we fall back to a normal library lookup.
Pull Request resolved: facebook#1328

Reviewed By: simpkins

Differential Revision: D20312046

Pulled By: yfeldblum

fbshipit-source-id: 2d6b4917b37a8ed1d553600599702259db22c212
  • Loading branch information
Laurent Stacul authored and facebook-github-bot committed Mar 10, 2020
1 parent 2501c25 commit b5ef0bf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
42 changes: 42 additions & 0 deletions CMake/FindFmt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

find_path(LIBFMT_INCLUDE_DIR fmt/core.h)
mark_as_advanced(LIBFMT_INCLUDE_DIR)

find_library(LIBFMT_LIBRARY NAMES fmt fmtd)
mark_as_advanced(LIBFMT_LIBRARY)

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
LIBFMT
DEFAULT_MSG
LIBFMT_LIBRARY LIBFMT_INCLUDE_DIR)

if(LIBFMT_FOUND)
set(LIBFMT_LIBRARIES ${LIBFMT_LIBRARY})
set(LIBFMT_INCLUDE_DIRS ${LIBFMT_INCLUDE_DIR})
message(STATUS "Found {fmt}: ${LIBFMT_LIBRARY}")
add_library(fmt::fmt UNKNOWN IMPORTED)
set_target_properties(
fmt::fmt PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LIBFMT_INCLUDE_DIR}"
)
set_target_properties(
fmt::fmt PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${LIBFMT_LIBRARY}"
)
endif()

10 changes: 8 additions & 2 deletions CMake/folly-deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ if (FOLLY_LIBRARY_SANITIZE_ADDRESS)
endif()

add_library(folly_deps INTERFACE)

find_package(fmt CONFIG)
if (NOT DEFINED fmt_CONFIG)
# Fallback on a normal search on the current system
find_package(fmt MODULE REQUIRED)
endif()
target_link_libraries(folly_deps INTERFACE fmt::fmt)

list(REMOVE_DUPLICATES FOLLY_INCLUDE_DIRECTORIES)
target_include_directories(folly_deps INTERFACE ${FOLLY_INCLUDE_DIRECTORIES})
target_link_libraries(folly_deps INTERFACE
Expand All @@ -214,5 +222,3 @@ target_link_libraries(folly_deps INTERFACE
${FOLLY_ASAN_FLAGS}
)

find_package(fmt CONFIG REQUIRED)
target_link_libraries(folly_deps INTERFACE fmt::fmt)

0 comments on commit b5ef0bf

Please sign in to comment.